Skip to content

SSH and Amazon Cloud

While trying to login to an Amazon cloud server from my Mac, with the following command:

ssh -i register.pem username@myamazonserver.amazonaws.com

I got this error message:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for 'tmn_register.pem' are too open.
It is recommended that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: tmn_register.pem
Permission denied (publickey).

Apparently, the permissions on the filesystem for the key file that was given to me were too secure.  I changed the permissions to disallow all access except me and all was well.

chmod 600 register.pem

Mac Application Bundle

So, I packaged up my native looking Mac application in my own Application Bundle.  It was super simple to do.

An application bundle is nothing more than a folder that has been renamed with the extension “.app” and conforms to a certain directory structure.  The directory structure looks like this:

/Contents/
/Contents/Info.plist
/Contents/MacOS/
/Contents/Resources/
/Contents/youricon.icns

The important piece is Info.plist.  It tells the system what to call your bundle and where the executable is located.

<plist version="1.0">
<dict>
  <key>CFBundleExecutable</key>
  <string>test.rb</string>
  <key>CFBundleGetInfoString</key>
  <string>Test</string>
  <key>CFBundleIconFile</key>
  <string>test.icns</string>
  <key>CFBundleIdentifier</key>
  <string>test</string>
  <key>CFBundleName</key>
  <string>Test Name</string>
</dict>
</plist>

Your application should go in MacOS.  I put my ruby script in the MacOS directory and it could not longer load my resources that were right next to it in that directory.  If I hard code the path to be an absolute path based on where the app is bundled (/Users/jasonxrowland/myapp.app/Contents/MacOS) it works.  I have a feeling, I need to call a Mac specific API to get the resource bundle path.  I’ll figure that out later…

I created the icon using the Icon Composer application included with the Mac.

JAVA_HOME on MacOSX

edit your ~/.profile (or ~/.bash_profile if you are using that instead) and add the following

export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home

Native Looking Mac App with Ruby

Ruby is really popular to make websites because of Rails, but I want to write a native looking application using Ruby.  I’ve discovered wxruby which is a really cool cross platform GUI library for use with Ruby.  It is built on wxWidgets which is a C++ library for making cross platform GUIs that appear native because they are built on the underlying native libraries of each platform (linux, OSX, and Windows).  Right now, I’m interested in Mac, but I plan on testing this on Windows and Linux too.

Installation

wxWidgets

You have to download the source and compile it yourself for Snow Leopard.  This means, you need to install the developer toolset that comes with your Snow Leopard DVD.  Just install everything, hard drives are cheap.  I don’t know if you have to actually run “./configure”, “make” or not.  My guess is you don’t, but I did.  Snow Leopard has some special challenges and you have to do the following:

$ set arch_flags="-arch x86_64"
$ ./configure CFLAGS="$arch_flags" CXXFLAGS="$arch_flags" CPPFLAGS="$arch_flags" LDFLAGS="$arch_flags" OBJCFLAGS="$arch_flags" OBJCXXFLAGS="$arch_flags"
$ make

DialogBlocks

After you download, Open the DMG image and copy the contents to wherever you want.  I copied mine to /Developer/Applications.  When you run this for the first time, it asks you to select the location of wxWidgets.

wxruby

The latest stable version is 2.0.1.  If you try to install wxruby through gems, it will install 1.9.3.  I don’t know what’s different between the two, but 2.0.1 is a year old so I want to use it.

wx_sugar

$ gem install wx_sugar

Ruby

You should already have a version of Ruby installed.  I list it here because the latest version as I write this is 1.9.2.  Unfortunately, one of the tools we will use to generate ruby classes does not support 1.9.2.  If you really want to use 1.9.2, you can follow the directions here.  I haven’t tried it so I don’t know if it will work or not.  I just switched to mine to the system version “rvm  –default system”

Making a simple app

There is a great tutorial on the wxruby website.  It shows you how all these tools work together to create an application. I created my frame using DialogBlocks.  I created my ruby file using xrcise.  I completed the tutorial.  Now if you forget that wxruby is 32bit only and you just try to run the app, you may see an error like this:

