How to write a self-executing Ruby script

Ruby logoLet me state right off that I’m a Ruby newbie and Rails rookie. Last week, I became acquainted with the language and framework when I had the distinct pleasure of attending a five-day Ruby on Rails boot camp. In addition to teaching us Ruby and Rails, our knowledgeable sensei instructed us in the ways of Test Driven Development and Behavior Driven Development. What an eye opener that experience was for me! Ruby, even without Rails, is such a powerful language. It seems to have all the power of Perl, but with none of Perl’s baggage. Combined with Rails, it’s like nothing I’ve ever seen before: database abstraction, presentation abstraction, database versioning, and libraries (i.e., gems) for every imaginable need. The techniques of TDD and BDD seem like much superior methods of developing software, making me question why they haven’t been embraced by all development teams worldwide. While they’re not silver bullets, I can certainly see them yielding better results than Waterfall, BDUF (Big Design Up Front), and cowboy coding.

As part of my new language learning process, if I discover something about the said language that’s cool or noteworthy, that may be of help to you, or that may assist me in my understanding of it by writing about it, I plan to write blog posts such as this one. Here’s something cool. Want to execute a Ruby script without having to run the Ruby interpreter? It’s as simple as doing the following. (Sorry, Unix-flavored systems only—such as OS X and Linux. This won’t work on Windows.)

  • Find out where the Ruby interpreter lives on your machine. Type the following on the command-line.
which ruby

Output:

/usr/local/bin/ruby
  • Create a new file. No file extension is necessary. The first line of the script should start off with #! (the shebang), followed by the above output. After that, enter your Ruby code.
#! /usr/local/bin/ruby
 
puts "Iron Maiden rules!\n"
  • Next, since we’re invoking our script—rather than the Ruby interpreter directly—we need to make it executable. (Usage of the shebang line will automatically invoke the Ruby interpreter on our behalf.) Some more typing on the command-line…
chmod +x example
ls -l example

Output:

-rwxr-xr-x  1 phillip  staff  52 26 Jun 19:47 example
  • Now, the only thing left to do is to run our script. The last bit of typing on the command line…
./example

Output:

Iron Maiden rules!

And that’s it! We’ve just created a self-executing Ruby script. It should be noted that self-executing scripts, with the shebang line, can be created for other languages (e.g., Perl and Python) as well.

Neo

, , , , ,

No Comments

Sistine Chapel To The Number Of The Beast

The Creation of Adam

The Creation of Adam. ~ Michelangelo

A week ago, I had the good fortune of stumbling upon the Sistine Chapel Virtual Tour. (Go ahead and check out the link; then come back. It may take several minutes to load.) What’s the Sistine Chapel, you ask? Well, it’s a chapel in Vatican City that happens to house some of the greatest art in Western Civilization. To speak of the Sistine Chapel is to evoke the names of the eminent artists of the Renaissance, such as Michelangelo, Raphael, Bernini, and Botticelli. As a lover of art and history, it was a treat to step foot inside the virtual chapel, look directly above my head to the ceiling, and gaze hypnotically at Michelangelo’s The Creation Of Adam.

In addition to his masterpieces in the Sistine Chapel—the ceiling decoration, of which The Creation Of Adam is an element, and The Last Judgment fresco, spanning the wall behind the altar—Michelangelo is best known for two sculptures he created before he turned thirty: David and Pietà. The former depicts one of the central figures of the Old Testament in a contemplative pose, while the latter shows Mary cradling the body of Jesus in her lap after the Crucifixion. Michelangelo was preeminent in several fields—painting, sculpting, poetry, engineering, and architecture—making him an archetypal polymath.

The word polymath, derived from the Ancient Greek polumathēs (“having learned much”), is loosely defined as a person who is very knowledgeable, while its more strict definition describes a person who excels or is highly educated in a wide spectrum of fields or subject areas (a “Renaissance Man”). I aspire to be a polymath of the first kind; Leonardo da Vinci is, unquestionably, the foremost example of the second. Intelligent Life magazine ran an article, The Last Days of the Polymath, in their autumn 2009 issue. In it, they discuss the difficulty of being a polymath, or generalist, in this age of the specialist. As an addendum to the article, they attempted to identify several living examples of polymaths. Their list just The Number Of The Beasthappened to include a personal hero of mine: Bruce Dickinson, the singer of Iron Maiden.

That Bruce is considered a polymath should come as no surprise. On top of being Maiden’s frontman, he writes, fences, and pilots Boeing 757 jets. One of those jets, Ed Force One, the band uses on tour to transport themselves, their crew, and their equipment to cities all over the world. They flew in Ed Force One extensively for the 2008-09 Somewhere Back In Time World Tour. As part of that tour, which featured an Ancient Egypt-inspired stage set similar to the one from the 1984-85 World Slavery Tour, they came to my burg on June 9, 2008 and performed a swath of their greatest hits from the 80s. Included in that night’s set list was The Number Of The Beast, one of the adrenaline-charging tracks from its namesake album—the album that cemented Maiden’s rightful place at the apex of the metal genre.

Agent Smith

, , , , , , ,

No Comments

Overkill

Lemmy.

