RobL Vs

Background

JRuby Swing

I was mulling at the end of last year that while I’ve been programming for far too many years now its been for the most part web development and databases. But I don’t know how to build a GUI, and least of all one that would be cross platform. Time to learn.

I’ve just picked myself up a copy of O’Reilly Java Swing 2nd Edition which, while its old, should help me get to grips with building my first GUIs.

As an interesting learning process I’ve decided that while of course this is all about Java that I am going to read the book in Java, I shall translate it all into JRuby since I use Ruby as my programming language of choice. So I’ll learn three skills in one;

  • GUI Development
  • Java
  • JRuby

I think the best way to pick it up is to go through every last example until it becomes second nature so all the Java AWT and Swing examples I come across in the book I shall be adding in a new jruby-swing github repository are here as JRuby.

https://github.com/braindeaf/jruby-swing

In fact here’s the first example

https://raw.github.com/braindeaf/jruby-swing/master/chapter2/ToolbarFrame1.rb

Desktop app here I come.

Disable startup items in Debian / Ubuntu

Needed to get rid of PostegreSQL on start up. That’s freeing up 8Mb of memory….its better than nothing.

1rails@cool-server-name-001:~$ sudo update-rc.d -f postgresql-8.3 remove
2 Removing any system startup links for /etc/init.d/postgresql-8.3 ...
3   /etc/rc0.d/K21postgresql-8.3
4   /etc/rc1.d/K21postgresql-8.3
5   /etc/rc3.d/S19postgresql-8.3
6   /etc/rc4.d/S19postgresql-8.3
7   /etc/rc5.d/S19postgresql-8.3
8   /etc/rc6.d/K21postgresql-8.3

New Relic - Get a FREE 'data nerd' t-shirt

Just signed up to a new New Relic account today for a client and got a free t-shirt to book. Now its not that I’m without clothes but I do like grey and I’m not afraid to admit I am a nerd. So why the hell not. All you need to do is sign up and deploy your first app which isn’t that much of a bother really and I was going to do it anyway.

Sign up for New Relic and get your free t-shirt and that also gives you 10% off your first bill which is nothing if you use the free version and $50 off my own bill that I am not paying anyway because I’m using the free version :)

Its all about the FREE.

Facebook Open Graph (Complex Types)

Complex Types

Music API

JRuby Resources

Just a few resources for the almighty JRuby Desktop app I will one day build, maybe.

MIDI Keyboard

Screenshot

Netbeans Tutorial

Soft Token

Screencast

Darkness Clone

Downgrading Rubygems

Installed latest Rubygems which broken my dev environment.

