Archive for June, 2007

We Got a Monopoly on Monopoly

Thursday, June 7th, 2007

A few months ago monopoly.com.au had this voting thing, which allowed anyone and everyone to vote for what should be on the Australian version of the Monopoly game, the more votes the more prestigious the location would be on the board, i.e. The place with the most votes gets Mayfair.

So mr_wizard from [url=http://www.valhalla.net.au/forum]the Valhalla Forums[/url] devised a program that voted FOR you over and over again, and voted for Barossa and Adelaide.

So now Barossa and Adelaide have got more votes than NSW, ACT, VIC and QLD combined to take out Mayfair and Park Lane on the new board.

Well done to all parties involved.

Here’s a few links: [url=http://www.news.com.au/adelaidenow/story/0,22606,21862445-5006301,00.html]news.com.au story[/url] [url=http://talbs83.razza.org/hack.jpg]news paper column scan[/url] [url=http://talbs83.razza.org/hack2.jpg]newspaper article scan (with picture)[/url] [url=http://img504.imageshack.us/my.php?image=monopolygl1.jpg]Colour Image[/url]

Video Mirrors: [url=http://users.on.net/~matthewd/valhalla/TenNews.rar]Mirror 1[/url] [url=ftp://juzzy.ath.cx/TenNews.rar]Mirror 2[/url] [url=http://users.on.net/~justin.zobel/TenNews.rar]Mirror 3[/url] [url=http://www.users.on.net/~alex109/pictures/TenNews.rar]Mirror 4[/url] [url=http://www.worldofwookie.com/val/TenNews.rar]Mirror 5[/url] [url=http://www.youtube.com/watch?v=c9T82xnRl9Q]Youtube Link[/url]

Podcast: [url=http://podcast.nova919.com.au/monopoly.mp3]And the Podcast[/url]

Update 9th June 2007: The threads have been removed from the Valhalla forums due to legal advice from Valhalla’s lawyer. Personally, I don’t understand anyone who would want to raise a lawsuit against these people who had only good intentions. Any other state could’ve made the “program”, but they didn’t. We had the initiative and the intelligence to create it, and in the end of the day, that’s what always wins.

Again, congratulations to the Valhalla members (NOT THE COMMITTEE) who had the initiative to propel our state into pole position.

Testing and Migrations

Wednesday, June 6th, 2007

So I begun a new, very awesome job on Monday. I would say the job trumps anything Coles has to offer and here’s some of the reasons:

  1. Chairs (something that Coles really needs), comfortable ones too
  2. Wide-screens
  3. Lack of green bags
  4. Great people with equally great knowledge about everything Rails and of course,
  5. Doing something I truly love

[font:size=4]Testing[/font] Before starting the new job, I had some knowledge of Ruby and Rails, but since then I think it’s expanded a bit. For example, I now know how to test. Say I want to make sure that it returns an error if the blog’s subject is blank, and assuming I’ve set up the model correctly.

[code] require File.dirname(FILE) + '/../testhelper' class BlogTest < Test::Unit::TestCase def testvalidation assert !Blog.new(:description => "Here's a description", :text => "And here's some text, but uh oh...").save end end [/code] Basically it says make sure that when I create a new blog using the fields and data provided that it errors. If it errors then it will pass the test. Testing is much more complex than that, especially when you get to the controller testing.

In this example we assume there’s already two blogs in the table, which is default for fixtures. We also assume that the blog controller’s action “create” is protected by the actsasauthenticated method of logged_in, which requires session[:user] to be something other than false!

[code] require File.dirname(FILE) + '/../test_helper'

beleive it or not, this line actually includes the blog controller (app/controllers/blog_controller.rb)!

require 'blog_controller'

class BlogController; def rescue_action(e) raise e end; end

class BlogControllerTest < Test::Unit::TestCase def setup @controller = ForumController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new end fixtures :blogs, :users def test_posting

posts to blog/create and specifies session[:user] = 1

post :create, { :blog => { :subject => "Alright, this should work.", :description => "At least, we hope so.", :text => "And we need text, don't forget text." }}, { :user => 1 } assert_equal 3, Blog.count end end [/code]

Again, that code should pass and everything should be OK. These can be so much more complicated, I’m just using basic examples to show why they are awesome.

Another feature of testing is the mocks, located in “yourapp/test/mocks” these allow you to create duplicates of the libraries that you would otherwise use in the application, but may want some of the methods to perform differently than what they do in the real version. For example today I used the following:

[code] module AuthenticatedSystem def logged_in? return true end end [/code]

So when the test runs it loads the mocked version of AuthenticatedSystem, and when the “logged_in?” method is called it uses the method defined in the mocked version instead of the one in the real version.

[font:size=4]Migrations[/font]

Another thing we covered was Migrations. Migrations let you keep track of the versions of your database, and therefore allow you to revert changes if you manage, and apparently you will manage, to stuff something up.

To generate a migration first of all you can run the “ruby script/generate migration “, where is something logical, like createtables. This will generate the first migration, or first version of your database. This file will be located at “db/migrate/001.rb”, go on and open it up to see something like this:

[code] class CreateTables < ActiveRecord::Migration def self.up end def self.down end end [/code]

Which we can flesh out to be something more like this:

[code] class CreateTables < ActiveRecord::Migration def self.up createtable :blogs do |t| addcolumn "subject", :string addcolumn "description", :string addcolumn "text", :text addcolumn "createdat", :datetime end createtable :comments do |t| addcolumn "text", :text addcolumn "userid", :integer addcolumn "createdat", :datetime end createtable :users do |t| addcolumn "login", :string add_column "password", :string end end

def self.down droptable :blogs droptable :comments drop_table :users end end

[/code]

Alright, so I elaborated a bit that time. Basically, that should create a very skeletised version of a blog + comments + users database for a blog application. So, how do we get it into the database? Well, you could go into mysql and type something like…

CREATE TABLE blogs ( id INT(11)… etc. etc etc. )

Or you could just go into your terminal/prompt and type the beautiful command of: [code] rake db:migrate [/code]

In a hassle-free instant your tables are in your database raring to go.

Now say that I forgot to put in the blogid field for comments (which I intentionally did in the example), you need to create a new migration by performing “ruby script/generate migration ” where anothername can be whatever you please.

Again you’ll see the familiar self.up and self.down methods if you open 002_.rb which we’ll alter to make it become:

[code] class addblogid < ActiveRecord::Migration def self.up addcolumn("comments","blog_id",:integer) end end

def self.down removecolumn("comments","blogid",:integer) end end [/code]

After that we run “rake db:migrate” again in the terminal/prompt and we’re now up to version 2 of our database. How do we know that? Look in db/schema.rb,

[code] ActiveRecord::Schema.define(:version => 2) [/code]

Now what if you stuff something up?

rake db:migrate VERSION=

So say you want version 2 because you obliterated the users table in version 3,

rake db:migrate VERSION=2

I would like to thank Anuj and Vishal for being exceptionally patient with me thus far.


Aside:

A few years ago I did work experience at this place called “Berlin Wall Software Supermarket”, and on my first day the owner (Rob) says to me “You shouldn’t be here.”, first impressions weren’t all that excellent. He emphasised his jerk-ness by making me and my work experience buddy go through the whole store and make sure the stock was in alphabetical order. Then we were seperated because we were getting on too well. So I went to the other store.

There I worked with the owner’s son, Jamie. First impressions were that he was a pretty decent person, but as soon as we got to the store it turned out he too was an asshole.

Now that I’ve got a new job I get to walk past both stores every day. The one closer to my work has faded displays of World of Warcraft and is always empty when I walk past it. The other store is now closed down and has been converted into a clothing store.

I make it my duty to walk past that store every day and silently laugh at them and think of how far I have come since those days.

Writer’s Block

Tuesday, June 5th, 2007

I tried to write a blog, it didn’t have the same feel as my old ones. So I scrapped it.

Then I tried to write another one, scrapped it too.

Then I wrote this one.

Now I need sleep.

I’ll have something more substantial up on the weekend, probably.

Blazin’ Guns

Saturday, June 2nd, 2007

Today I went shooting at the Marksman Security Training & Indoor Range on Franklin Street in the city with Tom, his dad, his uncle and his dad’s friend.

It was $60 each for the five of us and we got to fire:

30x 9mm Glock semi-auto 10x 45ACP Glock semi-auto 12x .357 Magnum revolver 6x .44 Magnum revolver

Firstly we watched a training video on how to use the guns and what safety precautions to follow, stuff like don’t point the gun at other people, always aim it down range and how to reload it.

Then we went into the “Range A” area, where we went through again the precautions and how to load and fire the two Glocks. I was much more accurate with the 9mm Glock due to the lower recoil on it, the 45ACP was a larger gun with more of a recoil, and it shot more to the left of where I thought I was aiming it.

After Range A, we moved into Range B where we fired the Magnums. We were pre-warned that we may experience “a slightly more powerful recoil” and I was surprised at exactly how much recoil these things had. The .357 wasn’t too bad, but the reload time wasn’t ideal, I guess someone who uses this gun in a real life situation would be more proficient at reloading than what I was. The .44 was nuts! You load up this massive revolver with 6 shots and you expect a similar recoil to the .357 but it’s nearly twice as much, it jars the whole arm, then you have another 5 shots to go.

9mm results: [img]/img/other/shooting/9mm.jpg[/img]

45ACP results: [img]/img/other/shooting/45acp.jpg[/img]

.357 results: [img]/img/other/shooting/357magnum.jpg[/img]

.44 results: [img]/img/other/shooting/44magnum.jpg[/img]

And I collected two shells from the magnums

[img]/img/other/shooting/44shell.jpg[/img] [img]/img/other/shooting/357shell.jpg[/img]

Was a wonderful time and I would suggest it to anyone who wants a way to rid themselves very quickly of $60.