Archive for the 'hacks' Category


MSSQL JDBC Drivers and getSchemas 2

At work, we’re in the process of trying out some new development projects in Java. And I guess we’re just masochistic, since we decided to write this new project against MSSQL instead of our usual MySQL. Anyways, everything’s coming together for the most part, except that few of the GUI database tools seem to be able to find our schema. Instead, it just seems to list the database users. We noticed this in Netbeans, Eclipse, and SquirrelSQL.

Yesterday, I started tracking it all down. Turns out, Microsoft introduced the concept of an actual schema in SQL Server 2005. Prior to that, tables were segmented by their owner. Consequently, the available JDBC drivers (both jTDS and Microsoft’s) implementations of DatabaseMetaData.getSchemas() actually return the list of database users.

Since I can’t do anything about Microsoft’s driver, I downloaded the source for jTDS and started poking around. In net.sourceforge.jtds.jdbc.JtdsDatabaseMetaData, around line 1589, you’ll find the following query:

SELECT name AS TABLE_SCHEM, NULL as TABLE_CATALOG FROM dbo.sysusers

After digging up a copy of the 1.5 JDK, I changed this to a query based on the information schema and recompiled. Then I fired up SquirrelSQL, and, bam. All my schemas were listed. Feeling quite proud of myself, I then discovered that someone had already filed a bug and the issue was fixed in jTDS’ CVS repository. Oh well.

Anyways, if you’re having issues browsing your MSSQL schemas with SquirrelSQL or other JDBC database tools, try building jTDS from source.

Instant Storage 1

Here’s one of my favorite PHP ‘hacks’: when I’m whipping up a quick script that needs a place to stash some persistent data, but don’t feel like coming up with a database structure, or doing anything remotely approaching a real solution, I instead stuff it into a “static” session. By static, I just mean that I set the session ID to a static value, so I’m always pulling the same session. Instant data store.

session_id('stash-stuff-here');
session_start();
$_SESSION['stuff'] = $w00tz;

(Another quick and dirty approach would be serializing an array into a local file… oh, wait, I just recreated the default PHP session handler. ;))

PHPUnit + FAM + libnotify == fun 3

Last night I ‘tweeted’ (man, I hate that word!) on some hacking I was doing with PHPUnit, FAM (the File Alteration Monitor), and libnotify/notification-daemon to automatically run unit tests as you modify files.

Credit where credit is due: this was inspired by other people’s work with other unit testing frameworks.

Anyways, the short screencast in my update last night has already generated some interest, so I thought I’d get this out on the web for perhaps wider exposure.

Coming soon: continuous integration on your desktop for your PHPUnit projects.

Binning it 0

Most of you are probably familiar with pastebin, officially, it’s a “collaborative debugging tool,” unofficially, it’s a place to temporarily stick random blobs of text for other people to look at.

We’ve set up our own instance of pastebin in the office, and I often found myself wanting to paste files on my system, or the output of commands (like svn diff). After getting sick of literally (copying and) pasting stuff into the text box, I whipped up a command line script that takes its input from a file or STDIN. Sure, these probably already exist, but who cares.

Aptly, it’s hosted at pastebin.

Digital Cloaks 0

Not too long ago, Matt talked a bit about p0f and it’s ability to distinguish your operating system based on the packets its sending.

Today, Hack a Day highlighted a project that can help you overcome some of the fingerprinting in p0f (and other tools, like nmap) by emulating the characteristics of other OSs.

Hack a camera 0

Seems that someone has made the Canon 40D to record movies. From the forum postings, it sounds like they’ve modified the CHDK firmware (which runs on a bunch of Canon cameras) to dump the live-view buffer on the 40D to the CF card. Unfortunately, that means that it’s probably not HD (the D90 does 720p; the 5D II 1080p), but interesting nonetheless.

Anyways, I’m still waiting for Olympus to release their Micro Four-Thirds body (that is, more than a few images of a prototype) before sending money anywhere.

Duck Typing 2

I’m in fairly creative mood tonight, as evidenced by one (now two) blog postings, the PHP coding I did earlier, and the upload of some 75 random pictures to Facebook. I guess that’s what happens when I avoid the work I really should be doing. (Blech, JavaScript.)

Anyways, a few days ago a coworker mentioned something to me about duck typing, and I again decided to shirk my responsibilities and experiment. The basic idea is to stand typing on its head and have an imperative system rather than declarative — as they say, “if it walks like a duck, and quacks like a duck, it must be a duck.”

Read more »

“High-Def” Webcams 3

(The term High-Definition appears to be able to be applied to anything these days, so why not webcams?)

For the past few days I’ve been obsessing watching this webcam over at the Red Rock visitor center, and just now I wrote a quick script to fetch the latest image and update my desktop background with it. It’s almost like having my desk near the window back. (OK, not even close.) But, truth is, it makes a pretty crappy background at 1920×1200. Look at this other one in comparison — now that’s a webcam.

Then I remembered. Since buying a used 20D, I have an old D30 just sitting around. With a bit of Canon software magic, that can easily be setup to take a shot at any interval and automatically transfer it to the PC. I just have to write a little plumbing to get it up on the web.

I want to do this!

Tunnel to the World 0

A lot of people know that OpenSSH’s client supports tunneling out of the box. But some don’t realize that it also supports tunneled SOCKS out of the box. Here’s how to set up a quick SOCKS proxy across an encrypted tunnel:

ssh -NfD 8888 user@host

The proxy will be on port 8888. The other flags just tell ssh to go immediately to the background (after getting your password, if needed) without running a command.

Disappearing Act 1

I’ve started trying to train myself to use Google Reader: rather than trying to remember all of the sites that I want to visit each day, and having to visit each one independently, I can go to one place and view them all. Sure, these are all benefits of RSS readers, and everybody else discovered them years ago. What can I say, I’m slow.

Anyways, Google Reader caches things on its own (which makes sense), and that has a peculiar effect: if Reader hits up the RSS feed while an article exists, and then the author decides to delete said article, said article will appear in Reader, but not on the site.

Which is where I find myself right now: I have an entry from Matt entitled, “A More Perfect Blog,” that shows nowhere on the site. So… where’d it go, Matt? 😉

Next Page »