Monday, December 12, 2011

Ah The Holidays, The Perfect Time For Gingerbread

I just got the update for gingerbread.  Wow, only a year late.  But here's a nice list of features that I'm excited about:

User features
  1. New on-screen keyboard. The standard keyboard has been greatly improved in Android 2.3, with faster input and more intuitive typing. Even cut-and-paste got a makeover.
  2. Streamlined user interface. New color schemes and various UI changes and polish make Android more consistent and simpler to use.
  3. Application and power management. Android 2.3 provides better insight into what is running in the background, how much memory and CPU time it is using, and even lets you kill misbehaving apps. Yes, after months of telling us we don’t need a task killer, they give us a task killer. Enjoy your chuckle, iPhone fans.
  4. SIP Internet calling. Voice over IP is integrated directly into Android 2.3. Unfortunately you’ll have to get a SIP account from a third party, and the ability might be curtailed on some carriers.
  5. Download management. All your downloads from your browser, email, and other apps, can now be viewed and controlled from one place.
Developer features
  1. Native development. The ability to write Android programs or parts of programs isn’t new but in Android 2.3 it gets a huge boost with Release 5 of the Native Development Kit (NDK). For example you can now receive input and sensor events, produce sound, manipulate 3D graphics contexts, access assets and storage, and more all from native code. They even added a NativeActivity class that lets you write your lifecycle callbacks in native code.
  2. JVM speed. For Java developers, 2.3 adds a number of speedups, most notably a concurrent garbage collector. According to Google garbage collection pauses will be under 3ms, which is small enough not to be noticed in a 30fps or even 60fps game. New JIT optimizations make Dalvik code run even faster than before.
  3. Faster event distribution. In previous versions of Android, just holding your finger down on the screen would cause whatever program was running to slow down, sometimes dramatically. This is all fixed in Android 2.3.
  4. Multimedia. Rich audio effects like reverb and headphone virtualization can be applied to local tracks or globally across multiple tracks. The platform adds built-in support for VP8/WebM video, plus AAC and AMR wideband encoding. Also, there are now official APIs for accessing the front and rear cameras. There is some limited support for extra large (tablet and TV) displays.
  5. Near Field Communications (NFC). In Japan, NFC is a Big Deal, and the hope is that it will catch on in the rest of the world too. It has all kinds of uses, for example with the right hardware and software you could use your phone as a replacement for your credit card to make point of sale purchases. Using the NFC API apps can respond to NFC tags embedded in stockers, posters, and even other devices.

Being able to use the updated api and the JIT optimizations are the parts that excite me most.  Woot woot!

Friday, November 18, 2011

New Old iPhone 4G

I recently got a new iPhone 4.  Ok, it was my girlfriends iPhone to be exact, so it's not really new.  But heres the problem I ran into.  I had previously used my MacBook Pro to sync and backup her phone.  Now that it was mine, I wanted to back it up fresh.  So I wiped out the iPhone using the restore, but everytime I plugged it into the computer, it would automatically start syncing and restoring all of her apps!  Frustrating.

But alas, there was a solution.  I had to create a new library for iTunes to use separate from my girlfriends.  On the Mac all I had to do was hold down the "option" key when I opened up iTunes and this allowed me to pick the directory that I wanted iTunes to use for its library.  I created a new directory called "Jon's iTunes" and simply selected that.  All of her stuff is not in the library so now its as if my girlfriend never even had the phone.  Excellent!

Thursday, October 6, 2011

Cygwin and Rxvt

More of a reference to myself, this is the rxvt script I use:

@echo off
chdir C:\cygwin\bin
set EDITOR=vi
set VISUAL=vi
set CYGWIN=codepage:oem tty binmode title
rxvt -sl 1500 -fn "Lucida Console-12" -bg black -fg white -sr -e bash --login -i

This is my keychain:

/usr/bin/keychain ~/.ssh/id_rsa
. ~/.keychain/${username}

Saturday, September 17, 2011

Upgrading Xcode

I had previously installed Xcode 3.x on my machine from the included disks I got with my Macbook Pro.  However, wanting to upgrade to Xcode 4 required me to use the AppStore, which installs Xcode in a different place.  Uninstalling Xcode 3.x was a snap, and here's how I did it (Remember not to be in /Developer/Library when invoking the command):

