Tagged "ruby"
Quick & Dirty Image Resizer with Ruby and RMagick
#ruby #threading #multiprocess #script #shell
I needed to resize a folder of images the other day. So I wrote this handy script: Update (08/10/12) — I had a conversation about shaders and threading with a SIGGRAPH attendee on a flight from LA back home. As a result of that conversation I've decided to multi-thread this script in an effort to make it faster. In the process I beat the crap out of my MacBook Pro but it took the beating like a champ. Thankfully this made me realize that the Ruby garbage collection wasn't working fast enough. So I added some code to free the image resources when they were no longer being used. This had an added benefit of speeding things up even more. I found the Parallel gem which made the multi-threading part of it insanely easy. See for yourself below.
Complex Default Values with Rails 3
I needed an extensible way to default values for new models in Rails 3.0.5 so I went Googling. I ended up finding a great question on StackOverflow. (of course) So I got started with the help of the answers on that question. I first tried the before_create callback but soon realized that it only fires when you save a new record. I needed the model (A) to auto-generate associated models (B) when a new instance of the model (A) is created. So the correct filter for that is after_initialize. I called my callback method set_default_values() and used it on my abstract super class (A) and the classes (C,etc) that inherit from it.
Lehigh Valley Ruby Meetup Notes 2011/03/02
Notes from the March second LV Ruby Meetup group. We built an 'IdeaShouter' app with haml, sass, and compass. By the end of these notes you should have built one too. Companion code can be had on github.