Monday, May 14, 2012

fun with clojure / lisp

(fn last_element [x] (nth x (- (count x) 1)))

Someone out there invented this language. That someone was not a normal person.

Thursday, April 26, 2012

Iterable interface

Learnt a new thing in Java today:

Given a class:

public class DocumentPreprocessor implements Iterable> {
    ...
   public Iterator> iterator()
}



You can use it like this:

for (List sentence : new DocumentPreprocessor(filename)) { ... }

Which I didn't know. So there you go. Learn a new thing everyday :)




Tuesday, March 13, 2012

Installing NLTK corpuses (NLP)

How to install the stopwords corpus:

1. mkdir /home/jim/nltk_data (obviously change the directory name to your user!)
2. Fire up a python console
3. >>>import nltk
4. >>>nltk.download()
5. Downloader> d stopwords

(d for download)


NLP and Installing NLTK

As part of my quest to bring my tech skills up to date I've signed up for a free course on Natural Language Processing (NLP) run on the Coursera website - it's based on a Stanford University CS Major course, and if the first week is anything to go by the quality is high, and the content interesting... An important part of the course is the weekly programming assignment, and here we have a choice of Java or Python as the language used. Given I already know Java I've decided to have a go at Python, and so it is I'm bringing my tech skills up to date by learning a language that was invented last century :)

One of the libraries Python offers is the Natural Language Toolkit (NLTK) which includes various tools to simplify NLP programming. Installing this library on Ubuntu was, as always, less than automatic. In theory, you install the library and then enter in a python console and type "import nltk" - this should work with no errors shown. But...

Things I tried and failed:
  1. http://nltk.github.com/install.html - easy_install, pip, and various dependency errors.
  2. sudo apt-get install libyaml-dev
  3. sudo apt-get install python-yaml
  4. Uninstall and reinstall the pip libraries (?) - numpy and nltk. No dependency errors, but still didn't work.
  5. sudo apt-get install python-nltk - installed apparently correctly, but then didn't work.
  6. sudo apt-get remove python-nltk
  7. Repeat various times
  8. sudo pip remove nltk
  9. sudo pip remove numpy
  10. sudo apt-get remove python-nltk
At this point god knows what crap is installed on my system, but the bloody thing doesn't work. Googling revealed this page: http://www.nltk.org/download - and finally I got the thing installed:
  1. Download PyYAML: http://pyyaml.org/download/pyyaml/PyYAML-3.09.tar.gz
  2. Unzip into a temp directory (tar xvf ...)
  3. sudo python setup.py install
  4. Download NLTK: http://nltk.googlecode.com/files/nltk-2.0.1rc1.tar.gz
  5. Repeat steps 2 and 3.
Success!


Saturday, March 03, 2012

Ruby on Rails, Ubuntu style

I've been going through the Ruby on Rails tutorial on my work laptop, but it's hardly ideal: it's not my machine, it's often at work, and unlike my home computer it's a Windows box. So I had the bright idea of installing Oracle Virtual Box, Ubuntu (like at home), and move the sample app I'm building onto a Dropbox shared folder.

So:
1. Install Virtual Box - painless, and very similar to VMWare
2. Install Ubuntu - basically painless, although the CD I was using was 10.10, and it required 2 further updates to bring it up to the latest version. Not sure why Ubuntu couldn't have just skipped to the latest without having to install 11.04 first - I didn't bother to check out the system update options, so this may just have been me being lazy.
3. Install Rails. And here's where things started to go wrong...

Installing Rails on Windows was easy: there's a ready made installer that covers everything, double click, next-next-next and you're done. There's even a cool video that runs you through setting up an account on Engine Yard, Github and so on. It's basically foolproof. On Ubuntu, however, and as with nearly everything else you install on it, you need to do a bit more work.

So, here's a simple how-to for a clean, new Ubuntu 11.10 install.

1. sudo apt-get install ruby1.9.1-full

2. export GEM_HOME=/home/jim/.gem (Here you need to set GEM_HOME to a directory that your user has write permissions for, I used the standard gem directory)

3. gem install rails

4. gem install bundle

EDIT==: after trying to follow these instructions on a different Ubuntu machine, I needed to include the $GEM_HOME/bin directory to my path (in bashrc), for whatever reason the install didn't leave a link to bundle in the /usr/local/bun/ directory... Given the amount of crap I installed and uninstalled when trying this the first time, I'm not overly surprised. == END_EDIT

Unfortunately, the basic bundle script currently defaults to ruby1.8, you need to modify it:

5. sudo vi /usr/local/bin/bundle (modify the shebang)

6. sudo vi /usr/local/bin/rails (modify the shebang)

If you're about to make a clean, shiny new Rails project you're probably done at this point, but as I wanted to run my sample app I had to do a couple more things to get it running.

I tried to install and fire up my sample app - developed as you'll recall on Windows. While I'd been following the tutorial fairly closely, I'd been forced to make a couple of changes to get the console to work correctly under cmd.exe. Unfortunately, these changes weren't directly compatible with Ubuntu, and I had to go through Gemfile and Gemfile.lock deleting the win32 dependencies. Further, there were a series of other dependencies that failed due to missing libraries:

