How to Run a Rake Task via Cron Under RVM

Cron needs to be explicitly told which RVM to use, the easiest way to do that is to pretend to open up a bash shell (as all the pre-reqs are loaded by default).

Save your afternoon and reuse the following in your crontab:

/bin/bash -l -c 'cd PATH/TO/RAILS/APP && $HOME/.rvm/gems/THE_RVM_RUBY_TO_USE/bin/rake RAILS_ENV=production THE_TAKS:TO_RUN --trace'

for me, it looks like this:

*/5 * * * * /bin/bash -l -c 'cd /srv/www/app/ && /home/garrick/.rvm/gems/ruby-1.8.7-p370@global/bin/rake RAILS_ENV=production cron:parse --trace'

huge thanks to Edgar Gonzalez, Hector Castro, Murtada Shah

Adding Custom Fields to an Existing Post via XMLRPC in WordPress

If you’re having difficulty adding custom fields to an existing WordPress posts via XMLRPC’s metaWeblog.EditPost command, try including a dummy entry in your code.

It worked for me.

I’m working on a project where we’re programmatically adding WordPress custom field data to thousands of posts, seemed like a great job for XMLRPC. I had assumed a simple Ruby call like this would work:


result = server.call('metaWeblog.editPost', wordpress_post_id, name, pass, {"custom_fields" => [{"key" => "note", "value" => "loves you"]})

It doesn’t – it gives a less than happy Error 500 ‘Sorry, your entry could not be edited. Something wrong happened.’

I read through WordPress’s xmlrpc.php file and noticed that the update post command is run (line 2460) before any of the custom field data is recognized (line 2476).

So, I added a line to not change the Post’s title, and new custom fields were added as expected.


result = server.call('metaWeblog.editPost', wordpress_post_id, name, pass, {"title" => POST_TITLE, "custom_fields" => [{"key" => "note", "value" => "loves you"]})

Fontue Font Optimization Workflow – Open Sourced

With the Fontue web font server open sourced, I’ve done the same for the workflow scripts I use to to generate the fonts for @font-face use.

It’s a pair of scripts that pipe fonts in and out of other conversion programs like FontForge, sfnt2woff, Batik, and EOTFast. Along the way, doing a little clean up of the font file itself.

These workflow scripts are now included in the Fontue source code.

Kernest’s Web Font Serving Engine – Fontue – Now Open Source

I’ve talked to a number of people and organizations that want to start adding web fonts to their websites – but aren’t comfortable relying on a third-party service for something so integral to their online presence.

With that in mind, I’m pleased to announced that Kernest‘s underlying web font serving engine – dubbed Fontue – has been released under the MIT License.

Fontue is designed to be the lightest, fastest way to serve web fonts to @font-face supporting browsers while saving bandwidth and keeping CSS clean and readable.

Get more information at Fontue.com or download the latest version from Github.

Installing ImageMagick & RMagick on OS X 10.6 Snow Leopard

This marks hour 4 of setting up ImageMagick & RMagick on my MacBook Pro – without MacPorts (MacPorts and I had a falling out years ago).

In an effort to save all of us that time, here’s how I got ImageMagick and RMagick working on my MacBook Pro running 10.6.2 Snow Leopard

  1. Download and unpack masterkain’s install script from github: http://github.com/masterkain/ImageMagick-sl.
  2. open up a terminal, cd into the install script’s directory.
  3. run ./install_im.sh .
  4. Let it run. Note – you will need to provide your admin password a couple times.
  5. Give the kids a bath.
  6. Download and unpack RMagick (I couldn’t get the gem to work)
  7. cd into the resulting RMagick directory and run ruby setup.rb config --disable-htmldoc
  8. then, provided no errors are thrown run sudo ruby setup.rb install

Update:
ImageMagick didn’t correctly guess the location of the Ghostscript fonts and threw the following error in my log when it ran

Magick::ImageMagickError (unable to read font `/usr/local/lib/ImageMagick-6.5.8/config//usr/local/share/ghostscript/n019003l.pfb' @ annotate.c/RenderFreetype/1043: `(null)'):

To fix this, navigate to ImageMagick’s config directory in the terminal, cd /usr/local/lib/ImageMagick-6.5.8/config then open up configure.xml in your favorite text editor. Then look for --with-gs-font-dir= and set it to the correct path (in my case I just appended /fonts to the path).

Passenger + Sinatra Tip: DocumentRoot is Always /public

I was getting 403 errors after deploying my newest Sinatra app with Passenger.

Turns out Passenger assumes and requires a /public folder.

This app is so tiny and new, it didn’t have one yet – so I was pointing Passenger at the app’s root. Resulting in the 403 errors.

Solution: Create an empty /public folder and restart Apache. Ta Da. Like magic.

If you’re still having issues – confirm your LoadModule passenger_module path is correct, mine looks like this:
opt/local/lib/ruby/gems/1.8/gems/passenger-2.2.7/ext/apache2/mod_passenger.so

After updating the Passenger gem to 2.2.7, my LoadModule path was way off, not helping the deployment troubleshooting efforts.

auth via params API Access with Authlogic

Authlogic, my current favorite Ruby-based authentication library and I were in a fight the last couple of days.

I was trying to add token-based, auth_via_params, authentication (vs. login and password) to a project – but Authlogic and I weren’t agreeing on how it should be done.

I had assumed:

@person_session = PersonSession.new(single_access_token => params[:token] )
@person_session.save

Instead Authlogic wanted me to give it a Person first.

@person_session = PersonSession.new(Person.find_by_single_access_token(params[:token]))
@person_session.save

Introducing: RE07.US – The Greenest URL Shortener

re07

According to a recent post by FuelInteractive.com, a link in Twitter is clicked for 5 minutes, then completely ignored.

That got me thinking about all the wasted short urls out there. So many tinyurl, culld.us, is.gd, et al, links just collecting dust after all that initial clicking.

Seems so wasteful considering “the current economic climate”. Maybe, we don’t need all those URLs. Maybe we should tighten our belts and limit ourselves to 1 short url – and continually reuse it.

With that in mind, I built HTTP://RE07.US. It’s 1 short url that we can all share.

All long URLs get shortened to the same link: RE07.US. And, it will be shortened to that – until someone else shortens their long URL to RE07.US. And so on and so on.

REDUCE. REDIRECT. RECYCLE.