bcrypt problems on dreamhost

So all of a sudden I start getting these cryptic msgs

LoadError (no such file to load — bcrypt):

I checked the Gemfile and it had the approp entry

gem ‘bcrypt-ruby’, ‘2.1.4’, :require=>’bcrypt’

The problem it seems is because I had checked in the Gemfile.lock from windows which had an entry for bcrypt with “x86-mingw32” in it. Delete the win specific part in the Gemfile.lock and presto everything works

So the order in which the events are dispatched by the application are preinitialize(), initialize(), creationComplete(), updateComplete() and applicationComplete().

The events in more detail:
– preinitialize() is dispatched when the component has been attached to its parent container, but before the component has been initialized, or any of its children have been created. In most cases, this event is dispatched too early for an application to use to configure a component.

– initialize() is dispatched when a component has finished its construction and its initialization properties have been set. At this point, all of the component’s immediate children have been created (they have at least dispatched their preinitialize() event), but they have not been laid out. Exactly when initialize events are dispatched depends on the container’s creation policy, as described later in this section.

– creationComplete() is dispatched when the component, and all of its child components, and all of their children, and so on have been created, laid out, and are visible.

– updateComplete() is dispatched every time the container or component characteristics are changed.

– applicationComplete() dispatches events after the Application has been initialized, processed by the LayoutManager and added to the display list. This is the last event dispatched during an application startup. It is later than the application’s creationComplete() event, which gets dispatched before the preloader has been removed and the application has been attached to the display list.

So you are trying to add eventListeners to the stage right from the start of your application execution, this will only work with updateComplete() and applicationComplete(). More information about the startup order of a Flex application can be found here.

Another solution for this is using the callLater() function.The callLater() function (or doLater() in previous versions of Flex and ActionScript), allows you to delay code execution until the user interface is updated.

When Explicit Type Annotations Are Required

1. A variable declaration, unless you assign a value to the variable (e.g., val name =”Programming Scala”)

2. All method parameters (e.g., def deposit(amount: Money)…)

3. Method return values in the following cases:

  • a. When you explicitly call return in a method (even at the end)
  • b. When a method is recursive
  • c. When a method is overloaded and one of the methods calls another; thecalling method needs a return type annotation
  • d. When the inferred return type would be more general than you intended, e.g.,Any

Grails vs Rails

So I took a detour off the well beaten path of the enterprise standards of Java and went wandering for a year in the interesting little nooks of Ruby and Rails – it was simply awesome. Throw in Flex and and I was able to see the productivity jump that the blend of these technologies was able to provide. So if it was soooooo good for me – why look at Grails ?

Enterprise standards are one of those things that are too difficult to work around – specially in technology divisions of investment banks where I’ve done time for over a decade plus some. So Grails seems to bring the best of both the Rails worl and the Java world together

  1. It allows you access to dynamic programming via groovy
  2. It allows you to leverage your existing s/w infrastructure such as app servers, custom java libs and the plethora of open source java libs
  3. It allows you to leverage existing skills of your programmers, support groups and deployment specialists (Of course if they need to learn Groovy – but the learning curve from Java is not steep)
  4. Finally there are the perceptions that are difficult to fight such as Java is better and more stable and show me whos using Ruby etc etc.

This point should not be taken lightly as most decisions by management are not based on technical grounds but on the perception of the technology being used.

Hence Grails fits the bill for enterprise development more that Rails. So now a deep dive into Grails is warranted and I’ll keep blogging about my progress here

Working with RJB, iText and PDF

So I needed to get PDF templating working within Ruby i.e merging data from our DB with PDF templates that were built by others. My first attempts were using prawn the fav ruby PDF toolkit. but this does not allow you to take as input a template PDF and spit out populated PDF.

So I moved to iText and this was great – worked beautifully but how to call it from ruby. Enter rjb. So installing it had some problems on Linux

1. gem install rjb always gave me this error
extconf.rb:48: JAVA_HOME is not set. (RuntimeError)

  • This even though my JAVA_HOME was set in my .bashrc. This can be fixed by the running as follows (note trailing / in JAVA_HOME) – just run the command exactly as – setting JAVA_HOME anywhere else wont work

sudo JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun/ gem install rjb

2. Once installed I could play around with it inside the ruby console – but running it within rails I always got a Segmentation Error

  • This link gave me some clues . So I removed the gem and reset the javac and the java to point to the same jdk – but no joy.
  • Then I moved back from jdk6 to jdk5 and voila everything works

I added the following to my config/environment.rb so that I could access PDFGenerator (my custom java class using iText api) within my rails controller

require “rjb”

Rjb::load(“#{RAILS_ROOT}/script/PDFGenerator/iText-5.0.3.jar:#{RAILS_ROOT}/script/PDFGenerator/:#{RAILS_ROOT}/script/PDFGenerator/groovy-all-1.7.4.jar”,[‘-Xms64m’, ‘-Xmx512m’])

PDF_GEN_CLASS = Rjb::import(‘PDFGenerator’)
PDF_GEN = PDF_GEN_CLASS.new

Then in my controller I can access the instance of my custom class as follows

PDF_GEN.convert(…..)

This allows for a single instance of the class to be reused – of course you have to ensure that the class is stateless as it will be reused in every call.