Archive for the 'Programming' Category

Ruby: Bad interpreter

Saturday, September 8th, 2007

If it ever happened to you to see a message like below starting your shining Ruby script from the Unix shell, you probably know how disappointing it can be.

: bad interpreter: No such file or directory

Yesterday I wrote a highly useful helper tool on Ruby, but every time I tried to start it without explicitly mentioning a Ruby interpreter in the shell command, it gave me the above error. Truth be told, it looked confusing; it almost melted my brain. The script had the correct shebang! pointing exactly to the interpreter, and I could invoke it manually using that path, but for some mysterious reason it refused to work alone, like this:

./script.rb

After a grueling scanning of forums I managed to find a blurry explanation and a dirty trick to fix this quickly. The thing is, the trailing ^M codes in code lines make the shell through out the error. The only way to fix that is to remove all these codes. Doing so manually is a pain, I know, hence the little shell command that I would love to share with you today.

Assuming the script name is “script.rb”, it looks as follows:

cat script.rb | tr -d '\15\32' > script.rb

The code dumps the script file into a pipe to the ‘tr’ command that cuts out all ^M’s and routes the output back to the script file. Hope you’ll find it useful.

Rails: vs. …

Friday, September 7th, 2007

Handsome guys from Rails Envy do a series of hilarious videos under the common “Rails vs. …” theme. I checked their latest “vs. PHP” and “vs. .NET” videos yesterday and have been laughing since then even when I slept.

If you have a healthy sense of humor, you are a Rails fan or simply ready for light critics, go ahead, check it out:

Also check their earlier flicks:

Don’t take it serious. I mean guys are having fun and exaggerating it a bit, but it looks like true more or less. Enjoy!

Rails: Exception Notifier plugin

Friday, September 7th, 2007

Found this one. It sounds like a great idea to use a notifier in the production environment and get all the errors and unexpected situations in your mailbox.

Before now, I was sitting in the environment logs forever trying to find my way through tons of debugging records, now it all becomes a bit more straight-forward. Check it out:

Exception Notifier

Rails: Excellent Resource for Trouble Shooting

Wednesday, August 15th, 2007

You know that I’m charmed with the simplicity and the development convenience of Ruby and Rails. I like how the authors of Rails thought out every little detail of their framework bringing it complete and consistent. The flexibility of Ruby language is so extreme that it makes every framework be more or less general for the effective use outside the boundaries set by the author. However, this very flexibility may turn the blessing into a curse, if you don’t know what to expect and where to look for answers to your questions.

Yesterday I found a growing, yet quite loaded, collection of links and cheat-sheets around the Rails kingdom. They all are nicely organized and easy to use. Hope you will like this little chest of knowledge and thank Ryan for his invaluable contribution.

Best of luck to everyone and have fun! Life is SO GOOD!

Ruby: Testing private and protected methods

Thursday, August 9th, 2007

Every time I think I have already seen all the major wonders of Ruby, I stumble upon something like this.

Ruby continues to teach me one important lesson — BE CURIOUS. I am… by nature, but I still notice a tremendous change in working habits — following what-if and is-it-possible models more often than usual. I used to evaluate the answers on these questions basing on my knowledge of the language. With Ruby things start to look different. The flexibility of syntax is so high that I seem can’t build the complete mental model of the language (like an interpreter embedded in a head) and quickly answer what’s possible and what’s not. It makes me to go Googling more and more to find existing solutions. Sometimes (as in example above) they are so elegant that it makes me cry.

Old man’s note: This workaround for calling private / protected methods smells to me. How they different from public methods then if all you need to figure out how to call that you weren’t supposed is only two more grams of brain cells. Hmmm. Do I get it wrong?

Rails: Installing (Freezing) a GEM in your application

Thursday, August 2nd, 2007

Sometimes you need to install a gem in your Rails application for distribution.

If it’s installed as a Ruby gem in your system and you need it to be packaged with the Rails application (/lib or /vendor/plugins directories), go to the target folder and do

$ gem unpack gem_name

If it’s not installed yet, you need to install it first like below and then do unpacking.

$ gem install gem_name

I also found several pages that may be interesting:

Rails: Malformed header from script

Sunday, July 29th, 2007

If you developed your application with WebBrick, deployed it to Apache and seeing something like below in your web server error log, make sure to check that you don’t have any output to console (like ‘puts’) left in the code.

[Sat Jul 28 07:11:05 2007] [error] [client xxx.yyy.zzz.xxx] malformed header from script. Bad header=["a"]: dispatch.fcgi

Whatever you output goes to the header section of the response and most probably the web server won’t understand it.

BB Plug-in: Pins Archive

Friday, April 27th, 2007

Many times I felt that I wish to mark some article I stumbled upon to get back to it later, or what’s better to save it somewhere for continued reference. There’s no doubts there are many of us in this club.

As you may know, I’m working for BlogBridge these days. Recently, we added a shining new wonderful plug-in framework that lets you or any 3rd party coder extend the functionality almost in a boundless way. Personally, my head is swelling with ideas to the point of explosion. That’s the main reason I’m starting the page where I publish extensions I write for the application. Be sure, I use them actively myself, so that’s not just a metaphysical exercise — it’s very serious stuff. Treat it accordingly. :)

Alright, that was a bit of introductory blah-blah, and here’s the real meat:

You can find the details on the plug-in page, but trust me, it’s that you always needed. :)

Have fun!

Post Tools Wordpress Plugin

Thursday, November 9th, 2006

The second plugin for Wordpress — Post Tools — has just been deployed. It’s a very concise collection of methods for convenient fetching posts assigned to categories. For example, I use them to fetch three random quotations for the BlogBridge site front page. Other potential usage is selecting top N posts from a news or announcements category.

Wordpress Plugins, Random Screens

Wednesday, November 8th, 2006

I’ve just created a section for Wordpress plugins I build. Hopefully you will find something interesting there for your own blog or blog-based site. Most of my creations are running for the benefit of the BlogBridge official site and prove to work well under high pressure.

I decided to release the Random Screens plugin first. It’s named this way because initially it was intended to pick up a screenshot of the BlogBridge application from the collection at random and show its thumbnail on a page at a specified place. The thumbnail would then be linked to a bigger image. Every time you refresh a page, a different picture jumps out. Very simple and nice.

Have a look, maybe it’s what you always missed.