Monday, May 11, 2009

Ugly SQL Pivot Reporting Queries Saved for Posterity

Here are some pivot reporting queries stored for future reference:





For SQL help and insight I recommend this book: SQL Cookbook (Cookbooks (O'Reilly))

Friday, May 08, 2009

Readability Bookmarklet

I like the Readability Bookmarklet a lot. With one quick click it removes the "noise" from a web page and presents a very readable view. You should check it out.

Thursday, May 07, 2009

Apache + Passenger + HTTP Basic

Say you've thrown together a simple demo application, thrown it out on the web, and now want to make sure that no one messes with the data before that big client looks checks out your demo and signs that big $$ contract. Being a demo - the quick and dirty way to get this up is to just throw in some HTTP Basic Authentication. With Apache + Passenger the way to do this is to add a Location directive inside your VirtualHost element:



You can configure HTTP Basic in a few different ways, but the above is usually what you are going to want.

Wednesday, May 06, 2009

Chad Fowler's 20 Rails Development No-No's

Chad Fowler, who will be keynoting at the Aloha on Rails RailsConf, recently released a list a 20 Rails Development No-No's on his blog. It is a decent list to review to help make yourself aware of various Rails "code smells." Throwing in my 2 cents, for number 10, Code in the Wrong Place, I would like to mention controllers that load the flash with HTML. If you are putting any HTML in your flash then you should use a proper view technology, such as a partial, to load it up:



Ok, so thats a pretty trivial example, what I really wanted to say in this post is that Aloha on Rails is coming and it is going to be pretty awesome. Seth Ladd released a nice blog post about it today. You should really check it out.

VPN fix after Ubuntu Update - LCP terminated by peer

I use a VPN connection to my corporate email system to pull in emails and send them over to a gmail account with fetchmail. After upgrading to Ubuntu 9.04 (actually I think it was the upgrade to 8.10, but I went from 8.04 -> 8.10 -> 9.04 on the same day) the setup came crashing down - the VPN would no longer connect and thus and I was no longer able to get any emails. It turns out that the problem was related to a change in a configuration file after updating...before I get to that however, let me note my configuration.

First, my /etc/ppp/peers/cambervpn file:



next, my /etc/ppp/chap-secrets file:



next, my /etc/ppp/ip-up.d/cambervpn file:



and finally, my /etc/ppp/ip-down.d/cambervpn file:



To bring that up, you type "sudo pon cambervpn". After the upgrade, my syslog was telling me "Non-zero Async Control Character Maps are not supported!" and "LCP terminated by peer". Googling around led me believe this was a problem with MPPE. Sure enough, in looking at the file /etc/ppp/options.pptp I found that both MPPE options were commented out. Uncommenting the line "require-mppe-128" did the trick.

Hey, well if you read this far I guess you might be wondering what kind of command I issue to get fetchmail to forward mail over to my gmail account. The following command causes fetchmail to fetch the mail every 300 seconds:



An entry in my .netrc file provides the password for the POP server.

Tuesday, May 05, 2009

Some Core Javascript Functions

I recently worked on two different projects that involved a fair amount of Javascript centering around using the Google Maps API. In doing so I began to factor out some of the components to be reusable in a general Google Maps project. While I usually use the excellent Prototype Javascript library I didn't want to leak Prototype code into these reusable components. This led me to using these functions, borrowed / evolved from various places, as the core functions to support the components:



I think these functions are a pretty good representation of the baseline support you will want in many Javascript projects.

Monday, April 13, 2009

Javascript Puzzler

Invoking an anonymous JavaScript function is a handy technique for avoiding namespace collisions in JavaScript code. The following two code snippets show the definition of a top level function followed by the invocation of an anonymous function. One of them, however, has a (easily fixed) problem (at least on Firefox 3.0.8). Can you spot what it is? Try figuring it out without running the code - don't cheat! Put your answer in the comments.

Snippet one:



Snippet two:



Surprising behavior. I'd be interested to find out if different browsers / JavaScript engines treat these code snippets in the same way.