Friday, 30 May 2008

Unit Testing

With apologies to The Monkeys
I thought unit tests were just for fairy tales
Never had the time to do things right
Going live was frantic
Development a drag
Changing all my code got real bad

Then I wrote my tests, now I'm a believer
Without a trace of doubt in my mind
I'm in love - mmmmmmm
I'm a believer, best thing I've ever tried

Ahem. Or something. I've just made substantial changes to two of our production systems over the last couple of weeks, but thanks to Andy and some stuff we did months ago in a pub, I have tests. They rock. Not saying they've nailed everything but certainly they've made a big difference.

The first system I changed it was remarkably painless and I felt remarkably confident. The second system was a bit more rushed but the go live had no major issues. The one issue that did crop up I changed on my test system here, ran the unit tests, watched them fail, fixed the code again, ran the tests again, watched them past, svn updated the live system and all was fine. Never felt in much panic and making the fixes was a much more pleasurable experience.

The only problem is - I can now see all the areas I don't have tests for ...


pg_top on Ubuntu Hardy - Postgres top utility

This morning I got pgtop working but had some questions which I forwarded to the author Cosimo Streppone. In his very polite reply he pointed out I should really be using pg_top (note the hyphen) so I then set to getting that to work on Ubuntu Hardy Heron.

Download the latest release from the site above (I downloaded pg_top-3.6.2.tar.gz) and then

tar -zxpvf pg_top-3.6.2.tar.gz
cd pg_top-3.6.2
./configure
make


It's very possible you might get some errors during this. The three I had were
configure: error: no acceptable C compiler found in $PATH

You don't have the basic build tools installed. Do.
sudo apt-get install build-essential


Also during config
configure: error: pg_config not found

Get the postgres dev libs - do
sudo apt-get install libpq-dev


During make I got a heap of errors - starting with
gcc  -Wall -g -L/usr/lib -lpq  -o pg_top color.o commands.o display.o getopt.o screen.o sprompt.o pg.o pg_top.o username.o utils.o version.o m_linux.o -ldl -lm 
display.o: In function `display_move':
/home/icottee/pg_top-3.6.2/display.c:257: undefined reference to `tgoto'
/home/icottee/pg_top-3.6.2/display.c:257: undefined reference to `tputs'
display.o: In function `display_write':
/home/icottee/pg_top-3.6.2/display.c:387: undefined reference to `tgoto'
/home/icottee/pg_top-3.6.2/display.c:387: undefined reference to `tputs'

The solution I found was to
sudo apt-get install libncurses5-dev

Then rerun config AGAIN and do a make.

Now I could
pg_top --help

And all was good. Read the web page for info about what you can do with it. But in short you can see all running postgres processes, see what they are doing, examine their query plan, what locks they have and examine table and index statistics of the relevant tables. Full info and screenshots can be found here.

Thursday, 29 May 2008

Old rails, rake - running on Hardy

From my own benefit ... to help with installing and maintaining our old ruby apps, do this

sudo apt-get install rails rubygems irb ruby
sudo gem install -y rails --version=1.2.3
sudo gem install -y rake --version=0.7.3
sudo gem install -y postgres-pr

The problem with this is that it's not sitting in your path and Ubuntu will keep asking you to install rails via apt. So

sudo ln -s /var/lib/gems/1.8/bin/rails /usr/local/bin/rails
sudo ln -s /var/lib/gems/1.8/bin/rake /usr/local/bin/rake

Monday, 26 May 2008

Apple are slick

Email from Apple to me after I registered my new purchase
Thanks for registering your new Mac. We have the following on record in your name:
[[IREG_PRODUCT_TEXT]]

Sunday, 25 May 2008

Strange Shinto Days

There was some kind of meeting in the shrine today. I have no idea what it was about and would not bother to ask. It didn't sound like the most interesting event in the history of Shinto but seemed to involve a lot of priests and study and talking.

