Check out this site: Forecast
That's some impressive web app for getting local, regional and global forecasts
Thursday, March 28, 2013
Thursday, January 10, 2013
Code Smells & Solutions in Rails Applications
I came across an interesting presentation by Brandon Keepers at GitHub that he gave in June of 2012. I didn't make it through the 35 minute video of the presentation, but there is also the slide deck. Scanning the rest of the presentation in the slide deck, I was delighted to see Brandon promoting appropriate separation of concerns with respect to the use of Rails and its components.
It's time to move away from Fat Models and get Domainy. Use ActiveRecord to be the encapsulator of things specifically related to working with the database. Build your domain model on top of that.
Gary Bernhardt of Destroy All Software fame promotes the same.
I liked Brandon's identification that test cases can illustrate where the code smells when the tests are too complex. Spot on.
It's time to move away from Fat Models and get Domainy. Use ActiveRecord to be the encapsulator of things specifically related to working with the database. Build your domain model on top of that.
Gary Bernhardt of Destroy All Software fame promotes the same.
I liked Brandon's identification that test cases can illustrate where the code smells when the tests are too complex. Spot on.
Friday, December 21, 2012
Dev Tools for Quick Mockups
Just so that I don't forget about it now:
- JSBin makes it easy to mockup some real HTML with some real JS and see the real result, then iterate through it with versioning.
- BL.OCKS.org will take your Github gist and render it for viewing. Here's the blurb: "This is a simple viewer for code examples hosted on GitHub Gist. Code up an example using Gist, and then point people here to view the example and the source code, live!"
Friday, December 07, 2012
Color & Git Branch in your BASH Prompt
This one will be easy. Place this into your .bash_profile:
This defines a function called "parse_git_branch", which reads the symbolic reference for the HEAD pointer (sending errors to /dev/null) and assigning the value to the "ref" variable. Then, it echos the value of the variable, but filters out "refs/heads/" from the answer (See example 10.10 here at tldp.org)
After setting the value for some colors, it sets the first level prompt to print the current working directory in green and the git branch in yellow.
Voila
Test your webpages from outside of your domain
I love tools like Firebug and Chrome's Developer Tools. But a tool originally developed at AOL and the open source has captured my attention: Web Page Test does a great job of displaying all the nitty gritty details that are otherwise hard to get, such as DNS lookup time. There are even developer tools with a RESTful API.
Highly Recommend
Highly Recommend
Thursday, December 06, 2012
Scrum Planning Poker for the Distributed Team
I've taken on the role of Scrum Master for our team and wanted to get everyone participating in issue scoping with independent votes. So I searched for a Planning Poker scoping tool for distributed teams. The one I like the best is Pointing Poker.
It's free, requires no login, is very easy to use and effective.
One person logs in and starts a new session. That person then distributes the URL with the session identifier to the rest of the team (we use Skype). Everyone else then visits the site and enters their name. No user account, no registration, no nothing. From there it is easy to clear the last vote, have everyone vote and see the results. Want to change your vote? Simply click on a different value.
Kudos for an effective tool. Hey Matt Ruwe, if you were to put a donate button so I could donate a few bucks, I would.
It's free, requires no login, is very easy to use and effective.
One person logs in and starts a new session. That person then distributes the URL with the session identifier to the rest of the team (we use Skype). Everyone else then visits the site and enters their name. No user account, no registration, no nothing. From there it is easy to clear the last vote, have everyone vote and see the results. Want to change your vote? Simply click on a different value.
Kudos for an effective tool. Hey Matt Ruwe, if you were to put a donate button so I could donate a few bucks, I would.
Monday, November 19, 2012
Introducing the Mamo
A while back, I was considering the infinite. I had some time on my hands, what can I say?
Infinity, as the saw goes, is really, really big. You think you know big? You don't know anything. Aunt Bertha's behind? Insignificant. The Earth? Pish. C'mon: the Milky Way galaxy is the smallest starting point with some 200 to 400 billion stars.
OK, now we're starting with something: a Billion. A 1 with 9 zeros: 1,000,000,000. We have 200 to 400 of these Billions when we count the stars in the Milky Way. And there may be some 100 Billion galaxies. That's 100,000,000,000 galaxies times 300,000,000,000 stars per galaxy! That's a lot of stars, but we can think of even bigger things!
OK, let's get sexy. From 2010, in the Huffington Post, Scientists believe there may be up to 300 Sextillion stars -- that's 1 with 21 zeros: 1,000,000,000,000,000,000,000. You know, typing that is quickly going to get boring. We're switching to scientific notation: 1021. But that's stars, not galaxies, so let's keep our units straight. If each galaxy had about 300 billion stars, then it would be 1021 divided by 109, so we subtract exponents and get 1012. Back to a Trillion. Boring.
Wikipedia talks about large numbers, and we get up to funky numbers like Vigintillion (1063) and Centillion (10303). Of course, there's also the Googol (10100) and the Googolplex (10googol).
But this really doesn't do it when one considers the infinite. Let's go back to the Billion; we can grasp that. Try this on for size, you may have heard it: if you spent $0.25 every 15 minutes playing video games, then you, and everyone else in your 100 person company could play non-stop for nearly 7,000 years. That's freaking big. Or, you could buy 1/3 of a nuclear powered submarine.
Or, you could build 3 schools. And hire 200 teachers and administrators. And build a police department and buy cruisers and all the nifty equipment. And a fire department with trucks. And hire 60 police officers and 30 fire fighters. And build a hospital. And staff it with 40 doctors and 80 nurses. And hire 50 engineers. And build houses for all of them. And pay their salaries. For over 14 years..
Or buy one B2 Stealth Bomber.
OK, that's helped me tremendously with one Billion. One. Just one.
We think there are a Trillion (that's 1,000 Billion) galaxies. Each galaxy with 200 - 400 Billion stars. And that doesn't even do the infinite justice.
No, we need another number. That Googol doesn't help us either. Psh, it has only 100 zeros in the exponent. No we need something really massive.
So, I invented a new number: The Mamo. The Mamo is 101,000,000,000. Yep, 10 raised to the Billion. Now that's a number. Now we can think about a Mamo sub-atomic particles in the conceivable universe and really expand our concept of wicked big.
But for the infinite, we need even more: We need the SuperMamo. That is MamoMamo. Yes, a Mamo raised to the Mamo.
Phew. I need to rest.
Infinity, as the saw goes, is really, really big. You think you know big? You don't know anything. Aunt Bertha's behind? Insignificant. The Earth? Pish. C'mon: the Milky Way galaxy is the smallest starting point with some 200 to 400 billion stars.
OK, now we're starting with something: a Billion. A 1 with 9 zeros: 1,000,000,000. We have 200 to 400 of these Billions when we count the stars in the Milky Way. And there may be some 100 Billion galaxies. That's 100,000,000,000 galaxies times 300,000,000,000 stars per galaxy! That's a lot of stars, but we can think of even bigger things!
OK, let's get sexy. From 2010, in the Huffington Post, Scientists believe there may be up to 300 Sextillion stars -- that's 1 with 21 zeros: 1,000,000,000,000,000,000,000. You know, typing that is quickly going to get boring. We're switching to scientific notation: 1021. But that's stars, not galaxies, so let's keep our units straight. If each galaxy had about 300 billion stars, then it would be 1021 divided by 109, so we subtract exponents and get 1012. Back to a Trillion. Boring.
Wikipedia talks about large numbers, and we get up to funky numbers like Vigintillion (1063) and Centillion (10303). Of course, there's also the Googol (10100) and the Googolplex (10googol).
But this really doesn't do it when one considers the infinite. Let's go back to the Billion; we can grasp that. Try this on for size, you may have heard it: if you spent $0.25 every 15 minutes playing video games, then you, and everyone else in your 100 person company could play non-stop for nearly 7,000 years. That's freaking big. Or, you could buy 1/3 of a nuclear powered submarine.
Or, you could build 3 schools. And hire 200 teachers and administrators. And build a police department and buy cruisers and all the nifty equipment. And a fire department with trucks. And hire 60 police officers and 30 fire fighters. And build a hospital. And staff it with 40 doctors and 80 nurses. And hire 50 engineers. And build houses for all of them. And pay their salaries. For over 14 years..
Or buy one B2 Stealth Bomber.
OK, that's helped me tremendously with one Billion. One. Just one.
We think there are a Trillion (that's 1,000 Billion) galaxies. Each galaxy with 200 - 400 Billion stars. And that doesn't even do the infinite justice.
No, we need another number. That Googol doesn't help us either. Psh, it has only 100 zeros in the exponent. No we need something really massive.
So, I invented a new number: The Mamo. The Mamo is 101,000,000,000. Yep, 10 raised to the Billion. Now that's a number. Now we can think about a Mamo sub-atomic particles in the conceivable universe and really expand our concept of wicked big.
But for the infinite, we need even more: We need the SuperMamo. That is MamoMamo. Yes, a Mamo raised to the Mamo.
Phew. I need to rest.
Tuesday, October 16, 2012
ActiveRecord, JSON & hashes
While testing a new script for some data loading, I found myself on our testing platform and stymied because the foundation things I needed were not part of that database. I needed certain license records and Forge records. While the staging system has a more or less complete copy of our production system, the testing system has a much more constrained data set. This is a one of my bugaboos: making sure there is sufficient data for testing. And, once again, I questioned the decision to NOT use TDD for the script development. That way, I could have mocked all the scenarios I needed and probably would have completed the script in less time to a greater level of quality. But I digress.
I was in the console of the testing environment (not the "test" environment) and needed to have a particular license as part of the testing dataset. I wanted to use the tools I had, not have to write a migration, start up PSQL, or any of those pathways. I wanted to be lazy and get the record from the staging environment and copy it into the testing environment.
So, I found the license in the staging environment and converted it to json with license.to_json. That was wicked easy. The next step was to parse the JSON, which will convert it to a hash, then extract the license value. That looks like this:
license_hash = JSON.parse(json)['license']
The result was a pretty little hash with all the necessary data that could be copied from one console to the next and then pasted into place. In no time at all, I had the needed record in the testing database.
I was in the console of the testing environment (not the "test" environment) and needed to have a particular license as part of the testing dataset. I wanted to use the tools I had, not have to write a migration, start up PSQL, or any of those pathways. I wanted to be lazy and get the record from the staging environment and copy it into the testing environment.
So, I found the license in the staging environment and converted it to json with license.to_json. That was wicked easy. The next step was to parse the JSON, which will convert it to a hash, then extract the license value. That looks like this:
license_hash = JSON.parse(json)['license']
The result was a pretty little hash with all the necessary data that could be copied from one console to the next and then pasted into place. In no time at all, I had the needed record in the testing database.
Wednesday, October 10, 2012
Nil Object in Reality Land
Recently I was reviewing some code with a colleague; we were looking at some new widget code. We switched to the branch and started our server. Looking at the first randomly selected project, everything looked good, so we copied the widget code and took a look at what the user would actually see.
Problemo. The user was going to see a 500 message through the tiny view port of the widget.
The problem was that there was code looking for the filename of the project logo in order to display the logo. However, this particular project did not have a logo. So, project.logo (which was nil) caused a problem when the code then sought to access project.logo.thumbnail. Boom. No method "thumbnail" on NilObject. heh.
Looking at the code, the obvious pattern would have been to do something like:
if project.logo && project.logo.thumbnail
But this is cowardly, timid code and I have been influenced by Avdi Grimm's thoughts on Confident Code. Once it was pointed out, it was clear that I was never very enamored with all those protective "if this and if that and if the other thing, then and only then do something". I really like the idea of writing code that knows how to handle itself.
My colleague and I decided to address the issue by using a NullObject pattern. Examining the code, we saw that we could have a NullLogo object that responded to a "public_filename" method and if the project had no logo, it would return the NullLogo object instead of a Logo object. The NullLogo#public_filename method returns "no_logo.png" and so we are always guaranteed to show something reasonable.
We eliminated quite a number of lines of timid code and were very pleased.
So we pushed our code onto the staging server and looked. Yes, the empty logo behavior was correct. So I deleted a logo from an existing project, something that can easily be done by our users. Boom.
Digging in we saw that the Logo derived from Attachment and Attachment did magic things. Including using a gem that managed file sizing and thumbnail generation and pushing logos to S3. A former colleague implemented clever logic to put files in the local filesystem during development and on S3 during production; all quite reasonable.
But, deleting the logo did not trigger the cascade of cleanup; the author of the gem had no support for cleaning up attachments and all the thumbnails it had created. Now the database had data about attachments that did not exist and S3 had files of logos that no one would ever see or even want again.
It turns out that this is the behavior that has been present in the system for ages. Our use of TDD and careful testing revealed this problem that no one has notice although this functionality has been in the product for a long time.
To wrap up the story; we implemented functionality to clean up the database and left it as a future exercise to clean up the logos from S3. After all, these are a tiny fraction of the storage we use there, so let's not get side tracked by the bicycle shed when we have a nuclear reactor to build.
Problemo. The user was going to see a 500 message through the tiny view port of the widget.
The problem was that there was code looking for the filename of the project logo in order to display the logo. However, this particular project did not have a logo. So, project.logo (which was nil) caused a problem when the code then sought to access project.logo.thumbnail. Boom. No method "thumbnail" on NilObject. heh.
Looking at the code, the obvious pattern would have been to do something like:
if project.logo && project.logo.thumbnail
My colleague and I decided to address the issue by using a NullObject pattern. Examining the code, we saw that we could have a NullLogo object that responded to a "public_filename" method and if the project had no logo, it would return the NullLogo object instead of a Logo object. The NullLogo#public_filename method returns "no_logo.png" and so we are always guaranteed to show something reasonable.
We eliminated quite a number of lines of timid code and were very pleased.
So we pushed our code onto the staging server and looked. Yes, the empty logo behavior was correct. So I deleted a logo from an existing project, something that can easily be done by our users. Boom.
Digging in we saw that the Logo derived from Attachment and Attachment did magic things. Including using a gem that managed file sizing and thumbnail generation and pushing logos to S3. A former colleague implemented clever logic to put files in the local filesystem during development and on S3 during production; all quite reasonable.
But, deleting the logo did not trigger the cascade of cleanup; the author of the gem had no support for cleaning up attachments and all the thumbnails it had created. Now the database had data about attachments that did not exist and S3 had files of logos that no one would ever see or even want again.
It turns out that this is the behavior that has been present in the system for ages. Our use of TDD and careful testing revealed this problem that no one has notice although this functionality has been in the product for a long time.
To wrap up the story; we implemented functionality to clean up the database and left it as a future exercise to clean up the logos from S3. After all, these are a tiny fraction of the storage we use there, so let's not get side tracked by the bicycle shed when we have a nuclear reactor to build.
Tuesday, October 02, 2012
SSH to VirtualBox Guest in Mountain Lion
My development system is OS/x 10.8, Mountain Lion. I run Ubuntu 10.04 LTS Server in a VirtualBox VM and all the development work is done in that server (easiest for the entire team to ensure we all have the same dev environment).
I switched over from a desktop system (Mac Pro) to a laptop (MacBook Pro), copied over my .vbi file with my Ubuntu server and something was different. I had been ssh'ing into the VirtualBox guest without any issues. Set up my ssh keys and an alias. Sweet. But, with the laptop, I couldn't get there from here. The host name couldn't be resolved.
Yes, VB Network mode was Bridged Adapter. At first, the issue was waiting for the DNS servers to refresh the IP address of the guest OS, which was now on a different subnet because I was connecting over Wi-Fi instead of Ethernet.
But, after closing the laptop for the night, the issue was back and I knew it wasn't from switching subnets. A clue was that I couldn't also connect to one of our development utility servers. Checked wireless -- default configuration had wireless connecting to the guest Wi-Fi and not the corporate Wi-Fi. Fixed that, but no love. Flushed the DNS cache and voila; ssh to the guest machine.
Here's the key: on Mountain Lion use:
sudo killall -HUP mDNSResponder
dscacheutils is still present, but doesn't work in all situations. Use the mDNSReponder.
I switched over from a desktop system (Mac Pro) to a laptop (MacBook Pro), copied over my .vbi file with my Ubuntu server and something was different. I had been ssh'ing into the VirtualBox guest without any issues. Set up my ssh keys and an alias. Sweet. But, with the laptop, I couldn't get there from here. The host name couldn't be resolved.
Yes, VB Network mode was Bridged Adapter. At first, the issue was waiting for the DNS servers to refresh the IP address of the guest OS, which was now on a different subnet because I was connecting over Wi-Fi instead of Ethernet.
But, after closing the laptop for the night, the issue was back and I knew it wasn't from switching subnets. A clue was that I couldn't also connect to one of our development utility servers. Checked wireless -- default configuration had wireless connecting to the guest Wi-Fi and not the corporate Wi-Fi. Fixed that, but no love. Flushed the DNS cache and voila; ssh to the guest machine.
Here's the key: on Mountain Lion use:
sudo killall -HUP mDNSResponder
dscacheutils is still present, but doesn't work in all situations. Use the mDNSReponder.
Subscribe to:
Posts (Atom)