1Rob-Laceys-MacBook-Pro:app roblacey$ ./script/rails s
2/Library/Ruby/Site/1.8/rubygems/specification.rb:990:in `date=': invalid date format in specification: "2011-9-23" (Gem::InvalidSpecificationException)
3    from /Users/roblacey/repos/app/ruby/1.8/bundler/gems/compass-cb709350942f/compass.gemspec:7
4    from /Library/Ruby/Site/1.8/rubygems/specification.rb:1346:in `initialize'
5    from /Users/roblacey/repos/app/ruby/1.8/bundler/gems/compass-cb709350942f/compass.gemspec:4:in `new'
6    from /Users/roblacey/repos/app/ruby/1.8/bundler/gems/compass-cb709350942f/compass.gemspec:4

One to remember next time something screwy happens, and I am to lazy to use rvm

1sudo gem uninstall rubygem-update -v 1.8.10
2sudo gem install rubygems-update -v 1.5.2
3sudo update_rubygems _1.5.2_

Extracting Blizzard Interface Code and Art

In order to start moving with building Warcraft AddOns you might want to extract the Blizzard UI Code and Art bundles. A little bit fiddly but…

1/Applications/World\ of\ Warcraft/World\ of\ Warcraft.app/Contents/MacOS/World\ of\ Warcraft -console

On the login screen hit /~ to open the console and type

1> exportInterfaceFiles code
2> exportInterfaceFiles art

You should now have two new directories in your World Of Warcraft (/Applications/World of Warcraft/) BlizzardInterfaceArt and BlizzardInterfaceCode directory.

 1Rob-Laceys-MacBook-Pro:World of Warcraft roblacey$ ls -la
 2total 3944
 3drwxrwxrwx  21 roblacey  admin      714 24 May 08:59 .
 4drwxrwxr-x+ 71 root      admin     2414 22 May 11:45 ..
 5-rw-r--r--@  1 rl  admin    12292 24 May 08:59 .DS_Store
 6drwxrwxrwx   3 rl  admin      102  3 May 18:35 Background Downloader.app
 7drwxrwxrwx   3 rl admin      102  3 May 18:35 Blizzard Updater.app
 8drwxrwxrwx   3 rl  admin      102 24 May 08:59 BlizzardInterfaceArt
 9drwxrwxrwx   3 rl  admin      102 24 May 08:59 BlizzardInterfaceCode
10drwxrwxrwx   4 rl  admin      136 21 Apr 23:50 Cache
11drwxrwxrwx  30 rl  admin     1020 24 May 08:59 Data
12drwxrwxrwx   2 rl  admin       68 18 Apr 22:19 Errors
13drwxrwxrwx   3 rl  admin      102 22 Apr 00:03 Interface
14drwxrwxrwx  11 rl  admin      374 22 May 11:45 Logs
15drwxrwxrwx   2 rl  admin       68  3 May 21:02 Movies
16-rwxrwxrwx   1 rl  admin    67140 22 May 11:45 Patch.html
17drwxrwxrwx  11 rl  admin      374 22 May 11:50 Updates
18drwxrwxrwx   5 rl  admin      170 22 May 11:56 WTF
19-rwxrwxrwx   1 rl  admin      177 24 May 08:59 WoW.mfil
20-rwxrwxrwx   1 rl  admin  1927052 22 May 11:45 WoW.tfil
21drwxrwxrwx   3 rl  admin      102  3 May 18:35 World of Warcraft Launcher.app
22drwxrwxrwx   3 rl  admin      102  3 May 18:35 World of Warcraft Repair.app
23drwxrwxrwx   3 rl  admin      102 22 May 11:45 World of Warcraft.app

World Of Warcraft AddOn - pt 1. Hello World

My first World Of Warcraft AddOn, ok so I found a nice tutorial on WowWiki – http://www.wowwiki.com/AddOn_programming_tutorial/Introduction .

- HelloWorld.toc

1## Interface: 40000
2## Title: Hello World!
3## Notes: My first AddOn
4HelloWorld.lua
5HelloWorld.xml

- HelloWorld.lua

1function HelloWorld()
2  print("Hello World!");
3end

- HelloWorld.xml

 1<Ui xmlns="http://www.blizzard.com/wow/ui/" 
 2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 3 xsi:schemaLocation="http://www.blizzard.com/wow/ui/ 
 4 ..\..\FrameXML\UI.xsd">
 5  <Script File="HelloWorld.lua"/>
 6  <Frame name="HelloWorldFrame">
 7    <Scripts>
 8      <OnLoad>
 9        HelloWorld();
10      </OnLoad>
11   </Scripts>
12  </Frame>
13</Ui>

And there if you look in the chat console ‘Hello World!’. Kungla is so impressed he needs to have a proper long sit down.

Code what you mean, not what looks right.

This

1redirects = []
2redirects << params[:redirect_to] || request.referrer

…does not mean this…

1redirects = []
2redirects << (params[:redirect_to] || request.referrer)

…it means this.

1redirects = []
2(redirects << params[:redirect_to]) || request.referrer

I18n Translations with a database backend

Having used Rails I18n translations in yaml for some time, we’ve recently started thinking about how users might want to customise content on the fly, without editing flat files and reloading our application. In my mind it should read from the database.

I found the Il8n Backend Database plugin, however it appears its not Rails 3 compliant yet and we can cope with and probably should build the interface for updating our own translations

https://github.com/dylanz/i18n_backend_database

It seems there was support for ActiveRecord in the i18n gem, but it has since been moved out into the i18n-active_record gem.

./Gemfile

1gem 'i18n-active_record', 
2  :git => 'git://github.com/svenfuchs/i18n-active_record.git',
3  :require => 'i18n/active_record'

./config/initializers/i18n.rb

1I18n.backend = I18n::Backend::ActiveRecord
2Translation  = I18n::Backend::ActiveRecord::Translation

./db/migrate/20101218175356_create_translations.rb

 1class CreateTranslations < ActiveRecord::Migration
 2
 3  def self.up
 4    create_table :translations do |t|
 5      t.string   :locale
 6      t.string   :key
 7      t.text     :value
 8      t.text     :interpolations
 9      t.boolean  :is_proc, :default => false
10    end
11  end
12
13  def self.down
14    drop_table :translations
15  end
16
17end

irb

1irb(main):001:0> I18n.t('loathsome')
2=> "loathsome"
3irb(main):002:0> Translation.create(:locale => :en, :key => 'loathsome', :value => 'dave')
4=> #<I18n::Backend::ActiveRecord::Translation id: 1, locale: :en, key: "loathsome", value: "dave", interpolations: nil, is_proc: false>
5irb(main):003:0> I18n.t('loathsome')
6=> "dave"

So fairly simple start, it shouldn’t be too difficult to build an interface to handle this.

You can even keep the existing flat files as a fallback if the translations don’t exist in the database.

./config/initializers/i18n.rb

1I18n.backend = I18n::Backend::Chain.new(I18n::Backend::ActiveRecord.new, I18n.backend)
2Translation = I18n::Backend::ActiveRecord::Translation