Monday, September 13, 2010

Hibernate Named Native SQL Queries mapping to POJO in xml

Spent sometime looking for a way to create named in the orm.xml. I would have ranted about why every single example I had related to annotations, but that's already been covered sufficiently here or even why they all related to returning entity results when all you need sometimes is a simple POJO. This had me yearning back to the good old days of iBatis.


That goes into the orm.xml.


FYI, I was using hibernate 3.2.x, with the orm_1_0.xsd. ResultTransformers to do the quick POJO thing are only available when using Hibernate raw i.e. not using JPA. A good example is available here.

Sunday, September 12, 2010

IceScrum2 on AWS Micro instances

It's been a while since my last post. I've been under the pump at work and job hunting as well. The announcement from AWS this week about Micro-Instances were too much of a temptation for me. A $54 yearly reservation cost works out to $9.61 reservation cost per month and $5.11 usage at $0.007/hr at 730.5 hours on average in a month. A member of the AWS user group compared it to about 4 Big macs a month at US$ 3.73. Being vegetarian I'd prefer to compare it to about 4 cups of coffee per month.

So, what to do with this new found power? I'm moving some of my development environment online. At the moment that includes:
  • A JBoss 4.2.2 staging server
  • IceScrum 2
  • Hudson integration server
I've previously covered how to get started with AWS for J2EE servers. However, there are some pitfalls using Micro Instances. First, you can only boot from EBS. This may or may not be a good thing. On the plus, your data will always be persisted regardless of shutting down the server. The main negative is the additional cost of the EBS. I'll put it at another cup of coffee a month. Second, I'm migrating my existing IceScrum instance so I need to create an instance of Amazon RDS and export my MySql data to the RDS.

IceScrum2 requires 512MB to work properly (Seriously? 512MB for a simple web-app). The micro instance comes with 613MB each. Which doesn't leave much to throw around. Still, it works well. Next, I'll be putting up Hudson.


Saturday, September 4, 2010

ASP.NET ReportViewer control Dynamic reports with Object Data Source

I've been recently playing around with the built-in reporting control that ships with Visual Studio 2005+. At the time of writing, I'm working with Visual Studio 2008, with Microsoft.Reporting version 9.0. There aren't that many tutorials I found on the web for creating dynamic reports using Object Data Sources. For the uninitiated, an object data source is simply a strongly typed collection of objects with pre-defined properties. Visual Studio should pick up any classes with a method returning a strongly typed list of the objects.


Once you've got that bit sorted, now how to load the data source dynamically...

That's it. All sorted. Clear the data source from the report every time you want to regenerate the report.

Thursday, July 8, 2010

Arduino Button Bouncing - Why doesn't my LED remain on?

This is an update to my last posting on Getting Started with Arduino. After a couple of days of frustration, I purchased an Arduino Prototyping Shield (I don't think I'm yet ready to pick up the soldering iron and build it from a kit) as the Freetronics Starter Kit I purchased only comes with a mini breadboard and lots of the tutorials come with a prototyping shield and needed to see something consistent. Anyway, I was looking at this button tutorial on the Arduino website.

The circuit is similar to the one in my last post, and the sketch from the arduino website is reproduced below:



When tested out, the LED only turns on when the button is pressed. Turns out, due to the spring mechanism in the button, a rapid sequence of on off signals are sent when the button is pressed (Remember Arduino is a continous loop!). Hence a delay of about 10-50 milliseconds delay correctly detects a transition, as seen below:



Wednesday, June 30, 2010

Getting started with Arduino on Freetronics TwentyTen

Barely a week ago, I was happily unboxing my Freetronics Arduino starter kit (available here in Australia) and the Getting started with Arduino book by Massimo Banzi one of the 5 developers of the Arduino environment. The introductory chapters of the book are well written and you get a good sense for the passion of Massimo for electronics and prototyping. The obligatory what is electricity and the water pump analogy out of the way, it gets stuck in the first sketch - making an LED blink. This is relatively easy to achieve and a nice quick and easy success for the beginner.