Strange that I should view such a thing as strange. It's a religion, people have views, I guess things need to be discussed. When I came back from the park with the kids I smiled and bowed to the people outside just in case I knew them. No reaction at all. A lot of strangers.

So a lot of people came to the shrine today to discuss 'Shinto things'. It's a religion - that's what people do.

This evening I had some wine and some beers, went to bed late. Not long after I fell asleep Akemi woke me up. The alarm that triggers when somebody had come into the shrine had sounded (I didn't hear, I was totally asleep) and Akemi said she thought there was a candle outside the shrine. I looked out the window at the candle. Looked like a light bulb to me - in a strange place. I went into the shrine and nothing human or supernatural jumped on top of me. When I came back upstairs Akemi thought the light might be a reflection from the illumination of one of the 'things' outside. She's probably right.

There's a story about that alarm but I'll tell it another time.

And I'm lying in bed now, wondering why I call the 'thing' outside a 'thing'. Why the hell don't I know what it is?

I'm also thinking I love superstition even though I don't "believe" in it. Makes life a little spicier.

Doug Stanhope - Would You Believe ?

Yeah I like this guy.

Welcome from the MacBook Pro

It arrived a day late and is looking pretty cool so far.

So I'm typing this with MarsEdit first of all to see how I get on what that.

What have I noticed about the new machine. Some random comments made in no particular order. Here's the low down on the specs of the Machine.

Model Name: MacBook Pro
Model Identifier: MacBookPro4,1

Processor Name: Intel Core 2 Duo

Processor Speed: 2.4 GHz

Number Of Processors: 1

Total Number Of Cores: 2

L2 Cache: 3 MB

Memory: 4 GB

Bus Speed: 800 MHz


It has a 250GB hard drive, 5400 RPM

I've been through a number of laptops in the last couple of years. I had the MacBook which replaced my old iBook and died a horrible death. Which was replaced by a Sony Vaio VGN-FE41Z. And I've also been running the Dell Inspiron 630m which I think become my second favorite laptop ever, just behind the 12" iBook before it too popped it's clogs. So maybe over three years I've had five major laptops - running a mixture of OS X, Linux and Windows (XP and Vista).

I had a bit of a epiphany regarding laptops a short time ago. Because even though I was loving Hardy Heron on the Dell I realised that linux laptop compatibility is a lottery - unless you get one with Ubuntu preinstalled which limits somewhat your choice of machines, trying to get all your laptop features running can become something of a fulltime job. Even on the Dell resume/suspend didn't work (although it did under Gutsy 95% of the time - I suspect I tweaked something in the past which I've since forgotten). So upgrades are exciting times with new treats and old ones sometimes taken from you. The Dell 630m was great but even it was showing it's age. I was plotting what to replace it with and was thinking of something like my last week's Vista setup but on a much nicer spec machine. You have all the drivers provided, suspend works, you can buy some crappy bargain bit of hardware not wondering if you'll ever be able to use it. So if the "X Server, VMWare" trick works and you can use Ubuntu easily within a windows environment it makes sense to go the Windows route.

Because the only other option is the Apple route and I swore to the gods I wouldn't give them my money again until they sorted out their production process ... i.e. I won't buy a MacBook until they start making them reliable and resilient. We've bought so many of them and had so many problems and the Apple Care they provided wasn't much use either because you have to sit there arguing that, no, you didn't crack the front casing of it and this is a problem that thousands of others have suffered from. And they still don't believe you. And why don't we just buy Dell's instead because you can get cheap accidental damage cover with that. And actually Vista is not that ugly. It's quite nice. But it's slow. And not very reliable. And 3GB of RAM is about your max. Oh and Steve Balmer.

Apple are evil. Microsoft are evil. Ubuntu are not evil (or at least, if they are, they're keeping it quiet so we don't feel bad about using an evil os). But we have to use evil hardware with the good software and maybe something won't work properly. Hmmm ... Apple.

Am I rambling?

