Saturday, October 27, 2012

RMagic - image processing for RoR

I have a few projects that required basic image manipulation. Easy stuff like cropping and resizing images that users upload in the application.

Image Magic provides a nice solution for this both on Windows and Linux (the two environments i use) although they also provide libraries for MAC.

To install on windows first download and install the windows installer for Image Magic.
Note that you will need the installer to include the C libraries as well.

Then proceed to install the RMagick gem by this command (source):

gem install rmagick -- '--with-opt-dir="[path to ImageMagick]"'
And don't miss any character. just replace the [path to ImageMagic] with the location the installer put the image magic installation.

The installation for Ubuntu  is slightly easier:

apt-get update
sudo apt-get install imagemagick libmagickcore-dev
sudo apt-get install libmagickwand-dev
sudo gem install rmagick

Once you have the gem installed, add the following line to the gem file:
gem "rmagick", "~> 2.13.1"
And run the following command:

In the files you want to use this gem include:
require 'rubygems'
require 'RMagick'

You may find the instructions for the image manipulation facilities useful as well.

Sunday, October 14, 2012

Book Review: Sencha's ExtGWT Coockbook

The past few days I've been going through the ExtGWT Rich Internet Application Cookbook which is fresh out the the PacktPub press.

This Cookbook reviews the usage of the Sencha's ExtGWT GUI packages, A GWT application framework.

The book has been written by Odili Charles Opute and Oded Nissan, the latter is an old friend and an inspiring professional I hold dear.

Oded says: "GWT allows the use a single high level, object oriented and strongly typed language for developing web application. (this is the same concept behind the DART programming language that Google in involved with). Developers who are not JavaScript, HTML/CSS experts can then develop complex rich internet applications using Java.
With Java, developers can use OO design pattern in their client code, a capability that is missing when developing web applications using JavaScript and markup.
The main criticism against GWT is that it prevents developers from using JavaScript and HTML markup directly, thus preventing flexibility.
I would say that if you are shooting to develop a complex and revolutionary web site, GWT would probably not be your first choice (although there are plenty examples of unique application built using GWT) . However, GWT is a very good fit for developing form based web applications, probably covering most of the Enterprise and SMB applications.

Using GWT for web GUI implementation can work not only for Java Server side. As long as you are using RESTful interfaces, RoR can suite just fine.

For me, the aesthetics of coding is a major concern. Much like writing prose, code should be expressive and clear. After all, it is telling a story. Clarity of code helps developers create the right mental image of the mechanics and stream line of the moving parts.
Noisy and cluttered code on the other hand induces malfunction (AKA Bugs).

The first impression I got from the book was the clarity and simplicity of the examples and explanations. Being a ruby sort of person as I am, it actually made me miss coding in Java just a bit.

What I found in the book were 80 examples for GUI development and appendixes for event handling, Icon manipulation, RPC and file uploading.
In short, all the floaters you might need when jumping into the ocean of GWT GUI development.

The examples took me from the obvious to the advanced, and although I have years of Java development behind me, the explanations are structured in a way that could be easy for the novice and not tedious for the expert.

When Choosing GWT and the Sencha package, get a copy of this cookbook. I give it the thumbs up.

Friday, October 12, 2012

RoR Double Clutch

This is a pattern have implemented in three different projects of mine, so I'm writting it down once and for all the next times I wrap my head arround this until I remember I have already have done it.

In the Dezquare project, the users are offered a game that helps them in finding a sutable designer. The game varies accorging to all sorts of conditions. The sequence is broken down into a series of basic elements that can be manipulated and tweeked from an admin consule.

The aim is to have an implementor grabbed from the database and react to a particular context as part of a user flow sequance

The players:

  • A controller
  • A context object (as an ActiveRecord)
  • A referenced implementor descriptor (as an ActiveRecord)
  • An implementor

The sequence:

  1. The controller identifies the context object and passes the request params
  2. The context object finds its implementor descriptor and passes itself as an argument
  3. The implementor descriptor converts its implementor class name field into an entity (imp.camelize.constantize)
  4. The implementor descriptor invokes on the implementor method with the context object and its own agruments field (if applicable)

The code 

Note: this code will not work by itself. its only expressing the idea
The standard controller answering a play request
def play
    @results = @game.set(params)

The context object (Game), persistant and stateful, belongs to a "stage" and passes the request and context
def set(params)

The implementor descriptor (Stage), persisted common object, known here as the "stage" generated an entity and calls it.
def klass

def set(game,params)

The implementor (name derived from a data field), unpersisted, statless entity, acts upon the context it is given and returns the results
def self.set(game,params,arguments)
    #pay dirt