Archive for the ‘Development’ Category

Story Driven Development in Ruby on Rails with cucumber, webrat, shoulda and factory_girl

Friday, June 18th, 2010

My company recently decided to give Story Driven Development in Ruby on Rails a go and got me to come up with an introductory tutorial.

So I came up with one that uses cucumber, webrat, shoulda and factory_girl.

I’ve also documented step-by-step setup, commands and code that you can follow.

Check it out at:

http://github.com/alvinlai/pantry-sdd

and let me know what you think! =)

How to migrate user data and preserve old links with Nginx

Saturday, June 5th, 2010

Yesterday I found that I’ve hosted 1GB of Freshlog-uploaded screenshots on my VPS account since I’ve launched in August 2009.

VPS (Virtual private server) are great for hosting Rails applications since they more or less provide you a guaranteed slice of CPU and memory. Furthermore, if another account on the same physical server dies, it’s self-contained and the other slices continue to run without a performance hit. Throw in a full-fledge root account and the option to independently reboot your slice – definitely more stability and control than a shared rails hosting environment. They’re cheap too, I’m only paying US$8 per month to my provider, prgmr.com, perfect for bootstrapping a startup, Freshlog in my case.

However, since I’m only selling Freshlog as a one time purchase and have been offering complimentary screenshot hosting, (the main selling point of Freshlog is uploading screenshots to other services), I wouldn’t be able to afford to upgrade to a bigger plan indefinitely.

Even so, I really enjoy using Freshlog myself and didn’t want to disappoint friends and fans by discontinuing my hosted screenshot service.

I understand the need for the links to existing Freshlog screenshots to continue to work, as users would have embedded HTML containing freshlog screenshot links in their own online documents and it would be very irresponsible to simple break them. I have also personally used countless Freshlog screenshots in my help and support documents on my Freshlog support site.

So here’s how I migrated 1GB of screenshots to another web host (VPS hosting costs are pricier for the full control you have over it) and freed up space on my VPS with an Nginx configuration, while preserving old links:

With existing Freshlog screenshot urls looking like this:

http://freshlog.com/photos/3704/large/ca2507287635411f76aade14a5a11d39.png

And I need them to be redirected transparently to my new host like this:

http://dh.freshlog.com/freshlog1/photos/3704/original/ca2507287635411f76aade14a5a11d39.png

I achieved this with Nginx rewrites, similar to Apache’s mod_rewrite, here’s what I added to nginx.conf:

if (!-f $request_filename) {

rewrite ^\/photos\/(\d+)\/([a-z]+)\/([a-z0-9]+).png$ http://dh.fres\

hlog.com/freshlog1/photos/$1/$2/$3.png;

}

Here’s what it does:

If the requested file ($request_filename) does not exist (!-f), parse the URL via regular expressions and redirect it to the new URL.

The changes are transparent to users and if you were to create new screenshots, the new screenshots will continue to be created and hosted my VPS, but if you were to access screenshots that were transferred to my other webhost, Nginx will find that the file does not exist locally and transparently redirect to the new host, all without any broken links.

In future, when storage starts to dwindle again, I’d simply transfer the screenshots to my secondary host and delete them locally on the VPS and Nginx will handle all the transparent redirects.

If you have a better way to migrate users’ data, do let me know in the comments.

Diagrammr – Great tool for quick, sentence-constructed diagrams

Thursday, May 20th, 2010

I saw Hiten Shah of KISSMetrics tweet about this useful tool that helps create diagrams with sentences you type.

Watch how easy it is:

  1. First, type in a sentence along like:

    37b5d79cdc2167bb9a93dd12b483f877

  2. After hitting , you get this diagram

    20c9bcb89ec0ed3540d5f8b7073fcfa0

  3. Try typing another

    D7faa05dc378f2ee07cee550937e4b90

  4. Easy yeah?

    509187955d42ed91245499ec24fd0516

  5. Now try to link 2 items together with a verb

    D854c9d2236e0389b9af599bd1be906f

  6. Awesome, it resizes itself nicely!

    53e54f4a3c0e0b2d6f88b36114c4111a

Try it out for free at http://diagrammr.com

Created by Freshlog Storyteller

UTF-8 encoding looks better in your browsers

Tuesday, May 18th, 2010

Jen noticed some weird characters in text in her browser, while mine looked ok. It turned out that Western encoding was the culprit.

Use UTF-8 instead of Western encoding in Firefox

  1. Previously I was using Western

    Dd57a8a0279359b8831654d24e20916d

  2. After switching to UTF-8 unicode, it worked

    D3788ff192c986c61dfb2e784c141a88

With Storyteller, it’s so much easier to tell stories! I’m loving my own product =)

A better (and easier) way to describe your work

Tuesday, May 18th, 2010

After I finished developing an AJAX feedback form that would send the company an email when our users used it, I wanted to show my team what to expect from this new feature.

Rather than typing tiresome bullet points of text and expecting my team to predict and imagine what it would look like, I just told my story with step-by-step screenshots.

  1. Click to send feedback

    66a74ad917adbe6634a0cd824fdd030a

  2. But user’s not logged in

    551c7a606631d057cd37f50843b6e255

  3. So login..

    8afbd2fed66daded182f0f41d665aa24

  4. User tries clicking again

    E727c6dc6ac7a8860df5a4b3c9b48233

  5. Facebox appears with feedback form.User fills up, clicks “Send feedback” without entering any feedback

    B4c2ce504d1ae699c9286916a1eae362

  6. Alert, telling him that he needs to enter feedback

    4e06cb82b234d979b0fda91f48038d0b

  7. User fills out feedback description and hits send feedback

    732ca127e265295d378f084394ee902d

  8. Feedback successful.User can close the facebox

    A3f70a0352a9b2ffbe8014f95de55057

Isn’t this descriptive and fun to look at?