Anyway, on the spur of a moment decision I went back to Apple. I bought a MacBook Pro because I was not aware of them suffering the same monumental build quality issues as the MacBook. It's a Unix based laptop. It has a great screen and a great keyboard. It has good battery life. It's fast. I was in Japan when the other laptop died and I could easily get a US keyboard and a worldwide warranty. I love OS X.

I'll blog a bit shortly when I have my same Ubuntu VMWare setup up and running. I'll blog a little bit later, maybe in a couple of months, when I've worked out whether this is really changing my life. If it can and I can reduce my laptops to one again, I'll be a happy man.

Friday, 23 May 2008

The Horror of Coding

Preach it brother.

These sorts of things that could broadly be classified as unexpected work are coming up with some regularity these days and I was complaining about it, as you do, while me and several folks from the crew I'm on were heading out to lunch at an entirely mediocre deli. The root of the complaint was, "Why?". "Why are we seeing an increasing rate of unexpected work?". Dark matter. Call it what you will, it sucks. It sucks your will to live. This tree search way of working gets tiring in a hurry. If you've been doing this for even a short while you know what I mean. How absolutely draining and demoralizing it is. How much it makes life, inside and outside of work, truly suck.

You know, you hit another problem you weren't expecting, you traverse back up the tree, sit back in your chair, maybe take a deep breath, and stare at the screen for a few minutes because, now, with so many traversals these days, it takes a real act of will to go deal with whatever it is that's suddently, annoyingily, in your way. This despite the fact that you're going to fall behind in your current task, which is already behind because of unexpected work during your previous task and you should get on this right now. And, if you love coding, really dig putting things together, you take that sighing resignation home with you when you stop typing for the day. How could you not?

http://www.artima.com/weblogs/viewpost.jsp?thread=231225

And they they'll ask when x,y and z are not done yet.

Thursday, 22 May 2008

Ubuntu / Vista / VMware / Xming


OK, I've been using this setup for over a week. I'm a developer /sys admin who needs a Linux environment and who is stuck with just a Vista laptop. So here's my solution. Certainly not a perfect solution but a lot better than some I've used in the past.

