Old Emmanuel Oga's Weblog (new one is at www.emmanueloga.com)

How to spec a rails plugin?

Posted in rails, rspec, Uncategorized by emmanueloga on junio 25, 2009

Basically, the same way you spec a rails application.
The cool trick is you take advantage of the spec_helper.rb of by loading it in the spec_helper of your plugin.

# ../vendor/plugin/YOUR_PLUGIN/spec/spec_helper.rb
  # load your main app spec_helper
  require File.dirname(__FILE__) + '/../../../../spec/spec_helper'
rescue LoadError
  puts "You need to install rspec in your base app"

I took this idea from Pat Maddox’s rspec-plugin-generator. You can use that generator to generate the basic plugin boiler plate for you.

The caveats are, you need to have rspec installed on your main app and you need to actually have the plugin installed in a rails application to test it. In any case, this works for my current needs.

For more info see this post.

Conferencia Locos X Rails tomorrow,

Posted in Uncategorized by emmanueloga on abril 2, 2009

Tomorrow starts Locos X Rails conference in Buenos Aires, Argentina. I’m very exited about it! Yesterday I met Desi McAdam, of DevChix fame, and also the keynote speaker Obie Fernandez, founder of HashRocket. I’m eager to hear their talks, and hope to see you in the conf. too!

Desi and Obie at the press meeting for the LocosXRails conf.

Desi and Obie at the press meeting for the LocosXRails conf.

Tagged with: , ,

ImageMagick vs GraphicsMagick, quick showdown

Posted in Uncategorized by emmanueloga on marzo 13, 2009

ImageMagick vs GraphicsMagick, no strings attached.

[emmanuel@going_merry ~/Desktop/test]
$ gm -version
GraphicsMagick 1.3.5 2009-01-26 Q8 http://www.GraphicsMagick.org/
Copyright (C) 2002-2009 GraphicsMagick Group.
Additional copyrights and licenses apply to this software.
See http://www.GraphicsMagick.org/www/Copyright.html for details.

[emmanuel@going_merry ~/Desktop/test]
$ convert –version
Version: ImageMagick 6.4.9-2 2009-02-08 Q16 OpenMP http://www.imagemagick.org
Copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC

[emmanuel@going_merry ~/Desktop/test]
$ du src -h

62M src

