All Posts

Page 20 of 21

Quick: Get random record efficiently in Rails

You could use SQL’s random function (RAND() or RANDOM() depending on database engine) - but this isn’t database agnostic, so isn’t really very quick. Instead you can use @nzkoz’s suggested method: Widget.first(:offset => Widget.count) …. the count() method is fast, and the first() method will limit it to the first result in the SQL as well.

ImageMagick: Cropping then Resizing a PNG

I’ve been working on an image processor class for work, and recently ran into this issue. I thought I would post it up here as normally I need to be quite desperate before I start trawling through email mirrors - hopefully somebody comes across this post first. If you use ImageMagick (in particular, in conjunction with MiniMagick), then you may...

Using setInterval to handle scroll() events

I’ve just added a nice unobtrusive scroll to top feature to my blog, and learnt an interesting tip in the process I thought I would share, originating from one of the many problems Twitter has had with it’s jQuery fanciness. The scroll to top stuff isn’t overly complicated - just detect when the user has scrolled x pixels down the...

Accessing controller instance variables in model (Urgh?)

I can tell that this title alone will irritate a lot of developers out there. It irritated me as well, until I figured out that sometimes, doing things the ‘wrong’ way is the best/only way. But let me get on with things. Every now and then, you will come across a scenario where you need to access something in the...

I18n ALWAYS escapes dots in chained backends :-(

Just a quick tip I’ve come across while browsing through the comments on a Railscast_I’ve_been_watching. It looks like the I18n gems that get automatically installed with Rails 3 have a teensy bug. When storing a translation to the backend (be it YAML, Redis, whatever), there is an :escape option that can be passed to enable (or prevent) the key from...

Spree Hosted Gateway

Spree Hosted Gateway is my second ‘big’ extension - one of the ones that isn’t just adding one or two bits of nice functionality, but actually and end-to-end solution to add something that I think would be useful to a broad range of Spree developers (My first was spree-import-products, see my post on it here). Spree (for those of you...

Running Rake tasks with Cron (RVM)

Recently I’ve had to deal with a strange problem with rake tasks being run using Cron, a UNIX tool for running commands on a scheduled basis. The problem was basically the server being slowly strangled of resources across a forty to fifty minute time period, as each time the rake task was run it would leave an entire bash process...

OK, So I Was Wrong

OK,_So_I_Was_Wrong So I was just flipping through my archives of blog posts, when I found this_one my first ever post to Tumblr, where I vowed to stop posting enormously long essays on silly ideas I have to change the world. Oops. Sorry everyone!

Dynamically Serving Inline Images with Rack

Following an insanely interesting presentation by Steve Souders at Webstock, I began thinking about ways to simplify (i.e. automate) certain processes to optimize performance of sites. Something that immediately jumped out at me from early on in Steve’s workshop (So early, I was able to start coding in the halfway break), was that inline images were an ideal candidate for...

Creating a Scalable Academic Signup System

While working at 3Months as a developer, I am also completing a Bachelor of Business Information Systems at Victoria University. One of the things that rolls around twice a year and always causes students headaches is the signups system - it’s one of the bragging points of the School of Information Management at Victoria, as it was build as a project...

Page: 20 of 21