Monday, October 20, 2008

Vim to Postscript

Thanks to Karl for the following tip:

Here's a little Vim trick that might be of interest. If you're on a non-Windows machine, you can make the Vim hardcopy command print to a postscript file instead of a real printer. Try issue the following:

:hardcopy > file.ps

You'll get a postscript output of the file you're currently editing.
From there you can view the postscript file with gv or convert it to a pdf with ps2pdf.

Thursday, October 16, 2008

MySQL DBD in Activestate

I'm currently doing some consulting work to bridge the gap between Oracle and MySQL. Being in a Windows environment, I'm using the Activestate Perl distribution. Fortunately, it includes a nice ODBC module for connecting to Oracle out of the box. The bad news is, it doesn't contain a MySQL module. Luckily, I found a third party host that does provide the module. The following ppm (Perl Package Manager) one-liner takes care of the issue.

C:\>ppm install http://cpan.uwinnipeg.ca/PPMPackages/10xx/DBD-mysql.ppd

The Golden Rules of Recursion

1) never iterate
2) always follow the first rule ;-)

Where I've Been

I've come to realize that my post per day ratio here at Daily Vim is a good measure of how busy I am in my daily life. To be more specific, my workload is inversely proportional to my blogging habits, but please don't think I've forgotten about this blog. I haven't, and the posting will continue. Lately though besides being buried under a mountain of side-work, I've been working diligently alongside the rest of the Grooveshark team to facilitate one of our largest launches in recent memory.

Today, all that hard work came to fruition, and I'm happy to announce that our streaming service, Grooveshark Lite, has been expanded with the addition of the following features.


  • Shared Playlists

  • Blog Widget

  • Improved Social Features (follow users, find similar users, etc...)

  • Music Upload Client

  • Autoplay Improvements

  • More Reliable Streaming


If you scroll down this page, you can see an example of the blog widget in action. The widget builder page allows you to embed a playlist or song of your choosing into any website, size it appropriately, and drop it in. I'll be updating my blog playlist frequently as a means to passively share music that I enjoy.

Back on the topic of Daily Vim, now that things are settling down a bit, I'm hoping to post more often, as I have some cool tips I'm looking forward to sharing.

Thursday, October 9, 2008

Why Ruby is My Favorite Language

I started programming seriously roughly ten years ago. I was working in the call center of an ISP, and there was a need for a reseller tracking application. I was attending the local community college at the time, and had been indoctrinated into the world of computer programming trhough what amounted to vocational training in Visual Basic and Microsoft Access. Fortunately, the ISP was a Linux shop, and a few employees were nice enough to introduce me to the basic philosophy of Linux and assist in learning some rudimentary shell commands.

One of these employees was a Perl hacker, and he assisted in convincing the company to form a small team of three programmers to tackle the programming job. I was lucky enough to be chosen for the position, and to be frank, after having spent a few months in the call center, I would have considered janitorial duties a promotion. The only problem was that I didn't know Perl. I quickly ran to the nearest bookstore, grabbed a copy of Learning Perl, and set to work learning the language. A week later, I was neck deep in the project and thankfully had an experienced programmer to lead me through my first big job. The project was a success, and the team became a permanent fixture at the company.

What impressed me so much about Perl was the succintness, mneumonic friendliness, and consistency of the language. After a few weeks of intense study, I could perform the majority of my daily programming tasks from memory and rarely needed to consult a reference.

A year or so later, PHP hit the scene. With the huge buzz surrounding the language, I figured there had to be something really groundbreaking going on. The team I was working on chose to build a large project in PHP, and once again, I set out in earnest to learn the language. This time, things weren't so easy. While Perl had "sunk in" right away, PHP lacked the natural abstraction I had come to love about Perl. As an example, I didn't understand why PHP needed sixteen sort methods (sort, arsort, asort, krsort, ksort, natsort, natcasesort, rsort, usort, array_multisort, uasort, uksort, dbx_sort, imap_sort, ldap_sort, yaz_sort) while Perl only needed one. The database methods lacked the wonderful platform independence of DBI, and a lot of other things felt redundant. Mostly though, I disliked the way the language encouraged mixing interface with your implementation. At the time, the PHP website frequently featured examples interpsersing functions and HTML and even touted this ability as a "language feature".

Progressing through my courses, I ended up taking a class on object oriented design. I learned about the model view controller architectural pattern and immediately saw it's advantages as a design strategy. I learned the basics of object oriented programming with Perl, but I was dissatisfied with the way it was implemented. I spent a considerable amount of effort learning Java and later Python. I found both languages to be "good enough" in the way they possessed a healthy amount of easily accessible OOP goodness, but I missed the fluidity of programming in Perl and neither ever became a "favorite".

At this point I was working at an environmental laboratory, and I was given complete freedom to use whatever technology I wanted to solve the problems at hand. I was tasked with writing a data analysis and computation software for an ICAP (Inductively Coupled Argon Plasma Spectrometer), and I was again at a crossroads. An article on Slashdot had drawn my attention to the Ruby programming language, and I found an excellent book that was freely available online. Reading the introductory walkthrough section, I was immediately impressed by the fact that literally everything in the language was an object. The core language was incredibly consistent, concise, and well documented with absolutely no cruft. All of the wonderful Perl idioms I'd come to know and love were right there at my fingertips; albiet, in a more readable fashion. I was sold.

I learned the language and developed the project simultaneously. This was long before Rails was even a whisper in the programming world, so I rolled my own MVC style framework containing a presentation layer that used a combination of XML, eruby templates, and LaTeX. This made it easy for the app to generate both HTML and PDF documents on a whim. The development cycle was fast, the project was finished ahead of time, and everybody loved the final product. Later I wrote a C extension for Ruby to easily access the Win32 serial port allowing an archaic lab instrument to dump data straight to an OpenOffice spreadsheet. I'd never considered writing a C extension to any other language, but again, Ruby made it easy.

Since then, Ruby on Rails has rolled onto the scene and has allowed me to develop projects in which I would have needed a team in the past. MVC is the core paradigm and being able to use my favorite language alongside my favorite architectural pattern is nothing short of a godsend as a web developer. I've used Rails to develop web applications on the fast track and have brought in a nice supplementary income doing so. Best of all, I feel good about the final product when writing a Rails app knowing I'm developing in a standardized way where another programmer will be able to come along later and easily maintain the work I've done. There are MVC frameworks for PHP, but there's still no de facto standard way to roll a PHP app. This makes every PHP app a "special surprise" when you look under the hood. Sadly, the surprise isn't always pleasant.

I'm not saying you can't write good code in PHP. Actually, working at Grooveshark has shown me that it's possible to write extremely clean code in PHP, but I still run to the PHP manual several times a day to lookup one of it's 3000+ core method signatures.

I'm acutely aware that languages are like religions among developers and that everyone has their favorite for one reason or another. I'm also certain there are people out there that would disagree with some of the arguments I've made here. Arguments aside, if you're looking for a new language to learn, and you haven't tried Ruby, take a look, and I think you'll be pleasantly surprised at all that it has to offer.

Wednesday, October 1, 2008

Vimperator

There's a plugin for firefox which allows firefox to behave more like Vim. Some of the features include:

* Vim-like keybindings (h,j,k,l,gg,G,0,$,ZZ,,etc.)
* Ex commands (:quit, :open www.foo.com, ...)
* Hit-a-hint like navigation of links (start with 'f' to follow a link)
* Vim-like statusline with a wget-like progress bar
* Macros to replay key strokes

etc...

The author really threw in the kitchen sink. I've seen my co-worker using this, and it's SUPER cool.

Vimperator Plugin