/Library/Ruby/Gems/1.8/gems/wxruby-2.0.1-universal-darwin-9/lib/wxruby2.bundle: dlopen(/Library/Ruby/Gems/1.8/gems/wxruby-2.0.1-universal-darwin-9/lib/wxruby2.bundle, 9): no suitable image found.  Did find: (LoadError)
/Library/Ruby/Gems/1.8/gems/wxruby-2.0.1-universal-darwin-9/lib/wxruby2.bundle: no matching architecture in universal wrapper - /Library/Ruby/Gems/1.8/gems/wxruby-2.0.1-universal-darwin-9/lib/wxruby2.bundle
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /Library/Ruby/Gems/1.8/gems/wxruby-2.0.1-universal-darwin-9/lib/wx.rb:12
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:36:in `require'
from main.rb:3

To run the app, you need to run ruby in 32 bit mode like this:

env arch -i386 ruby -rubygems main.rb

Here is the screen shot of my app running on a mac.

Homebrew

I am currently trying out a new package management system called Homebrew.  I am not really sure how it’s any better than MacPorts yet.  I think the only thing I know is that you aren’t forced to download multiple versions of a package if you don’t need to.

http://mxcl.github.com/homebrew/

Ruby on Rails Plugins

Not sure if this is worth doing or not since these ruby plugins change so frequently, but here are a list of plugins that I find interesting as a java guy coming up to speed in ruby on rails.

Referential Integrity

script/plugin install http://svn.hasmanythrough.com/public/plugins/validates_existence/

From “Learning Rails” by O’Reilly.  Page 149

Scaffolding

ActiveScaffold.com

Geo Coding

http://geokit.rubyforge.org/

Image Processing

attachment_fu

ImageScience

http://seattlerb.rubyforge.org/ImageScience.html

Background Applications on the BlackBerry

Useful articles about background applications on the blackberry.

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/796557/800738/800901/How_To_-_Setup_an_alternate_entry_point_for_my_application.html?nodeid=800820

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800639/How_to_-_Make_a_running_UI_application_go_to_the_background_and_resume_in_the_foreground.html?nodeid=800545&vernum=0

http://docs.blackberry.com/en/developers/deliverables/6625/Dimensions_for_screens_images_and_icons_476251_11.jsp

http://rim.lithium.com/rim/board/message?board.id=java_dev&message.id=2519

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=392

Blackberry JME has very limited threads

I had written a CRON scheduler for the blackberry for one of my clients.  This CRON scheduler was failing seemingly randomly where the thread that checks the schedules would just die.  In order to make sure a task is launched exactly when it should, I would spin off a thread and execute that code.  You can see where this is going right?  It worked just fine under my development tests.  When it went to QA, it would fail.  After tracing it down, it was failing on the line:

thread.start();

After finding the exact line of code where it was crashing, I surrounded this line of code with a try/catch on Throwable with this code:

System.out.println(“Error: ” + exc.getClass().toString() + ” = ” + exc.getMessage());

The output from this was:

Error: class net.rim.vm.TooManyThreadsError = null

Which of course led me to my problem.  Now there is no mention of a limitation in the Blackberry documentation telling me how many threads I can have.  In hind sight, I should have know given that even in desktop apps you should use threads sparingly.  These threads I created were supposed to be very short lived.  They spin up, do their action and then go away.  In my testing that’s exactly what was happening but I wasn’t stressing the system with lots of tasks.  Consequently under real-world use, trying to start that last thread was killing the thread that created it.

I can’t simply use the ThreadPool class provided in java.util.concurrent because that is not available in J2ME/JME.  I just created my own based on an article written by IBM about Thread pools and work queues.  I had to use Vector instead of a linked list (didn’t feel like writing my own but I should because removing an element from a vector is expensive and I have to do it every time I pop an element out).  Worked like a champ!

iPhone web caching sqlite3

If you are using the iPhone simulator to test your web application, you can query sqlite3 cache tables by going to the following directory:

~/Library/Application Support/iPhone Simulator/User/Library/Caches/com.apple.WebAppCache

Command to open the cache database:

sqlite3 ApplicationCache.db

Once inside, you can use the following command to view the tables:

sqlite> .tables

This is very helpful in troubleshooting caching issues.

UPDATE: Windows Mobile 6 Smart Phone Signed Cab displaying “Program is from an unknown publisher”

Previously, I wrote about signing cab files for Windows Mobile 6.  The application was initially created for Windows Mobile 5 Pocket PC devices.  We got it working on Windows Mobile 6 Pocket PC.

Recently, I was tasked with creating an installer application to get around some of the browser inconsistencies they’ve been experiencing with the various Smart Phones.  They have an installer app that has an executable and an XML file that the executable reads for it’s configuration.  Pocket PC allows you to download the XML file and the executable file and everything just worked.  The Smart Phones do not behave this way.  I created an app that downloads both the EXE and the XML file to the My Documents directory and launches the EXE.  Works great.

My problems started when I tried to cab up the whole thing and install it from a mobile device.  I signed each file inside the cab as well as the cab itself.  I kept getting prompted by the device asking me if I want to trust this unknown publisher?  At first, I thought maybe I had screwed up the signing.  Turns out that no, I did sign it correctly… for windows clients.  The Windows Mobile platform uses a different technology than Authenticode.

On this MSDN article about how to Sign your Windows Mobile Application, it states very clearly: ”Authenticode signatures for other Windows platforms, such as Windows Client or Windows Server, use a different technology than Windows Mobile code signing and are not recognized as valid normal or privileged mode signatures.”  What I don’t yet understand is that it states Windows Mobile (not Smart Phone) uses a different technology, yet we used Authenticode to make the prompts go away for the Pocket PCs we were testing on (Windows Mobile 5 and 6).

The Windows Mobile code signing seems very expensive.  From what I can tell it costs $350 for 10 signings.  There is an additional fee for each signing after that.  What this means is that you better be darn sure your application is finished before signing your application.  I’ve read that you have to submit your signed cab to Verisign who then signs your cab file with their certificate.  I am beginning to hate the Windows Mobile platform and might actively root for their demise…