1. nokigiri dependencies:

sudo apt-get install libxml2-dev
sudo apt-get install libxslt1-dev
sudo apt-get install libpq-dev

2. spork dependencies:
sudo apt-get install nodejs

EDIT==
3. Sqlite3:
sudo apt-get install sqlite3
sudo apt-get install libsqlite3-dev
== END_EDIT

... finally, all was well:

rails s - no problem entering in http://127.0.0.1:3000
bundle exec spork and bundle exec rspec spec - 40 something tests run perfectly, and 0 failures :)

Thursday, April 28, 2011

iDave diet, day 3

Day 3, all still going well.

Breakfast: roast veg + chickpeas
Pre-workout at gym: protein shake (definitely not part of the diet!)
Lunch: same as breakfast
Post-swim: cereal bar (again, not part of the diet)
Dinner: yet more chickpeas.

Getting bored of chickpeas now, and I'm really missing having a proper breakfast with porridge, juice and a white coffee.

End result (weight @6:30am, 28/04/11): 74.8kg. Pretty much the same as yesterday which (I hope) confirms current basic weight is <75kg.

Wednesday, April 27, 2011

iDave diet, day 2

Success on day 2, no fails.

* Breakfast: peas. First time for everything, I suppose, but I don't think I'll voluntarily eat peas for breakfast again.

* Lunch: Spicy lentils. Yum.
Post spinning: cereal bar

* Dinner: huge bowl of salad, turkey steaks, a bit of roast veg (peppers and aubergines), a handful of the chickpeas I was preparing for today.

* Snacked on almonds during the day, trying hard not to eat too many of them. Black coffee, water and diet coke.

Only negative was the gym: I was doing squats, series of 25 with a 20kg bag on my shoulders, managed two series without any problem but completely failed on the third, the legs just wouldn't respond. Spinning after was a nightmare, and I'm feeling pretty stiff today. Hopefully this is simply the result of overdoing it, 105km on Sunday, spinning Monday, and then more squats than usual on Tuesday...

Edit: 74.6kg, down 1.5kg since yesterday?

Tuesday, April 26, 2011

iDave diet, day 1

Started yesterday on the iDave diet plan (see: http://www.singletrackworld.com/forum/topic/idaves-diet-plan-members for examples), all went well at the start:

Breakfast: two-egg omelette.
Carb bar after spinning
Lunch: spicy lentils + diet coke
Dinner: it all went horribly wrong, and it Wasn't My Fault.

Daughters 1&2 had decided to have an "international dinner", with 5 dishes on the menu: papaya dip from Peru; bread scone things from Alaska; French peas; Chinese empanadillas (though they tasted pretty much like the standard Spanish bar ones, to be honest); and fruit skewers (not sure what country). The food was pretty good - surprisingly so - but apart from the peas none of it was allowed on my diet, and I after spending all day in the kitchen I could hardly tell them I wasn't going to eat it!

So, the results from day 1: FAIL. 76.1kg, no change there.

Wednesday, October 13, 2010

Scala

Time for a new language, Scala looks to be interesting:

* Mixins
* Closures
* Functional programming.

Of course, the only problem is finding something I really want to build with it, just playing around with code examples is going to be entertaining for all of about 5 minutes...

Any suggestions?

Sunday, March 14, 2010

Flickr Photo Download: Above Moralzarzal

Had a great ride today, with Gelu and Pedro. It was pretty chilly out, there was still a fair amount of snow about, but the sun beat down - and now I'm sunburnt! The route was nothing new, Villalba - Moralzarzal - Cañada - entrance to La Pedriza - Matalelpino - Becerril - Moralzarzal - Villalba, but I haven't been out on the bike for a while and it felt wonderful! I felt really strong, leading on all the climbs, no slack feelings on the flats, and enjoying the downhill bits.


Above Moralzarzal

Wednesday, January 27, 2010

Working life

10 Modify
20 Compile
30 Deploy
40 JUnit
50 Goto 10


Fun fun fun for all the family. Will I ever manage to deliver this bloody project?

printf("Voy por aqui"); para java

For when log4j just won't do*:

System.err.println( new Exception().getStackTrace()[0] );


* Which is pretty much all the time when you're trying to debug an application in S*****s.

Friday, May 29, 2009

Ooh look, nearly two years have passed!


Bollocks, where did they go then?

Saturday, July 01, 2006

Learning to ride a motorbike, part 1

For your amusement and edification, here's my take on learning to ride a motorbike in Madrid.

I've had a (car) driving licence for almost 17 years, and perhaps the first sign of an incipient mid life crisis is the fact that I've decided to get a bike. The justification for it is the hour-a-day I'll save on travelling, but that's beside the point. I want a bike. I've always wanted a bike. And I'm going to get one.

So what does this learning to ride malarkey consist of in Spain, then? For someone with a valid car licence it's a two stage process:

1) Theory test
2) Riding test

