Tuesday, June 17, 2008

'Temp'ting

I was working on a personal project. I needed to create my outputs in temporary folder. How do we get the temporary folder path in Ruby?

In Windows, we have an environment variable named TMP or TEMP to point to the temporary folder path. In order to access environment variables, Ruby defines ENV object. So

ENV['TMP']

would get me the temporary folder path. But this is windows only. Linux need not have this environment variable defined. So we need some other portable technique.

As you would know, it is easy to create a temporary file using Tempfile.

require 'tempfile'
tmp = Tempfile.new('foo')

It is portable way of creating a temporary file. A temporary file will be created in temporary directory. Tempfile also has a neat path method which would help us.

require 'tempfile'
tmp_path = Tempfile.new('foo').path # we got the temporary directory for any platform

But wait. Creating a dummy file just to get temporary folder path? Yuk. There must be a better way. Hey, you know what? There is a better way.

I almost forgot Ruby is open source. We could take a look at tempfile and see how they did it. Here is what we get. I simplified it a little bit for readability.

require 'tmpdir'
class Tempfile
  def initialize(basename, tmpdir=Dir::tmpdir)
  end
end

We have tmpdir library, which has a neat Dir::tmpdir just fit for our purpose. Let's just try it out with our little friend irb:

irb(main):008:0> require 'tmpdir'
=> true
irb(main):009:0> Dir::tmpdir
=> "/tmp"

I got what I want. I don't have time to snoop around further and see how Dir::tmpdir gets the temp path portably. May be some other time...

Wednesday, June 11, 2008

Windows Tools Without Which I Will Feel Handicapped


Right tool for the right job makes a lot of difference. I usually believe one big difference between the professionals and the ordinary is the tools and the way they are used.

I have to use windows at work. I am not happy with the 'default' windows. So I am in constant look out for better tools. Here are some tools I use regularly that might help you. This list is for anyone who uses windows.


Notepad++
I cannot work without it. It is very useful notepad replacement. It has tabs, syntax coloring, and plenty of features. Open source.

Launchy
Takes a big pain out of windows. Stop searching your programs in Start-->Programs. Open source.

Safarp
Small and fast replacement for the Add or Remove Programs dialog of Windows 2000/XP. Open source.

PDFCreator
Adds a new printer entry. If you print your file with that printer, you will get PDF file. Open source.

Ruby one click installer
This is all you need to start coding in Ruby on windows.

TortoiseSVN
Subversion source control (better CVS), which you can run from Windows Explorer. Easy. I use it for my code backup until I check in/commit to common source control. Open source.

SuperCopier
"SuperCopier replaces windows explorer file copy and adds many features, Transfer resuming, Copy speed control, Copy speed computation , Better copy progress display, Copy list editable while copying , Error log, Copy list saving/loading,..." Another must have windows tool. Open source.

VLC media player
The only media player you need. Open source.

Winmerge
Visual text file/folder comparison tool. This is another tool I cannot work without. Open source.

Netbeans IDE
The IDE I use for coding in Ruby. Open source.

CCleaner
A system optimization and privacy tool. It removes unused files from your system - allowing Windows to run faster and freeing up valuable hard disk space. It also cleans traces of your online activities such as your Internet history. But the best part is that it's fast (normally taking less than a second to run). Freeware.

Clear Type Tuning control panel applet
Improve your fonts display for your LCD screen. In windows xp the clear type is turned off by default. I have seen so many people don't make the best use of their costly LCD screen. Turn it on and improve the display with this goodie.

Defraggler
Hard disk defragmentation tool. You can defrag individual files. Freeware.

Recuva
Recover the files you have mistakenly deleted. Freeware.

Orbit downloader
Better download manager with Firefox and IE integration. Freeware.

Unlocker
It shows whether the file is in use by an application and provides a way to unlock. Freeware.

Wordweb
Best free English dictionary for windows. Quite handy. Freeware.

FastStone Capture
Screenshot utility.You can even do your arrows, text, and other markings for your screenshots easily. I think versions newer than 4.8 are not free.

And of course, Firefox, one of the finest of the browsers!

What stuff you have in your tool box? I am also interested to hear about better alternatives to the above tools.

Thursday, June 5, 2008

Technical Reading & Heavy Weight Books

This is the blog entry I have posted at TWINCLING.

I love reading technology books. But whenever I see a bulky technical book I stay far away. By bulky I mean the books that you cannot read by lying on your couch. Many people tend to believe the bigger the book the more useful it would be. It is incorrect. In my experience, the technical books have a paradoxical aspect.

"The thinner the waist line of the book, the more you learn from it"

It is natural to think the more pages a book contains the more information it has. But the question here is 'how much you can learn from it?' How many of us have Technology XXXX Bible and those biggies-with-reddish-jackets in their personal library? I could never imagine reading any of them completely.

Think about it. I had to pay more money to buy these heavy weights since publishers seem to think the price of the book in terms of number of pages. I cannot read them at my convenience (Possibility to read the book while lying on the couch is a major criterion for me!). I have to spend more time to read them. And God knows how much I read is really useful to me, not to mention the space they invade in your book shelf!

Okay. Biggies make good reference books then? Nope. I would still stick with the humble ones. Thinner reference books are much more handy than the giant alternatives. If small reference books are not sufficient, web would be the best place to head to, not those inconvenient 'complete references'.

Of course, there are exceptions to this. Occasionally I come across wonderful books no matter how big they are. 'Head First' books are the ones I am really addicted to. They are slightly big but they are the most entertaining and very practical technical books I have ever read.

I will wrap it up with a short list of my all time favourites:

  1. Effective C++ by Scott Meyers (288 pages) – This is the book that got me hooked to technical reading. The chapters are short and arranged like simple recipes. Scott Meyers is a master technical writer. The technical world need more such writers. (Is he writing anymore?)
  2. Design Patterns by GoF (416 pages) – GoF has changed the way I thought about software with this book. Good literature on software design is hard to find. I believe this one belongs to every developer’s book shelf.
  3. Head First Design Patterns by Freeman (676 pages) – Another design pattern book. It is graphical. Funny. But seriously very technical. It is not a kind of book you will just read. You will work with it. You will laugh with it. When it is all over, you will realize you have really learned something.

Coincidentally, all these books won the prestigious Jolt award. You can expect quality technical writing from Jolt award winning.

Feel free to share your ideas on technical books, and of course I am interested to know about your favourite books.