I don’t often use profanity in written discourse. Conversational discourse is another matter. :-) But sometimes, something astounds you so much that a conventional adjective simply won’t do; only a vulgar one will suffice. Having said that, I stumbled upon the following video the other day and four words describe it perfectly: it is fucking awesome! It’s Motörhead‘s live performance of their early hit, Overkill, in Düsseldorf, Germany on December 7, 2004. It was filmed for their 2005 DVD, Stage Fright, which was released to celebrate their 30th anniversary. The video makes me want to pick up the DVD and watch the rest of the show.

Overkill is from Motörhead’s second album of the same name and is a favorite at their concerts. It was covered by Metallica—along with Damage Case, Stone Dead Forever, and Too Late Too Late—as a birthday gift to Lemmy (also known as Ian Fraser Kilmister), Motörhead’s singer and founding member. Metallica’s version was featured in their album, Garage Inc.. Alan Burridge, Motörhead’s official biographer and organizer of the Motorheadbangers fan club, had this to say about the song:

Phil Taylor instigated that double bass drum killer steamroller intro upon which the title track is so firmly built. Lemmy thought, “That’s a bit of an overkill!” and there it was, the song and album title for one of rock’s mightiest classics was born. Coupled with Lemmy’s machine gun bass and Fast Eddie’s landslide chords this track tears the roof off your home – and the vocals haven’t even started yet!

Enjoy the video and be prepared to have your inner headbanger unleashed!

, , ,

No Comments

All Nightmare Long

I can’t rave enough about this song and this video, All Nightmare Long by Metallica. Nightmare is from their wicked new album, Death Magnetic, which I finally picked up a few months ago, about a year after its debut. To say the least, I am nothing short of awestruck by the song and the album. Despite Metallica’s plethora of hits—which include the likes of Battery, One, Enter Sandman, and For Whom The Bell Tolls—I’d venture to say All Nightmare Long is perhaps the best song they’ve ever produced. It’s that good!

I absolutely love the video. I don’t want to spoil it for you, so watch it below first and then read on.

I love the fictitious documentary of how the USSR decimated the USA by using a “special” kind of biological weapon—a spore of of extraterrestrial origin—to trigger an American zombie apocalypse. The video is creative and original, two traits that are sorely lacking in the videos of today’s mainstream music.

Trees were knocked down and burned over hundreds of square kilometres by the Tunguska meteoroid impact. ~ Leonid Kulik expidition, 1927.

Trees were knocked down and burned over hundreds of square kilometres by the Tunguska meteoroid impact. ~ Leonid Kulik expidition, 1927.

Though the video is a fantastic piece of fiction, it’s based upon an actual, historical occurrence, the Tunguska Event. In the morning of June 30, 1908 (not July 30, which is displayed in one of the video’s captions), a sizable chunk of meteoroid or comet exploded in the sky above the Podkamennaya Tunguska river, in what is now the Krasnoyarsk Krai of Russia, obliterating 80 million trees over 2,150 square kilometres. The blast occurred 5-10 kilometres above the Earth’s surface, with its force estimated to be approximately 10-15 megatons of TNT; that would make it 1,000 times as powerful as the atomic bomb that was dropped on Hiroshima, Japan during World War II by the American B-29 bomber, Enola Gay. That’s quite a wallop!

Update (February 5, 2010). Last week, during a hunt for a live performance of this song—which I have now officially declared to be Metallica’s best song ever—I happened upon the following video. It’s a superb performance of All Nightmare Long that was recorded in Nîmes, France on July 7, 2009 for the DVD, Français Pour Une Nuit. For me, as a lover of antiquities, what’s most notable about the performance is the venue, the Arena of Nîmes. It’s a Roman amphitheater that was constructed circa 70 A.D., during the reign of Emperor Augustus, and is still used to this very day for public events, such as bullfights and concerts.

, , ,

No Comments

Phantom Of The Opera

Phantom Of The OperaI thought, what better way to celebrate the commencement of my blog than with the ultimate song by the greatest band to have ever walked the earth: Phantom of the Opera by Iron Maiden. It would never be my desire to pick a favorite from Maiden’s vast collection of magnificent melodies, but if I had to pick one, it would undoubtedly be Phantom.

Based on the 1910 novel The Phantom of the Opera by French author Gaston Leroux, the song was written by Maiden bassist Steve Harris and was featured in Maiden’s self-titled, debut album, Iron Maiden. I could try to describe the song, but Steve did a pretty good job of that himself:

This is a very long song that was done in sections. The middle part was totally separate but it fit in very well. It felt right to go from the slow part into the middle section. Phantom is one of the best pieces I’ve ever written, and certainly one of the most enjoyable to play. It’s got all these intricate guitar lines which keep it interesting. Then there’s the slow middle part which creates quite a good mood. It’s also got fast heavy parts which are really rockin’. And it’s also got areas for crowd participation. It pretty much covers all the bases for the band. It was also a good example of what I wanted to get across.

For your enjoyment, following this paragraph is a video of Maiden’s December 1980 performance of the song at The Rainbow in north London. The video features Iron Maiden’s original frontman, Paul Di’Anno.

, , ,

2 Comments