That's assuming you want to ride something bigger than a 125, otherwise assuming you've been driving for over two years you can simply extend your licence (no test required) and get the bike you want. (This licence is an A-1, the full one is an A).

24/05/06: Sign Up
I pootled off to the local driving school and explained to the young ex-catholic school girl behind the desk that however fit she may be, what I wanted to learn to ride was a bike. No problem, you give me 210 euros, plus another 70 odd for the test, and you're on.

Total cost so far: 280 euros

So what did the 210 euros (that's about 145gbp) get me? One 158 (A5 sized) page book. It's got a nice cover though, with a picture of a highly relevant VW Golf on it. Chapter 1, Definitions and Concepts (aka what is a motorbike). 2, Rules of the Road. 3, Licences... and so on up to 7, Basic Mechanics. Each chapter with a 16 question multiple choice (3 choices) test to drive (ho ho) it all in. At the end of the book are sample tests, same format as the chapter ones but covering all the material. And that's the theory test.

The test can be divided into three parts - the totally pointless, numbers, and the blindingly obvious.

Totally pointless (at least from my point of view) are questions about what 16 year olds can ride, and sidecars. Apparently an A class licence will also allow me to ride a load carrying trike. Great, I've always wanted to drive a Robin Reliant.

Numbers questions are the tough ones. Speed limits vary according to how much of a hard shoulder there is, depending on the vehicle a load you carry can be 0.25m longer or more than the wheelbase, the A-1 licence is limited to 0.11kW/kg...

Most of the questions, probably about 75%, are so blindingly obvious that you wonder what kind of idiot could possible get them wrong:

If you fall off your bike, what clothing will protect you best:
a) Cotton
b) Jeans and a denim jacket
c) Leathers

The fairing on the bike...
a) Is part of the transmission.
b) Has an influence on the aerodynamics.
c) Automatically adjusts the chain tension as this wears out.

I should point out that deaths/million inhabitants/year in Spain is about 125, compared to about 70 for the EU as a whole... So perhaps the blindingly obvious questions are a population reducing measure?

28/6/06: Test Day.
Over 4 million people live in Madrid province, so obviously it only has one test centre, and the only way to get to it is by car (enjoy the traffic!) or by train then bus. At least getting up at 5:30am means it's not that hot. The test centre is huge, hundreds of cars with car-school signs on top, buses and lorries, even a few bikes warming up around a couple of cones. It's 7:30, and I've got 30 minutes to spare. Time for a coffee.

It was probably a bit optimistic of me to expect any signs to the actual room where I'd take the exam, but a bit of walking around and asking soon led me a large train station like waiting room, complete with graffiti detailing what the authors thought about the traffic authorities. I'm not sure that they are all the offspring of prostitutes, but I have to agree with the sentiment.

8:00 am, and nothing happens. Glad I got here on time then.

8:15 Nothing yet. I chat to the guy next to me - he's here for the car test - and try not to stare too much at the eighteen year old girls. God I feel old, and as the only one out of 50+ wearing a suit...

8:30am, there's about 200 of us here now, and finally a civil servant type tells us all to shut up and listen. We're to be called up, one by one (!), present our ID cards, take the answer sheet and enter the room.

8:35am My name is mispronounced and off I go. The answer sheet is one of those optical scanning ones, a cross in the right answer, and fully fill in the square if you get it wrong. Don't even think about trying to recorrect... The final part of the instructions? When you sit down, put the answer sheet over the questions, which are sitting face up on the table.

8:45am My knees are beginning to hurt. The table and chair have probably been robbed from a primary school. Loads of people are reading through the questions, and some have already started. I can only assume they're nephews/nieces of the invigilators.

9:00am You may start. Those of us doing the bike test only have 16 questions, car tests seem to have 32, and there are some tests with even more. Not quite sure what, though.

9:05am I've finished, time to read through it again.

9:07am I hand it in. I'm going to be late for my meeting, luckily the only people present will be the client, my boss and the chief financial officer.

29/6/06
I pop into the driving school, I've passed. Time to start learning to actually ride a bike then ;)

More later, as Engerland-Portugal is about to start...

Friday, August 12, 2005

Some useful and not so useful links

Some links, some of which may even be useful. Saves me having to keep the unread check marked in Outlook, anyway.

del.icio.us is a social bookmarks manager. Apparently.

Very funny and slightly weird mental health blog

A link farm full of crypto links

falling bikini girl

Tuesday, May 24, 2005

Google desktop search

It's a great search tool, but if you're planning on running various tomcats, a jboss, an apache and eclipse at the same time forget it. It slows the whole system down to a grinding halt...

Tuesday, May 17, 2005

Classloading fun

How to find where a class is loaded from:

myClass.getClass().getProtectionDomain().getCodeSource().getLocation()

This may not work with rt.jar loaded classes, it's worth checking if getCodeSource() returns null or not.

Sunday, June 06, 2004

That all important first post

Not really got anything to say, but as everyman and his dog has a blog these days, who am I not to have one?