by simon baird

Friday, July 28, 2006

Aw... my first real inject

It's a special moment for any ruby programmer when they create their very first real inject. I don't mean in some sample code but in a real live program. It just happened to me and I'm very proud. :) Here it is:
#!/usr/bin/ruby

require 'uri'
require 'net/http'

LINE_MATCH       = /\/\/DATA\|\|\|/
FIELD_DELIM      = /\|\|\|/
NAME_VALUE_DELIM = /:/

url = 'http://www.jcu.edu.au/app/timetable/?subjectslist=CP1010&campus=Townsville&sem=2&doit=yes'

data = Net::HTTP.get(URI.parse(url)).to_a.grep(LINE_MATCH).map do |line|
  line.strip!.sub!(LINE_MATCH,'').split(FIELD_DELIM).inject({}) do |hash,pair|
    name,val = pair.split(NAME_VALUE_DELIM)
    hash.merge(name.to_sym => val)
  end
end

p data
I'm writing a hack to scrape timetable data from an existing web app and convert it to iCalendar format. I have the ruby iCalendar gem so I think I'm almost done. ...happy dance...

Wednesday, July 26, 2006

gpokr.com

Speaking of poker, this is cool. More info here.

Poker Night 3

The night went on later than previous poker nights. The third game finished about 2am. First game was won by me (the best one to win since it had the most players), second by my brother Nathan, (visiting from Sydney), third by my brother Daniel. Some may claim there was some family collusion going on. To this I point out that Nathan knocked me out in the second game (pair of kings vs pair of queens) and I knocked him out in the third (flukey straight on the river vs two pair). Despite some email sledging neither previous winner Michelle or Alex C made it to the winners circle, though Alex came second twice (second wins your entry fee back) and took home two bags of salty plums, so he wasn't too far out of pocket. Michelle had some bad luck when she bet hard on a four card "straight". Oops! Derek picked up a second place against Nathan, and Alex S was chip leader for a while in the final three on the last game, but she couldn't close the deal. Losers enjoyed a game of (erotic) 31 Bustop. We now know the rules governing when you can re-raise and also are getting a bit better at handling side pot confusion. So all-in-all a good time was had by all and blah blah etc. Next poker night some time in September maybe.

Tuesday, July 25, 2006

Hail Google Overlords

I just tried Gmail Mobile. I read some email and sent a message from my phone. It's pretty cool. The page says you can view attachments like pdfs, images and word docs on your phone. Wow. I wonder if I can send a photo as an attachment.

Update:
No sending attachments. I tried viewing pdf and word doc. Works nicely.

Monday, July 24, 2006

zune, regina spektor

Microsoft is going to launch an iPod competitor. It's called Zune. More here. But I really just wanted to show you the little cartoon and music here. The sweet tune caught my attention. It is Regina Spektor. Conan likes her. So does Julian Casablancas, so she must be good. Hang on a sec... Try this. Note to self, still haven't found any Françoiz Breut. She doesn't exist on iTunes, YouTube or my usual torrent fetchers. Might have to (gasp) purchase a cd...

Friday, July 21, 2006

The wonderful expressivity of why the lucky stiff

Oh rapture! Oh, delicious zesty snacks! Oh, steamed uncles in a cabbage display! OH, LAMB MEDALLIONS!

If you like that try some more of why's prose.

Thursday, July 20, 2006

Oracle PL/SQL function to split strings into tokens

I was trying to find how to split or tokenise (tokenize) a string in Oracle SQL. Technically you can do it directly with just instr and substr but your statement becomes very long and hard to read, mainly because you can't reuse the result of an instr. I found this which was interesting but not what I needed, so I wrote my own function to do the job. I'll post it here in the hope that it will be useful to someone.
create or replace function get_token(
   the_list  varchar2,
   the_index number,
   delim     varchar2 := ','
)
   return    varchar2
is
   start_pos number;
   end_pos   number;
begin
   if the_index = 1 then
       start_pos := 1;
   else
       start_pos := instr(the_list, delim, 1, the_index - 1);
       if start_pos = 0 then
           return null;
       else
           start_pos := start_pos + length(delim);
       end if;
   end if;

   end_pos := instr(the_list, delim, start_pos, 1);

   if end_pos = 0 then
       return substr(the_list, start_pos);
   else
       return substr(the_list, start_pos, end_pos - start_pos);
   end if;

end get_token;
/