The idea is that we run Ubuntu (or any Linux disto) within a VMware machine (I assume the free VMware player would work for this, but i'm using VMware workstation). We then install the free X server Xming and use that to start X applications from the Ubuntu machine. In reality I use this for two main reasons - running Emacs with a Linux backend and controlling ssh tunnels. I can do both of these things natively in Windows or using Cygwin but both are painful in real life. And if all your live deployments have Ubuntu at the backend, you really want the same for your development environment.

First thing you need to do is install Linux on your Vmware machine. I use the Hardy Heron server install as it's a lot lighter than the desktop and we don't want to run a linux desktop anyway. Yes, a desktop inside a desktop could be construed as cool for the first day or so if you have never done it before but it soon becomes a pain in the arse. There are some other versions of Ubuntu which are even more stripped down but we use Ubuntu Server for our normal server installs so I went with that.

My Vista laptop has 2GB of RAM and is dual core. In the VM I assign both processors and 512MB of memory. I also preallocated the disk to try and eek some more performance out of it (60GB in this case). See my comments later on performance. For networking I used Host. If you are moving your laptop around a lot this may be a small pain as you'll need to keep an eye on the ip address your VM is given each time. Probably better solutions for this.

Make sure you install the ssh server. On Gutsy and Hardy it's an option you get at the end of the install process. Otherwise "apt-get install openssh-server".

On Hardy Heron default server install, once it's up and running, the important setting to change is

   /etc/ssh/sshd_config


add the entry

   X11UserLocalhost yes


and then do

   apt-get install xauth

Now install Xming and Putty. We'll use Putty to ssh into VMware and launch our apps. The settings you need in Putty are wonderfully described here along with other useful troubleshooting tips which may be of use if you are not going the Ubuntu route. On Ubuntu I just needed to do what I've described above.

Start up Xming. Now, using Putty, log into your VM. The first time you log in, if you've done what I've outlined, you'll see a message saying words to the effect that .Xauthority is being created. Now launch an X app. You might want to "apt-get install x11-apps" and launch xclock as a test. Revel in it's minimalistic glory. If you don't see xclock appear then check if Xming is trying to tell you something - check if the Xming window is flashing at the bottom of the screen for example.

If that doesn't work, check out the Xming web site or post a question here.

Now you can install anything you want to run. In practice, for me, that's meant
  • emacs
  • Firefox
  • gSTM
I have Firefox installed, as I sometimes need to browse sites through the tunnels I create with gSTM. gSTM is a Gnome app. Here it is running, on my Vista desktop. On the right hand screen you can see the obligatory x apps running which are of little use at all. The putty session on the right screen lower is running top on the VM. The upper putty session is connected to a remote system behind a remote system via the tunnel manager.

Problems.
It's not without it's problems. The screen shot at the start of this post shows me running Emacs and running some unit tests within Emacs which are doing a lot of python and postgres processing. Check out the cpu and RAM usage in the sidebar widget at the right. At that stage the machine was somewhat sluggish although useable. Certainly after a day of heavy development I found a good reboot of the whole setup (from Vista downwards) would help. Having more RAM in the laptop would also benefit although having a 3GB limit with 32bit Vista sucks. In short, you're using a VM and you'll be taking a slice (maybe I should say 'a chunk') off your performance compared to just running Linux directly.

Two other issues. Not major but to be kept in mind. I find that over the course of a day I end up with a lot of Putty sessions open. I might be able to manage these better if I spent some time looking at it - and it doesn't help that I launch my X apps from Putty as well. Xming goes with a launcher program which I haven't tried yet. That might be useful.

Final issue is copying and pasting. Sometimes this seems hit and miss but frankly that's not a lot different from what I experience in native Ubuntu. Ctrl-Insert and Shift-Insert sometimes had to be done a few times before something would wake up to what I was doing. This is something I could improve if I had the time (so you can see it wasn't that big a deal).

Benefits
I've been laughed at once already today for saying this, but I'll say it again. I like the look of Vista and I've grown really attached to that sidebar (can somebody recommend a Mac solution to give me similar functionality). But Ubuntu is damn pretty as well. More importantly, if you're running Vista natively then you don't have to sit there for HOURS on end loading up drivers to get your audio working with your webcam and - oh - that makes the wireless drop out. Hang on, I'll recompile the wireless module - that's better. Oh, the webcam's gone again - and where did the memory card support go to? And don't even BEGIN to talk to me about hibernation. God that drives me mad. Dual boot is a pain in the arse as well. I just want to sit in one environment working.

So if I need native Vista to get the most out of my laptop my two current options are Cygwin and this. Cygwin is great if all the stuff you need is available in it. It sucks like a hoover if you start having to compile stuff natively under cygwin. Does for me anyway.

Having the VM as your development environment also makes it a lot easier to move it around to new machines. We'll see how that pans out later today when the new MacBook Pro is due to arrive.

Conclusion
This time last week I was wondering whether I could make this environment my full time environment. I nearly can. In the end the problems are not so much with the solution as with the laptop. It needs a bit more power and it needs more RAM (and I can only go up one more GB easily). Also (this is a Sony Vaio VGN-FE41Z) the fan is bloody loud. I usually sleep with the laptop next to my head. The noise is getting annoying.

So the MacBook Pro is arriving today. I'll gain more power, illuminated keyboard, Mac loveliness and maybe (maybe) a quieter fan. We'll see. But I'm intending on trying a similar setup on the Mac as well. I'll let you know how I get on. If anybody else is running a similar setup as this on their Windows system let me know how I can improve performance.

Tuesday, 20 May 2008

Cyrus IMAP on Hardy Heron #2

See the previous post to this for the first steps. Note, I posted the following on the Ubuntu forums here and there may end up being feedback there to read.

Please note I am just trying to get a simple cyrus install working so I can test some python code that wants a cyrus server. This is probably insecure, toxic, illegal in most countries and prone to spontaneous combustion.

