Debugging delayed_job jobs from within the console

Did you ever want to step in with the Ruby debugger to fix or inspect
a background job? Here’s how:

DISCLAIMER: Tested with delayed_job 2.14. Should work with recent
versions, too.

Open a rails console within your project

$ rails c
Loading development environment (Rails 3.2.13)

Initialise a delayed_job worker, and make it output to console by
passing {quiet: false} to its initialiser.

1.9.2p325 :001 > worker ={quiet: false})
 => #

Start the worker

1.9.2p325 :002 > worker.start

Now you can put a debugger statement into your jobs and debug nicely
without using loggers.


Where am I now?

It has been two year since my Google Code-In participation in 2010, and today the 2012 grand-prize winners were announced.

That event help me as a milestone my life. I look back to it, to remember what I achieved when I hardly had any programming skills.

What happened in 2 years professionally?

  • I am proficient now in Ruby and JavaScript, and learned a dozen different programming languages.
  • I worked with start-ups, companies and awesome clients, gathering the important social skills I hadn’t had before, and getting to know the frustrations working with bad clients, freaky time-schedules and bad pay, so-called “experience”.
  • Launched various projects.
  • Continuous contributions to Open-Source.
  • I write better code, but it still sucks, just less than before.

Still I feel mediocre. I feel like I could have contributed more, learned more languages, met more cultures, played less games, studied more for college, done more ambitious projects.

Though, I firmly believe, fighting mediocrity has been the most important challenge I have picked up ever since I know that I am just as any other guy, and that I am fully motivated to kick ass.

Byte for Byte.


Show latest commit ID in Rails

I find it useful to display the current git commit ID of my application:

In your application’s Gemfile add the grit gem, which is a Ruby wrapper for git, and run Bundler.

If you deploy your web application via Capistrano and git, then you can put the following in your app/helpers/application_helper.rb:

[gist id=3679774]

Make sure the repo you are deploying to is non-bare. If you are not sure about that, in the project’s directory run:

[gist id=”3679892”]

If you see a SHA-1 Hash, life is good.

Now in your template you can add the helper anywhere you like – most people prefer to put that info in the footer:

[gist id=”3679825”]

How easy was that!


Sencha Touch 2 JSONP response with Ruby on Rails

I had a hard time how to make JSONP response data render in a Sencha Touch 2 list view, but I made it. WOOT.

Maybe, truth to be spoken, I had a harder time figuring out how JSONP actually worked. I had to understand that I had to wrap the JSON object into a JavaScript callback function and change the content type of the response to “text/javascript”. ( I still don’t get it. ;) )

So, here’s the code:

The last line of the the index method will be clear when you understand read the query string parameters which Sencha sends to the server:

and, ultimately the Sencha Store object:

I wonder if you can write a more elegant method?


Why Evernote sucks

I love Evernote, and I hate it for taking notes. Seriously, the concept is great, but the editor does not fit my needs.

I am not very picky, there are just a few things about Evernote that need to be fixed:

  • Documents have no semantical structure. There are no sections. Plain text is as intelligent as an Evernote note.
  • Outline support. Even headlines would be acceptable.
  • Table of contents. Notes get large and messy; scrolling and searching (and not finding) will be unavoidable.
  • Export notes. I want to create a spreadsheet whenever I feel like doing so.
  • No one needs fonts (at least I never needed them); I just want to write down notes and capture ideas.

Obviously, there are some things Evernote got right:

  • Cross-device. Don’t want to take out your laptop? No prob. Just take a note from your iPhone.
  • Developer API. There are some awesome 3rd party services built on top of Evernote. Lastly I have discovered Hello which keeps track of people you meet and automatically syncs to Evernote.
  • Voice memos.
  • Image scanning

I am feeling so dirty…

I am aware of a premium version, but it doesn’t fix any of the current issues. Awkwaaard. So, I am still waiting for a miracle, (or for a person who joins me on the next Evernote-killer project).

If you know something similar to Evernote tell me about it.

In the next post I will compare Evernote with org-mode, and talk about why it’s so much better, and should be far more popular than Evernote.


Facebook Puzzle #4 Solution – Breathalyzer

After reading this part of the the puzzle’s description:

A change is defined as replacing a single letter with another letter, adding a letter in any position, or removing a letter from any position. The total score for the wall post is the minimum number of changes necessary to make all words in the post acceptable.

I was immediately reminded of the Levenshtein algorithm I read earlier in the PHP documentation.

Ironically, I didn’t come up with a solution in PHP, but Python:

[gist id=1377213]

Here are some sample benchmarks:

$ time python "hello world"
0 0 real 0m0.235s user 0m0.170s sys 0m0.020s

The program processes all the words quite fast if they are found identically written in the list.

Here is the the levenshtein algorithm in action:

$ time python "hellofdsf worldtra"
3 3 real 0m1.121s user 0m1.110s sys 0m0.007s

Just above a second… passable.

I want it to actually do some work, so let’s throw the phrase found at the puzzle’s page to the program: “tihs sententcnes iss nout varrry goud”

$ time python "tihs sententcnes iss nout varrry goud"
1 2 1 1 2 1 real 0m4.092s user 0m4.013s sys 0m0.070s


4 seconds! I haven’t benchmarked other solutions, so I cannot say if my implementation is one of the faster or slower ones… so leave your comments about your solution (and also some rocking benchmarks).


Emacs Dired Mode – The Basics

I did not tend to use Dired mode often, as I was not aware about its usefulness. After digging in I found out it is really easy to use and can save you some time when managing files.

So, I shared my experience by creating this video:

You can also watch it on Vimeo:

Please, do leave your comments! :-)


My first impressions of the Play! Framework

Lately I have been searching a Java web application framework to develop a Competition Manager, which you can fork here. As my fellow schoolmates only had some experience with Java it had been an indispensable requirement to use Java, and Play! (the commonly used shortcut for “Play! Framework”) really seemed to be an interesting approach.

The name, at first, made me a little skeptical about the seriousness of the project, but pretty soon I knew that the people behind Play! were exceptional professionals with goals.

I remember having tried other Java web frameworks like Struts or Spring, but I couldn’t see my own code anymore amongst dozens and dozens of XML configuration files to set up your database, and start writing your application logic. I eventually gave up on those, and gladly found that there was a Java framework written by web developers for web developers: Play!

Having a strong Django and a not-so-strong Ruby on Rails background, picking up Play! was a real charm. Play! features a built-in server which allows you to run a Play! application with just a few keystrokes after installing it.
Instead of ./ runserver I just had to type play run in a terminal, and voilá, a local development server was running on port 9000.

I appreciated the excellent NetBeans integration, which allowed me to use a full-fledged IDE. The good thing about that is: it’s entirely optional.
It is just a matter of typing play netbeansify in a terminal, but those who had tendencies to other IDEs or text editors were generally well served.

Certainly the very best thing about Play! is that it is Open Source software, and straight after that the awesome community. It has a very active mailing list to which I have been subscribed for a month or so now, and the response time feels good. The people are awesome and helpful.

I don’t really want to go through all the awesome features of Play!, but you can do that yourself! Visit the website, watch the introduction video (I fell off my chair after viewing that) and start your own Play! application. Today.