Archive for the ‘Coding’ Category
Automatic Elastic Block snapshots with a cron job
Amazon EC2 really is amazing, and the Elastic Block storage is pretty darn good too, however I wish you could automate the snapshot process form the EC2 console.
It is however pretty easy to do yourself using a simple cron job.
Before you start make sure you have a JRE:
sudo apt-get install sun-java6-jre
You will also need the EC2 API tools:
wget http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip unzip ec2-api-tools.zip
At this point you should make a metal note of where you unzipped the api tools to.
Now that you have the prerequisites you need the following simple script:
#!/bin/bash export JAVA_HOME=/usr/lib/jvm/java-6-sun/jre/ export EC2_HOME=/root/ec2-api-tools-1.3-42584 export EC2_PRIVATE_KEY=/data/misc/pk-Umbongo.pem export EC2_CERT=/data/misc/cert-Umbongo.pem export AWS_ACCESS_KEY_ID="Twinkle Twinkle Little star" export AWS_SECRET_ACCESS_KEY="If your happy and your know it, clap your hands" $EC2_HOME/bin/ec2-create-snapshot vol-999999
Obviously you need to specify your volume id where i have vol-999999
Once you have modified this file to be executable you are ready to test it.
chmod +x snapshot.sh ./snapshot.sh
Once your have ran it go to the EC2 Console and verify that the snapshot process has started.
And thats it, the first time you run this script the snapshot will take a while to complete but the next one will be much quicker as the snapshot process is incremental, so only the changes since the last snapshot will be read.
Oh, don’t forget to create a cron job for this (*/5 * * * * /path/snapshot/sh)
How to respond to the IPhone Shake Gesture
The IPhone 3.0 SDK includes support for detecting when a user “Shakes” the IPhone, this is intended to be a usability feature allowing app developers to implement Refresh or Read All functions on shake, wow those crazy guys at Apple really do know how to innovate!
It’s pretty easy to implement all you need to do is register your view controller as the first responder and listen for the motion event.
-(void) viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; [self becomeFirstResponder]; }
Once your controller is the First Responder you can receive the motion event like so:
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { if (motion == UIEventSubtypeMotionShake) { refresh; } }
This will work beautifully but you will however notice that any views you present over this one will not respond to all touch events, for instance the keyboard will not show when you touch a text field, this is because you need to resign the First Responder before you present the view like so:
- (IBAction)showMyCustomView { [self resignFirstResponder]; [self presentModalViewController:myCustomViewController animated:YES]; }
As you can see this is all pretty easy and the only gotcha is the First Responder stuff, which also is pretty trivial.
Enjoy and please people, Shake Responsibly!
JRuby.com
For as long as the JRuby project has been going the jruby.com domain has been owned by a nasty little Domain Squatter, but recently the Company I Work For purchased the domain off the before mentioned toe-rag for a small fortune.
Today the domain is being send to it’s rightful resting place, that is, we are giving it to the JRuby project.
Hip Hip Hooray!
Code Spaces Website Redesign
We have been working on the CodeSpaces.com website for a while and today released it to the world, it’s likely to evolve quite quickly as we are trying to catch up on all the SEO work we haven’t done over the last 2 years.
Check it out at http://www.codespaces.com
New Sourceforge Design
Wow, isn’t the new SourceForge style absolutely awful?
Fixing the little things.
When your developing, enhancing, evolving your software you will introduce bugs which range from trivial UI issues to “Show Stopping” issue in business logic that will drive your customers away.
Its pretty easy to prioritize these bugs as tasks for your development team by making the “Show Stoppers” #1 priority and so on… and this list of priorities is often geared around the customer, we make sure the issues that the customer will react to the most are sorted out first and then we get to the other “trivial” issues later (if ever).
While this method of prioritization works well in theory I have observed that developers who are not allowed to fix bugs that annoy them or are “easy” to fix, often loose motivation and interest in fixing those bugs that are not so easy to fix.
I have myself worked on projects where the PM has taken exception to me spending an hour to fix and test a bug because I felt that it was worth doing even thought the “Plan” didn’t express this.
Its so important to let your development team cherry pick issues to fix as well as prioritizing the “Show Stoppers”.

Why?
Developers love marking tasks as “Dev Complete”, it gives us a sense of achievement that motivates us to crack on with the next task at hand.
“Wasting” (if your a PM) an hour on a task that isn’t the most pressing one at the time can have a profound impact on your teams productivity, letting the developers mould the shape of the product by picking the issues, tasks to work on gives them a sense of ownership which brings with it a sense of determination to deliver.
I liken this to the Broken Window (Tip 4) theory expressed in The Pragmatic Programmer by Andrew Hunt and David Thomas.
Profound #1
An Investment in knowledge always pays the best interest.
Benjamin Franklin
Daily Dose #4
Bourbon Creams and Bananas are not a balanced diet.
Phusion Passenger on Amazon EC2
Some useful stuff relating to Phusion Passenger (mod_rails) on Amazons Elastic Computing Cloud.
Moving from Java to C#
A senior ThoughtWorker talks about his first C# project 10 years after he first tasted the Java bean.
IPhone GUI PSD
Some photoshop goodies for mocking up IPhone UI’s.
Exception Notifier in Rails 2.1
If you have recenlty or are about to Upgrade an existing Rails application to Rails 2.1 (and why wouldn’t you), be aware that your implementation of Exception Notifier might not work due to a scope change in Rails where:
@controller.filter_parameters
Is now protected, therefore the code in Exception Notifier that called it needs to be change as follows :
1 2 | #exclude_raw_post_parameters? ? @controller.filter_parameters(parameters) : parameters exclude_raw_post_parameters? ? @controller.send!(:filter_parameters, parameters) : parameters |
Utilizing the send method allows you to call the protected method.
Fortunately the Exception Notifier plugin on GitHut has already been updated to accommodate this fix and can be installed by :
1 | ./script/plugin install git://github.com/rails/exception_notification.git |
NOTE
Exception Notifier (like most plugins) comes with a suite of tests that you should run as part of your build or at the very least whenever you change something as fundamental as the Rails version your using… BTW I did neither of these things and found out the hard way :-/
Catch-All routes in Rails
Sometimes you need a catch-all route in rails to support dynamic applications like Content Management Systems, where all requests that are not matched by an existing route get passed to a controller who can deal with the request.
Add the following to the end of your routes.rb :
map.with_options(:controller => ‘page_engine’) do |site|
site.connect ‘*url’, :action => ’show_page’
end
If that’s your last route, it means that anything that isn’t recognised by any of the other routes will get routed to that controller/action (page_engine/show_page). It shouldn’t interfere with images/assets because they are served with higher priority than Rails routes. It lets you have any number of forward-slashes.
So if you hit your site with the following URL:
http://localhost:3000/we/really/hate/wcf
The request will be routed to the show_page action in the page_engine controller where you can then access the actual url elements with :
1 2 | path = request.path # '/we/really/hate/wcf' path_elements = request.path.split('/') # ['', 'we', 'really', 'hate', 'wcf'] |
While this isn’t the type of thing you would do on many Rails projects you certainly will find this useful for projects that have an element of dynamic routing that goes beyond the RESTful style that rails implements, and its especially useful for implementing Content Management Systems.
