Archive for February, 2008

My blue belt 5

Last night our club's latest batch of coloured belts were awarded. I was among five students that received a shiny new blue belt.

Adam has traditionally had his coach, John Will, present the coloured belts every 3-4 months when he's in Western Australia for a jiu jitsu seminar.

When I was in Melbourne last year at the Machado Nationals I talked to Adam about me receiving a blue belt, and how I imagined it happening. I said that whilst I respect John and his skill, to me he's not really an important or influential part of my jiu jitsu. I asked that when the time came (and if it came!) for Adam instead to present me with my blue belt.

Adam's been my coach from the beginning and is immensely influential in my study of the martial arts. Considering the achievement that attaining a blue belt is, I wanted to get all that I could out of the presentation. It might sound corny, but it was Adam that was acknowledging my progress over the last two and half years, so I wanted it to be him that presented my belt. A few weeks ago I gave Adam a gentle reminder that I wanted this, and he let me know that he hadn't forgotten.

I'm not sure if it was this discussion specifically, or if it had any influence at all on Adam, but he decided that he was going to present all the coloured belts from now on. I mean, he's a black belt in his own right, so he doesn't need the "approval" of John when issuing belts.

This meant that I was the second person ever (I should have pushed in front of Joe ;) to have a coloured belt awarded by Adam, and I was among the first group ever. Sure, he's graded people to that level before, but it's never been him actually awarding the belt.

That was really meaningful to me.

To top things off, Phil received his purple belt, which is another first for Adam. In the next 3-6 months I think we'll see a few brown belts being issued at the club too, as there's a few guys that are really close.

Joe, myself, Adam, Rory and Jin

Nick's not in this photo because he didn't come to the beginner's class, but he was awarded his belt at the beginning of the advanced class.

The "problem" with getting your blue belt is that now toe, ankle, knee, hip and all other leg locks are available to me. It's a problem because I've never defended these attacks before, so traditionally you're given a nice ass-kicking by one of the senior belts as a "welcome to the big leagues."

My first roll was with Phil, and though he made a few attempts at my legs I was able to keep him at bay and finish the wrestle un-touched. I even managed a really nice figure-four sweep on him from my guard, so I was happy with how that wrestle went.

I had a roll with Adam, which never really counts. He won't ever make you tap, but instead he puts moves on and lets them go before you've even worked out what's going on :)

But it was the roll with Nathan where I consider my "cherry popped." I got out of a few knee-bar attempts, but he ended up catching me with a great leg lock about 60 seconds into the match. His grin, though kind and cheerful, said it all:

"Welcome to the next level."

Building SQL queries with Ruby 0

Now that I can require "dbi" in my scripts and have access to ODBC databases, I worked out what I think is an easy way of building dynamic SQL strings from an array of field names. Consider the following:

search = 'findme'
fields = ['ServiceClientID', 'Company', 'Firstname', 'Lastname', 'HomePhone',
          'WorkPhone', 'MobilePhone', 'MailingAddress', 'Email', 'SiteAddress',
          'SiteContact', 'Region']
sql = "SELECT " + fields.join(', ') + "
       FROM tblServiceClients
       WHERE " + fields.map {|f| like_search(f, search)}.join(' OR ') + "
       ORDER BY Firstname, Lastname"

This requires a method called like_search which takes two parameters: the field name and the search string. It looks like this:

def like_search(f, search)
  "#{f} LIKE '%#{search}%'"
end

Altering the fields means that you add or remove elements in the fields array. Although it's not anywhere near as nice as the interfaces that Rails provides, it's still very handy. The resulting SQL string is:

SELECT ServiceClientID, Company, Firstname, Lastname, HomePhone,
    WorkPhone, MobilePhone, MailingAddress, Email, SiteAddress,
    SiteContact, Region
FROM tblServiceClients
WHERE ServiceClientID LIKE '%find_me%' OR Company LIKE '%find_me%'
    OR Firstname LIKE '%find_me%' OR Lastname LIKE '%find_me%'
    OR HomePhone LIKE '%find_me%' OR WorkPhone LIKE '%find_me%'
    OR MobilePhone LIKE '%find_me%' OR MailingAddress LIKE '%find_me%'
    OR Email LIKE '%find_me%' OR SiteAddress LIKE '%find_me%'
    OR SiteContact LIKE '%find_me%' OR Region LIKE '%find_me%'
