DerekAllard.com

Finding the Second Highest Value with SQL

For a project I'm currently working on, subscribed users get up to the minute most current information (as outlined by a date field in MySQL).  Unsubscribed users get the information still, only it is a day behind. 

Due to the way the information is going into the system, there could be multiple entries for one date, and then no entries for a few days, then new, etc.  Basically, the information cannot be predicted by the application.  Retrieving the most recent date is trivially easy with a MAX command, but there is no "almostMAX" command, so I found myself staring at the screen wondering what the most efficient way to approach this was.  Here's my solution:

SELECT * FROM table GROUP BY dateIssued ORDER BY dateIssued DESC LIMIT 1,1

Fortunately for me, LIMIT accepts offsets, and I can specific to grab only the second entry.  If you can think of a more elegant way to do this (or heck, if you just want to comment), please leave a note below.

The Vast Cornfields of Canada

In the last ten days I've gotten three separate emails from people about something that, I have to admit, really surprised me.  They were concerned about my use of the words "colour" (two emails on this one) and "favourite" (this one appeared in my post on Code Igniter Wiki resources).  And honestly, "concerned" is probably a good choice of words.  I've written back to 2 of them with a brief explanation - but since 1 of the notes came from my contact form with an obviously fake email, I couldn't respond directly to the writer.  I also don't mind quoting a few lines here.

...if you're trying to show people professional resources, maybe you should use the accepted international spelling don't you think?...

Go ahead, read that again, I needed to read it three time before it made sense.  Look, I have absolutely NO problem with how you choose to spell colour, or favourite, or centre, but please, please, please don't think that the rest of the planet should spell it like that simply because you want to.

Finally, maybe there was a time when people didn't recognize that some words are spelled differently in other countries (I'm Canadian), but I don't think its been in my lifetime, so lighten up - there are SO many other things you could criticize me for anyways.

Sage Vulnerability Reported

As if you needed a reason to stay up to date, but its worth noting that a validation error in the processing of certain tags has been reported in the Sage RSS reader extension for Firefox.  This can be exploited to insert and execute arbitrary HTML and script code in a local context by tricking a user into adding a malicious feed and then viewing its contents.

I've recommended Sage in the past, and fortunately this was fixed some time ago in Sage 1.3.10, so run your updates.

Going to SxSW 2007

Come March 9th I’ll be on my way to Austin to partake in a few days of nerd revelry at South By Southwest.  The main reason I’m going to to hang out with the guys from pMachine, (I’m a card-carrying member of Team Festering Carbuncle), but I’d love to meet as many people as I can.

If you’ll be heading down (I know Matt’s going to be there) then drop me a note so I can keep an eye out for you.

Quick Link: Plotr javascript graphing library

A beautiful piece of work!  Bas Wenneker has written Plotr, a charting engine in Prototype that uses canvas.  Now if only IE would support SVG, my world would be complete (until I found something else to complain about). The library is released under a BSD license, and requires prototype to run.

The rendered graphs are not bitmap graphics (no GIFs or PNGs here), but rather plotted using SVG or Explorer Canvas, as is appropriate. And if I may say so, the output is sexy as hell.
Example of a Plotr Graph

Moonlighting for ExpressionEngine

Well, its out in the open now!  I'm moonlighting at pMachine.  I'm like a real-life Bruce Willis... er... wait.  My title is Senior Technical Support Specialist, which is really just a long way of saying that I'm going to work my butt off to keep ExpressionEngine as awesome as it already is.  I join an amazing team of dedicated, smart, and hardworking people.  Its an honour to count myself among them.

