Rolling Windows and Sticky Bytes

<tagline type="clever"/>

Hacking House Numbers for Fun (?) and Profit (?)

My wife and I recently bought a set of reasonably tasteful LED house numbers and I decided to work on putting them up today. They’re the modular kind where you can hook up to five numbers together and power them with a single module.

Well, I popped the numbers out of their packaging and screwed them together following the instructions. Added the power module. Plugged it in. Covered the daylight sensor.


Time to look closer.

Mini-USB-B-type-Cable 13916-480x360 (4817557098)

Boy, that connector on the power adapter sure looks familiar. It’s our old friend Mini-USB B! Each of the included numbers has a pair of Mini-USB connectors, one male and one female that are used to connect the numbers together.

Wait. It can’t be that easy… can it? Checking the adapter carefully showed the output as 5V DC 0.2A. The pin-out diagram had +5V on one side and Ground on the other, matching the Mini-USB spec. Maybe…

A quick rummage in my Big Bag O’ Cables and I found that powered USB hub that I bought in college and the Mini-USB cable that came with it. Plugged in the hub, hooked the sign up to it and we’re off to the races. Turns out these fancy LED signs are literally a USB power adapter, a $2 daylight sensor, and a pile of LEDs in a waterproof housing. You can even power them from either end of the bus.

Turns out the power adapter is bad, so the power module is going back tomorrow. In the meantime, I put the house numbers in the front window and plugged the USB hub into a day / night timer so they turn on and off when they’re supposed to. Not quite according to plan but hey, it’s progress.


No Comments »

Officially Open Source

Well, I finally made my first contribution to the Open Source community with this pull request for the “axlsx” Ruby library, used to programatically generate Excel spreadsheets.

I’m grateful that my employer and my management team have allowed me to contribute to the project on company time.

1 Comment »

Debugging an Android Action Bar Menu Issue

I’ve been working through the University of Maryland Programming Mobile Applications for Android Handheld Systems course and recently ran into an issue during one of the labs. I could not figure out why one of my views was not calling its onClick handler. Turns out, the handler was being called but log messages were not being recorded in LogCat.

I eventually determined that the issue was that the location had not been set in the mock location provider included in the lab. For some reason, the action bar overflow button was not appearing, meaning I did not have access to the location provider settings that should have appeared under this button.

I eventually learned on the course forums that you can force the action bar overflow menu to appear by pressing the Page Up key on your keyboard. Once I was able to summon the menu, everything worked as expected.


No Comments »

Heartbleed OpenSSL Vulnerability

The Heartbleed SSL vulnerability is big news in the media right now (and rightly so — it’s a scary bug).

I’ve been contacted by some organizations and software vendors and I’ve contacted others about it. I thought I would compile the list here, mainly for my own reference.

Financial / Banking

President’s Choice Financial – Not Affected (a telephone rep confirmed they do not use the affected versions of OpenSSL)

CIBC – Reply pending but likely unaffected (they provide banking services to PC Financial)

Online Services

CACert – Recommends revoking and regenerating any certificates or keys installed on vulnerable systems

GitHub – Recommends changing your password, enabling two-factor auth and resetting all your tokens

Amazon Web Services – Recommends upgrading OpenSSL on any vulnerable systems (EC2), running update_dependencies for OpsWorks and rotating any keys and certificates for Elastic Load Balancing, EC2, Elastic Beanstalk and CloudFront


VisualSVN – VisualSVN Server is not affected. The client should be upgraded to version 4.0.6.


Minecraft (and other Mojang games) – Recommends changing your password

No Comments »

Installing Windows 7 on an ASUS S400C Ultrabook

Edit (2016-01-08): I’ve since installed Windows 10 on this system so it’s unlikely I’ll be able to answer questions about this post in future.

My wife had a very reliable, very handy ASUS Eee PC that served us very well on our travels. It’s small, it’s light and the battery lasts for ages. Unfortunately it’s started to show its age so we decided to shop around for a replacement. The local computer store had an ASUS S400C Ultrabook on sale for $500 even which was exactly the budget we had in mind so we picked it up.

We knew going in that this new beasty shipped with Windows 8 on it but I have an unused Windows 7 license hanging around so I figured that if reports of the “suck” slider being turned up to 11 in Windows 8 proved to be accurate, I could just nuke it, install Windows 7 and we could move on with our lives. Oh, how wrong I was.