I just want to create some mailboxes (I'm not even sending mail to them!). I've changed my permissions as per the previous post and I'm trying to use cyradm to administer my server. cyradm doesn't seem to want to administrate anything. It wants a password and nothing seems to work. This is what I did.

apt-get install sasl2-bin

Then edit /etc/default/saslauthd as it suggests and set START=yes
/etc/init.d/saslauthd start

edit /etc/imap.conf and make sure that the following two settings are uncommented and with these values

admins: cyrus
...
sasl_pwcheck_method: saslauthd

restart cyrus and log in with
cyradm -u cyrus --auth login localhost

Oh, you may need to set the cyrus user passwd first. Just become root and set it with passwd. Now you can login and create a mailbox.
localhost> cm ijc
createmailbox: System I/O error

Or maybe not - another permissions error it turns out.
chown -R cyrus /var/spool/cyrus

Log back in again and ... weeeeeeee
localhost> cm ijc
localhost> lm
ijc (\HasNoChildren)
localhost>

There, nice and simple. Cough.

Cyrus IMAP on Hardy Heron

So you've just installed cyrus imap on Hardy Heron and you can't seem to connect. You try a test telnet session and get

icottee@ijcdev:~$ telnet localhost 143
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
* BYE Fatal error: can't write proc file
Connection closed by foreign host.

Take a look in /var/log/mail.err and you'll see stuff like

May 19 22:13:15 ijcdev cyrus/imap[8316]: DBERROR: dbenv->open '/var/lib/cyrus/db' failed: Permission denied
May 19 22:13:15 ijcdev cyrus/imap[8316]: DBERROR: init() on berkeley
May 19 22:13:15 ijcdev cyrus/imap[8316]: DBERROR: reading /var/lib/cyrus/db/skipstamp, assuming the worst: Permission denied
May 19 22:13:15 ijcdev cyrus/imap[8316]: locking disabled: couldn't open socket lockfile /var/lib/cyrus/socket/imap-1.lock: Permission denied
May 19 22:13:15 ijcdev cyrus/imap[8316]: IOERROR: creating /var/lib/cyrus/proc/8316: Permission denied
May 19 22:13:15 ijcdev cyrus/imap[8316]: Fatal error: can't write proc file
May 19 22:13:15 ijcdev cyrus/master[8260]: process 8316 exited, signaled to death by 11

The solution is simple

chown -R cyrus /var/lib/cyrus

I'd give cyrus a restart after that as well.

Monday, 19 May 2008

Magical Otters @ Misfits, Nagoya May 16th, 2008

video
On Friday Brian Cullen and the Magical Otters got back together again to provide their usual brand of drunken inspirational shouting and yelling and banging things. Ah - sorry. No, that's what I do. The other, rather more accomplished musicians, struggle bravely on whilst I let out months of pent out aggression and drink copious amounts of beer. Although in my advancing years the amounts are slowly declining.

As always we prepare meticulously by turning up an hour beforehand and try to get the drums working. In this case I think I finally managed to get sounds from them about ten minutes before we were due to start and get them mostly working at the appointed time. Therefore our rehearsals started at the point of the first song in the set. I'm sure nobody noticed ;).

Anyway - here's just a taste of that night - a real life Otter's set right down to the high fidelity sounds and blurred vision. Yes, I know it says June 2008 but we can move in time you know ... see you at Shooters on the 6th of June 2008.

More Otter's stuff at Brian's site ... http://briancullen.blogspot.com/

Thursday, 15 May 2008

Cloning/copying postgres databases

Do
createdb newdatabase -T olddatabase
always forget this and end up dumping the old database and loading it into the new one. It takes a lot of time that way. This way is quicker.

For richer, for poorer

Currently being assembled, should be with me by the end of next week:
2.4GHz Intel Core 2 Duo
MacBook Pro 15-inch Glossy WS
4GB 667 DDR2 SDRAM - 2x2GB
250GB Serial ATA @ 5400 rpm
SuperDrive 8x DL
No iWork Preinstalled
No Final Cut Exp Preinstalled
No Aperture Preinstalled
No Logic Exp Preinstalled
US KYBD/User's Guide -JA
Country Kit-JPN

Wednesday, 14 May 2008

Linux / VMWare / Vista / Useful ?

OK, I've got two laptops. The one I'm typing on which has no hard disk and is currently just booted from an Ubuntu Hardy Heron CD Rom and a Vaio VGN-FE41Z. Now I tried sticking Hardy onto it the other day using wabi and it works. But it ain't slick. And there's a list of things as long as your arm which don't work properly. And even if I do get it booted into Linux I'm going to lose iTunes (which I'm trying to DRM myself out of but is a slow process). And don't even talk to me about trying to make multiple monitors a painless process.

In short - it's a Vista laptop. Not even a bad Vista laptop since I took the abomination which is the Sony default install and gave it a clean OEM Vista install.

So I've been trying to use Hardy in VMWare as a desktop client and it sucks. Sorry, sucks is too strong a word. It's not seamless though - even with the VMWare client. I only want one desktop and having a desktop within a desktop is not good for asthetic, productivity and performance reasons.

So then I went off on a Cygwin trail. I've used Cygwin before but it doesn't take long for the wonder of what it gives you to be offset by the pain of what it doesn't give you. Example - you want pysycopg installed - you have to compile it. That's not trivial. You want terminal windows that are not the brute ugliness of DOS circa 1990? Not trivial. you just want to "apt-get install foo" ? Not possible.

So I want VMWare at the backend, but for the windows to appear in Vista as normal windows. The answer is simple and you already know what I'm going to say. You want Xming running under Vista and talking to your X apps which are launched from a server only install of Ubuntu. That makes Ubuntu reasonably lightweight and gives you the X apps fully integrated into your desktop environment.

That's what I'm trying now and will be trialling over the next couple of days. If it works and works well I'll document a little more about what I've done and how it fits together.

In the meantime, I might just cave in for the sake of getting some done and go and get a MacBook as well.

Monday, 12 May 2008

Dead laptop

Nothing like starting the day with a dead laptop. Well here I am - in Japan. And my main work laptop is dead. Sigh.

Forcing fsck on reboot in Ubuntu

This works on Hardy and presumably well back
sudo touch /forcefsck
sudo reboot

Learning LDAP

I've never got a grasp of LDAP but the gods have conspired against me recently in such a way that I can't avoid it any more. One of my colleagues found LDAP For Rocket Scientists and I'm completely smitten. It's written extremely well. It's amusing, informative and makes no apologies for the fact that it's not a HOWTO. In fact they have some very thought provoking comments about the whole HOWTO thing. e.g.
There are innumerable excellent HOWTOs scattered over the Internet which are great if you need a tactical solution to a particular problem and are happy to put up with the vaguely uncomfortable feeling that you are entirely dependent on something you don't really understand. We didn't want a tactical solution we wanted a strategic solution to a whole set of problems all of which all appeared to be ideally suited to LDAP but we had to understand stuff ..we needed a WHYTO.
Excellently said I think. There's nothing worse than having a system which you have got running because you followed somebody elses instructions because the first thing that's going to happen is that it's not going to work and you haven't a clue why. Last week I bit the bullet with some VPN work I needed to do and didn't take any shortcuts. Got it all up and running and I was a happy man. Of course, the next person who tested it from a different machine told me it didn't work. Although that doesn't fill me with joy (it still works from the test environment) I'm not too perplexed because I understand the basics of how it all fits together. If I'd cobbled the thing together with a HOWTO I'd be stuck.

Back to LDAP. Here's a nice little taster of the sort of thing you'll read.
In the documentation the subject of the root is treated in one of two ways. It's assumed to be an automagic thing that is the beyond the scope of mere mortals to understand and is treated in a ritualistic way as if it had been handed down from one generation to another and certainly no attempt is made to explain it. Conversely the other camp handles it at extreme length usually accompanied by much wailing and gnashing of teeth and incantations to the twin gods of the ITU and IETF.
or how about this, following the defintion of LDAP as being a 'write-once-read-many-times' service.

It is never clear in the phrase 'write-once-read-many-times' just how many is many?

Where is the line between sensible use of LDAP vs a classic transaction oriented relational database, for example, MySQL, PostGreSQL. If we update every second access, is this a sensible LDAP application or should it be every 1,000 or 1 million times.

The literature is a tad sparse on this topic and tends to stick with 'slam-dunk' LDAP applications like address books which change once in living memory.

There is no simple answer but the following notes may be useful:

and then proceeds to list some very useful notes. In short it's a damn fine read. They've got a similar one for DNS as well which I'm going to have a nice long look at soon.

Sunday, 11 May 2008

Kani Miso

Kani Miso. Kani=Crab and Miso=brain. But actually these are not crab brains. I often wondered how the hell you managed to get so much brain from a little crab. The answer is, of course, you can't. Apparently (and not surprisingly) crab brains are quite small. Kani Miso appears to be anything within a crab which is not good wholesome white crab meat. That apart, I love the stuff. I can consume vast quantities of that dark, deep sea tasting, mush and often do, given the opportunity. I gained the nick name kani-miso in my old band here because of my passion for it.

Had an odd experience the other day though. Had lobster-miso which I've never seen before (even Akemi couldn't remember seeing it before). It's similar to kani-miso but has a less full taste. As a lot of people find kani-miso a little powerful this might be a thing to look for if you're after something a little more delicate.

There's one other good thing about kani-miso (well, it has a positive aspect). You can buy it in cans which means my mother in law will sometimes ship some back to me. Kani-misi and a pint of english beer. Heaven.

Friday, 9 May 2008

Those cheeky BBC headline writers

Great tits cope well with warming
Don't tell me the BBC Headline writers didn't know what they were doing. Or maybe it's just my puerile sense of humour.

Tuesday, 6 May 2008

Cygwin Permissions Under Vista

Was somewhat surprised to discover that although my account is an administrative account, I can't edit system files from within cygwin by default. To change this right click on your Cygwin shortcut, go to the Shortcut tab, click on Advanced and select "Run as administrator". This is not just limited to Cygwin apps by the way - you'll get the same glorious issue if you try and edit hosts using Notepad.

AIM / Gmail Integration

Did you know you can talk to your AIM buddies with your AIM account, direct through Gmail's chat i/face? You did? But you can't see the option? Switch your language to English US (I know, I know, you have standards but come on - this is for a greater good). Now you'll be able to login with your aim id and chat away. And all your chats will be archived within mail for you to search on later when your friends deny everything you ever said.

Saturday, 3 May 2008

Cygwin / Emacs / Problems

If you are trying to get emacs working 'nicely' on Windows and you've gone the cygwin route and are now having messages like

apply: Doing vfork: resource temporarily unavailable

Try reading http://pseudocode.cc/2008/03/17/fixing-emacs-m-x-shell-or-m-x-compile-for-cygwin-on-vista/

Worked for me. Thanks pseudocode.cc !!

Nagoya Aquarium

IMG_0325 It was Selina's birthday yesterday (ten years old - TEN YEARS!). Happy Birthday little one. Today we all went to Nagoya Aquarium which we've been going to for ... well, nine years now! It was a hot day, 28 degrees. Nowhere near as hot as it gets and without the humidity that will come after the rainy season but having spent a year in the UK with a crap summer it was hot. The aquarium never gets old for me and Alisa just LOVED it. Both Selina and Hugo never really showed any interest in animals as such (the first time we took Selina to the aquarium she just fell asleep I think). But Alisa loves all that stuff.

The dolphins (as always) were great and they have a killer whale as well which is cool. There are a number of shows during the day where you get to see them doing cool things. If it's too hot (or too cold) you can always view it from under the water in the viewing chambers. They've had music events there as well and I can see that would be cool. It's very chilling and relaxing down there (unless you go at the beginning of golden week with three manic kids and the rest of the Nagoya population). When you've done that part there's the normal aquarium to go to where you can see a lot of fish, crabs, turtles, penguins and most other things. When you're there with somebody like Alisa it makes it all worthwhile.

if you've ever in Nagoya go and visit. It's a nice day out. With car parking (but excluding food and pressies) it cost us about 6,000 Yen (30 quid).

Django OR statements / conditions

I'm having major problems focusing on one thing at a time at the moment. I thought that being in Japan would help me but it appears not. I've made some changes to how I work recently and I'm going to have a go at documenting what I'm doing with code and sysadmin stuff here. Partly as a brain dump for when I can't remember how I did stuff and partly to see if it makes it stick in my brain. Past experience shows this won't be something I keep up by anyway. Today I'm plodding through writing some Django code which is a rewrite of some pure python/sql stuff I did before. I know a lot of sql and therefore am having to force myself to try and use the Django API efficiently as much as possible (partly so I know when I shouldn't use it). Todays question is how do I do OR statements.