ExpressionEngine is the content management system that CodeIgniter is abstracted from.  Its flat out awesome (but now I'm paid to say that ;))

Most Useless Code Igniter Helper Ever?

Have I written the most useless helper Code Igniter will ever see? I think so.

It takes an arbitrary image and arbitrary text and builds an image out of them.

Code Igniter logo becomes Code Igniter logo as text(full size)

Which really doesn't do it justice until you see it full size, or run the demo. Here's a zoom.
Code Igniter logo as text zoomed in

I should note that the helper handles colours just fine. Here's the rendered robot (2.7MB... be kind)

A red robotRed robot Rendered as text

I proudly present the most useless helper ever written! The (useless) helper is available for download, and I've appropriately named it "useless_fun_helper". Run it just like you'd run any other helper.

$this->load->helper('useless_fun');
$txt = 'Code Igniter is an Open Source Web Application Framework that makes writing kick-ass PHP programs simple as apple pie';
$img = 'http://yourserver/ci_logo.jpg';
echo image_to_text($img, $txt); // typically you'd pass that into a view... I know... no hate mail ok

So this is my formal entry into the most useless helper of all time. Any runner-ups?

I’ve been joe jobbed again

Hmm... It seems some [censored!!!] thoughtless individual has decided to send their email entitled "placid dissident" to several hundred thousand of my closest friends.  This is the second time I've been joe jobbed in a year.  Lucky me.

Anyone who knows me knows that I'd be much more creative though.  For example, the email said xvhehqjetpi yhmsc ombrnyw nypeki ijysf qwdyeq.  C'mon really?  Honestly?!?  At least steal a quote from today's headlines or a passage out of some Gutenberg text or something like most of the "cool" spammers today.  Goodness.  And also, what's with the attachment?  "traffic light.png".  There's a space in that name!  Years of linux and web development have scared all the spaces out of my filenames long ago.  And the piece de resistance?... they forged an Outlook Express sender header.

X-Mailer: Microsoft Outlook Express 6.00.2900.3028
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028

I think the funniest thing so far (even funnier then 2 dozen bounce messages) has been the 1 person who kindly took the time to write me back.

Victor, thanks. Your single sentence (take me off your list as***le) is like poetry to me.  You're good people - and I'll be sure to take you off my list right away.

Hear me now and believe me later

This blog post is about advice I'd give to aspiring webmasters. I'm going to try to lay down my honest thoughts here. If you are an aspiring webmaster, you might find some useful nuggets. If you are in a position to give advice to others, you might also find this interesting, if only to spark of discussion or actively and violently disagree with me.

I'm sometimes asked what advice I give to aspiring webmasters as they learn how to code and design. I always try to make up a new answer on the spot so that I can look smart, but the truth is that I don't really remember what I say from one time to the next. When I lecture and/or teach, I tend to fall into a stream-of-consciousness speaking style, and I don't really have a set script I follow. But today I had a unique opportunity to really gauge myself, and listen to what I said; today I started instructing the next cohort of Toronto webmasters in the art of code-fu...

The first day is always an interesting time, because what I invariably see are 15 or 16 highly gifted people, but they're clean slate in the sense of prior experience and expectations. They don't know who the W3C is, but they also don't use the <font> tag. They don't know about the Web Accessibility Initiative, but they also don't layout their pages in a soup of <td> elements. In short, they are starting their education without the baggage of years of bad habits and mis-information.

So today I made a concerted effort to not censor myself, and keep track of what I said. I wasn't totally successful, but I made a series of notes at the end of the day, which I present here for reference, review and general interest.

So there you have it. A few gems, straight from my stream-of-consciousness to yours. Oh yeah, one more thing... the title of this blog post? It was an homage to Hans and Franz ("We're going to PUMP - YOU UP!"). What advice would you give?

nofollow no more

I’ve been thinking a lot about comment spam lately (I’m only getting 4 or 5 a day, and of those I only need to manually reject 1 or 2). Google, (way back in 2005) pioneered the use of the rel=“nofollow” attribute in hyperlinks; links with this attribute would not influence the link target’s ranking in the search engine’s index. Seems like a nice way to discourage people from putting comments into a blog if their only goal is to have a link to their site. Thus, one of the very first things I did when I built this blog was to make sure the nofollow rule was implemented in the links to commenters websites.

But nofollow is not without controvsery, and entire sites have sprung up with the goal of explaining why nofollow isn’t so great. But to me it boils down to one thing… if people are putting useful, interesting material on my blog (which you have been… thanks!) then why shouldn’t I share some of my meager pagerank?

So from now on, if you’re taking the time to write, then you darn well deserve a non-crippled link back to your site. Thanks for commenting!