sudo /Developer/Library/uninstall-devtools --mode=all
And my output:
Use of uninitialized value $pkgutil_volume_basename in concatenation (.) or string at /Developer/Library/uninstall-developer-folder line 35. Start time: Sat Sep 17 10:22:35 EDT 2011 Analyzing devtools package: ''... Analyzing devtools package: ''... Analyzing devtools package: ''... Analyzing devtools package: ''... Analyzing devtools package: ''... Analyzing devtools package: ''... Analyzing devtools package: ''... Analyzing devtools package: ''... Analyzing devtools package: ''... Analyzing devtools package: ''... Analyzing devtools package: ''... Analyzing devtools package: ''... Analyzing devtools package: ''... Analyzing devtools package: ''... Analyzing devtools package: ''... Analyzing devtools package: ''... Analyzing devtools package: ''... Analyzing devtools package: ''... Removing devtools files... Removing generated files... Removing Xcode Caches... find: /var/folders/pb/__7g8h0s0y5d87rh096hfd400000gn/C/ No such file or directory Removing Xcode Documentation... Removing empty devtools directories... Finish time: Sat Sep 17 10:25:28 EDT 2011 IMPORTANT: If you are going to install a previous version of the Developer Tools, be sure to restart the machine after installing.
Not sure what that error is at the top, but didn't seem like it affected anything.  After that, I just removed /Developer since I'll be installing Xcode into /Applications anyways.

Wednesday, August 31, 2011

Easy SSH and Cygwin

SSH-ing into a remote machine (that's running an SSH server) is super easy, but can be a major pain having to input the password over and over.  This is especially true on a Windows machine.  You can use putty, but I prefer using Cygwin because I get all my favorite linux utilities :)  Here's how to make all that work:

  1. Download and install cygwin with the openssh and the keychain package
  2. Run cygwin
  3. Enter in the terminal:
    1. ssh-keygen -t rsa
    2. choose some password, and enter it again to confirm
  4. vi ~/.bashrc and put this at the button of the file:
keychain ~/.ssh/
source ~/.keychain/${HOSTNAME}-sh

To get be able to log in to the remote machine, simply append the contents of your local ~/.ssh/ to ~/.ssh/authorized_keys on the remote machine (create the file on the remote machine if it does not exist). *If the authorized_keys file doesn't exist, create it and make sure that the permission is at least 700!

If you typically ssh using another user, or want to setup an alias to be able to quickly ssh somewhere, you can configure ssh to do this.  Simply vi ~/.ssh/config (create the file if it doesn't exist) and model your entries after the following:

Host server
  User admin

Now to be able to ssh into as the admin user, simply type in:
ssh server
whereas before you had to type in

Friday, August 26, 2011

Run Jetty Externally and Connect Remotely With Eclipse

There's another alternative to embedding Jetty inside Eclipse.  We can also use Eclipse to use Maven to start Jetty for us.  Then we can remotely connect and debug/manage it.  It's your choice as to which option you prefer.

Configure Maven to run Jetty

<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                  <!-- Use whatever you want the http port to be -->
<userRealm implementation="">
          <!-- If you plan on changing this file during execution, turn the scan interval higher than 0 -->

You will need a file and a webdefault.xml file.
user1: pass1,role1
user2: pass2,role2

Mine looks like the "JSP configuration" section

Setup Start Server Command
  1. Run -> External Tools -> External Tools Configuration 
  2. Right Click Program -> New
    1. Name: Whatever
    2. Location: Browse to your mvn executable
    3. Working Directory: click Browse Workspace button and select ${YOUR_WEB_PROJECT}
    4. Arguments: jetty:run
  3. Click Environment
    1. Click New
    2. Enter a variable names MAVEN_OPTS and set it to "-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"

Setup Remote Debugging
  1. Run -> Debug Configurations
  2. Right Click Remote Java Application -> New
    1. Name: Whatever
    2. Project: ${YOUR_WEB_PROJECT}
    3. Connection Type: Standard (Socket Attach)
    4. Host: localhost
    5. Port: 8787
  3. Also click "Allow termination of remote VM".  It's going to be the only way to elegantly kill your Jetty server without opening the task manager.

  1. Start the server using the external tools 
  2. Start the remote debugging once the server is up
  3. Open up the debug perspective -> Right click the VM and click terminate to kill the server

Setting up Jetty to run inside of Eclipse

Jetty is a great lightweight server that I'm using to do both my frontend and backend development.  For the focus of this tutorial, we will have a frontend slant.  This tutorial in particular will cover how to setup Eclipse (Helios) to deploy my webapp to Jetty so that I can quickly see my UI tweaks and changes.

Install Jetty
  1. Help -> Install New Software
  2. Work with:
  3. Click Add
  4. Install Jetty and restart Eclipse

Prepare Your Web Project
  2. mvn eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true
  3. Import your project into eclipse as an existing project
  4. Right click your web project and go to Project Facets
  5. Click Dynamic Web Module
  6. Select Deployment Assembly
  7. Make sure your Deploy Path: / is the directory one above where WEB-INF lives.
    1. If not, go to Add... -> Folder and select WEB-INF's parent folder (It'll be something like webapp, or WebContent).
  8. Now click Add.. -> Java Build Path Entries
  9. Select them all using shift for multiselect and click ok

Prepare Jetty and Eclipse
  1. Click Window -> Show view -> Servers
  2. Right click the servers view -> New -> Server
  3. Select Jetty 8 or whatever you fancy
    1. Server's host name: localhost
    2. Server's name: Whatever you want
    3. Server runtime environment: click the add button on the right
      1. Name: Whatever
      2. Jetty installation directory: click the Download and Install button to the right -> Accept agreement -> select a location to download
      3. This is important....Wait a bit for the download to complete (look at the eclipse progress in the lower right and wait for it to complete.  
      4. When done, set the Jetty installation directory to the directory you just downloaded and installed jetty to
    4. JRE: Don't let this fool you, configure it to point to a jdk, not a jre.  
      1. If you don't have one, dl it and configure it using the Installed JREs... button
  4. Click Next
  5. Select your ${YOUR_WEB_PROJECT} to add as a deployment
  6. Click Finish

Setup Realms for Login
  1. Open up etc/ and add in your favorite user and passwords (USER1: password,role1,role2)
  2. Save and close
    1. If you edit this file later to add more users, remember to clean and publish for the changes to be picked up.  You do this by right clicking the server in the servers view and selecting clean.  After its finished, right click it again and select republish/publish.

Setup Ports
  1. Double click the server you just created to open up its configuration
  2. Select the Overview tab
  3. Look for the Ports section
  4. Click HTTP and change to whatever port you want

Right Click the server in the Servers view to manage the server.  You'll be able to start, stop, restart, and debug from here.

And thats's pretty much it.  Super easy and straightforward.

Thursday, August 18, 2011

No Time for SQL Date

We have a stored proc (ugh) that is called from within Hibernate.  We pass in values to this stored proc using the type, java.sql.Date.  The stored proc then does comparisons against some date column against the date object we passed in, but we were noticing that the time portion was being ignored!  The answer was simple and frustrating, java.sql.Date ignores time (should have read the javadocs sooner) :( We had to instead use java.sql.Time.  I would have much rather preferred we NOT use stored procs.  A few quick benchmarks and noticed that the stored proc to get a count versus a Hibernate projection was on average four times slower.  What can you do when the client loves stored procs?

Tee Off!

I love the tee command.  It's simple and beautiful and allows you to echo your output to both the console and to a file.

./ | tee run.out

Here, my output will be nicely shown on the screen for me, but if the contents exceed my console's buffer, have no fear!  The output is also echoed to run.out.  Yay!

Java Integration Tests

You have unit tests and integration tests, but how do you manage the two?  Can you easily partion them so that you only run unit tests at one time and integration tests at another?  Then have them both run before building your artifact?  Yea, maven makes it real easy.  You might already know about the surefire plugin, the plugin used to run unit tests.  It looks for classes ending or starting with Test (**/Test*.java, **/*, and **/* and runs them in the "test" phase.  But there is another plugin, failsafe, which is used to run integration tests and is run during the "integration-test" phase.  The failsafe plugin looks for classes ending or starting with IT (**/IT*.java, **/*, and **/* and runs those.

The failsafe plugin has four phases that it uses:
  1. pre-integration-test - the setup phase.  use it to start a webserver or configure data in a database.
  2. integration-test - runs the tests.
  3. post-integration-test - the teardown phase.  use it to stop your webserver or clean your database.
  4. verify - used to help intepret results of the tests.  if any tests failed, the build will exit.



Another approach that I have done on previous projects is to leave all my unit tests in their appropriate projects and package all of my integration tests into a separate project that I run every few hours everyday in an integration test environment.

Wednesday, August 17, 2011

Spring and JBoss Integration

Oh Spring and JBoss, can't you two just play nice? What is this "" nonsense? Well turns out that JBoss attempts to standardize all of its resource access, regardless of where the actual resource is located, be it a jar or some directory. This is accomplished by abstracting away this access using a VFS, or Virtual File System.
This is where Spring and JBoss collide. When Spring performs its resource scanning, it assumes direct access from either a jar or directory, and consequently uses corresponding URLs, which clashes with VFS. JBoss has a fix for this however and replaces Spring's ClassPathXmlApplicationContext with its own VFSClassPathXmlApplicationContext.

All you have to do is include the snowdrop-vfs.jar and one or both of the following:

If you load spring using the ContextLoaderListener say for services, then you would do the following:


If you also have a servlet for web requests, then you would do the following:


*JBoss EAP 5.1
*Spring 2.2
* (version 1.0)