Example usage:
select
   get_token('foo,bar,baz',1), -- 'foo'
   get_token('foo,bar,baz',3), -- 'baz'
   --
   get_token('a,,b',2),        -- '' (null)
   get_token('a,,b',3),        -- 'b'
   --
   get_token('a|b|c',2,'|'),   -- 'b'
   get_token('a|b|c',4,'|')    -- '' (null)
from
   dual
/

Notes
  • Remember that the index starts at one not zero just like strings in PL/SQL.
  • Empty tokens are counted. You get null if you ask for an empty token.
  • You also get null if you ask for an index greater than the number of tokens.
  • The delimiter defaults to a comma but you can specify any delimiter. A delimiter of more than one char should work also.

Update 22/8/12

When I wrote this I didn't know about regexp_substr. (Or maybe the version of Oracle I was using didn't have it). You can do this much easier using the regexp_substr method. Have a look at the regexp_substr docs or see some examples in the comments below. For example:

regexp_substr('abc_def_ghi','[^_]+',1,3);

==> ghi.

would you take $1000 a month to do what you were already doing?

Netscape is reportedly offering money to lure successful digg posters over to post at the new netscape.com a digg rip-off. There are some interesting comments on the article. Would you take the money? I would...

theory on movies

I have a theory that a movie based on a play has a higher chance of being good. Plays have to work without action scenes. The dialogue must be sound and snappy otherwise the play will bomb. This is obviously not the case for movies, eg [insert example bad movie here]. Here is a list of movies that helped me form my theory:
  • Hurly Burly
  • Rosencrantz & Guildenstern Are Dead
  • SubUrbia
I have another theory that states that any movie with Parker Posey in it has to be good, at least when Parker is in a scene. (See third example above). This leads me to believe that Superman might be worth seeing. It hits one out of two of my good movie indicators.

I saw Pirates of the Caribbean: Dead Man's Chest. It was pretty good. The action scenes have taken a leap towards the completely ridiculous but it didn't bother me like it did in Charlies Angels II. And the voodoo lady... wow! How is it possible that a woman with back teeth and red eyes could be so incredibly beautiful? I don't know but the voodoo lady was worth the price of admission for me. My one gripe: Davy Jones had too many tentacles. Surely he would have had just eight.

Tuesday, July 18, 2006

Animated music thing

Tuesday, July 11, 2006

Thom Yorke - new song live

If you're like me and the sound of Thom holding any tuneful vowel sound longer than 4 seconds has a reasonable chance of inducing involuntary goosebumps no matter how unlistenable the song then click here to see Thom live and accoustic on the Henry Rollins internet TV show. (Did that sentence need commas?) And it's almost listenable. Apparently he has a new solo album coming out soon. Via Stereogum

Sunday, July 09, 2006

Jack Black's Talent

I'm a huge fan of Jack Black and Tenacious D. School of Rock is one my favourite movies. Let alone his comedic talent, his musical talent truly would slay demons. Hope you enjoy this as much as I did. I'm sure I hummed this tune for days after just one listen. It's his song about King Kong from his spot on SNL (a show that, thanks to the miracle of bit-torrent, I no longer have to watch via three year old repeats on Arena TV). Brought to you by some guy on youtube.

Sunday, July 02, 2006

Disco Tex and his Sex-o-lettes

There's a Pet Shop Boys song on their 1996 album, Bilingual, that goes "It's the greatest show with the best effects since Disco Tex and the Sex-o-lettes". Well I never really knew that Disco Tex and the Sex-o-lettes were real, until Saturday when I found this: I don't have a record player so I can't tell you what they sound like. But judging by the cover and the Pet Shop Boys lyric it's going to be pretty special. Probably better live though. I don't generally dig through op-shop records. This one was on the top. So it's quite lucky that you're getting to see it. :) Check out the Amazon Reviews.

Thursday, June 29, 2006

Sure-fire get rich scheme #127

It seems like Christian rock bands don't have to be that good to sell records. I know this since a certain now-closed Salvation Army store in my neighborhood used to tune regularly to Live FM. I would listen carefully while browsing the shirt rack on a Saturday morning. Live FM will play below average quality music if it mentions loving Jesus. Hollywood is not unfamilar with the Christian dollar. For example Narnia - I would suggest (without any evidence mind you) that the marketing of that movie involved strategically engaging the backing of influential Christian groups and spokespersons. And that Mel Gison movie about torturing Jesus made $611 million. I wonder how many people went because their pastor/TV evangelist recommended it? (Once again speculation. For quality, researched articles please try another blog.. ;). Anyway my get rich scheme is to make Christian video games. I only wish I'd thought of it first. These guys are going to be very rich! Daniel is trying to download the free demo. Stay tuned for a mini-review. Via The Raw Feed.