Well according to the docs you setup Q objects. OK ... I'll stay calm. Here's my current code.

    usages = Usage.objects.filter(parttype=parttypeid)
usages = usages.filter(client=self.client)

Just to point out that I'm doing two conditions here which are AND'ed together. Firstly to find any Usage record with a parttype of whatever parttypeid is and secondly to find any client which is the same as our client record. I could have given the first condition a PartType record or I could have given the second condition an id instead of a Client object. Although these two conditions are given in different lines they won't be evaluated until I try and access the records at which point just one query will be thrown at the database. I also want to do an OR statement so that whatever is found in the above two statements much match. This is where I must use my Q object. Import it from django.db.models.Q

    Q(dockcode__productionline__destination=destinationid)
That looks like a long fieldname. Actually it's some black magic that Django does for working across relationships. dockcode is a related table to usage, productionline is related to the dockcode table and destination is the actual destination we want to get to. They are double underscores to show you are referring to a related table. I don't like the syntax but I can live with it for the moment. OK - but we want to look for two possible destination ids. So we end up with this
   qs = ( Q(dockcode__productionline__destination=destinationidA)|                  
Q(dockcode__productionline__destination=destinationidB))

And we just add that to our filter which we haven't actually executed yet. So in total we end up with

    usages = Usage.objects.filter(parttype=parttypeid)
