January 2012
3 posts
3 tags
Fixing Pixelated Images on the iPhone
When an iPhone with a retina display (iPhone 4+) displays an image on a web page that image’s size is doubled, so each pixel in the image actually takes up 4 pixels and looks pixelated. This looks unprofessional and tacky. Here’s an example of a 245x80 image: You’ll have to load this page on an iPhone to see the problem in the above image. The pixels in the image have...
Jan 30th
3 tags
Adding Responsive Design to Tumblr Themes
If you’re using a single-column fluid layout theme in Tumblr then adding responsive design is dead-easy. If you’re using a more complex theme, that is not fluid width and single-column, then you’ll have to put a lot more work in, but it is still well worth the effort. By default Tumblr overrides your theme with a mobile-friendly theme when your blog is accessed by a phone. ...
Jan 29th
1 note
2 tags
Adding Syntax Highlighting to Tumblr Posts
I’ve just moved my blog to Tumblr. One thing that most my posts have are code examples. Here’s how I added this to my Tumblr blog. Go in to the customization section of your blog where you can configure the theme. Once there, click the “Edit HTML” button and add this somewhere before the ending </head> tag: <link rel="stylesheet"...
Jan 26th
September 2011
1 post
5 tags
Check out SQL::Abstract::Query
During the last few months I’ve been working on the CPAN distribution SQL::Abstract::Query. The drive for doing this is that DBIx::ResultSet (another module of mine) currently has lack-luster support for auto-incrementing IDs, has a custom and inflexible solution for GROUP BY, and has no support for JOINs. To solve the first problem, with lack of good auto-incrementing ID support I wanted...
Sep 20th
August 2011
2 posts
2 tags
Using DBI Effectively: bind_columns()
One of the most under-utilized features of DBI is is the bind_columns() method. The majority (as in everyone) that I show bind_columns() to have never seen it before or used it. Here’s what it looks like: my $sth = $dbh->prepare('SELECT name, email FROM users'); $sth->execute(); $sth->bind_columns( \my( $name, $email ) ); while ($sth->fetch()) { print "$name:...
Aug 17th
3 tags
Chained Git Hooks
So I’ve be wrestling with getting chained git hooks working. I’m surprised that Git doesn’t support this out-of-the-box as it seems very short-sighted. Here’s a Perl script I implemented to get this working: #!/usr/bin/env perl use strict; use warnings; use autodie; use File::Temp qw( tempfile ); use IPC::Cmd qw( run ); if (@ARGV and $ARGV[0] eq 'wrapper') { shift(...
Aug 2nd
July 2011
1 post
2 tags
Adding Files to Subversion With @ in Their Name
I just ran in to this today. If you try to do this: svn add this\@that svn: warning: 'this' not found In order to ‘svn add’ a file with a ‘@’ character in it you must end the add command with an ‘@’ character, as in: svn add this\@that\@ A this@that
Jul 21st
August 2010
1 post
5 tags
Presentation: Moose Best Practices
I wrote this for the TO.pm meeting on August 11th, 2010:
Aug 14th
June 2010
2 posts
3 tags
Presentation: Tools of the CPAN Ninja
I wrote this for the TO.pm meeting on June 10th, 2010:
Jun 10th
6 tags
BLOBs, Synonyms, and DBD::Oracle
INSERTing, UPDATEing, and SELECTing LOBs (CLOB/BLOB) in Oracle using Perl can be a PITA. Case in point: 2 years ago a fellow coworker ended up writing some extremely complex code using ora_lob_write(), etc, when all he really needed to do was use bind_param() and declare that the blob column is a blob so that DBD::Oracle would know to treat is specially. At the time I believe he did try...
Jun 4th
May 2010
1 post
2 tags
Generating Constants in Perl
The other day @ $work I was throwing together a module that creates constants based on a fairly static table in the database. Of course I didn’t want to hard code the contants, I wanted them to be magically created by what was in the database. For the sake of this example I had a table called “toy_categories” where each record has a unique ID (toy_category_id) and a name that...
May 22nd
April 2010
2 posts
4 tags
YAPC::NA 2010 Talks are Being Approved
I just got my approval for the two proposals I had submitted for this coming YAPC::NA 2010! I’m very excited. This will be my first time doing any sort of talk at a YAPC. I’ve been wanting to do this for years and I am very grateful that the organizers of the conference considered me. Over the last few years I’ve been trying to hone my presentation skills by presenting...
Apr 18th
5 tags
Cassandra Presentation
I wrote this for the TO.pm meeting on April 14th, 2010:
Apr 16th
January 2010
1 post
5 tags
Robust DBI Transaction and Connection Handling
Edit: It turns out there is already a module on CPAN that does exactly what I talked about here. Its called DBIx::Connector. I haven’t tried it yet, but it looks like the guy that wrote it designed it with input from the DBIC guys. I’m a big fan of DBIx::Class. Among DBIC’s many great features is its superb transaction and connection handling via DBIx::Class::Storage::DBI. ...
Jan 24th
October 2009
1 post
3 tags
use HTML::FormHandler;
I’ve been meaning to give HTML::FormHandler a try for quite some time now. Over the weekend I converted a form from some home-grown form validation and html generation to use HTML::FormHandler instead. HTML::FormHandler was inspired by, and quasi-forked from, Form::Processor. There are many options for processing forms, such as FormValidator::Simple (Catalyst’s default) and...
Oct 12th
September 2009
1 post
2 tags
IE8, another screwed up version.
I was really hoping that Internet Explorer version 8 (IE8) would finally be the version of IE where Microsoft stepped up to the plate and produced a fast browser, with few bugs, less Microsoft-only features, and a good and modern UI. I’m the kind of guy that holds judgment for a very long time, sometimes too long. So it comes with great sadness that I announce that IE8 is not the browser...
Sep 1st
August 2009
1 post
3 tags
use Path::Class;
The CPAN (Comprehensive Perl Archive Network) distribution, Path::Class, provides a simple OO API alternative to the built-in perl file IO functions such as open, opendir, stat, etc. Code written to use Path::Class tends to be smaller (concise, easier to maintain, etc) than similar code that uses the standard built-in functions. Here is an example of how a small utility might be written without...
Aug 6th
July 2009
7 posts
3 tags
Upgrading to Catalyst 5.8
Update: Catalyst now comes with an upgrade document: http://search.cpan.org/perldoc?Catalyst::Upgrading Over the last few days at $work I’ve been upgrading Catalyst from 5.7 to 5.8. This new version of catalyst, released in April, has been completely overhauled to use Moose for it’s OO system, among other enhancements and bug fixes. I found that the...
Jul 29th
3 tags
XS Hits Newb; Bystanders Watch in Dismay
Last year I wrote GIS::Distance::Fast to provide some much needed speedups to the pure-perl GIS::Distance. This ::Fast version used Inline::C which isn’t all that optimal and was just a scapegoat for doing the right thing. So, this evening I rolled up my sleeves and went to work. I first looked at a module I already knew to use XS, Cache::Memcached::Fast. That was overwelming. Then I...
Jul 21st
1 tag
$(document).ready() Shortcut
When writing jquery you almost always put your code within a ready block: $(document).ready(function(){ // Code... }); And I always forget the exact syntax. I just found that jQuery has a shortcut: $(function(){ // Code... }); Much better!
Jul 18th
3 tags
Authoring a CPAN Module
I’ve been authoring CPAN distribution since early 2003 with my first module being Geo::Distance. Since then I’ve authored several other distributions and do my best to keep my RT bug list small and fix FAILs. This process of authoring and maintaining modules on CPAN is in my top-10 list of all-time most educational experiences of my career. I strongly encourage anyone that wants to...
Jul 16th
3 tags
I'm in the Top 100!
So, I’ve been hearing about this CPAN Top 100 list but nobody seems to want to provide a link to it in their posts. Well, I dug that out and come to find that one of my very own modules is in the top 100… FAIL list. Woot! Anyways, I fixed it up and all should be well in an hour or two when everything gets mirrored out/re-indexed/etc by CPAN. There are 3 different top 100 lists on...
Jul 14th
3 tags
Scientific Troubleshooting
Over the years I’ve naturally applied scientific principles to the way I program. There are two main principles that I think most good programmers ought to know. Occam’s Razor (Wikipedia) The idea behind Occam’s Razor, when applied to programming, is that when you are presented with a problem you should pick the simplest solution first and go try and prove it. We naturally...
Jul 14th
2 tags
The Perl is Dead, Long Live the Perl 5
Andy Lester recently wrote Promote Perl 6 by saying “Perl 5”. I think its a great idea, and as you may notice I’ve changed my blog in the few spots necessary to fit. Thanks for all the great work, Andy!
Jul 6th
June 2009
5 posts
2 tags
use autodie;
When writing perl code you’ll often find yourself using built-in functions that do not throw a fatal error when there is a problem. Instead you are expected to check the return value of the function, and if it is false, call die() yourself. Consider the following code: open( my $fh, '>', 'testfile.txt' ) or die('Unable to open testfile.txt for write'); print $fh "Hello...
Jun 30th
4 tags
Class::Measure 0.04 Released
I’ve just uploaded Class::Measure 0.04 to CPAN. Get it here. The changes for this release are optimizations and cleanups in preparation for using Moose in the next release. Class::Measure provides a simple and intuitive way to treat units of measure as basic data types with support for mathematical operations. use Class::Measure::Length qw( length ); my $width = (length(2, 'feet') +...
Jun 28th
4 tags
use Moose;
If you’re used to regular OO perl you’ll recognize this: package Dog; use strict; use warnings; sub new { my ($class, %args) = @_; $args{name} ||= 'Spot'; return bless \%args, shift; } sub bark { my ($self) = @_; print $self->{name} . " barks!\n"; } 1; With Moose this becomes drastically simpler and more powerful: package Cat; use Moose; has 'name' =>...
Jun 24th
3 tags
Modern Perl Presentation
I wrote this for the TO.pm meeting on June 10th:
Jun 12th
2 tags
Flash Bleeding Through
If you use mint.com you’ll notice that whenever a modal dialog is displayed they hide the flash content. This is because the flash normally bleeds through any HTML. Even if the flash has a z-index of -1000 and a div has a z-index of 1000, the flash will still appear on top of the div. There is an easy workaround for this with the WMODE parameter: <object...
Jun 2nd
May 2009
3 posts
1 tag
CSS Element Sizing
While working on our new UI at $work we ran in to issues using the YUI layout manager as its very quirky and hard to customize. So, I ended up writing an entirely new layout manager. As part of this I found that the way I thought elements resized was nothing like reality. I’m a big jQuery fan so this diagram below refers to jQuery methods, but the concept applies to CSS in general. As...
May 12th
1 tag
CSS Element Positioning
I spent a good day trying to completely understand how CSS positioning works. There are a lot of misconceptions and superstitious out there and I found many people answering questions about CSS positioning with answers that were completely false. So, I had to dispel the mystery. I think that w3schools.com explains the possible values for the CSS position property the best. static Default. An...
May 12th
2 tags
Setting an Element's Outer Size
When setting an element’s width or height you are setting the inner-most width and height, without taking in to account the padding, border, or margin. When writing application-like web sites this is not the behavior you want - usually you want exact control of the entire width and height of the element. Here’s a very simple jQuery plugin that I wrote to make this very easy to...
May 12th