ORDER BY Firstname, Lastname

Connecting to MSSQL with Ruby on Ubuntu 0

I'm working on a problem for a client which involves connecting to a Microsoft SQL Server 2005 database from Linux using Ruby. Here's what I did to get it working, based off some useful instructions that are tailored for Ruby on Rails:

Firstly, update your ~/.profile to include the following:

export ODBCINI=/etc/odbc.ini
export ODBCSYSINI=/etc
export FREETDSCONF=/etc/freetds/freetds.conf

Then reload your .profile, by logging out and in again.

Secondly, on Ubuntu 7.10 Server I needed to install some packages.

mlambie@ubuntu:~$ sudo aptitude install unixodbc unixodbc-dev freetds-dev sqsh

With FreeTDS installed I could configure it like this:

mlambie@ubuntu:/etc/freetds$ cat freetds.conf
[ACUMENSERVER]
  host = 192.168.0.10
  port = 1433
  tds version = 7.0

The important thing here is ACUMENSERVER, which is the DSN that I'll use when connecting to the database. The host, and port are self-explanatory, and it's worth noting that I had to use 7.0 specifically as the tds version.

Testing FreeTDS is not too hard:

mlambie@ubuntu:~$ sqsh -S ACUMENSERVER -U username -P password
sqsh: Symbol `_XmStrings' has different size in shared object, consider re-linking
sqsh-2.1 Copyright (C) 1995-2001 Scott C. Gray
This is free software with ABSOLUTELY NO WARRANTY
For more information type '\warranty'
1> use acumen
2> go
1> select top 1 firstname, lastname from tblClients
2> go

[record returned]

(1 row affected)
1> quit

Next up it's necessary to configure ODBC:

mlambie@ubuntu:/etc$ cat odbcinst.ini
[FreeTDS]
Description     = TDS driver (Sybase/MS SQL)
Driver          = /usr/lib/odbc/libtdsodbc.so
Setup           = /usr/lib/odbc/libtdsS.so
CPTimeout       =
CPReuse         =
FileUsage       = 1

mlambie@ubuntu:/etc$ cat odbc.ini
[ACUMENSERVER]
Driver          = FreeTDS
Description     = ODBC connection via FreeTDS
Trace           = No
Servername      = ACUMENSERVER
Database        = ACUMEN

I then tested the connection with isql:

mlambie@ubuntu:~$ isql -v ACUMENSERVER username password
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL> use ACUMEN
[][unixODBC][FreeTDS][SQL Server]Changed database context to 'Acumen'.
[ISQL]INFO: SQLExecute returned SQL_SUCCESS_WITH_INFO
SQLRowCount returns -1
SQL> select top 1 firstname from tblClients;

[record returned]

SQLRowCount returns 1
1 rows fetched
SQL> quit

 
OK, so we've got ODBC using FreeTDS to connect to a remote MSSQL server. All that's left is to add Ruby into the mix.

mlambie@ubuntu:~$ sudo aptitude install libdbd-odbc-ruby

The last thing to test is that Ruby can use DBI and ODBC to hit the actual database, and that's easy to test:

mlambie@ubuntu:~$ irb
irb(main):001:0> require "dbi"
=> true
irb(main):002:0> dbh = DBI.connect('dbi:ODBC:ACUMENSERVER', 'username', 'password')
=> #<DBI::DatabaseHandle:0xb7ac57f8 @handle=#<DBI::DBD::ODBC::Database:0xb7ac5744
@handle=#<ODBC::Database:0xb7ac576c>, @attr={}>, @trace_output=#<IO:0xb7cbff54>,
@trace_mode=2>
irb(main):003:0> quit

And a more complete test (only with SQL SELECT, mind you):

#!/usr/bin/env ruby

require 'dbi'
db = DBI.connect('dbi:ODBC:ACUMENSERVER', 'username', 'password')
select = db.prepare('SELECT TOP 10 firstname FROM tblClients')
select.execute
while rec = select.fetch do
  puts rec.to_s
end
db.disconnect

 

 

Chicks love big discks 2

Adam and I have had our MacBook Pros for about 18 months. The plan was to refresh them after two years, but they way they're going I don't know if that'll be necessary. The processor is still fast enough and we upgraded them to 2GB of RAM a little while back so spec-wise the only thing lacking was storage - we had the standard 80GB disks still. This needed to change.

I had Digilife order in two 250GB disks last week and they arrived on Friday. I called this morning to arrange installation, but it was going to take too long to have the disk content copied across. Even though we're capable of installing the disks, and there's guides online, it voids the Apple warranty. With these being business machines that's definitely not something we want to do. Installation would take about 30 minutes for each disk while cloning the data was going to take a few hours. We couldn't afford to be without the machines for that long so we decided to get two external hard disk caddies and clone the data ourselves at a suitable time.

Well it turns out that OS X doesn't officially support booting from an external USB2 hard disk, and the two CoolerMaster XCRAFT-250 caddies I bought don't work at all under OS X. Yikes! I called Austin Computers in Cannington to confirm that they had an alternative brand of caddy available and drove from West Perth to collect them. I paid the invoice and went to dispatch, at which point they told me the didn't have any of the items in stock. I wanted someone to take some responsibility and was told "let's not play the blame game" by some pencil-neck geek. The guy that stuffed up my order was more appologetic and suggested a few other shops.

I want to go on record as saying:

Fuck You Austin Computers

Thankfully Storm Computers (who have a broken website at the moment) in Welshpool had two types of caddy so I bought one of each. They both appear to be working fine.

I used Time Machine to restore Adam's computer completely, and did a fresh Leopard installation on mine. I then used the Migration Assistant to copy over my old data. I enabled the Guest account and logged in as the Guest to allow me to overwrite the mlambie user.

Hopefully this extra disk space will mean that the MacBook Pros are useful, longer, and we'll squeeze even more value out of them... though the rumours are that Apple's announcing new MBP models in a few hours :)

Academy boys put in a good showing 1

Today we had three guys from The Academy of Mixed Martial Arts compete in Shooto II, a local MMA event. I checked it out with Aaron and Jacob, and a bunch of other dudes from the club. In all there were 10 fights, though we only stayed until Ian's fight, which I think was 8th or 9th. Entry was only $15 and it was popular, which translated to everyone being crammed in.

On a side note, I'm always surprised that these gyms never had mega-air-condooli... it'd be the first thing I'd install when renovating, in this case, an old church.

Andy was the first fighter up and he suffered a first-round knock out. He is a kickboxer so I don't really know him but he put in a good showing before he was caught with a jab, jab, right-hook combo that sent him to sleep. The other fighter we recognized as having a few fights under his belt so it was a good effort on Andy's part, but an unfortunate outcome.

Our second fighter was Joe, who I train jiu jitsu with. He's a strong grappler who'll be getting his blue on Thursday with me. He has a really good side control which we saw demonstrated in his first round submission. He went for the take down and gained side control, on the left of his opponent. He set up a head-arm choke, jumped to mount, and then jumped off to side control on the right. He sunk the choke in deep and scored the tap out in his first MMA fight.

Last up was Ian, one of our blue belt grapplers. This was his first fight and he was competing against a seasoned fighter (it was class-C but we all recognized this guy from other fights). Ian held his own in the first round, scoring more take downs but I thought his boxing wasn't as good as the other guy's. In the second round we all thought Ian dominated but loose kick at the end of the round was converted into a take down by his opponent, and the two points he gave up as a result ended up being the deciding factor - 19 vs. 20 at the final bell. Ian was in good spirits and was happy with his showing, as were we all. Adam disputed some of the points but it didn't end up changing anything.

The club's got some great talent and it's good to see our guys tested in this kind of environment. A solid performance always does well for the club's moral, which will be soaring after today's efforts.

I took some video on Merv's camera (that's what I get for being 6'2" - I'm the camera man) so hopefully that gets uploaded and I'll link it in.

Next Page »