Archive for August, 2011

Wildcard string matching on linux

If you’re on linux, the GNU C library has a handy function for doing wildcard matching called fnmatch. I notice it’s also supported in Python, PHP and Perl and probably in a few other scripting languages.

I’m amazed that I haven’t ever needed to do this before but I had the case this year that I needed to allow a list of strings to contain wildcards. At first I just implemented this myself as I only needed to support the wildcard on the ends of strings but once I started using it, I wanted to allow matching the wildcard in the middle of strings too. That’s the point at which I realised I’d need some kind of stack and parsing and grammar so after 3 seconds on Google, I found fnmatch. It’s times like this you wonder why you didn’t just look this up in the first place.

Leave a Comment

Postgres Table Sizes

Sometimes it’s handy to know the tables in your DB that are taking up the most space. Here’s a quick query that returns the table names and pages used in descending order:


SELECT table_name, relpages
FROM information_schema.TABLES
INNER JOIN pg_class
ON relname=table_name
WHERE table_schema='public'
ORDER BY relpages DESC

 

The reason for the join on the information schema is to limit the results to just the tables you created. If you just use pg_class, then you also get the sizes of indexes and views including the postgres owned objects.

Leave a Comment

Streaming MMS to iPhone

It’s possible to listen to an MMS stream on an iPhone/iPad using the TuneIn Radio app. Read on to find out how it’s done.

Like many hip and in-the-know people around Australia (and indeed the world), I tune in to The Thursday Morning Herald (posterous) with Sam Gunders on Phoenix Radio at 8:45am EST (Thursdays obviously) which is an online only station.

However, due to school drop-off commitments, I’m often driving to work for most of the show. Thankfully, there is a cool new invention called 3G that allows the Internet to be accessed from mobile devices. Also, because I am a hip and in-the-know kind of guy, I have an iPhone and one of those car-stereo mp3 to radio transmitter things that plug into the cigarette lighter aka “12V power outlet” of the car.

The TuneIn Radio app is available in the Apple App Store in two flavours. For this exercise you’ll need the full version which set me back a massive 99c this morning. With the full version of TuneIn installed, you can enter in a custom URL: tap the search bar and press the ‘Custom URL’ button. At this point, you’ll want to double tap the home button and head over to Safari. Browse to the phoenix radio USQ page and tap and hold the “Listen Live” link and choose the ‘Copy Link’ menu option that pops up. Now double tap home over to TuneIn and tap the search box again, you should get a little ‘Paste’ popup button that will allow the MMS URL to be entered into the search box. (Or you can just copy and paste from here: mms://media.usq.edu.au/springfieldradio

From here it’s a simple matter of tapping the ‘Custom stream’ search result which takes you to the player screen. Once on the player screen, you can tap the heart on the top right of the screen to save the radio station for faster access next time.

The ‘connecting’ bit can take a long time. I had to wait five minutes the first time I connected and three minutes later but once it started up, I had no glitches at all and drove from North Ryde to Blacktown along the M2 with uninterrupted hip and grooving Thursday Morning Herald sounds.

Comments (1)

Menus in Gvim under Ubuntu 11.04 (Natty Narwhal)

The text editor Gvim has menus that aren’t compatible with the new Unity window manager in Ubuntu 11.04 (Natty Narwhal). To get around this, you can tell Ubuntu to fall-back to the old Gnome style menus by setting the UBUNTU_MENUPROXY environment variable to null:


UBUNTU_MENUPROXY= gvim filename.ext

 

Leave a Comment