usages = usages.filter(client=self.client)
qs = ( Q(dockcode__productionline__destination=destinationidA)|
Q(dockcode__productionline__destination=destinationidB))
usages = usages.filter(qs)

That will return any usage record which has the given parttype, the given client and one of two possible destination ids. Well it will - when you try and access the result.

Thursday, 1 May 2008

Bento Box

I have a long list of items I like to complain about regarding England. One of my favourite is food. I don't subscribe to the common misconception that there's nothing worth eating in England - there is. But generally you have to make it yourself or pay a lot of money. There's a chain of sandwich shops the North West called Philpotts and they do wonderful sandwiches and you pay for that. Where we currently work there's one place that does sandwiches. Their idea of variety is brown or white. Anyway - back to Japan where I am currently sitting.
Left is a standard bento box picked up from the local convenience store. This is actually one of my favorites as I'm such a greedy guy. My in-laws here view these are being frankly low cost rubbish but they've never tried getting a cheap lunch in the UK. Within the box you get (deep breath and in no order)
Fish, Potato Croquet, Hamburger, Rice, Seaweed, Chicken, Sausage, Potato Salad
Chikuwa, Potato Salad, Pickle and Spaghetti. You'll also get it heated up if you want but I eat mine cold. There's a huge amount (I only ate about 2/3 of it) and it tastes great. The cost of this is 460 Yen. At todays exchange rates that's £2.23.

Still, try getting a decent cheese sarnie here.