Perl module of the day

Programming Perl book cover

Image via Wikipedia

Next up in the Perl Module of the Day series is Getopt::Long::Descriptive. It gives you the ability to have options passed to your programs like Getopt::Long, but allows you to also set up some descriptive text to be displayed when you need it, formatted in a nice, consistent way.

Use is pretty straight-forward. Call it via:

my ($opt, $usage) = describe_options(
 '%c %o',
 [ 'id|i=i', 'the id to look for', { default => 1 } ],
 [],
 [ 'help|h', 'some help messages' ]
 );
 print($usage->text), exit if $opt->help;

This will print out a nice help message with both the long and short options detailed, along with their descriptions so the users actually understand what the option actually does.

Here’s the exact output from the above code, written as ‘descriptive.pl’:

descriptive.pl [-hi] [long options...]
	-i --id     the id to look for

	-h --help   some help messages

You’ll notice that this spits out information based on the above information you supplied, just as you’d expect. It’s up to you to determine how detailed you want to make the descriptions. The options work just like Getopt::Long do, so you can have items that you specify multiple times, using arrays (arrayrefs, really) etc. You’re even offered the ability to give each option a default value.

Recently, I was listing to an older episode of “The Dev Show“, with Jason Seifer and Dan Benjamin, where they stated that perl was a write once, read never language. While this module won’t keep you from read never, it will at least help you later when you do have to read it again, an also when you have to run it again for the first time in months.

Any module that helps keep your sanity in line is a good module for me.

Stupid Choices

m, 07 June 2011, No comments
Categories: Pet Peeves, Relationships
Tags: , ,

I just learned that an old friend overdosed a month ago at 31. My cousin passed a little over a week ago today at 36 because of major health related complications. What do these two deaths have in common besides me? Stupid choices!

The Old Friend. She died from an oxy-cod overdose May 7th. She left behind three small children because she couldn’t handle her partying.

My Cousin. He died May 23rd because he had type two diabetes, failing kidneys, a staff infection, and who knows what else. He died because he did not take care of his diabetes when he was originally diagnosed and it created this down hill spiral for 5 years until the day his mother found him dead in his bed… the day he was supposed to start dialysis.

Stupid decisions! Both of them! Aren’tyou supposed to grow up and take responsibility for yourself as you grow older? When you have kidsaren’tyou supposed to put them before any of your wants or desires? Isn’t your health one of the most important things to consider?

Please help me understand why people make suck dumb choices. Leaving behind them hurt and questions of “why”.

The Most Badass Muscle Car of All Time

griffigr, 03 June 2011, Comments Off
Categories: Favorites
Tags: , , , , , ,

I’m a muscle car fanatic. Specifically, I’m a sucker for all things GM. There a few things in this world that get me as excited as the rumble of a nasty, mechanical flat-tappet cam thumping away at the heart of an eight cylinder Chevrolet mill. The mere sight of a first-generation Camaro puts a huge smile on my face. A brief encounter with a second-generation Chevelle invokes a sense of nostalgia I simply can’t explain.

Yet, there is one car forged by the hands of GM that encapsulates every characteristic that comprises a great muscle car. It’s classy. It’s extremely sexy. It’s got enough power to transform any frown into a shit-eating grin within a matter of seconds. Most importantly, it’s unique (due to the fact that this little gem was the last of its kind is largely over-shadowed by many of its predecessors). Of course, I’m referring to the ever-so-badass 1967 Chevelle SS.

According to the General, the 396 big-block that was available in the SS package cranked out 375 horsepower. Yet, any schmuck knows these power numbers were severely underrated (by as much as 50-75 ponies) from the factory as to avoid higher insurance premiums. Couple gobs of power with a four-speed gear box and you’ve got enough fun for a lifetime.

Gentoo Install Scripts

dp, 11 May 2011, No comments
Categories: Computers, Internet, Software
Tags: , ,
The Gentoo Linux logo in SVG format, without r...

Image via Wikipedia

Recently, I’ve been installing a lot of Gentoo boxes at work. Because of the tedium of following the Gentoo Handbook every time, and clicking through the steps, I’ve started working on some install scripts. Currently, there’s just one, that downloads the stage and portage files from the closest mirror. And I’ve got other scripts in mind.

But only using them on our specific machines makes for very specific scripts. If anyone out there is setting up new Gentoo boxes, please give these a try, and suggest some improvements. So here it is, the git repository for my Gentoo Install Scripts.

Perl Module of the Day

dp, 19 April 2011, No comments
Categories: Perl
Tags: , ,

I’m going to start a new series on my blog, called Perl Module of the Day. It won’t have posts every day, but any day that I find an interesting perl module, that I think might help others, I’ll post it here.

Todays module isTime::Duration. It simply takes a number of seconds, and converts it to a human-readable duration. But that’s not a simple task to do properly, as many (including me) have figured out.

By default, Time::Duration gives you an approximate value, to two expressed units. IE, 1 hour and 4 minutes. But another method exists to give you the exact value of that duration.

This is a really helpful module that I wish I’d have known about many years ago, when I wrote my own functions to do this.

Time Lapse Solar Panel Installation

Very cool time lapse video showing an Ann Arbor mans solar panel installation. Many thousands of dollars were spent to get it all right; he expects a $0 electricity bill “soon”.

via YouTube – Ann Arbor Michigan Solar Roof Installation.

PHP and nl2br

dp, 17 March 2011, No comments
Categories: Computers, Software
Tags: , ,
The PHP logo displaying the Handel Gothic font.

Image via Wikipedia

PHP has a nifty function callednl2br, which will convert newlines within text to
tags (optionally enabling the XHTML syntax). I’m curious though, why a br2nl function was never written? Instead, now I have to hack one together.

BLARGH!

Overheard in the office

dp, 15 March 2011, No comments
Categories: Overheard in the Office

“I have to set the date when I create it? Stupid!”

Reasons to use a cartesian join

The Greek lowercase omega (ω) character is use...

Image via Wikipedia

All over the Internet you’ll find people telling you that cartesian joins are a bad idea. And for the 99% of the time you’d run in to them, they are. But I found a legitimate use for them.

I needed to get a count of records from table A for all the records in table B, but the only thing to join them was with a field that was in table C; so, using a nested join, I managed to run the select. The actual select is below:

SELECT COUNT(*), d.name
FROM rfis r,
(divisions d INNER JOIN division_site_rfis dsr ON d.id = dsr.division_id)
WHERE r.site_id = dsr.site_id
AND r.division_id IS NULL
AND r.site_id = ?
AND MONTH(approval_ts) = ?
AND YEAR(approval_ts) = ?
AND status = 1
GROUP BY d.name

 

How to Correct Grainy Images in Flash

When building a new Flash project (from a PSD, for example), you’ll notice Flash likes to compress the absolute HELL out of all images within the asset library upon import. This causes your project to look like absolute shit, but ALAS! There’s an easy solution.

After you’ve imported your images to the asset library, right-click the file you want to drop on to the stage and change the image compression settings from lossy (JPEG) to lossless (PNG). It’s that easy.

After the change, you’ll notice a large improvement in image quality while still retaining a relatively low file size. Enjoy.

It's Already Been...