The next challenge was to use a push-button switch to add some interactivity to the mix. This is where the lack of an endorsed starter kit makes following the book a challenge. There isn't enough of an introduction to the electronics components required (other than explaining where they can be purchased). The diagram uses a full-size bread board which is different to the tiny breadboard that comes in the Freetronics starter kit. Still, its not impossible to figure out. My circuit is shown below:



The LED is partially obscured but the other connections can be easily figured out. A slightly more challenging tutorial is available here.

Friday, June 25, 2010

SQLCMD CSV Output

SQLServer (both express and full versions) provide a useful command line tool (sqlcmd) which you can use to run batch tasks. See the full list of options here. Here's a quick way to get usable CSV output from this tool.



The main things to watch out for are specifying the correct delimiter.
  • -s: For Comma-Seperated-Values (CSV), the value of -s ","works a joy.
  • -W: The -W option removes the trailing whitespace.
  • -h: Setting this to -1 removes the headers of the fields (if your query is returning a result set).
  • -i: This is the input file (the file with the sql to be executed). For interactive scripts and to make your batch file resuable, set this to %1 to use the first command line argument
  • -o: This specifies the output file
  • -S: The server.
  • -U: The user
  • -P: Password
The complete version of the reusable script with comments and usage:


I'm still working on how to remove the number of rows affected line after the result set.

UPDATE: Setting NoCount On (Set NotCount On) in the SQL file disables this behaviour.

DOS Scripting Text Parsing

I've been most unfortunate to have to be involved in some Windows scripting at work. What is that you say? A colleague of mine recently needed a script that rearranged some images and icons based on some fields in a database. I started off with exporting the database records into a comma separated file.

A few tips about DOS scripting:
  1. www.dostips.com: One of the best resources on the web on DOS.
  2. REM: Useful for commenting your scripts. I cannot emphasize enough how important it is to comment your scripts.
  3. @echo off: Setting this at the beginning of your script stops the script from printing out the commands it is executing. This makes the output nice and tidy, printing only when echo is called explicitly. Not setting it is good for debugging.
Lets start of with some simple examples and pitfalls:

Parsing text and printing out line numbers:
See the script listing below:


Note that the delims option is set to blank (delims=). This is to counter the fact that spaces and tabs are the default delimiters so you need to override this. Another interesting aspect in the script is the use of the "enabledelayedexpansion". This allows variables in for loops to be evaluated correctly.

Splitting a line delimited by commas
Once your lines have been split, you may want to split the individual lines either by comma (for CSV files) or other delimiters.


This will display the first 3 words of each line after line.

Update: I've found a site with interesting tutorials on DOS.

Tuesday, June 22, 2010

Arduino Unboxing

Finally after a few days of waiting, my Arduino (I/O) board has arrived and I can get stuck into some prototyping. For those not in the know, Arduino is an open source physical computing platform based on a simple microcontroller board.

Pics below of my box...




More soon on my exploits and the abilities of this nifty little board. Did I mention its dead easy to program?

Wednesday, June 9, 2010

Perils of a Polyglot - part 2

This is part 2 of my Perils of a Polyglot series. I looked at tokens to mark identifiers ($ vs @) and where to put semicolons (;) to terminate statements. I'll continue this rant looking at other pet hates.

