10 August 2011

Put a Diaper On It

Inspired by Adam Machanic's T-SQL Tuesday topic of 'Crap Code' I decided to take a bit of a different bent--preventing crap code.  Instead of coming off as incredibly arrogant by admitting that I cannot recall code that I have written that I am embarrassed of, I thought to answer why that is.

There is definitely code that I revisit that I would like to rewrite bits of.  Generally, this is because I am better today than when I wrote the code; learned a new trick, new version has a better function, got a bit more sleep. So what is it that prevents, or at least corrals, crap code?  Defined purpose and consistent code.  If your code explains why it is doing what it does and is consistently formatted, it is hard to argue with your original reasoning.

So go easy on yourself, jamiet--that is not crap code, that is good code dealing with crap.

27 April 2011


"Good design is anticipating the stupidity of users."


07 March 2011


If your work isn't documented, it is worthless. This is my new modus operandi. A couple years of silence is largely due to working projects with failed documentation. It is incredibly draining.

I spent my 20's shirking documentation; excuses like, 'the code is self-documenting (I am decent at effective minimal commenting),' 'this is a one time deal.' There were always reasons not to document.

I am paying for that now.

So do yourself a favor and document. It is a little something to make certain that two parties have reached an understanding. It is a little something to help those that follow you. Sure, it is mundane, but documentation is for heroes.

27 May 2009

SSRS: Current Month Date Parameter Defaults

Now and again, I have to pretend that I am a report monkey. SQL Server Reporting Services makes that easy, since most of things are relatively intuitive. Today, I got to figure out (and by 'figure out,' I mean 'Google') the easiest way to create report parameters that default to the first and last days of the current month. The following is what I came up... Surprised that there is not a function to readily do this. So, without further ado, for my future reference, I present the following expressions.

The first of the current month:

dateserial(year(Today), month(Today), 1),
DateFormat.ShortDate -- Format as mm/dd/yyyy

The last day of the current month:
dateserial(year(Today), month(Today), 1)

And free of formatting and comments, for your copy-and-paste convenience:

=FormatDateTime(dateserial(year(Today),month(Today),1), DateFormat.ShortDate)

=FormatDateTime(DateAdd("d", -1, DateAdd("m", 1, dateserial(year(Today),month(Today),1))), DateFormat.ShortDate)

16 May 2009

Wolfram Fail

I have been looking forward to Wolfram Alpha going live. I am no longer so impressed. After trying to find how many state employees California has, to no avail, I asked a simpler question. It looks like, contrary to the hype, Google is safe for a while...

06 February 2009

Perl: Convert PDF Files to Text

Using the CAM::PDF package, it is easy to extract the text from PDF files. The following script takes all PDF files from a directory and extracts the text of the entire file and writes it to a text file.

This script is also available at dba4Life.

use IO::Handle;

use strict;
use warnings;

use CAM::PDF;
use CAM::PDF::PageText;

my $PDFDIR = "./SomeSubDirectory";
my $pdf;
my %ddl;

opendir DDL, $PDFDIR || die "Error in opening PDF directory $PDFDIR\n";

while((my $filename = readdir(DDL)))
# Skip non-PDF files
next if ($filename !~ /\.pdf$/);

$filename = $PDFDIR . '/' . $filename;

if(!-f $filename) { print "\nCould not load $filename";}

# Name output file same as the PDF
my $output = $filename;
$output =~ s/\.pdf/\.txt/;

print "Creating $output...\n";
open(TXTFILE, '>' . $output);

# Load the PDF
$pdf = CAM::PDF->new($filename);

# Total number of pages within the PDF
my $pages = $pdf->numPages;

# Get the text for each page
for(my $x = 1; $x <= $pages; $x++) { print TXTFILE text_from_page($x); } close(TXTFILE); } closedir DDL; sub text_from_page { my $pg_num = shift; return CAM::PDF::PageText->render($pdf->getPageContentTree($pg_num));

16 October 2008

Simple SQL: Optional Parameters, Static Statements

Dynamic SQL, as wonderful a thing as it is, is horrible for security and maintenance. Your best bet is to avoid it. People often whine about making parameters optional. If you set the parameters that you are not using to null, this is a simple thing to do:

@state char(02),
@zip char(05)

set @state = 'CA'
set @zip = null

State = coalesce(@state, State)
and Zip = coalesce(@zip, Zip)

Simple and elegant.


01 October 2008

EC2-SQL: Competition in the Cloud

Not to be outdone by Oracle, Microsoft SQL Server will be available on Amazon's EC2 come late autumn. Read about it here... And you may want to read up on Microsoft's Windows Cloud operating system for developers at Slashdot. Is Microsoft adapting? Come on, now... It happens... Sometimes... Seldom.

And so goes another step for cloud computing...

Tags: , ,

25 September 2008

Sulphur Clouds! Oracle on Amazon's EC2

Oracle puts its 11g database in Amazon's cloud. With a title like that, what can I add? This is a well written article about Oracle on EC2. They are also supporting backups being shipped to Amazon. Anything else and I will be reiterating the article.

Tags: ,

19 September 2008

Oklahoma Finds Next Level of Stupidity

Wow. That is all that I have to say after reading this article:

Oklahoma Leaks Tens of Thousands of Social Security Numbers, Other Sensitive Data.

Technically, State information is public... But this goes beyond overshare. You just know that the application account has escalated privileges... I have to go back to my opening statement; wow. What a kick in the head...

Tags: ,