Bonus Picks!

Every once in a while we’d win.  Now let’s not get carried away, it would only be a few dollars every once in while.  Occasionally, as much as $10.  We had decided that any “modest” winnings would be re-invested as extra tickets for the next draw.

So I needed to provide a mechanism for adding “bonus” picks.  I’d already made allowance for this in my model, by providing a boolean “perm” column, which indicated whether or not a row of picks was part of the permanent collection.  I already had the mechanism for input from the view, using the rails <% form tag %>, all I needed to do was extend that to provide a multi-line input field. Easily done.  And to add the code in the controller to iterate through each line and add the temporary picks to the database.  Again, easy to do with text parsing and splitting on a carriage return line-feed, before reloading the page, all from within the controller.  One small thing to look out for was that the “params” were passed as an array, therefore I need to access the zero index element in the action.

Not a huge increase in functionality, but satisfyingly easy to implement and deploy.  The complement to these new functionality, was add another button to erase any temporary picks from the database, which was literally a single call to destroy_all for any non “perm” rows.

Great!  Now how about the annoying task of having to enter the twice-weekly draw.  Time to research some URI and HTML parsing.

On the subject of soda cans

I bought a can of Coke today, which is fairly rare for me.  On the way home I noticed that the top looked a little bit different than usual, and I was reminded of conversations I had in the early Nineties, when the shape of soda cans noticeably changed last.

The change that happened in the Nineties was that a crease appeared near the top of the can.  At work where industrial design was a common topic of conversation, various theories were suggested for this.  One of which was that it was to allow the contents to expand if the can should be stored below freezing.  It seemed vaguely plausible and I didn’t give it much thought until some years later, when I decided to find out once and for all what the real reason for the change was.  After some lengthy and devious boolean searches on AltaVista, I came across a research/presentation paper by the company that owned the patent on the new can design.  I turned out that the freezing theory was very much wrong.  The real reason for the switch was to reduce the weight of the can, thereby saving money on raw materials and shipping.  The new design eliminated the solid base of the can, as well as reducing the amount of aluminum required for the top, without compromising the rigidity of the container.  The savings were actually quite impressive.

I suppose that someone has improved on the design once more.  The top looks even smaller in diameter, and has a deeper groove.

The continual optimization of design always impresses me, especially when it shows up in something that most of us would consider mundane, such as a soda can.  But it’s going on all around us, all the time.  Not because of a philanthropic drive to improve our consumption of natural resources, but to maximize profit and increase efficiency of effort.  Even still, it’s nice to know that somewhere, someone is thinking, or being to told to think about ways to improve something.

Deploy, Deploy, Deploy!

So now I have a working application. It’s pretty simple, an activerecord model stores the lottery picks, the user enters the current draw, and the resulting display shows the results, as well as any winning lines. I even added a helper to take logic out of the view to handle the formatting of the SPAN elements.  All the layout and formatting is handled through CSS.

Now it’s time to try and deploy it to my hosting service.  At this time I was still with Network Solutions, which had a nifty ZIP deployment procedure for uploading Rails apps.  I create a database in the MySQL admin.  I migrate the data, such that it is, with and SQL export/import. Upload the Rails ZIP, restart the server and…. Failure, 500 error.  I check the logs, they’re empty.  I try to check versions, can’t check the version because I don’t have shell access!  I find that the versions are not the same, so I go back and recreate the app with the version running on Network Solutions, including the gems.  Still getting the 500 error, and nothing in the logs!  I change permissions on the log folder, still nothing in the logs. I determine that the 500 page is the one from my application, so something is working, just not sure where to look.  I manhandle the environment.rb configuration to force everything into development, and suddenly I have log entries.  Aha!  It was running in production all along, and coupled with a permissions issue was the reason I had no logs.  Now I see that I never updated the database.yml config for production, which I had assumed would run in develpment until I implicitly switched it over.  Wrong!  So I update the database.yml file and after a couple of iterations while I determine the correct connection details to the database, I finally get my application running from Network Solutions, accessible over the internet.  “Hello World”, indeed!