Sunday, August 1, 2010

Ruby on rails 3 - rvm, bundle, eeeekk

Having a freshly loaded Ubuntu 10.04 on my main desktop (after checking it out for months on my laptop), I thought I'd get ruby on rails set up. After setting up Rails 2 with the minimum of fuss, I took the challenge of upgrading to Rails 3 (release candidate).

RVM is now an essential component of any rails environment, letting you change between rails version in an instant (Theoretically, but more on that soon).

Installing it was as simple as:
$ bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )

After installing all the necessary ubuntu packages

$ rvm install 1.9.2-rc2
$ rvm 1.9.2-rc2
$ gem install rails --pre

I can't seem to switch between rubies as I would like, but I'm sure I can solve this soon.

To start a new project we have to forget the rails 2 ways and start with:

$ rails new test
_project

You should see the usual files (plus a few new ones) being created.

$ cd test_project
$ bundle install

This is where I had some problems with mysql. I had installed every possible mysql package but it stll wasn't working.

Using activeresource (3.0.0.rc)
Using bundler (1.0.0.rc.1)
Installing mysql (2.8.1) with native extensions /usr/local/lib/site_ruby/1.8/rubygems/installer.rb:483:in `build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

/usr/bin/ruby1.8 extconf.rb
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/ruby1.8
--with-mysql-config
--without-mysql-config
--with-mysql-dir
--without-mysql-dir
--with-mysql-include
--without-mysql-include=${mysql-dir}/include
--with-mysql-lib
--without-mysql-lib=${mysql-dir}/lib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mlib
--without-mlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-zlib
--without-zlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-socketlib
--without-socketlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-nsllib
--without-nsllib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mygcclib
--without-mygcclib
--with-mysqlclientlib
--without-mysqlclientlib


Gem files will remain installed in /home/stumacd/RoR/projects/wiki/ruby/1.8/gems/mysql-2.8.1 for inspection.
Results logged to /home/stumacd/RoR/projects/wiki/ruby/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out
from /usr/local/lib/site_ruby/1.8/rubygems/installer.rb:446:in `each'
from /usr/local/lib/site_ruby/1.8/rubygems/installer.rb:446:in `build_extensions'
from /usr/local/lib/site_ruby/1.8/rubygems/installer.rb:198:in `install'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/source.rb:96:in `install'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/installer.rb:51:in `run'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/spec_set.rb:12:in `each'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/spec_set.rb:12:in `each'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/installer.rb:40:in `run'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/installer.rb:8:in `install'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/cli.rb:115:in `install'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/vendor/thor/task.rb:22:in `send'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/vendor/thor/task.rb:22:in `run'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/vendor/thor/invocation.rb:109
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/vendor/thor/invocation.rb:116:in `call'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/vendor/thor/invocation.rb:116:in `invoke'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/vendor/thor.rb:161:in `start'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/vendor/thor/base.rb:379:in `start'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/vendor/thor.rb:140:in `start'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/bin/bundle:13
from /usr/bin/bundle:19:in `load'
from /usr/bin/bundle:19

The trick was to install it with the correct parameters (found by using $ which mysql)

$ gem install mysql -- --with-mysql-conf=/usr/bin/mysql --with-mysql-lib=/usr/lib/mysql

This allowed all the applicable gems to be installed.

And now with a:

$ rails server

WEBrick was up and running and http://localhost:3000 was showing the standard page. Gold dust :)

Saturday, July 17, 2010

Decapus - 10 legged power supply



Having built guitar effects pedals for the last 10 years, I've progressed from battery power to requiring a power splitter for a decently powered DC adapter.

The overall plan is to put the power supply on the underside of the pedalboard, so I needed about 10 outputs and four to be longer than others.



It's a very simple design, but it really needs to work reliably and a minimum parts count was desireable.



So it's not that pretty, but it's rugged enough to sit on the bottom of the pedalboard without to any dramas.

Friday, July 16, 2010

Codility

I was reading a blog concerning how to hire new programmers. According to this blog, one of the classic mistakes some recruiters make is that they don't get the propsective candidate to write any code during the interview. This seems a bit odd, but I guess in some small companies they may not have the competence to select their first programmer. This blog mentioned Codility, a way to test a candidate's programming skills.

I headed over and liked the design and thought I'd take the demo test. I recommend you give it a go and come back after that.

It was a neat and easy to understand interface. I selected C as it's my weapon of choice for everything except for applications that need extensive string handling (in which case the String class makes bothering with Java worthwhile).

They had a fair problem and a suboptimal solution as a framework. After coding my most intuitive solution (for those who tried the demo, getting the righthand side total then:

for(i=0;i<n;i++){
rsum -= arr[i];
if (lsum == rsum) return i;
lsum += arr[i]; }


To avoid arithmetic overflow, the array consists of doubles to be on the safe side. I overlooked this the first time in.

Anyway, in the 30mins I got it except for the overflow, which I went back and checked that it worked. I wish there were a few more tests like this as work doesn't exercise all my c muscles :) Props to Codility hopefully a thing of the future.

Thursday, March 18, 2010

Round up of the Google AI Competition

Well the competition got a lot harder once the maps changed, the real top bots certainly rose to the top. Congratulations to the winners!

My reflections on the competition:
  • Nicely run and nice that it adapted to the demands of the players
  • Great to have the ability to watch the matches afterwards.
  • Some very talented AI guys out there - with a fair bit of time on their hands.

My bot:
  • Instead of doing a minimax on my move then the opponents move, it should have used the syncronous nature of movement to analyse the 9 (apart from the first move with all 4 directions available to both players) feasiable options.
  • I would have ideally trimmed the resultant decision tree in a logical manner, searching deep on both sideways options and that would often beat the opposition, by adventagously cutting the areas.
  • My initial implimentation of 'first to the most squares' was buggy, it would have been great to sort it out. so the bot didn't make such obvious bad moves.
  • Using a more optimized 'first to most squares' algorithm. I should have made a list of the coordinates to go over in the next run, meaning that only 1-20 squares were checked rather than all squares.
I lacked the time to impliment these options, but that's no excuse, just the way it was. I had great fun and I'll be looking for the next challenge from the University of Waterloo CS Club.

I'll throw my code up here for anyone that wants a slightly buggy (but very fixable) tron bot.

In fact I have a few versions - one in perticular was stable but didn't search very deep.

Sunday, February 21, 2010

Google AI bot

Well I achieved my initial goal of getting into the top 10, only to be hoinked out to around 100 as the opposition got a lot stronger once the maps changed to avoid draws.

The bots that seem to beat mine have great depth in their searches. I'm using minimax with alpha beta pruning which is probably what they're using so search depth isn't the issue. So I figure their evaluation functions are finding the better moves at the same depths. My rudimentary 'most available squares' approach needs an upgrade. Without adding too much time as the evaluation function is called quite frequently (around 10000 times per second).

With the middle island forming a significant 'block' I need to get better at luring them my way, cutting their approach off then going around the other side and cutting at a point favourable to me. I'm going to try changing the evaluation function that evaluates which player is first to each square. This should give me a better sense of where a future border will be and hence try to maximize my player's area.

Link to my bot

Wednesday, February 10, 2010

Google AI Competition

Hmmm, how good are AI comps? I am letting my inner geek take over for the next few days as I put the evil stumac bot in Google's AI comp.

I am currently 30th (out of 415 entrants) with a few things still to do to really make my bot competitive.

To begin with I implemented a basic strategy and that had me at 90th out of 400. When I say basic, I mean really basic (code to come after the competition).

I then added a minimax look ahead, this currently looks ahead 9 moves, a bug was causing me to lose games.

So now I will:
  • alpha beta prune my minimax.
  • upgrade my evaluation function.
  • add a 'in same area' check and revert to flooding if in separate areas.
  • Add a timing check (if possible) to give a good answer before timing out.
Should be fun!

Hopefully this should be able to get us into the top 10.

Wednesday, November 11, 2009

Projects on the table.

Well it took longer than expected to get the 16MHz crystals, but now that I have some and I've updated the code to communicate by packets. Testing tonight.

I've been playing around with a few things recently. Software wise I've been honing my Java skills with a few little apps. I usually program in Eclipse but recently I've found I get a project up and running faster with NetBeans. I'll post them soon once they're a little prettier. The apps are:

A basic Race for the Galaxy game this interfaces with a PHP server but is incomplete as a mate implimented the game on his server.

A Tigris and Euphrates tile counter. This can read in the game log from the online implimentation at BoardGameGeek and tell you what tiles are left in the game eg. the tiles left in the players hands and the bag. Useful for those precious game winning final moves.

A program for sending data via the serial port to a 8 x 8 RGB Matrix. I saved myself the etching and purchased the semi constructed board from here.

To come: Organise and finish my guitar's pedalboard. I'm hoping to find an unwanted computer requisition the PSU and perform this instuctable again to get a nice smooth 12V.

Good thing it's winter - plenty of time to do all this :)