Faker 1.0 released

10 September 2011

Earlier this week I released version 1.0 of the Faker gem. It's been about 4 years since the initial release of the gem, and the API has been fairly stable for the last couple of years, so I figured it was a good time to make the jump to 1.0. :)

This release finishes the conversion to I18n. Just about everything is in the locale files now, including the ability to define custom formats for everything -- company names, street addresses, etc. And, with the magic of method_missing, you can add new items to your locale file and have them show up as methods in the Faker classes.

The 1.0 release also settles some long-standing issues people have had with bad interaction between Faker, Rails 2.3, and locales (especially fallbacks). Though I'm not actively seeking to support Rails 2.3, I at least don't want it to be broken, so this release should cover that. Both Ruby 1.9.2 and 1.8.7 are fully supported.

Finally, I want to send out a big "thank you" to everyone (and there are a lot of them) who contributed code and ideas to this release. I really appreciate the interest shown and the work done by so many people who use and love Faker. According to rubygems.org, it has been installed over 400,000 times — over 1,000 times in the past few days!

Of course, I'm not done yet... next on the feature list is Faker::Image, which will provide an interface to all those cool fake image generator services out there. :)



Unwrapping UploadJuicer

20 July 2010

It says something about the sorry state of my blogging lately that my blog is the last place I'm announcing my latest project, Juicer. :) It's a handy service for offloading image uploading and resizing from your web app. Now you don't have to tie up your server to handle long uploads or to do a bunch of thumbnails. You can keep your app super-responsive for the core of what it does, and leave the uploads and resizes to us.

Though my blog is the last place I announced the project, it'll be the first place I announce the Ruby gem that goes along with it. :) I just published a gem that uses the Juicer API (via RestClient) and makes it pretty easy to integrate Juicer with a Rails 3 app. I've done the hard work of getting the direct-to-s3 upload with swfupload working for you, so all you have to do is make a few tweaks to your model and you have uploads and thumbnails done for you. You can get at the gem (and a sample Rails 3 app) at Github.

We'll be posting more about Juicer at the Juicer blog, but I imagine I'll mention things about it here from time to time. :) And hopefully I'll get around to posting some of the fun code-related things that make up the service.



Automating ec2 deployments with Ruby

24 July 2009

Recently I've had a couple of clients choose Amazon EC2 for their deployment environments, so I've been spending more time playing with EC2 lately than I ever had before. I set out to create a repeatable and time-efficient deployment process, and the result of my work is an easy to use ruby script, detailed below.

Read the rest of this entry »



Fun with instance_eval

30 June 2009

Recently someone asked for a combination discount at the RailsKits store -- he wanted to purchase both the SaaS Rails Kit and the Helpdesk Rails Kit to get his site rolling quickly. I didn't have combo discounts at that time, but I figured that was a good excuse to build that feature into the store. :)

Previously when I have implemented combo discounts for my clients in their e-commerce platforms, I would do so by creating models that stored the combinations and the products that make up those combinations. These models would contain info like what quantities of each product were required, if one product out of a set could qualify for a combo, etc. It can get complicated fairly quickly.

This time, though, the client was me, and I'm comfortable with Ruby, so I decided to simplify the code by simply allowing the store administrator (me) to use Ruby to specify the rules for qualifying for a combo discount. In this case, instance_eval came in quite handy.

I already had a Coupon model, so I just added a text field named conditions to store the code that would be evaluated in the context of a cart instance. Then in my Cart model, after checking that a coupon was otherwise available, I ran instance_eval on the contents of that conditions field. That allowed me to create a coupon that requires at least two items in the cart with prices above $100 quite easily:

line_items.select {|i| i.unit_amount > 100 }.size > 1

It was fun to be able to implement something that can be hairy in just a few lines of code, thanks to the awesomeness of Ruby.

BTW, if you are interested in using that discount -- 15% off! -- just enter the discount code 'combo' (without the quotes) during checkout while shopping for excellent Rails code.



Taking snapshots of web pages with Ruby

22 May 2008

Last summer I had a client project that involved customers using a web application to create web sites that were themed (think hosted CMS or hosted blog), and the client wanted to provide screenshots of how the hosted site would look before the customer purchased the site and actually got access. My solution was to create a ScreenShot model that belonged to the Site model, and the screenshot images were stored via the ScreenShot model.

The fun part was that the client wanted the best-looking shots, so that meant using webkit on OSX, and the OSX box wouldn't be in the same datacenter as the servers running the web application. I ended up using Drb to send the screenshot requests to the shooter, which then used Net::HTTP to upload them back to the web application. :) It was a fun project.

I was reminded of all this when Tobi recently blogged about doing something very similar. Though my code for taking screenshots doesn't meet his requirement for it to run on Linux, I thought I'd share my code anyway for others who don't have that requirement.

As usual, I'm standing on the shoulders of giants here, as most of the heavy-lifting was done by others -- specifically, here and here. I just wrapped their code up in a handy little class I called Snapper. Enjoy!