So I gave Windows 8 a shot. I used it for about two weeks while my poor Alienware system was off recovering from my clumsiness carrying a drink. I was told by somebody who is a fan of Windows 8 that the key thing is that Windows 8 is designed for touch screen devices so if you have a touch screen device (and the S400C is a touchscreen device), you will love the Windows 8 experience.

I hated it.

I hated every moment of it.

I hated switching between the Metro and desktop user interfaces.

I hated the Metro interface itself.

I hated all the crap they put on the home screen.

I hated the app store.

I hated the fact that Chrome crashed every time I switched out until I figured out how to put it into desktop mode.

Since my wife and I picked up the system for travel and she would be using it too, I decided to leave Windows 8 on the system so she could give it a try. Before she flew to the U.S. on business, I showed her some of the Windows 8 basics so she wouldn’t be completely lost. When she got home, I asked her how she felt about the system.

“The computer’s good. Windows 8 sucks.”

Today I finally decided to wipe the system and install Windows 7 on it. It was not a smooth road. After much Googling (and swearing), I managed to figure it out.

WARNING: Following the instructions below will cause the loss of all data on the system, including the Windows 8 recovery image. This is a one-way trip. You have been warned.

Since the system has no optical drive, the first thing you have to do is put a bootable Windows 7 install image onto a USB stick. From a system running the 64-bit version of Windows 7, do the following:

  1. Insert your Windows 7 DVD.
  2. Format the USB stick as an NTFS volume. Make a note of the drive letter assigned to it (I’ll use F: in the example below)
  3. Start up a Command Prompt as an Administrator.
  4. Change drives to the Windows 7 DVD and run the following:
    cd boot
    bootsect /nt60 F:
  5. In Windows Explorer, copy the entire contents of the Windows 7 DVD to root directory of the USB stick.
  6. While you’re at it, you’ll probably want to grab the LAN driver from the ASUS support site and copy it onto the stick. I saw some posts online from Asus support that said the Windows 8 drivers and the touch screen don’t work in Windows 7 but the NIC driver and touch screen both work fine for me.

USB stick prepared, you now have to start monkeying with the UEFI configuration of the ultrabook. Apologies if any of the options aren’t exactly as written below. I should’ve taken notes while I was working.

  1. Shut down the system if it’s running. If you reboot, it will skip the POST and you won’t be able to boot into the UEFI interface.
  2. Power on the system. While it’s booting, press F9 to enter the UEFI interface.
  3. Select Troubleshoot, then Advanced. Select UEFI Configuration.
  4. In the UEFI configuration, go to the Security page and set “Secure Boot Control” to “Disabled”. Reboot.
  5. Go back into the UEFI interface, then into the UEFI configuration. On the Boot page, change “Launch CSM” to “Enabled”. Plug in the USB stick and reboot.
  6. Once again, go back into the UEFI interface. On the Boot page, you should now see the USB stick (at least I did — YMMV). Go to the Save & Exit page and select the USB stick from the list of one time boot options and you should find yourself booting into the Windows 7 installer.
  7. Since Windows 7 doesn’t support GPT, you’ll have to nuke all the partitions to proceed with the install. Yes, this means delete all the listed  This includes the recovery partition and all the OEM partitions so you can never go back to the factory Windows 8 image.

Edit: Since this seems to be a common pitfall, let me just add in that when I say you need to nuke all the partitions to proceed with the install, I mean you need to hit “Drive Options (advanced)”, then select each partition on the system disk (normally Disk 0) and hit the delete button. Deleting a partition will destroy all the data on it. Data loss! Unrecoverable data loss! You’ve been warned (again).

Now that I read it over, this is a really short set of instructions considering how much time it took to figure all this stuff out. Good luck!


Factory Reset a Nexus S

I found lots and lots of terrible, incomplete or inconsistent advice on how to factory reset a Google Nexus S running Jelly Bean on stock firmware so here’s how you actually do it.

Note: Performing this procedure will wipe all your data. Make sure you have a good backup.

  1. Power off the phone
  2. Press and hold the volume up button, then press and hold the power button until the phone powers on. The phone will start up in the fastboot menu.
  3. Press volume down several times until recovery is highlighted, then press the power button to boot into Recovery mode.
  4. A picture of an android laying on the ground with an exclamation mark over his chest will appear. Press and hold the power button, then press volume up key to open the recovery menu.
  5. Press volume down several times until factory data reset is selected, then press power.
  6. Press volume down until the one “yes” in the field of “no” entries is selected, then press power to wipe the phone.
  7. Select the reboot option to power the phone back up and re-launch the initial configuration wizard.

Amazon Simple Storage Service, Heroku and Rails

