MPOV

my point of view (programming stuff mostly)

EC2 = Everything Cleared 2Day (FIXED)

I created a free micro instance on Amazon EC2 a few weeks ago. Today I remembered it and thought I would tinker around a little, only to find out that when I logged into AWS console, I had to "re-activate" my account using a phone number. Hmmm, that's weird. I distinctly remember doing that two weeks ago. So I jumped through the hoops and got logged in again to discover that my instance was gone, my security group was gone, and my elastic ip was gone. Gone. No trace whatsoever.

This gives me the willies. Luckily, I wasn't yet using the EC2 instance when it just up and vanished, but I doubt that Amazon knew that. What's to make me believe it wouldn't happen again?

I think I might stick with Rackspace for now.

PS and yes, I am logged in with the right account -- I verified against the confirmation email I got when I signed up.

Update: Ahhh... found the cause, and the solution! I posted on the Amazon support forum, and it turns out that it's possible to have what is called a "MASE" problem, which stands for "Multiple Account, Same Email." WTF!!

Indeed, I logged out, used the SAME email address, but a different password, and was able to log in with my other account and see my running instance.

OK, Amazon that isn't so bad I guess. Except, it's weird. And how in the world did I get another account?

 

 

Winexe on Ubuntu

If you're running a Linux desktop in an otherwise Windows environment, winexe may be something you'll enjoy.

Winexe allows you to execute commands from a Linux machine on a remote Windows machine, as if you're sitting at the Windows command prompt. Think of the possibilities!

Recently, I found a way to get it to compile on my beloved Ubuntu Maverick (it broke when I dist-upgraded for some reason), and I thought I'd share. Winexe doesn't have a Debian package that I'm aware of, and getting documentation on how to make it compile is spotty at best. The official SF page might be the obvious destination to find out how to get it, but alas, it no workie.

Fortunately, the peeps at Zenoss got your back. Here's the scoop:

(The patch is necessary to fix a tiny typo in winexe/service.c -- if it doesn't apply properly, chances are good the typo has been fixed since this blog post.)

Once you've compiled, now for some fun!

Never again must you VNC into a Windows box just to restart a service! I even have a script that remotely executes a "git pull" and then restarts all the relevant Windows services. Poor man's deploy FTW!!1

Use a Proc With ActiveRecords' Default_scope Method

Today, my small patch to Rails was applied by the core team. This is only my second contribution to Rails, so I’m fairly stoked about it being accepted.

This will allow you to pass a block to the default_scope method in ActiveRecord. It doesn’t sound like much, but opens up some wonderful possibilities.

First, a review of what default_scope does:

The first call to Person.all applies the default scope and adds a where clause that returns only non-deleted folks.

The next two calls are passed through the unscoped { } block so that the default scope isn’t applied.

Great! Using default_scope keeps me from having to specify a common condition over and over again on every (or nearly every) query.

What else can we use this for?

Well, let’s say you have an app with different customers. Each customer needs to have the illusion of operating in their own “database” while your server has just one.

Each customer has their own subdomain, say foo.example.com or bar.example.com. Depending on the hostname, let’s scope our queries to that particular customer.

Oops! This doesn’t work because the call to where() is made at the time the class is created. Instead, we need the where() to be called each time a query is made.

With named_scope1, you can pass a lambda/proc, but with default_scope, you cannot. Until now that is!

With my wonderful, 6-line patch (plus tests of course), you can now pass a proc to default_scope:

This technique is exactly what my project OneBody uses to scope customer “sites” to their specific site_id based on hostname. The Person.current_site_id bit is actually called inside the ApplicationController once the hostname is determined.

It won’t change the world, but being able to contribute this small bit of code back to the framework I love and use everyday feels great.

Footnotes:

  1. named_scope is just scope as of Rails 3.

Use Rsync Instead of Cp

I tend to use rsync when others would typically use a simple cp for copying files. A few reasons:

  1. It can be canceled in the middle, and resumed later.
  2. It can show a progress bar that (while not perfect) is great for large files or lots of files.
  3. It will only copy the changed files and won’t clobber already existing directories of files at the target.

rsync is available on Linux, Mac, and there’s a binary somewhere on teh intarwebs for Windows.

To use, you almost always want to pass the -a flag, which stands for “archive” – basically a convenience flag for -r (recursive), -p (permissions), -t (timestamps), and a few others. I can’t think of a time I haven’t used -a when using rsync.

Following that, basic usage looks like this:

1
rsync -a source destination

The other thing to remember when using rsync is that it’s picky with slashes; if you put a trailing lash on a path, then rsync takes that to mean you want to copy the contents of that path. If, on the other hand, you leave off the slash, it will copy the path and its contents. A few examples will help:

1
2
3
4
5
# This will copy the stuff directory (and its contents) to the documents directory
rsync -a /home/tim/stuff /home/tim/documents

# This will copy only the contents of stuff to the documents directory
rsync -a /home/tim/stuff/ home/tim/documents

Some other handy arguments:

  • --stats
  • --progress

So, to put it all together:

1
rsync -a --stats --progress /home/tim/stuff /home/tim/documents

And, better yet, rsync can work over ssh (if it’s installed on both hosts). Just put an ssh host on the front of either path:

1
rsync -a --stats --progress /home/tim/stuff tim@foo.example.com:/home/tim/

or

1
rsync -a --stats --progress tim@foo.example.com:/home/tim/stuff /home/tim/

So, there you have it. rsync can do tons more stuff, but this is a great start. If this is all you learn of rsync, you will be that much better off.

MBP Upgrade

My 1st generation Macbook Pro is starting to show its age, but tonight I used my birthday money in an effort at rejuvenation.

First, a new Seagate hard drive. 500gb, 7200rpm, $99 at Best Buy. It took about an hour to get my machine apart, with all its tiny screws, get the new drive in, and put it back together.

Next, I said good-bye to Mac OS X. I installed the brand new Ubuntu 10.04 LTS, and man it screams on this machine. I’m not sure if it’s Linux, the new drive, or a combination. This machine has new life!

Some pictures of the operation are below:

Whiteboard Icons

Bulb

Back in 2005, I uploaded a bunch of crude little pictures to my Flickr account and called them my “Whiteboard Icons” set. Hundreds of people have, over the years, found them to be useful on their blogs, flowcharts, and more.

Today, I finally added a couple new icons to the set (1, 2). Only took me five years.

Enjoy.

Update: Various sizes and scalable versions are available in the whiteboard_icons git repository.

csv2wufoo.com

Csv2wufoo

csv2wufoo.com is a little side project I wrote using Sinatra, my WufooParty lib, and James Edward Gray's FasterCSV lib.

After the tenth time my wife asked me to write a one-off script to import data into her Wufoo form, I decided to generalize it a bit, slap a Sinatra app around it, and give it a domain name (well, there was a little more to it than that, but ya know...)

It hasn't quite been battle tested yet, but hopefully it will be useful to someone.

We love Wufoo at our church and use it almost daily for all sorts of things. Gathering submissions is only one small trick in its bag of 'em -- Wufoo's reporting makes it a really good platform for visualizing flattened data, among other things. Staff in our church use Wufoo in ways they should probably be using Excel, but Wufoo makes it so much easier.

With csv2wufoo, we should now have a better way of getting data into the system.

FacebookParty

I wanted to understand the Facebook REST API better, and decided I needed a simple wrapper for it. HTTParty to the rescue again!

FacebookParty (rdoc) is along the same lines as my other _party style api wrappers. I can't take much credit for it though, since HTTParty is what makes this stuff so easy. Slap a pretty class on an api endpoint, and the rest is cake. And cake goes good with parties.

Fbparty