Working with Resque? perform_later is at 1.0, you should use it

Last night, I released the 1.0 version of perform_later.

Now or later?

The gem is being used in production for over 6 months now, in a big-scale website (Gogobot), so I thought it’s time to put in some extra needed work, some major refactoring and to release 1.0.

What’s new?

  • 1.0 is basically the same in the core functionality, I refactored big bits of the codebase, it’s much cleaner and more readable then before (still need to work quite a bit on code documentation)
  • Added the later method support for ActiveRecord models.
  • Added the loner support, now you can mark methods to be loners, meaning only a single instance of this method can exist in the queue at all times, this is super useful when a user does many actions that will result in say a cache clear for the user, there’s no reason to do a clear more then once. (and there are many more cases like this)

So, right off the README, here’s simple usage for this gem

So, now you can do this:

The best thing about perform_later (not new in this version) is that you can pass in any param, and it will get translated into JSON with no problem.

You can pass in AR objects, hashes, arrays, anything you need, there’s no need to rewrite your methods.

I would love your comments, feel free to contribute issues, pull requests, documentation or anything else.

undefined method `relation’ for nil:NilClass on Heroku

I host almost 100% of my open source projects on Heroku, it’s amazing how easy it is to setup and how “out-of-your-way” they are.

Today, while working on one of my open source project I encountered this error:

It was right after I deployed and migrated the database.

After about 5 minutes of head scratching I came across an answer on stackoverflow saying you have to restart your app after a migration for it to pick up on schema changes.

Had a DAH! moment there :-)

10 Things You Didn’t Know Rails Could do

James Eduard Grey published a presentation of a talk he did in RailsConf.

It is pure gold, so many tips and tricks, I promise you, some of these will be new even to the most experienced of Rails developers.

10 Things You Didn’t Know Rails Could do // Speaker Deck.

Pivotal Tracker Git integration with ease

This post makes 2 assumptions

  1. You are working with Git
  2. You are working with Pivotal Tracker

At Gogobot, we work with Pivotal Tracker (for various reasons).

Pivotal Tracker has very good Git integration, when you commit (and push), the commits can show up as comments to the story.

Another very good thing is that you can change the status of a story just by a commit, you can finish, deliver or anything else you might want.

Usually, you need to add the story id (#12123123) to the commit message yourself, obviously, I never remember to do that.

So, the link in the bottom is a gem that integrates git with Pivotal Tracker very easily and effortlessly.

highgroove/git_tracker.

It has a very good README so keep on reading there.

Decorating Devise’s current_user with Draper – Ariejan.net

A great trick to decorate the current_user method from devise using Draper.

IMHO it’s actually applicable to any authentication system out there that is using current_user but that requires some testing.

Decorators are an awesome way to remove logic from the view or the models, so the models have real business logic and the rest can be “decorated” with another class.

If you are looking for more information about decorators, Ryan Bates has a great screencast about it here: http://railscasts.com/episodes/286-draper

Enjoy

Decorating Devise’s current_user with Draper – Ariejan.net.

Find the source location of a method in your project

Ruby/Rails project sometimes make it hard to find the source location of a method.

Sometimes, Duck typing, meta-programming and just plain bad design make it really hard to find where a method was defined and how.

Luckily, there’s an easy way around this.

So, here’s an example.

A few moments ago, I came across this line:

First thing I did (obviously) was going to the user class and searching for this method. Obvious enough (or this post would not exist) I could not find it.

I immediately realized it’s being defined by some cache mechanism we have.

So, I opened up a console and typed this:

And it returned

So, the method IS defined on the user somewhere, you can see exactly where like so:

This will give you an exact location where the method is defined, I found this line:

This trick saves me time, hope it will save you some browsing around helplessly, especially in bigger non-single-dev projects

EDIT: 12 APR 2012 10:51PM
I posted a link to this post in the dev chat room on Campfire.

Steve, had an awesome comment:

Campfire conversation

We are using Octopus gem in our application (Gogobot), this gem is used to connect to databases with master/slave architecture.

Just as a general warning, you may get some results like that. but if you follow the source location, it’s usually a very good hint of where the method is actually defined and in any case, I think those Proxy situations are rare.

Awesome comment nonetheless, so I though I might update the post with it.

EDIT: 12 APR 2012 11:01PM

Jonathan Jackson replied to me on twitter, he said, that if you are using Pry (which you should) you can actually do it even better.

if you open up the console and do:

This will open up the default editor (Vim in my case) in the exact location where the method is defined and you are able to edit it in place.

Another awesome comment that was worth a post update :-)

Pull Request #5340: Added wrapper tag for simple format, added test by KensoDev · rails/rails

Following my latest post about the simple_format, I think that it’s broken to assume only “p” tags are valid wrappers.

So, I opened a pull request to Rails itself.

Basically, it changes simple_format so you can pass in the wrapper tag you want, I found myself wanting a “div” or a “span” too many times.

Pull Request #5340: Added wrapper tag for simple format, added test by KensoDev · rails/rails.

Enjoy!

Essential Sublime Text 2 Plugins and Extensions | Nettuts+

I switched from TextMate to Sublime Text 2.

Been using it for months now and it keeps surprising me with how fast, smooth of an experience it is.

If you are still using TextMate or something else, you need to look at this post.

Essential Sublime Text 2 Plugins and Extensions | Nettuts+.

Do your own Agile…

There’s a lot of buzz going on about software development methodologies, people talking about Agile, Kanban, Pair, XP and more and more.

There’s not much people are talking about when it comes to a single developer.

I have been a consultant/developer for the past ~3 years or so, working from home for several clients both in Israel and abroad (US mainly).

During this time I gained tons of experience in knowing what works and what doesn’t, this may be specific to me, but I don’t think so, so I decided to share this knowledge. So… what am I doing to keep productive during the day?

Pomodoro

The pomodoro technique I am using is simple, I have a small application running on my Mac constantly (there’s windows versions as well).

When I start work, I simply choose start pomodoro, input what I am going to work on and dive in.

Now, all that’s pretty standard, but I am using it with get-shit-done, so once I start a pomodoro, get-shit-done executes work mode.

This work mode shuts down all outer traffic to time-sinks like Facebook, Twitter, news sites, YouTube and many more.

The script is customizable so I keep changing what I want/need. Along side with shutting down the time sinks, I execute a “busy” mode on Skype and any IM I am using at the moment. This is completely automatic, you can see it in the following screenshots

Pomodoro scripts
IM status change by Pomodoro

As you can see, any pomodoro I do is going into “Things” which I can then look at my day and see where my time went, what did I accomplish during the day and so on (it has OmniFocus integration as well).

If you want to get the app, you can get it here

Stay Hydrated

This may seem stupid so up high here, but it’s REALLY important. I found that in days where I drink and stay hydrated, I am much more productive, less tired and get a lot more done during the day.

Water break

Another benefit is that I need to visit the restroom quite often :) so I don’t slack around in the chair too much. I use an application for that as well, it sits in my top bar and reminds me to take 5 minute water breaks every hour. if you are wired in, you can just ignore that, but don’t ignore it too much, it’s not the point :-)

If you want to get the app, you can get it here

Things To Do

Things To Do

I open every day with a “things to do” list.

I write down anything I need to do, and then I forget about it, I don’t keep my mind occupied with all I need to do, I look at the list during the day.

One important thing is that I set times for stuff

  • 1-2pm => working on the cashier module
  • 2:30-3:30pm => working on the master/slave @dirty variable

While of course, these 2 tasks don’t actually take an hour, it’s here just for an example :-).

Anything you need to remember during the day, write it down, than simply let it go, don’t keep you mind occupied about that.

I keep any blog post idea, stuff that come to mind on other project that are not currently in work order and more…

Knowing I have it written down saves me the trouble of having it in my brain, and I dedicate all my brain resources (which are slim to begin with) dedicated to my code.

I must say, I have tried any TODO app out there, the one that works best for me is a pen and a paper, I use Things as a history for my pomodoros and nothing more (usually)

TDD

Another possible controversial title in a “be productive” blog post :-)

When I am TDD’ing my mind goes into a “small piece” mode, I think only about the next 2-3 steps in what I need to accomplish.

People (wrongly) think that TDD is time consuming and they get less done, I have proven it numerous times in the past that this is incorrect, people that TDD are often 2-3X more productive then others.

Just think about every time you open a browser to “test” something, it can be done in TDD while you save your file, and you can instantly see if you broke something else in the code you are not thinking about.

The right side code is test, left side is actual controller code :-)

TDD your ass off

When you are not productive…

There are simply days when you are not productive on the actual things you need to get done, in these days I don’t try and force myself into it, I simply move to other exciting stuff for 20-30 minutes (sometimes more)

I do a TON of open source, I help people in groups, forums etc..

Sometimes, answering a question, gets me back into code mode and I can find myself wired in for 2-3 hours after it.

To sum up

I touched but a fraction of my work methodology.

The thing is, you need to find YOUR groove, you need to find your pace, the hours where you are productive, the things that excite you.

You may take some of what I said here, you may take all and you may take nothing, all I am saying is that regardless of where/how you work in the team, you can have your own thing going on.

You may work with Pivotal Tracker or Trajectory, but still maintain your TODO list for the next few hours (like I do).

Share your thoughts…

I would love to hear what you think in the comments and have a discussion.