I wasn’t able to find a concise walkthrough for getting access controlled download links for S3 resources up and kicking in a Heroku web application so I thought I would put something together.

First step — users and permissions!

You will need to create an IAM user to which you can grant permissions to generate pre-authenticated URLs for your bucket objects. I’m going to assume you already know what an S3 bucket is (or you know how to Google), that you’ve created a bucket and that you’ve populated it with a few non-public folders and files. When you create the new user account, be sure to generate an access key and record it somewhere safe — you’ll need to plug the Access Key Id and Secret Access Key into your application environment later.

After you create the user, you’ll have to assign permissions by using groups or roles or (if you only ever intend to have a single user account that your web app uses to interface with S3) by assigning permissions to the user directly. The permissions will look something like the following:

"Statement": [
    "Effect": "Allow",
      "Action": [
      "Resource": [

The permissions above grant the applicable user / group / role the ability to Get or List any object in the bucket. You can make the permissions more (or less) restrictive if appropriate. Keep in mind that because these permissions do not include the ListAllMyBuckets action, the user account will not be able to access the S3 console. This may make testing the permissions using a web browser challenging but you can always temporarily grant the account the ListAllMyBuckets permission or use an interactive ruby shell (irb) to instantiate a bucket object directly and test from there.

Before going further, you’ll need to make sure the aws-sdk gem is installed on the host you’ll be using for development / testing. Again, not going to cover this here.

Once you’ve assigned the permissions, fire up irb and test that your access controls are working correctly. Substitute your own access key information, bucket name, and object key, obviously. The object key is just the path to the file as it appears in the AWS S3 console. Keep in mind that objects aren’t actually stored hierarchically (i.e. in folders) on S3 but it’s a useful convention for making S3 objects people-friendly and URL-friendly.

s3 = :access_key_id => 'ABCDEFGHIJKLMNOPQRST', :secret_access_key => 'abcdefghijklmnopqrstuvwxyz1234567890ABCD')
bucket = s3.buckets['mybucket']
s3obj = bucket.objects['path/to/private/object.ext']
@download_url = photo.url_for(:read, :expires => 15.minutes)

This code will create a connection to S3, instantiate a ruby object for your bucket, select a (presumably private) bucket object and give you a download URL that can be used by anybody to read the object for 15 minutes. If you receive a forbidden message anywhere along the way, go back and recheck your permissions. For testing purposes, paste the URL that irb spits out into a browser with the cookies and cache cleared (an incognito window is good for this) to make sure you actually get the file back when you visit the URL.

Once you can safely retrieve URLs, you can punch similar code into your Rails controller to make these temporary object URLs available to your views. The current code does, however, present a problem — how do you keep your access key secure? Well, you’re going to want to use Heroku environment variables to store this information. Punch the following command into the command line on the box where you normally run your Heroku deployments to set the appropriate environment variables in your Heroku environment:

heroku config:add AWS_ACCESS_KEY_ID=ABCDEFGHIJKLMNOPQRST AWS_SECRET_ACCESS_KEY=abcdefghijklmnopqrstuvwxyz1234567890ABCD S3_BUCKET_NAME=mybucket

You can now replace the hard-coded values in your code with environment variables so you don’t end up checking your credentials into revision control accidentally:

s3 = :access_key_id => ENV['AWS_ACCESS_KEY_ID'], :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'])
bucket = s3.buckets[ENV['S3_BUCKET_NAME']]

One other useful trick — if you want to override the default browser behaviour for a file type and force the file to be downloaded instead, you can set the Content-Disposition header. This can be done in the Metadata section of the S3 console for a file:

Key: Content-Disposition
Value: attachment; filename=Downloaded Copy of object.ext

You can also set this header when you call url_for (which is probably more scalable):

@download_url = photo.url_for(:read, :expires => 15.minutes, :response_content_disposition => 'attachment; filename=Downloaded Copy of object.ext')

Setting the Content-Disposition header lets you do neat tricks like give bundles of files the same filename in S3 (e.g. but have them save to the user’s computer with a unique name (e.g. “An Album of Boring Family”).


No Comments »

Painless Thumbnail Creation

I recently had a need to create thumbnails and discovered that using off the shelf photo management software to generate thumbnails is not very practical since these applications tend to try to preserve the quality of the image regardless how small you make the image itself. The end result of my first attempt was a set of images that were 150px on their longest edge and still over 30KB each. For a thumbnail, that’s an awfully large file.

My wife has a copy of Photoshop so I fired that up and created an action to create a 150px thumbnail from an arbitrary image and used Photoshop automation to thumbnail them all in a batch. Here’s the rough process I followed:

  1. Make a copy of the images you want to thumbnail, just in case. Make a second backup and store it somewhere safe, just in case.
  2. Start up Photoshop and open up one of the images.
  3. Bring up the Actions panel if you don’t already have it open. Create a new action — it should start recording automatically.
  4. To size your image down, you’ll want to use the image fitter instead of the resize function. This is particularly important if you have a mix of portrait and landscape images since the resize function will only resize one dimension. If you resize a portrait image to 150px width, the height will be larger than 150px which is probably not what you want. To use the image fitter, select File => Automate => Fit Image. Set both dimensions to the desired longest edge (in my case, this was 150px) and click OK.
  5. Select File => Save for Web… and choose appropriate settings (I used JPEG High which gave me a thumbnail size of ~7.5KB with minimal quality loss). Save your thumbnail to a new location.
  6. Close the file. This is important because it keeps your action from opening up hundreds of files and leaving them open if you use it in Batch mode.
  7. Stop the action. You should now have an action you can use to generate one thumbnail.
  8. Finally, once you have your action set up, you can run it in Batch mode by selecting File => Automate => Batch… to run it against multiple files. Select the source directory and target directory. Make sure these are different or you may accidentally overwrite your originals (you made a backup… right?). In the Batch options, be sure to check the Override Action “Save As” Commands checkbox. The name is somewhat misleading — checking this checkbox prevents Photoshop from popping up the JPEG Options dialog and overwriting your tiny thumbnail file with a large one as part of the batch. If you leave this checkbox unchecked, the JPEG Options dialog will open for every image and your thumbnail will be overwritten with a larger file during the action.

The thumbnail run took about 5 minutes to process 150 images.

No Comments »

Reflections on the Social Web

I thought I would take a break from the technical mumbo-jumbo to reflect on a fascinating thing that happened recently when I added a new feature into the project on which most of these Ruby posts are based.

I don’t usually like to talk about the project or its purpose in specific but I think that would be hard to pull off in this context and still have the post make any impact.

As those of you who know me personally are aware, I will be getting married in a few short weeks to my beautiful fiancée and I’ve been working furiously on hacking together a website to help our guests, both English and Polish — and us — keep track of it all.

In addition to providing information about the wedding itself and allowing people to RSVP online, the intention was to let people make song requests for the reception and, eventually, to upload and download photos of the big day itself. Those were the major features, anyway.

About a week ago, I managed to finish the last of the code required to get the song requests portion of the site going and punched out a notification to everybody who gave their e-mail address that the feature was live. On a whim, I decided to make the song list public, including a simple ranking for how many times a particular song had been requested.

I was not prepared for the response.

Since the song requests feature went live, we’ve had 200 requests come in. People are talking about it. People are excited. Now, instead of this being our wedding reception, I get the sense that people feel that it’s also their wedding reception and that’s amazing.

When we talked to the DJ the first time, he asked us to make him a list of some song suggestions. We met with the DJ over the weekend and when I described the site (and the response) to him, he was amazed. Floored. Totally blown away. I created an account so he could monitor the incoming requests and now he’s watching with glee as the requests come in and rise through the rankings.

I never would have thought that such a small thing would generate such a huge response.

The lesson I’m going to take away from all this? Never underestimate the power of social.


flash and

Are the flash messages in your Ruby on Rails application persisting through multiple pages in strange and exciting ways or failing to appear completely?

If so, you may be confusing flash[:warning] = "Some Message" with[:warning] = "Some Message"!

The key difference is that flash will persist to the next request before being cleared, where only persists until the end of the current request.

In practice, this means that your controller methods should use flash if your exit point is a redirect (since a new request will be created following the redirect) and should use if your exit point is a render (since will be presented to the user during the natural lifespan of the current request, then cleared).

Render — Wrong Way (flash will persist too long):

if song.valid?
  flash[:notice] = "Song saved successfully."
  flash[:warning] = "Unable to save song."
render :edit_song

Render — Right Way:

if song.valid?[:notice] = "Song saved successfully."
else[:warning] = "Unable to save song."
render :edit_song

Redirect — Wrong Way (flash will not appear):

if song.valid?[:notice] = "Song saved successfully."
else[:warning] = "Unable to save song."
redirect songs_url

Redirect — Right Way:

if song.valid?
  flash[:notice] = "Song saved successfully."
  flash[:warning] = "Unable to save song."
redirect songs_url


No Comments »