[emmanuel@going_merry ~/Desktop/test]
$ time find src -type f | xargs -I {} gm convert -sample 25%x25% {} ./dst/{

real 0m24.593s
user 0m22.172s
sys 0m1.383s

[emmanuel@going_merry ~/Desktop/test]
$ time find src -type f | xargs -I {} convert -sample 25%x25% {} ./dst/{

real 0m29.137s
user 0m24.888s
sys 0m2.953s

Conclusion: GraphicsMagick 1.2X faster than ImageMagick


Conferencia LocosXRails: falta poco!

Posted in Uncategorized by emmanueloga on marzo 10, 2009

Estamos a poco mas de 20 días para el inicio de la primer conferencia de ruby y rails en Argentina. Todavía no te anotaste? Podes hacerlo mediante la web: http://www.locosxrails.com/registration

Si ya te anotaste, “spread the word” mediante alguno de los siguientes badges:


Tagged with: , ,

Locos X Rails Conference: Registration Opened!

Posted in Uncategorized by emmanueloga on marzo 4, 2009

Locos X Rails

Ya se pueden anotar en la conf. El valor de la entrada es de 300 Argentinos. Claro, antes de anotarse van a querer saber quien va a dar las charlas:


Nos vemos ahi!

Tagged with: , ,

Have you ever been told….

Posted in Uncategorized by emmanueloga on diciembre 28, 2008

…that your code sucks, that one of your ideas is horrible, totally unusable or even (alas) that you or other developers are dumb because they choose to do things in certain way? I have, once or twice…. :-).

Leaving aside the fact that the person proffering those kind of comments has probably not reached maturity yet and/or has not good people skills, there are some good tips to take into consideration when that happens.

I’ve stumbled upon this excellent article:  http://mumak.net/stuff/your-code-sucks.html. I will simply copy-paste cites from it in blue. It talks specifically about code reviews, but we can adapt its tips if we think of a comment like mocking/stubbing is a horrible idea and it can hurt the development process” as if it were a code review… (By the way, David show us in his article the proper way to handle these kind of statements. Excellent post!)

First, don’t take it personally. Very often programmers tend to confuse personal preference with objective worth. I tend to take the “let’s do it your way” path -in cases where there is no harm in doing so- to avoid never ending discussions.

In the positive side of things, consider:

…someone has just tried to improve your product. They’ve put thought, effort and creativity into helping you, and now they have put their work up for critique: thank them.

Divmod have a policy of always saying one good thing in each code review. There is always something nice to say, even if it’s just I’m glad someone is looking at this part of the code

Code reviews provide an amazing opportunity to grow as a programmer and to improve the software we make. Off course! Just because the comment does not come wrapped in a polite sentence does not mean that it is wrong.

At the other side of the coin, If we are the ones reviewing other people work, then:

Ad hominem

This ought to go without saying: review the code and not the coder. Comments about a person will only make it harder for that person to apply critiques about their code.

When making negative comments, refer to the patch or the branch rather than you. For example, You’ve introduced a bug in get_message becomes this patch introduces a bug in get_message.

Unclear Outcomes

If all you say is, this patch introduces a bug in get_message, then you have failed as a reviewer. The goal is to improve the code, not to provide a series of puzzles for the author.

The author should be able to look at a review and be able to tell how to address each point and also when they have addressed all points. Reviews with unclear outcomes turn into open-ended discussions about the patch, which sometimes become focused on making the reviewer happy, rather than improving the code.

Confusing personal preference with objective worth

This is a problem in all spheres of review. Film critics, literary editors and acadamic reviewers all do it. What I like is not necessarily the same as what’s good, although part of becoming a better programmer is having your preferences align better with reality. What I dislike is perhaps even less likely to be the same as what’s bad.

When reviewing a perfectly acceptable patch that solves a problem using imperative-style programming, do not criticize it simply because it isn’t in a more functional style. Doing otherwise makes reviews a game of guess what the reviewer likes rather than write good code.

Reviewers can avoid this trap by phrasing review comments as questions, Did you consider using a more functional style?, Why aren’t you using regular expressions to solve this problem? etc.

I encourage you to read Jonathan Lange’s post, there are a lot of excellent tips on it!

Tagged with: ,

Handling URIs in ruby a walk in the park? Don’t think so….

Posted in rails, ruby, Uncategorized by emmanueloga on octubre 17, 2008

I got sick an tired of juggling around with String urls and URI objects just to get a correct URI for http GETting, POSTing, etc…

For example, if you

Net::HTTP.post_form URI(“www.somewhere.com”)

you get an error…. but if you

Net::HTTP.post_form URI(“www.somewhere.com/”)

(notice trailing slash) you don’t… Boring stuff. The URI lib does provide a normalize method, but it does not always add the trailing “/”. For consistency I wanted normalize to add the trailing slash always. Update: seems like my “consistency” politic is not correct…. Oh, well… at least google does not like it. 🙂 I’m updating my Gist to remove that behavior…. Off course! Adding a trailing slash means you are looking for a directory and not for a resource, so you can’t go berserk adding trailing slashes in all your urls :p

But, the most boring stuff is joining uris and adding query params to them… This should be simple, right?:

uri = URI("something.com/?some=params")
uri.query = "other=params" # WRONG, previous params are overwritten
uri = URI("something.com/")
uri.query << "other=params" # WRONG, previous query is nil
uri = URI("something.com/?some=params")
uri.query << "other=params" # WRONG, params should be joined with & char...

We need to <a href="http://github.com/jnunemaker/httparty/tree/master/lib/httparty.rb#L113">juggle with the URI object</a> to get the job done. More boring stuff. I wrote<a title="Joining an nomrmalizing URIs in ruby" href="http://gist.github.com/17342"> two simple methods to handle these problems</a>. Now I won't have to manually tweak those urls again... never more! (I hope :-).

  describe NormalizeURI do
    it "should add scheme and final / to an uri" do
      NormalizeURI("www.yahoo.com?something=true").to_s.should == "http://www.yahoo.com/?something=true"

  describe JoinURI do
    it "should join a string, an uri and additional query params" do
      one = URI("www.yahoo.com?uno=dos")
      two = URI("/peteco/carabal?tres=4&cinco=seis")
      result = "http://www.yahoo.com/peteco/carabal/?uno=dos&tres=4&cinco=seis"
      JoinURI(one.to_s, two, :more => :params).should.to_s == "#{ result }&more=params"

This is such small stuff I don’t think a gem for this would be cool…. maybe later (no gemspec fighting yet hehe). And yes, because I’m lazy I’m using active_support this time…. I’m using this inside rails anyways.

Tagged with: , ,

rspec 1.1.8 in `exit?’: undefined method `run?’ (rails 2.1.0)

Posted in Uncategorized by emmanueloga on octubre 16, 2008

I had to add this to the bottom of my spec_helper.rb:

  self.class.send :remove_const, "Test" if defined? Test

to avoid this error when running my specs:
Finished in 0.064605 seconds

1 example, 0 failures, 1 pending
/usr/lib/ruby/gems/1.8/gems/rspec-1.1.8/lib/spec.rb:25:in `exit?’: undefined method `run?’ for Test::Unit:Module (NoMethodError)
from /usr/lib/ruby/gems/1.8/gems/rspec-1.1.8/lib/spec/runner.rb:193:in `register_at_exit_hook’

Fake update 🙂 (because I found this while writing this post) : Lighthouse Ticket describing the problem.

A somehow less ugly solution is to require ‘spec’ after you required your library code.

There is life outside google search engine

Posted in Uncategorized by emmanueloga on junio 6, 2008

Wow, I almost forgot about the existence of other search engines. But for chance I stumbled upon this cool command line utility and ended searching for my name on Excite search engine. It showed me a link that I had not seen before related to my nam (dhaka gem).

That gem packages a very cool language parser I used back in the times when I worked with this ancient, ugly language call Natural. It was so awful that I began making a parser to syntax high-lite the my code base (a sort of doxygen for that ugly language). Because I had a very slow machine then, I bothered the guy again and again about the performance of the lib. Is very nice that he list me as a contributor, although and indirect one :-).

Anyway, the conclusion of all things is: I should use other search engines apart from the google one.

Tagged with:

Oh my God! Dave Thomas is an evil Cracker!

Posted in Uncategorized by emmanueloga on abril 28, 2008

Yes, he is a malevolent cracker and I bet he has an evil world dominance plan!

So you want proof? Here! He has a wordlist!


LOL :p

UPDATE: No, he is not… Or at least he has hidden better his word list now :p

Tagged with: