Ubuntu 12.04, RubyMine, Java Problem and the Fix

Ubuntu 12.04 was released, before upgrading any computers, I always test it out in a virtual machine to ensure my critical development tools work as expected. With Ubuntu 12.04, I found that I could not get the Java6 JDK installed or working. This is required for running RubyMine, my tool of choice.

The previous approaches do not work.

The solution is thankfully easy.

Solution

Following the links on the last-best working approach, there is a link to the Flexion.org blog. The post “Install Sun Java 6 JRE and JDK from .deb packages” explains why it is broken (Canonical disabled it for violating Oracle’s license) and explains his clever workaround solution.

Run this Script

This following script pulls code from the Github project “oab-java6” to locally create .deb packages and a local package repository. After running the script, you can use apt-get or synaptic to install “sun-java6-jdk”.

cd ~/
wget https://raw.github.com/flexiondotorg/oab-java6/master/oab-java6.sh -O oab-java6.sh
chmod +x oab-java6.sh
sudo ./oab-java6.sh

Kudos to Flexion.org for the good work and nice solution.

2 Quick Tips for Git and Ruby Developers

2 Tips for Developers On-the-Go

Here are a couple tips that are easy to setup and can be very helpful for developers who are on-the-go but don’t want to hit a wall when there’s no Internet for a period of time.

Git – browse local repository

Git comes with a built-in web application for browsing, searching, viewing, diff'ing, etc. your local git repository. It is a read-only application.

By default, it wants to use the ‘lighttpd’ package. It is a Light-weight HTTP Daemon for *nix systems.

Then, using a command-line, go into your project folder and enter the following command:

git instaweb

A browser window opens and you can explore, search, diff, etc. your local git repository through a web interface. Slick!

Rubygems Local Server

Rubygems comes with a light-weight web server you can use to browse your installed gems locally.

This is most helpful when you are expecting to be somewhere where you won’t have Internet access. Great for traveling (plane, train, bus, car trip, …), attending a conference with overloaded WIFI, etc.

With a little preparation, it will be ready to go when needed.

The command is:

gem server

It runs a server on http://localhost:8808 (it tells you that too). It shows the gems, a link to the gem’s website, the dependencies, etc. If you have ‘rdoc’ installed and have generated the documentation for your gems, then the [rdoc] link will work. Otherwise not. Running “gem sever” isn’t really helpful without the gem documentation, so you can do that on a individual gems like this:

gem rdoc activerecord

Or for all gems like this: (NOTE: It will take some time and more disk space). Assuming you are using RVM gemsets, it is easier to keep the list of gems to build docs for small and more applicable.

gem rdoc --all

Show SQL in IRB/Console for ActiveRecord

This is here mostly as a reference for myself. Hopefully others can find it useful.

At times I want to see the SQL query being used for an ActiveRecord operation while I’m playing on the command line.

In IRB or Rails Console after loading the classes and the Rails environment, run this command…

Rails 2.3.x

ActiveRecord::Base.connection.instance_variable_set :@logger, Logger.new(STDOUT)

Rails 3.x

ActiveRecord::Base.logger = Logger.new STDOUT

Subsequent operations will log the generated SQL.

Example

This shows an example query using scopes that runs and shows the query output.

Customer.active.count
#> Customer Columns (1.0ms)   SHOW FIELDS FROM `customers`
#> SQL (0.1ms)   SELECT count(*) AS count_all FROM `customers` WHERE (`customers`.`active`=1) 
#> => 30015

jQuery Solution to "Your changes will be lost" Prompt

Looking for a General Solution

I recently had the need to give the familiar “Your changes will be lost” prompt before a user navigates away from a page with changed data. There’s plenty of examples around of using the javascript onbeforeunload event to stop and prompt the user. I found a nice minimalist solution.

var msg = "If you proceed, your changes will be lost";
$('body').delegate("form.confirm_discard input", "change", function() { window.onbeforeunload = function() { return msg; }; });
$('body').delegate("form.confirm_discard", "submit", function() { window.onbeforeunload = null; });

I based my solution on it but adapted it for my project’s needs.

Requirements

  • Should not destroy other “onbeforeunload” event handlers. There are valid cases for other handlers to clean-up resources without prompting that I didn’t want to interfere with.
  • Needs to work with multiple forms per page. I use AJAX fetched forms displayed in jQuery UI dialogs. So one page may have a number of forms on it at a given time.
  • Needs to detect changes to inputs, selects, and textareas.

Javascript

Here’s gist of the javascript needed.

Formtastic Form

I really like Formtastic forms. This is how to enable the behavior for a Formtastic form. All that is required is adding the class ‘confirm_discard’ to the form.

<% semantic_form_for @customer, :html => {:class => 'confirm_discard'} do |form| %>

<% end %>

jQuery Dialog

The following javascript is used when a jQuery UI Dialog is closed. This happens when the user hits “ESC” on the keyboard or the “Cancel” button. It removes the dirty flag on the form and resets the form to its original state.

// Register the dialog
$('.popup-dialog').dialog({
    close: function(){
        var form = $(this).find('form:first');
        if (form.length == 1) {
            // Remove any flags that the form was changed
            if (form.hasClass('confirm_discard')){
              form.data('data-changed', false);
            }
            // Reset the form inputs
            form[0].reset();
        }
    }
});

Feedback

This solution works well for me. Let me know if it helps and share any improvements you make.

Ubuntu Natty, Rubymine, Run Rake Task problem

Today I upgraded my desktop machine to Ubuntu 11.04 (Natty Narwhal). Getting back up and running as a productive developer wasn't too bad. I didn't just upgrade, I did a clean install with my /home folder backed up to another drive.

I got Rubymine up and running quickly. All my gems were still there thanks to RVM. When I got back into coding, I discovered that something was stealing the Rubymine shortcut of CTRL+ALT+R that I use with reflex-like habbit for running rake tasks. I couldn't figure out what was stealing it either. It was driving me insane!

After spending far too long on it, I found the culprit. The Compiz setting for Window Management > Grid functionality. It's a compiz plugin I don't even use. I just don't personally find any value in it. Regardless, it maps the CTRL+ALT+R to restore a window's original size once the Grid settings were applied to it.

I really wish Compiz settings had a way to see what keybindings are being caught and an easier way to change it.

The fix for me was to turn off the Compiz Grid plugin. I could have remapped the keybinding in Rubymine or Compiz if I cared enough for the feature.

Install the "compizconfig-settings-manager" package if you don't already have it. It gives easy access to changing the settings. Once installed, it is System > Preferences > CompizConfig Settings Manager.

Moved to Posterous from Tumblr

I have moved my blog to brainlid.posterous.com from Tumblr.

If anyone cares, here are the reasons:

  1. Posterous has HTTPS signup/login. With the high-profile Firefox plugin firesheep which makes it dead simple to grab passwords out of the air, it is amazing that Tumblr still doesn't support it. I contacted Tumblr support by email when I signed up asking about HTTPS/SSL. They responded with "we'll pass that along".
  2. Syntax highlighting for code snippets is really a pain on Tumblr. While not 100% ideal on Posterous, it is far ahead. Posterous supports code posts via Github gists and through posts formatted using markdown.
  3. I want people to be able to comment on my posts. Tumblr can't. Posterous can.
  4. I want to add graphics to an article. With Tumblr you can't. Any images added to an article must be already hosted elsewhere. I can't upload an image and include it in an article. I even tried posting the image as a Tumblr "Photo" post and then linking to that image. That works only for a limited time because an allowed duration for the link is embedded in the URL and it won't load without it. I noticed other Tumblr users had custom images on a Tumblr post and, low and behold, the image was hosted on Posterous and then linked it to Tumblr!
  5. Tumblr has an Android app to make creating new posts easier. But without SSL/HTTPS, I don't ever dare even open the app when I'm out of the house. Then what's the point of it really?
  6. Posterous has a nifty migration tool to pull in my Tumblr posts. It did a pretty good job of it too.

 

Tropo, Ruby on Rails, and WebAPI Explained

I’m using Tropo for a fun and cool project. Tropo, in their own words, is:

a powerful yet simple API that adds Voice, SMS, Twitter, and IM support to the programming languages you already know.

I want to use Tropo for sending out SMS messages and occasionally responding to them as well. There is a huge amount of documentation and examples. [1] [2] In my case, it seemed too much. I didn’t have a mentor to clear up those early questions and share the basic concepts that can all be done in about 2 minutes. So instead I trudged into it alone and got very, very frustrated.

This is an effort to explain it all very clearly so that, perhaps, some poor lost soul like me can save many hours of frustration.

Concepts Required for Tropo’s WebAPI

First, understand is the difference between a “Tropo Scripting” project and a “Tropo WebAPI” project. I got confused by Rails project examples that I thought of as WebAPI projects but were instead Scripting projects. Lets jump in.

Read the rest of this post »

Review: Linphone as Skype Alternative?

I previously wrote about looking for Skype replacements. Now I’m going to give a brief review of Linphone from the perspective of a potential Skype replacement on Linux.

Linphone is open source, is true peer-to-peer, and has a nice list of supported clients. It runs on Linux, Windows, MacOSX, and for mobile phones: Android, iPhone, Blackberry. NOTE: The Mac version does not support video yet.

One limitation with this (and other software solutions) is the lack of a centralized source for finding people you aren’t already setup with. This makes the Skype equivalent of “my Skype account is butterflyboy123” harder. This affects broader adoption by people like my Mom. Regardless of how bad she wants to see a grand-baby.

I tested version 3.3.2 which is in the Ubuntu 10.10 repositories.

Critical Missing Features:

  • No screen sharing
  • No conference calling

Other Missing Features (not critical):

  • No IM (plenty of other options available for chat, but integrated is easier).
  • Contact linking is separate and harder.

Good Features (on Linux):

  • Uses a free SIP account
  • Video chat worked well

My “Skype Score”: (0-10)

I give it a 6. The video quality (tested over an internal network) was great. Better than Skype for me. The inability to screen share, IM or conference call (with or without video) is a serious limitation for me.

I really like the multi-device aspect. If ease-of-use can be improved for non-technical people (like Mom), then it will be a better option.

I intend to check in on it again in the future.

For now, I guess I’ll keep looking…

Review: Blink as Skype Alternative?

I previously wrote about looking for Skype replacements. Now I’m going to give a brief review of Blink from the perspective of a potential Skype replacement on Linux.

Blink is open source and has an impressive feature list …if you’re on a Mac. The right-side of the feature list is the “Blink Qt” side. They are using the Qt framework to provide the Windows and Linux version. Qt also works on MacOS X, but they are using Cocoa (Mac specific).

Critical Missing Features:

  • No video chat
  • Desktop sharing (via VNC-like protocol) is only on Mac (not Windows or Linux).

Other Missing Features (not critical):

  • Chat not implemented on Linux (plenty of other options available for chat, but integrated is easier).
  • No mobile client support

Good Features (on Linux):

  • Uses a free SIP account
  • Supports conference calls
  • Integration with Google Contacts
  • Can easily record a call

My “Skype Score”: (0-10)

I give it a 4. The audio quality was good and the conference feature seemed nice. It is usable and friendly enough. As the Qt feature side fills in, it will certainly become more appealing to Linux users. Until video is supported, I fear it won’t be a good Skype option.

Maybe it does what it was designed to do, and I’m trying to use it for something it wasn’t intended. I intend to check in on it again in the future.

For now, I guess I’ll keep looking…

Skype now in Microsoft, I want alternatives...

I use Skype for both professional and personal communication. It is now common knowledge that Microsoft purchased Skype for $8.5 Billion in an all-cash purchase.

I now use Linux full-time for desktop (Ubuntu), phone (Android) and web servers. I’ve abandoned the Microsoft “tooling” story and their developer and platform lock-in.

I’m now very concerned about the future of Skype and the future of video conferencing tools for Linux.

Microsoft’s Bad Track Record

Having been burned by Microsoft many times before, I have a deep mistrust of the company and its management. I don’t want to see Skype go the way of Connectix VirtualPC. Around 2004, Microsoft bought Connectix VirtualPC, software for virtualizing PC hardware, letting you run additional operating systems at the same time as the main operating system is running. At the time, Connectix had a Linux version of the software that allowed Linux users to run Microsoft Windows in a virtual machine. After being purchased, Microsoft ended the Linux hosting abilities.

Read the rest of this post »