Programblings

Rambling about programming and life as a programmer

Archive for October, 2007

JRuby, not in its setting (or configuring jirb under Windows)

Posted by webmat on October 18, 2007

Update: This article has has a new home on programblings.com. Go to the article.
Comments are closed here but still open there :-)

For a good while now, I’ve been using Ubuntu on my main home machine. Working with Ruby and JRuby on Linux is a charm.

Tonight, as I tried to set myself up to work with JRuby on Windows*, I bumped into an annoying problem. When I tried to configure jirb, the JRuby version of IRB, it didn’t always seem to find the .irbrc config file in my home directory. I looked a bit on the ‘net and found nothing that helped me solve my problem. I’ve worked out a fix, you can follow along in this wonderful adventure.

So to configure irb, I create the .irbrc file in my home directory.

C:\Documents and Settings\Mat\.irbrc

Note: Windows will yell at you if you try to make a new file starting with a “.” in windows explorer. Just use any good text editor to create it directly.

In it I put some configs for auto-completion and auto indent, as suggested on the Tips and Tricks page on the Rails wiki:

IRB.conf[:AUTO_INDENT] = true
IRB.conf[:USE_READLINE] = true
require 'irb/completion'
puts "Yay! Completion's loaded!" #Uhh, that's my special debugging code :-)

Now I fire up a console and start the interactive Ruby shell with

C:\Documents and Settings\Mat>jirb
Yay! Completion's loaded!
irb(main):001:0>

Hmmm, it works. What am I yelling about? :-) Let’s say we fire it up in an actual project directory instead.

C:\projects\an_actual_project>jirb
irb(main):001:0>

Oops! My “special” debugging code isn’t executing now :-)

If you care to see what’s the code that hints at how to solve the problem, you can open

…\jruby-1.0.1\lib\ruby\1.8\irb\init.rb

Or check it out a snippet of IRB.rc_file_generators online.

As we can see, if the HOME environment variable is set, the method looks for .irbrc in the directory, otherwise it looks for it in the pwd (present working directory).

Nice! That explains why it works in my home and not elsewhere :-)

So now I just have to set a HOME variable and I’m all set:

home.png

Now after restarting my console (to have the updated environment variables):

C:\projects\an_actual_project>jirb
Yay! Completion's loaded!
irb(main):001:0>

Note that even though Windows variables are not case sensitive, you must name your HOME variable in capital letters. Ruby expects the ENV hash to contain the HOME variable in caps.

* Q: Why would I want to set this up on Windows, if I’ve got a perfectly good Linux setup at home?

A: I’ll be giving a talk about JRuby at the next Montreal on Rails, and since I haven’t really needed a laptop in at least two years, well, I only have 3 years old laptop. This old geezer can run equally old versions of Linux, but I wouldn’t like my audience to have to suffer the visually challenged distro I currently have on there.

Posted in garbage out, programming, ruby-rails, windows | Tagged: , , , | 2 Comments »

Using Windows? Try Powershell!

Posted by webmat on October 16, 2007

Update: This article has has a new home on programblings.com. Go to the article.
Comments are closed here but still open there :-)

Recently, at work I’ve had to implement a couple of simple scripts. They were yet again not simple enough to be captured completely in a batch file. For example I needed to have an arbitrary precision and format date/time that I could use in a file name. date /t and time /t weren’t cutting it.

I thought about implementing a small command-line tool just to give me the functionality I was missing, but it felt too patchy for my taste, this time. I had to use it on other test machines so I wanted to be able to just copy the script without having to update some executable utilities as well.

Sadly I could not use Ruby because my company doesn’t use it, and I don’t want to sneak it in the wrong way. And as I said it was to be used on another machine, so it was not like creating a personal script on my own machine. In fact it even had to be documented in a manual testing procedure.

So I decided that it was time to try Powershell. I’ve been hearing about it for quite a while now, and I heard it’s pretty powerful. Since it’s the future of Windows console/scripting anyway, I figured nobody sane at a Windows shop would yell at me for introducing this particular technology.

Now that I’ve been dabbling with it for the past few weeks, my opinion is starting to form and it goes a little bit like this. If you’re a Windows power user (especially an admin or a developer) and you don’t know Powershell, you’re at a disadvantage :-) The “Power” in Powershell is very well deserved. If you’re still flopping along using batch files, you’re using a weak, error-prone tool where a new, very powerful tool is available. It’s free and it’s by Microsoft, so there’s no reason it wouldn’t be well received in most Windows shops :-)

I decided to capture my understanding of Powershell in an introductory article. In it I explain some of the basics of the language and introduce you to all that’s necessary to get started with Powershell. In the reference section at the end I also mention other good sources of information if you want to learn more. Depending on the amount of fiddling around you do while following along, I guess it’s a 30 minutes to 2h read tops.

So without further ado, Discover Powershell (it’s an order!)

Posted in garbage out, programming, windows | Tagged: | Leave a Comment »

Quick idea to get used to blogging

Posted by webmat on October 6, 2007

Update: This article has has a new home on programblings.com. Go to the article.
Comments are closed here but still open there :-)

I started this blog sometime in August. However, in order to get used to posting online, I already had a tumblr where I could post stupid stuff that occurs to me, come across, hear about or find at the grocery store, even. I think the absent pressure about content quality helped me get the ball rolling.

Tonight I was inspired and even went to the extent of expressing myself in video :-)

Posted in garbage out | Tagged: | Leave a Comment »

Free PDF Rails Book for beginner Rails developers!

Posted by webmat on October 3, 2007

Update: This article has has a new home on programblings.com. Go to the article.
Comments are closed here but still open there :-) 

As seen on the Rails blog, sitepoint.com is giving away free PDF copies of Patrick Lenz‘s book, Build Your Own RoR Web Apps. The offer is good for 60 days. Well, 59d15h at the time of posting :-)

It involves jumping through a couple of hoops, and the book contains a couple of pages containing ads about other Sitepoint books. But nothing too bad, at first sight. And it’s still a free PDF book! So if you know anybody who’s curious about Rails and might want to try it out, you have until the beginning of December to point him/her to rails.sitepoint.com.

Posted in garbage in, programming, ruby-rails | Tagged: | 3 Comments »

Montreal on Rails tonight

Posted by webmat on October 2, 2007

Update: This article has has a new home on programblings.com. Go to the article.
Comments are closed here but still open there :-) 

Tonight is Montreal on Rails #3! I can’t wait to attend: this will be a nice refreshment from my gruesome C++ tar pit at work, ugh! :-)

The first 2 were very interesting and filled with great people to meet. Tonight promises to be just as great, and as a bonus, we’re leaving behind the small McGill University classroom to be welcome instead by Fred and Ben from Standoutjobs. Can’t wait to see that either!

And great big thanks to Mat and Carl for organizing this monthly meetup!

Posted in garbage in, programming, ruby-rails | Tagged: , | 1 Comment »