Monday, June 26, 2006

one last thing

Go socceroos. I'm recording the 1am game. I figure I can watch it at 7am and still make it to work roughly on time. And if it's a slow game I can watch on double speed, though I must remember not to turn on the news.

Update
NOOOOOOOOOOOOOO!!!!! Oh that was horrible.

Scooter fuel economy

My fuel gauge is coy. It's a five LED display that prefers to give gentle hints about how much petrol I have left rather than just come right out with it. So I noticed last time I filled up that my mileage was exactly 17000 kms. I thought, "Aha! I will remember that, and use it to calculate my miles per gallon or whatever the youngsters are calling it these days". So I rode for a while until the gauge intoned to me that just maybe it was that time again. When I pulled in to Shell on the way to work my mileage was exactly 17200 kms. "How about that" I thought. "This will make my sums a little easier". The tank seemed pretty dry. I filled it right up so the fuel was a couple of millimetres from spilling out. It was exactly 7.00 litres. I was a little startled by this. I thought perhaps God doesn't trust me with decimal arithmetic. So anyway, I crunched the numbers in Excel, double checked with Matlab, and I can now reveal the following analysis:
Distance: 200km
Fuel:     7 litres
Economy:  3.5 L/100km
I also discovered my round trip to work is 13 km, so that means I should fill up every 15 work days, with a 5km margin for error, (unless I take trips to the shops or the video store). Now that's some applied mathematics. A Honda Jazz is supposed to get 5.7 L/100km. A Prius is supposed to 4.4 L/100km so my scooter beats them by not by that much considering it's a scooter.

tiddlyspot.com

tiddlyspot.com is a brand new web site that Daniel and I put together, starting last Friday. It's a little hard to explain. First you need to know what a wiki is. Yeah? Ok. Then you have to know what TiddlyWiki is (not too hard, it's a wiki that runs in your browser). Then I can explain that tiddlyspot.com is a easy, free service for creating and hosting a TiddlyWiki. Stay tuned for more on this later. Trust me, it is extremely cool. Plus I am getting to learn ruby which is a bit like trading in your crappy analogy for a really awesome red one with a top speed of say 300 km/hr.

geeky stuff

Long time readers might have noticed my super home media thingy in the photo in my previous post. A slight update on that fine piece of kit is that I fixed by bandwidth problems between upstairs and downstairs. I can now watch any video and share iTunes libraries from upstairs. I will try to explain with a diagram. Old configuration (problematic): [Upstairs PC] <--wireless--> [ADSL Box (kitchen)] <--wireless--> [SHMThing] The wireless card in Upstairs PC was a bit flakey and causing drop outs in connectivity. Now I have this new configuration: [Upstairs PC] <--good old wired ethernet--> [ADSL Box (study)] <--wireless--> [SHMThing] I moved the ADSL box from the kitchen to the study with Upstairs PC. If I position in right I can get a good signal strength to downstairs. And now everything is cool. Except I need to get some more disk space upstairs (more room for mp3s, torrents and dvd rips) and down (more room for recorded tv shows).

My new recliner

Once I had the idea of writing a blog called "op shop treasures". In it I would describe and photograph all the beautiful stuff I've found at local salvos, endos, vinnies, lifeline, etc. Milly and I love to tour our favourite spots on a Saturday morning. There are so many amazing things we've found. I think Townsville is probably better than a capital city since there anything slightly cool or valuable is likely to be picked up fast and resold by professionals from trendy used clothing/furniture/bric-a-brac stores. Nearly all my clothes (and I only buy top quality), a lot furniture, my drum kit (incl Zildjian cymbals and a Ludwig snare, $100 total), etc, etc, have all come from the smorgasbord of delights that is Townsville's op shop world. Yesterday we found: blue recliner, excellent condition with matching love seat; a large glass topped coffee table. I can report the recliner is extremely comfortable. I'm trying to demonstrate this in the third photo. The recliner and lounge was $220. I know, seems like a lot but keep in mind that they in very good condition. And the colour matches our dark blue wall perfectly. The coffee table was a bit expensive for a coffee table, $150, but it is cool because you can display small items under the glass. Milly has put her collection of Japanese plastic miniature thingies under the glass. The effect is very artistic especially when you scatter various remote controls and coffee table clutter on top of the glass.