no such file to load — openssl (RuntimeError)

I was trying to deploy an older Rails 2.2.2 app to a new server and when I started up the application, I ran into the following error:

in `require_frameworks': no such file to load -- openssl (RuntimeError)

Hmm…my app doesn’t even use SSL. Whatever…(think this is because capistrano is involved?)

To fix this, I installed openssl by running

sudo apt-get install libopenssl-ruby1.8

Success!

no such file to load — openssl (RuntimeError)

Changing video playback speed

I was using iMovie ’08 to do some video editing and I wanted to turn a one hour long video into something shorter.

It turns out iMovie ’08 doesn’t support a slow/fast motion effect even though previous versions supported this. I struggled to find a good alternative that allowed me to speed up playback of my video.

I ended up using two command line tools. FFmpeg and MJPEG Tools.

I installed both using MacPorts:

sudo port install ffmpeg
sudo port install mjpegtools

The command to create a fast motion video was:

ffmpeg -i [input_file] -f yuv4mpegpipe - | yuvfps -s [frame_rate] -r [frame_rate]  | ffmpeg -f yuv4mpegpipe -i - -b 57600k -y [output_file]

where

  • input_file – the original source file
  • frame_rate – the resulting frame rate (X:Y)
  • output_file – the output file

The key here is the frame_rate value. Assuming your original video file is X and you want your video to play N times faster, you should sent your new frame rate to be (X*N):1 For example, if your video has a frame rate of 25 fps and you want to increase playback by 4 times, you should use 100:1 for your frame_rate value. You can use the same command to create a slow motion movie. If you wanted to slow the video down to about half speed, you would use 12fps or 13fps for a 25 fps movie. You can find the current fps of your video by running

ffmpeg -i [input_file]

What I did to turn a 50 min movie to a ~12 min video:

ffmpeg -i video.m4v -f yuv4mpegpipe - | yuvfps -s 100:1 -r 100:1  | ffmpeg -f yuv4mpegpipe -i - -b 57600k -y result.avi

It’s been awhile since I played around with video editing. I forgot how long video processing takes. I need a new computer.

Changing video playback speed

Running IntelliJ 9 Public Preview Community Edition on Mac OSX

JetBrains just announced they are open sourcing IntelliJ in a community edition with a subset of features from their commercial product.

Having used Eclipse almost exclusively in my Java work, I was interested in trying it out and went to download the .dmg file. I unpacked everything and tried to run the poorly named Maia-IC-90.94.app

Nothing came up. Lame.

I dug into the package and executed idea.sh which prompted me that I need to set the environment variable IDEA_SDK or JDK_HOME.

Ah ha!

In my .bash_profile, I set

export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
export IDEA_JDK=$JAVA_HOME

And ran idea.sh again and IntelliJ came up.

Picture 1

Running Maia-IC.90.94.app still doesn’t run the app but at least now I can play around with IntelliJ.

Running IntelliJ 9 Public Preview Community Edition on Mac OSX

Linode API for Java

I’ve been really happy with my recent move over to http://www.linode.com.  I was checking out their API and noticed there wasn’t any Java client.  I wanted a do a small pet project so I took a couple hours this weekend and wrote a Java client for the API.

The API leverages Apache HTTP Client and JSON.org Java libraries and is built using Maven.

The project source code can be found here.

If anyone runs into any problems with using it, please feel free to ping me!

Update: Linode was nice enough to update their API page with a reference to my project.

Linode API for Java

Terracotta acquires Ehcache

Pretty big news in the Java world today.

Open-source with a business model company, Terracotta, acquired Ehcache, the very popular caching library.

The creator and maintainer of Ehcache, Greg Luck, had these things to say about the acquisition:

What this means for Ehcache Users

  • Ehcache remains under the Apache 2 license
  • New feature development is accelerated with the addition of a team of engineers working full-time on Ehcache
  • I am full-time on Ehcache. I have not had the time I would have liked to devote to Ehcache (I have been doing a miserly 10-15 hours per week for the past 6 years) but now I do. Look out!
  • Ehcache extends its standards support. There are multiple emerging standards in this area and I plan to work with the community to lead further standardisation efforts. A lack of time has been my biggest obstacle in doing more on this to date.
  • Ehcache gets new hosting at ehcache.org with state-of-the-art forums, source control and bug reporting. The changes will happen slowly and carefully.
  • File release at sourceforge.net is retained
  • Maven deployment to oss.sonatype.org and Maven Central is retained.
  • Distributed caching via Terracotta is seamless. Ehcache users can have full confidence that they can start single node and scale as high as they need to with Enterprise features.
  • Enterprise support, training and professional services for Ehcache. I have provided these for a few years now, but now we will have the full Terracotta organisation behind them with the usual SLAs.

What this means for Terracotta Users

  • Ehcache APIs will replace Terracotta distributed cache APIs as a single caching interface / standard for Terracotta distributed caching
  • a single-node version of Terracotta ala Ehcache will be available for the first time
  • Full freedom to run on the latest version of Ehcache at all times, knowing it will work with Terracotta
  • Single vendor support structure for caching interfaces / libraries as well as their scalability / reliability runtime.
  • the investment protection of standards

It’s pretty cool to see open source companies like SpringSource (recently acquired by VMWare) and Terracotta making big moves. I look forward to seeing what’s next for these guys.

Terracotta acquires Ehcache

Google App Engine adds Java support (Review)

Last night Google announced Java support on Google App Engine.

After a bit of toying around, here are my findings.

The Eclipse plugin is pretty slick. Deploying and build is simple.

The dev server that you spin up locally looks to be jetty under the hood.

Objects intended for storage are JDO annotated and after compiling, you run the .class files through the DataNucleus Enhancer which adds additional metadata so Google can map it to BigTable. The Eclipse plugin automatically performs this step for you after compiling. The examples provide a bunch of ant macros to help facilitate building/deploying.

One issue that I had was that the project was building with Java 1.6 and I would get an error after compiling:

Caused by: java.lang.UnsupportedClassVersionError: Bad version number in .class file

Even though they say they support Java 1.5 and 1.6, I guess this doesn’t work on the Java 1.6 for the Mac. Switching the build to 1.5 allows the DataNucleus Enhancer to run successfully.

Even though they are using JPA, some features have not yet been implemented or supported ( see http://code.google.com/appengine/docs/java/datastore/usingjpa.html#Unsupported_Features_of_JPA)

Overall, I like what I see so far and think this would be great for quick prototypes of web apps/services.

Going through the tutorial, my awesome Guestbook application has been created and deployed.

Google App Engine adds Java support (Review)

Custom field names in Rails error messages

The defaults in Rails with ActiveRecord is beautiful when you are just getting started and are created everything for the first time. But once you get into it and your database schema becomes a little more solidified, the things that would have been easy to do by relying on the conventions of Rails require a little bit more work.

In my case, I had a form where there was a database column named “num_guests”, representing the number of guests. When the field fails to pass validation, the error messages is something like

Num guests is not a number

Not quite the text that we want. It would be better if it said

Number of guests is not a number

After doing a little bit of digging, I found the human_attribute_name method. You can override this method in your model class to provide alternative names for fields. To change our error message, I did the following

class Reservation < ActiveRecord::Base
  ...
  validates_presence_of :num_guests
  ...
  HUMAN_ATTRIBUTES = {
      :num_guests    => "Number of guests"
  }
  
  def self.human_attribute_name(attr)
      HUMAN_ATTRIBUTES[attr.to_sym] || super
  end
end

Since Rails 2.2, this method is used to support internationalization (i18n). Looking at it, it reminds me of Java’s Resource Bundles and Spring MVC’s error messages. Messages are defined based off a key and there’s a chain of look ups that get applied to resolve an error’s message.

Although, I don’t see myself doing any i18n work in the near-term, it is cool that we have that option now in Rails.

Custom field names in Rails error messages

Checkboxes in Stripes and Spring MVC

When building dynamic web sites with lots of javascript UI components being created on the client, understanding how the web framework you’re using will process the request and what must be done to update fields accordingly is even more important.

Specifically, checkboxes have always been a pain to deal with. The gotcha with checkboxes are if a checkbox isn’t checked, the request doesn’t send the parameter so it requires some additional checks to detect that the user deselected something that was there to update the field accordingly. I’ve been playing around with the Stripes framework and ran into this issue.

With Stripes, you can render a checkbox using their JSP tag:

<stripes:checkbox checked="true" name="property1" value="yes"/>
<stripes:checkbox checked="true" name="property2" value="no"/>

When the “checked” value is equal to “value” value, Stripes will render the checkbox as checked. So with the code shown, two checkboxes will be shown with the first checked and the second unchecked.

If a user reverses this by unchecking the first, checking the second, and submit the form, the HTTP request will only see that property2=no. Before the form was submitted, “property1” had a value of “yes”. Now, “property1” won’t even appear in the request parameters, so we have to do special handling to check for the absent of the parameter to update “property1” to whatever value it should be when it is not checked.

In Spring MVC with form binding, checkboxes are dealt with a little differently. Using Spring MVC’s form JSP tag, you can do:

  <form:checkbox path="property1" value="yes"/>
  <form:checkbox path="property2" value="no"/>

Assuming your command bean is named “person”, this will generate the following HTML:

        <input name="person.property1" type="checkbox" value="yes"/>
        <input type="hidden" value="1" name="_person.property1"/>
        <input name="person.property2" type="checkbox" value="no"/>
        <input type="hidden" value="1" name="_person.property2"/>

As noted by the docs,

What you might not expect to see is the additional hidden field after each checkbox. When a checkbox in an HTML page is not checked, its value will not be sent to the server as part of the HTTP request parameters once the form is submitted, so we need a workaround for this quirk in HTML in order for Spring form data binding to work. The checkbox tag follows the existing Spring convention of including a hidden parameter prefixed by an underscore (“_”) for each checkbox. By doing this, you are effectively telling Spring that “the checkbox was visible in the form and I want my object to which the form data will be bound to reflect the state of the checkbox no matter what”.

Spring MVC also provides a “checkboxes” tag which allows you to render a list of checkbox boxes without having to wrap the “checkbox” tag around a JSTL forEach.

Hopefully, that gives you some insight into how to work with checkboxes in Stripes and Spring MVC.

Checkboxes in Stripes and Spring MVC