3. if, elseif, else if, elif, end if, then, else:
This is probably a point about scope, whitespace and indentation (I'll whinge about that later). Different programming languages have different ways of doing pretty much the same thing. I must say the most annoying of them all I find is Python. Why? First, 'elif' for 'elseif'. Second, parenthesis outside the condition is optional. That may be convenient but I always pause a second thinking is it right?

if request == "good":
#do something good
elif request == "bad":
#do something bad
else:
#do nothing

You can also do:

if (abooleanVariable):
#do somethihing

VB.NET takes the Pseudo code analogy a bit to serious for me. If ... Then ... ElseIf .. Then .. End If. I always wonder, "If End If is two words, why is ElseIf one word?". Another interesting point is the fact that an If statement spanning a single line does not need an "End If". Example below:

If Not anObject Is Nothing Then anObject.ToString()

VB.NET also brings you niceties such as no parentheses around the conditions and real worlds for the boolean operators (And, Not). Thankfully the Visual Studio IDE should keep you from straying with its auto correct features that include correcting the case of reserved keywords. Nice.

Finally, how the major programming languages handle scope within conditional statements (This could be repeated when b***ching about indentation and whitespace) :

Curly Braces:
  1. Java
  2. C++
  3. C#
  4. PHP
  5. Javascript

The Rest:
  1. Python (Indentation)
  2. Ruby (Keywords: end)
  3. VB.NET (Keywords: Then, EndIf)
Enough about conditionals, I'll try cover the rest of the issues in one post next time.

Tuesday, June 8, 2010

Perils of a Polyglot

A polyglot is linguist - a person who speaks more than one language. Most programmers worth their salt tend to be polyglots in the never ending quest to improve productivity and I'm no different. My day-to-day programming is most in Java and .NET languages VB.NET and C# as I'm mostly doing enterprise development and integration work. My website runs on Joomla! in PHP and I occasionally write some modules for it. The rest of the small projects I work on are some Python (for Google App Engine), Ruby (on Rails) and I'll include Javascript because with node.js and coffee script, I'm doing quite a bit of Javascript.

One of the greatest pains of jumping between different programming languages is the different syntax rules and the obscure error messages you get when you violate these rules. You stare at the code, the error message and nothing makes sense, especially if you are not using an IDE. It was when I was facing such a mistake that I got the idea for this post. So I'll start with that.

1. In PHP variables are denoted with '$' not '@'.
You can guess that I'd been doing some Ruby programming before this. The code I wrote was:

@usr = new StdClass();

The error message was 'Parse error: syntax error, unexpected '=' in on line '. How cryptic is that! I should have typed:

$usr = new StdClass();

However, just @usr; is a valid PHP statement!

2. Where to put those semicolons?
Semicolons are neat statement delimiters. Where to put them and where not to is an error that's easy to make and easy to pick up but worth a mention.

Of the programming languages I use the following use semicolons:
  1. Java
  2. Javascript
  3. C++
  4. C#.NET
  5. PHP
And the languages that don't:
  1. Visual Basic .NET (and VB6)
  2. Python
  3. Ruby
Next post I'll look at the "if, elseif, else if, elif, end if, then" dilemma, Case Sensitivity, Whitespace (tabs vs space), Comments and much more. Share your pain in the comments.

Casein CMS on Heroku

When evaluating some Ruby on Rails CMSes I mentioned Casein (which I wouldn't really classify as a CMS). Its more of a plugin that provides admin authentication and pretty CRUDification of resources. I'm doing my development staging on Heroku and needed to ensure that it runs on Heroku. Here's a couple of Gotchas!

Gems
Gems on Heroku are installed using a .gems manifest file. 2 gems required: calendar_date_select (>=1.15) and will_paginate (>=2.3.11). Adding these two gems to the manifest will ensure they are installed when you push the application.

calendar_date_select --version '>=1.15'
will_paginate --version '>=2.3.11'

You'd be forgiven for thinking this would resolve the issue, however, there is another reference to the gems as part of the plugin that causes the application to fail. In /vendor/plugins/casein/init.rb comment out the two lines that configure the gem.

#config.gem "calendar_date_select", :version => '1.15'
#config.gem 'mislav-will_paginate', :version => '~> 2.3.11', :lib => 'will_paginate', :source => 'http://gems.github.com'

Caching
As part of the magic the Heroku fairy godmother provides (Building upon the AWS and S3 storage service), the clock strikes 12 when you attempt to write to the file system. Simple, Heroku slugs operate in a readonly context. The caching currently written in Casein, primarily for static resources like Stylesheets and Javascript, attempts to write to the file system. The first instance you will encounter this is on the authentication page. The layout file is in /vendor/plugins/casein/app/views/layouts/casein_auth.html.erb. Change the line:

<%= javascript_include_tag :defaults, "/casein/javascripts/login.js", :cache => "casein_auth_javascripts" %>

to:

<%= javascript_include_tag :defaults, "/casein/javascripts/login.js" %>

That should get you up and running. My next stumble was running the casein:init rake task but as I'm probably not sticking with the platform I may or may not investigate a solution for that.

UPDATE: Not sure what's wrong with the rake task, but the task is not doing much. See /vendor/plugins/casein/tasks/casein_tasks.rake to see what the task does. It runs the migration, removes all existing users and then creates the admin. If you've already run this locally, I'd suggest simply using heroku db:push to transfer your local data to Heroku. Sadly I'm not going ahead with Casein so this is it for me.

Monday, June 7, 2010

Ruby on Rails customizable CMS

As mentioned in a previous post, I'm staging my coming-out-of-the-ruby-on-rails-closet party with the rewriting of my scheduling system, Chex. The system was coded from scratch on python/django on the Google App Engine. One of the things I didn't like about the original application was the fact that the static content was tightly coupled to the functionality of the application. My experience with this blog and my website is that it is much simpler to update the content using specialized systems. Especially as I program in many different languages, if I want to quickly change some presentation aspects and my day programming job does not include that language, I don't want to be fiddling with code, sticking semicolons where they don't belong!

My initial googling returned several possible options I could use, including Radiant, BrowserCMS, ... Here's a dated list of the top 20. I found overall that there were a handful that were mature in the classic CMS sense (coming from someone who's website runs on Joomla!) and off course plenty that were experimental and flaky. I'll leave the critique to others.

This evaluation process got me thinking about what a CMS is and what I was really after. I needed to do registration, authentication and quickly managing static content. I also needed something that would drop into my application. After reading an insightful article on how Rails + Plugins effectively equated a CMS, I'm feeling upto the challenge for creating a DIY which hopefully can become reusable in time.

Monday, May 31, 2010

Quartz Task Scheduling on JBOSS 4.2.2

I've been working on a J2EE app which needed to run a specific task at 8.00 AM every morning. I've used Quartz as a scheduler with Spring on Weblogic, but I'm not using Spring on my current project so I was probably going to have to use Quartz raw. That is, until I read that JBOSS has Quartz built in. This has been handled as a resource adapter. That's the quartz-ra.rar file.

How to use this goodness, is to create a Message driven bean (MDB). You can do this by creating a class that extends the org.quartz.Job interface. See an example here.

Notice that I have commented out the annotations just above the class definition as I believe those are deployment specific decisions hence would prefer to make those declarations in configuration files. If you're not as picky you could uncomment them. Note that the @ResourceAdapter annotation is JBOSS specific and would impact negatively on the portability of your code!

In your ejb-jar.xml you define the class as an EJB. See example here.

If you're following my advice and not using proprietary annotations, you'll need to create a jboss.xml file like this.

The jboss.xml file creates the link between the EJB and the resource adapter while the MDB definition in the ejb-jar.xml file. Be careful with the cronTrigger property as it does not behave in the exact same manner that cron does in UNIX (Cron on Wikipedia). There is an additional position on the left for seconds. Follow the Quartz Scheduler tutorial here. Deploy and enjoy!

Sunday, May 23, 2010

Creating On-Demand Demonstration Sites for Java Based Systems using EC2

If you have developed web-based Java systems and are a small time shop, you will have encountered the issue of how to showcase your work given the relatively higher costs of Java hosting compared to Ruby, PHP and Python (Google App Engine). Did I mention the inexperience of many shops that try to provide Java hosting outside of Virtual Private Servers? Ever counted how many times you need to restart Tomcat when debugging deployment? After recently attending an Amazon Web Services meetup (where I got 50$ in AWS credit), I decided to give it a go.

The Requirements
The application in question has the following specs:
  1. Runs on Java 1.5+, Apache Tomcat 5.5.x+
  2. MySql
In addition to these 'undemanding' technical requirements, I've decided the following for prospective users of my system:
  • Demos should only be created when a propsective client requests them. I only want to pay when a real opportunity is present.
  • Prospective clients are to have individual instances. No sharing of instances or data.
  • Prospective clients are to have unlimited time trials. Their test data should also be retained should they chose to go ahead with using the system.
  • Provisioning of new instances should be automated with no human actions required (except of course the prospective client request).
I've managed to get it working with the following architecture:



As can be seen from above, the user requests an instance from my website. A request is sent using a PHP library for EC2 to create an instance based on a prepared image stored in Amazon S3. The user can then access this instance [n] through its public dns once the instance is up and running. Sounds simple enough?

The details for getting all this up and running is very involving and writing a tutorial for all the steps would be quite consuming given the information for this already exists elsewhere. What I will outline here are links to the tutorials and web resources I used to get this going and point out some of the challenges I faced i.e. things not pointed out in the tutorials and generally problems I had with the implementation.

Creating an Amazon AWS Account
This is off course the easiest part of the setup. Here's a presentation by Simone Brunozzi (AWS Evangelist) on how to sign up. I suggest playing around with EC2 instances before carrying on and Elastic Fox is an excellent Firefox plugin which you can use to manage your instances. When I was working on this, ElasticFox did not come preconfigured with the APAC region. This is easily fixed. Other minor stumbles include changing the permissions for the .pem files (chmod 0600 ...) otherwise ssh won't use the key to connect to the instances (Another gripe I had was the fact that the wizard for launching an instance on ElasticFox is to big to display on my MacBook even at top resolution).

Preparing your AMI Image
Hopefully by now you are familiar with what an AMI image is. Here's an excellent tutorial(which links to an existing Fedora 8 image with almost everything required to run java) on how to prepare your image on EC2. I opted to have MySql storing the information on the instance instead of on a Elastic Block Storage device because it is expected that the instances will be running for the life of the user trial. This is a simplification I chose otherwise I would need to have an EBS for each instance which is an excessive complication. However, should the instance terminate unexpectedly, the user would lose their data.

The MySql database for my application is created using a script that is 120MB. It has a lot of sample data. I uploaded it using Cyberduck for MacOS using SFTP.

Creating an S3 Bucket
S3 is AWS simple storage service. You need to have a bucket created. You need to make a decision as to which availability zone you want to run your instance from because buckets are not shared between instances. The image referred to in the preparing your AMI image tutorial is available in the us regions whereas I wanted to have my instance running of the newly minted Singapore region. I used the S3 Fox Organizer plugin to create my bucket and its a nice plugin overall to manage your S3 storage.

Automating the Creation of Instances
Once you are happy with the Image, you need a way of remotely creating instances. My website is currently running on Joomla! so I needed a PHP way of doing this. There is a PHP client library as part of the sample code and it works like a charm as well as provides sample code. For my purposes I only needed to execute the "runInstances" command to create the instance and the "describeInstances" command to check the status of the machine and get the public dns of the site in order to create the url to show the user.

Create Instance

  1. include_once ('/<path-to-the-ec2-library>/Amazon/EC2/Samples/.config.inc.php');
  2. $service = new Amazon_EC2_Client(AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY);
  3. try
  4. {
  5. $response = $service->runInstances(array('ImageId' => '<your-image-id>', 'MinCount' => '1', 'MaxCount' => '1'));
  6. if ($response->isSetRunInstancesResult()) {
  7. $runInstancesResult = $response->getRunInstancesResult();
  8. if ($runInstancesResult->isSetReservation()) {
  9. $reservation = $runInstancesResult->getReservation();
  10. $runningInstanceList = $reservation->getRunningInstance();
  11. $instance_id = 'NA';
  12. foreach ($runningInstanceList as $runningInstance) {
  13. if ($runningInstance->isSetInstanceId())
  14. {
  15. $instance_id = $runningInstance->getInstanceId();
  16. $state = 'pending';
  17. $response = $service->describeInstances(array('InstanceId' => $instance_id));
  18. if ($response->isSetDescribeInstancesResult()) {
  19. $describeInstancesResult = $response->getDescribeInstancesResult();
  20. $reservationList = $describeInstancesResult->getReservation();
  21. foreach ($reservationList as $reservation) {
  22. $runningInstanceList = $reservation->getRunningInstance();
  23. foreach ($runningInstanceList as $runningInstance) {
  24. if ($runningInstance->isSetInstanceState()) {
  25. $instanceState = $runningInstance->getInstanceState();
  26. $state = $instanceState->getName();
  27. if ($runningInstance->isSetPublicDnsName())
  28. {
  29. }
  30. }
  31. }
  32. }
  33. }
  34. }
  35. }
  36. }
  37. }
  38. }
  39. catch (Amazon_EC2_Exception $ex)
  40. {
  41. echo("Caught Exception: " . $ex->getMessage() . "
  42. ");
  43. echo("Response Status Code: " . $ex->getStatusCode() . "
  44. ");
  45. echo("Error Code: " . $ex->getErrorCode() . "
  46. ");
  47. echo("Error Type: " . $ex->getErrorType() . "
  48. ");
  49. echo("Request ID: " . $ex->getRequestId() . "
  50. ");
  51. echo("XML: " . $ex->getXML() . "
  52. ");
  53. exit();
  54. }
Line 8 is where the instance is created. Line 33 and 36 get the state of the created instance and the public dns name respectively. I've experienced wait periods of up to 5 minutes from creating the instance to when its fully up and running, therefore you need to find a way of either doing this check asynchronously. It was a touch of irony, when my first thought was to execute a "popen" call so that the process could run in the background, only to discover "popen" is disabled by my current hosting providers. How long till I move my website to run on its own EC2 instance where I can do whatever I want?

WareRU Online

Finally! After a weekend full of blood, sweat and tears, I now have an on-demand trial of the WareRU Inventory management system online backed up by the wonderful Amazon Web Services. It has been a real learning experience getting this going and it allows me to showcase a great piece of software that was not available to try due to the prohibitive costs of Java hosting.


Enough said! Give it a go at http://bit.ly/blJxMi

Saturday, May 22, 2010

Amazon Web Services Meetup - Melbourne

I recently attended a cloud computing meetup in Melbourne hosted by an Amazon Web Services evangelist. I'm usually quite sceptical of the content of such meetups - I've met my share of salesmen from big vendors in my career - but the community aspect of such a meeting was too tempting to ignore. There was about 35 developers in attendance, mostly rubyists and sys-admin types. In all it was a productive session which had me thinking, when will I put this to use?

It turns out, one of the systems I've previously built has been languishing in neglect because of expensive and unmanageable Java hosting. I used to host a Virtual Private Server (VPS) for about 90$ (AUD) a month. This hosted a Tomcat Server, MySql, mail server and my website (PHP). I found this to be quite an expense, given the demo was rarely accessed - as it is specialised software. Also I had the hassle of cleaning up the data so that prospective clients found a professional demo ready for their use. This also needed to allow for long term trials so cleaning up the database every hour wasn't feasible.

It is a tribute to the maturity of Amazon's Web Services that it has been able to meet my requirements. I am in the process of chronicling the challenges I faced in creating this on-demand demo service.

Saturday, May 15, 2010

NameError: uninitialized constant GData

I was trying out the GData gem from Google as part of my chex rewrite when I got struck with a bit of an idea how the Ruby console works. This has been one of the things I've loved about programming in Ruby as opposed to Java / NET or the other programming languages I program in. I installed the gem using: "sudo gem install gdata" which worked like a treat. Next thing I did was fire up the console to start playing around with gem - "ruby script/console", only to be greeted by this error.

  1. trevors-macbook-4:chexscheduler trevor$ ruby script/console
  2. Loading development environment (Rails 2.3.5)
  3. /Library/Ruby/Gems/1.8/gems/rails-2.3.5/lib/rails/gem_dependency.rb:119:Warning: Gem::Dependency#version_requirements is deprecated and will be removed on or after August 2010. Use #requirement
  4. >> client = GData::Client::Calendar.new
  5. NameError: uninitialized constant GData
  6. from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:443:in `load_missing_constant'
  7. from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in `const_missing'
  8. from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:92:in `const_missing'
  9. from (irb):1
  10. >> client = GData::Client::DocList.new
  11. NameError: uninitialized constant GData
  12. from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:443:in `load_missing_constant'
  13. from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in `const_missing'
  14. from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:92:in `const_missing'
  15. from (irb):2
  16. >> client = GData::Client::DocList.new
  17. NameError: uninitialized constant GData
  18. from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:443:in `load_missing_constant'
  19. from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in `const_missing'
  20. from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:92:in `const_missing'
  21. from (irb):3
  22. >> ^Dtrevors-macbook-4:chexscheduler trevor$
  23. trevors-macbook-4:chexscheduler trevor$ clear
This is peculiar as the gem has already been installed globally. However, as it was not added to the environment.rb, it was not picked up during the launch of the console. Only when I added the line " config.gem 'gdata', :lib => 'gdata' " to environment.rb and relaunched the console did it work. Back to playing around with the gem.

Adjusting to the Agile way

As I mentioned in a previous post, I'm rewriting one of my previous applications written in Python in Ruby on Rails. I've decided to spend sometime thinking and journalling the process - not just the technical hurdles of reimplementing in Ruby, but also the changes in project management methodology. I've fully embraced a scrum methodology for this project and I'm writing user stories on a notebook when I'm on the go and inputing them into Ice Scrum for traceability.

One of the challenges I find when I'm developing a new product is to treat myself as a client. I get so many brain waves and at times I'm not always disciplined enough to write them down. I just assume that since I originated the idea, it'll always be there. Sometimes its not necessarily a technical solution, it could be something that inspires the general vybe of the application (To be fair this also applies to when I'm using other methodologies). Having to condense this into a user story is a challenge.

Also, as the sole developer, there is a laziness involved in spending time writing something which your never sure will be read by anyone else. I feel like jumping straight into the actual deliverable. Note to self: Need to find out whether apps like twitter / facebook were built by their original developers using a strict development methodology. Do these methodologies apply at the edge of such innovation? I'd love to write the user stories for Twitter. I'm sure they could fit in 140 characters. Someone should write a tool using twitter for user stories.

Monday, May 10, 2010

Rewriting Chex Scheduler on Ruby on Rails

I was recently taking some speculative phone interviews a few weeks ago and I came across an international consulting company with a strong focus on Ruby on Rails and Agile practices. I remember remarking that I was not 'over-enthusiastic' about RoR (big mistake!). Anyway, I justified my reasons. I recently thought over my reasons for my dislike and decided to do my next major project using RoR. This happened to be my rewrite of Chex Scheduler - an online scheduling application written in Python and ExtJS running on the Google App Engine.

I'm also fully embracing the Agile way - using scrum in this instance - and I'll be cataloguing my experience. I'm pleased to have some tool support for project management in scrum in the form of Ice Scrum. Its great! The application will be deployed to Heroku and I'm hence using the git, version control system. I'm still undecided on what to use for Javascript, perhaps JQuery-UI. I think ExtJS was a bit heavy handed for what I wanted to achieve. So far, those are the design decisions I've made. I'll be updating the blog on how I'm proceeding.

Sunday, May 9, 2010

My experience map

Now, for some shameless self-plugging...

I've been answering some deeply personal questions about my experiences across my employment history for a head-hunting website and below is my experience map. I'm not sure the information is very useful - more than the nice graphic - and it doesn't capture all the technologies that I've worked on. It's interesting though, and cute.

To see my full career page, click here
http://mycareer-headhunter.com.au/people/trevorkimenye


Monday, April 19, 2010

Math for Software Engineers

I've recently gotten into TopCoder (don't ask me where I've been all this time). As a software engineer of about 7+ years, I was quite keen to find out where I stacked up in the programming stakes. I've programmed mostly in Java, so that was the language I chose to use in practice area of the Arena. I should also disclose that I got a tip to attempt some of the division 1 and 2 problems from a Google page about preparing for their interviews. This sparked my curiosity even further.

After starting the Arena (TopCode should have a UI contest to find a more user friendly place to show link to the jnlp. At the footer seems an odd place to have a link that is used frequently) I went into one of the practice rooms and picked a problem related to gambling. TopCoder does not allow unauthorized reproduction of their problems, so I won't violate their copyright. The problem can be found in practice room SRM 144 Div 1.

The crux of the problem is to find out how many combinations of a particular set of items that can be selected from another set of items. For example, if you have to pick 2 numbers from 1-10 inclusive, how many combinations can you include? What if the order is important (i.e. the second number you pick must be greater than the first)? What if the numbers must be unique (i.e. no repititions)? What if both the order and unique rules are necessary?

While I was intrigued with the logical challenge of solving this puzzle, I wondered whether this has a place as a problem for a software engineer. I suspect, depending on how the client has explained this problem (you would have to see the post for the problem from TopCoder) it either becomes a computer science or mathematical problem rather than one about building software. Many computer solutions are replacements for manual processes so sometimes it is necessary to ask the client, "What are you doing currently to solve this?" It could however be a new problem and it is unreasonable for the engineer to tell the client, "Sorry, I can't quite remember my high school math."

The solution to the problem required 4 routines:
  1. A method to calculate exponentials. In java - Math.pow is sufficient.
  2. A method to calculate permutations.
  3. A method to calculate factorials.
  4. A method to calculate binomial_coefficient.

Exponentials
Exponentials can be used to calculate the number of possibilities without any rules regarding order or uniqueness. For the example of 10,2 the number of possibilities is 100.


Permutations
From wikipedia, a permutation of a set of values is an arrangement of those values into a particular order. Going back to the original problem of picking 2 numbers between 1-10, regardless of order and ensuring the numbers are unique (i.e. 1,2 is valid but 2,2 is invalid), calculating the number of permutations of the 10 integers with 2 options for each.

  1. private long permutation(int n, int opts)
  2. {
  3. long result = 1;
  4. for (int idx = 0; idx < opts; idx++)
  5. result *= (n - idx);
  6. return result;
  7. }
Factorials
Factorials are a little more interesting than permutations. The factorial of a positive integer n (n!) is the product of all positive integers less than or equal to n. The factorial of zero is defined as 1. This is useful for calculating binomial coefficients.

Tuesday, January 5, 2010

Mobile Safari - Why am I developing for it?

This is my first post for the new year, 2010, so I thought perhaps to have a look at a new subject (to me). I've been fiddling with some iPhone development so far, brushing up on my Objective C and written a few posts on some of the lessons I've learnt. I also stumbled on an e-book I hadn't read in a while - Professional iPhone and iPod Touch Programming: Building applications for Mobile Safari, by WROX. This got me thinking, why would someone create a safari app, given the richness of the native applications?

The initial attraction I suppose is for those websites that already have an online community and would like to accommodate their mobile browsers. Then there are those whose applications would not be approved by Apple's App Store - on one end of the scale, those pioneers of online business - the purveyors of Adult entertainment a.k.a porn sites and on the other, competitors of Apple e.g Google. Amongst those looking to provide iPhone friendly versions of their websites, a huge chunk are media organisations. Wanting a slice of this market, I've decided to get onto learning how Mobile Safari works. I also expect the launch of the iSlate or whatever the call it, will herald a return to more content / feature driven demand for applications, and this is where some form of web applications will re-emerge. The main draw cards of Web 2.0 - community and content - ultimately belong server-side.

Initial impressions of Mobile Safari are not very promising. There is not much integration with many of the phone's key services but some are promising e.g. Geolocation. One sore point is the inability to directly upload photos. I expect this list to increase on both counts and look forward to interesting posts this year.