Murphy Bytes

April 19, 2012

SATA Drive Unrecognized By Ubuntu Installer

Filed under: Uncategorized — John Murphy @ 9:10 pm

I just picked up a super beefy HP desktop machine that I wanted to use for a development box at home. Of course the first thing that I did when I got it home was to attempt to blow away the pre-installed Windows 7 OS and replace it with Ubuntu 11.10. When I tried to install Ubuntu, the installer wouldn’t detect my SATA drive. It turns out that the drive had raid configuration information that was telling the installer to skip the drive. This is what I did to get around the problem.

  1. I created a live USB with 1 GB of writable space and booted to that.
  2. Open a terminal and become root sudo su
  3. Type fdisk -l to find your SATA device. ( Mine was /dev/sda )
  4. Type dmraid -E -r /dev/sda ( Substitute your device for /dev/sda if required )
  5. Confirm that you want to proceed.
  6. Run the Ubuntu installer.  It should recognize the volume now.

March 30, 2012

Screwing off at work with @net_zer0 and Vert.x

Filed under: Technical — John Murphy @ 7:07 am

Rich and I have been on a sacred quest to find an ESB that’s powerful and versatile enough to meet our needs, yet simple at the same time. I saw vert.x mentioned in a tweet by @headius. So we decided to give it a try. We built an on-line magic eight ball ( largely inspired by @net_zero because he’s all creative like that ). The application was very easy to build. The only odd issues we had were that the Array.sample method didn’t work for some reason so we had to come up with a much clunkier way of randomly selecting the message displayed by the magic eight ball. Looks like the Vert.x project itself is in it’s early stages, broken links, spotty documentation and examples, but I was largely pleased with what I’ve seen so far. I’m planning on evaluating Vert.x ESB capabilities by trying to use it as a microcontainer. I’ll post about that soon.

March 14, 2012

IronMQ and Heroku

Filed under: Uncategorized — John Murphy @ 8:44 pm

I went to Chicago Ruby Hackfest tonight. We experimented with IronMQ and IronWorker. These products are cloud hosted compute grid/message queue products. I was able to build a Heroku app that listened for messages that I sent from a Ruby console in a matter of minutes. Here’s the code for the Heroku listener. Obviously, polling for messages is a pretty crude approach, an event based approach would be better. Unfortunately, if you want some sort of notification based approach you’ll have to roll your own.

August 16, 2011

Consume SOAP Webservices the Easy Way with JAX-WS and JRuby

Filed under: Uncategorized — John Murphy @ 7:42 pm

SOAP has a bad reputation in the Ruby community. Most Rubyists prefer Restful services because they are a lot easier to consume and are well supported in tools like Rails. However, there are times where you have to consume a SOAP based web service. In this article, I’ll show you how you can easily consume a SOAP client using JRuby and JAX-WS. The source code for this exercise can be found here.

First, I’m going to grab the wsdl that defines the service we want to consume. Then I’m going to use the JAX-WS wsimport utility to turn the wsdl into java code. Then I’ll compile the Java code and create a jar that I will then use in my ruby code to interact with the web service.

Requirements

You’ll need to install a couple of things to get started. These include the following:

I’d also suggest RVM but that is optional. If you want to build something based on my example you’ll want to clone my git repository.


> git clone ssh://git@github.com/murphybytes/SampleSoapClient.git
> cd SampleSoapClient
> bundle install

So now you have your environment set up. What next? Let’s think a bit about how we want to structure our project. We are consuming the web service so lets make that a sub project of our main project. We’ll put the web service artifacts in SampleSoapClient/Webservice So we end up with something like this.


SampleSoapClient/lib
SampleSoapClient/spec
SampleSoapClient/script
SampleSoapClient/Webservice/generated
SampleSoapClient/Webservice/test
SampleSoapClient/Webservice/wsdl

I like to include the wsdl files defining the service in my project. With the wsdl files in place I’ll need to write an ant build script that will turn my wsdl into a jar that I can use in my Ruby code. Creating the build.xml is probably the hardest part of the project. Once you create your build script, you can use it as the template for the script to consume any SOAP based web service. Here’s mine.


<project name="OrderHistoryServiceAdapter" basedir="." default="jar">
  <taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport">
    <classpath path="lib/jaxws-tools.jar" />
  </taskdef>
  <target name="clean">
    <delete includeemptydirs="true" failonerror="false" >
      <fileset dir="bin" includes="**/*" />
      <fileset dir="generated" includes="**/*" />
      <fileset dir="dist" />
    </delete>
  </target>

  <target name="compile" depends="clean">
    <wsimport
wsdl="wsdl/OrdersHistoryService.wsdl"
destdir="bin"
sourcedestdir="generated"
xadditionalHeaders="true"
/>
    <javac destdir="bin" >
      <src path="test" />
      <src path="src" />
      <classpath path="lib/junit-4.9b3.jar" />
    </javac>
  </target>

  <target name="jar" depends="compile">
    <mkdir dir="dist" />
    <jar destfile="dist/OrdersHistoryService.jar" basedir="bin" />
  </target>

  <target name="test" depends="jar" >
    <junit printsummary="true" showoutput="true" >
      <classpath>
<pathelement path="dist/OrdersHistoryService.jar" />
<pathelement path="lib/junit-4.9b3.jar" />
      </classpath>
      <formatter type="plain" />
      <test name="com.eris.orderhistory.test.SessionTokenManagerTest" />
    </junit>
  </target>
</project>

Now, using JRuby, we can interact with our web service using pure Ruby code. All we have to do is add the requisite requires and import the classes that we want to use. Here’s an example.


# required to import native java
require 'java'
# the jar that implements our web service
require 'WebServiceClient/dist/OrdersHistoryService.jar'

# import native java classes
java_import com.currenex.webservice.definitions.AuthenticationPortType
java_import com.currenex.webservice.definitions.OrdersHistoryPortType

That’s all there is to it!

April 24, 2011

Rails Development Environment

Filed under: Technical — John Murphy @ 1:51 pm

I’ve experimented with different Rails development environments over the years. I started with an Emacs/shell based environment. Then switched to TextMate because I had a Mac and that seemed to be what all the cool kids were using. Then I switched to Netbeans because of it’s Rails support and the amount of Java development I was doing at the time. (I’m not very smart. I prefer to conserve my limited intellectual resources by sticking to one editor) . Unfortunately Netbeans stopped supporting Rails and Rails 3 so I went back to Emacs and the shell and I’m very happy I did. The advantage of the other tools I mentioned is there is a short learning curve to get up to speed compared to the Emacs based system I use. IMHO the Emacs/shell bashed system is well worth the extra effort involved in getting up to speed. Even if you opt to stick with your GUI based tools it can be very helpful to have a shell based environment in the event you have to do production support on *nix servers that typically don’t have a GUI. I hope that this post will make it easier for you to become productive in a shell based development environment.

I like my current setup for a number of reasons. First, I’ve learned you can save yourself some unpleasant surprises if you develop on the same OS you deploy to. Like most Rails devs, I deploy to Linux so I like to develop on Linux. Unlike TextMate, Emacs runs on Linux, and unlike Netbeans, you don’t require a GUI to run emacs. Note that Emacs runs fine on Windows, Mac, Linux, AIX, Solaris, and BSD. No other development tool I know of save Vi does the same. I find I’m a lot more productive if I can keep my hands on the keyboard and avoid interrupting my work flow by reaching for the mouse. My shell based development environment helps me keep my hands on the keyboard.

OK, so here’s how I set everything up. You’ll need to have GNU Screen, RVM, and of course Emacs installed on your system. Emacs is your code editor of course. RVM is a tool that I use to create a development sandbox with explicit ruby/jruby versions and gemsets, pretty much required if you work on multiple Rails projects. The last thing is GNU Screen. From the GNU Screen page, “Screen is a full-screen window manager that multiplexes a physical terminal between several processes, typically interactive shells.”. I use screen because it lets me easily hot key through several shell screens as I work. For Rails, I like to have the following:

  • A shell running the Rails server
  • A shell where I tail the development log
  • A database console or mongodb shell
  • A command prompt
  • Emacs running in nox mode
  • The Rails console

To get all this set up you’ll need to write some shell script. Note that to my knowledge, the script I provide only works on Linux with Bash. If you are using some other shell or OS you’ll need to adapt the script to use your shell and OS. I add this script at the end of .bashrc. The script will cause a menu to be displayed (See Below) when you open a shell. You can select from your projects which in my example are hireme, naiku, and swap. When you select a project from the menu RVM is invoked setting up the Ruby interpreter and the Gems you’ll be using, the directory is switched to that of the selected project and screen is kicked off setting up the several shell windows according to your preferences. Each project has a file in it’s root directory called screen-startup-commands that is used to control the tools and shells that will be launched. (See Below). When the script is finished you’ll have Screen running several windows with all the stuff you need to develop productively in Rails.

Script


# this goes at the end of .bashrc
[[ -s "$HOME/.rvm/scripts/rvm" ]] &amp;&amp; . "$HOME/.rvm/scripts/rvm"
[ -n "$RAN_ONCE" ] && return
echo "========================================="  
echo " Select Development Environment          "
echo "========================================="
select selection in swap hireme naiku shell; do
  export RAN_ONCE='y'
  case ${selection} in 
    shell ) break ;;
    swap )
      . rvm use ruby-1.9.2@swap
      cd ~/code/swap/ssrails
      screen -c screen-startup-commands
      exit 0
      ;;
    hireme )
      . rvm use ruby-1.8.7@hireme
      cd ~/code/hireme
      screen -c screen-startup-commands
      exit 0
      ;;
    naiku )
     . rvm use ruby-1.9.2@naiku
      cd ~/code/naiku
      screen -c screen-startup-commands
      exit 0
      ;;
  esac
done

Startup Menu

Screen Startup Commands


# screen startup commands
screen -t emacs emacs -nw .
screen -t console rails console
screen -t log tail -f log/development.log
screen -t shell
screen -t server rails server

April 21, 2011

Down to the Metal

Filed under: Uncategorized — John Murphy @ 9:11 pm

I just spent a few days over at Pedal Brain programming (or trying to program) an MSP 430 Micro Controller. Embedded is hard but I think it’s worth trying if you are a coder. It’s kind of the essence of coding. Unlike most of the programming I’ve done, in embedded there is nothing between you and the machine. Typically you don’t have a lot of memory or CPU so you have to be very efficient with resources. I think in the long run the economy you pick up in the embedded realm makes you a better coder in other areas.

December 25, 2010

Kinney/Murphy Annual Holiday Message

Filed under: Uncategorized — John Murphy @ 7:33 pm

It’s Christmas Eve and we’re hanging out at home waiting for Santa. It’s been a busy year for our family. This was our first full year in our new house and Plymouth is now starting to feel like home. We love our neighborhood. Sam has other little boys nearby to play with and Lisa and I love our neighbors. We were able to take a family vacation to Disney World this year and Lisa and I went to NYC in June. We were thinking that our first year in our new house would be our last as my employer, Dow Jones, was asking me to relocate to Princeton, NJ. However, the relocation was canceled and it looks like we’ll be staying in Minneapolis for the time being. It’s going to be a white Christmas, 36 inches of snow already this year. I don’t need to go to the gym, I get all the exercise I need shoveling tons of snow out of the driveway.

Santa Meeting 2010

P1030005.JPG
P1030455-adjust.JPG
photo.JPG
P1030338.JPG

Sam

This has been a big year for Sam. He learned to swim and got a green belt in Karate. Last year, Santa brought Sam an Australian Shepherd puppy named Pete. We all liked Pete so much we got him a little pal, another Aussie pup named Gus. It’s pretty chaotic around our house with two Aussie pups and an energetic six year old running around. Samuel started Chinese Immersion School in Excelsior this year. He loves school and is doing great. We love the school too. We’d heard a lot in the media about how bad public schools are so we were concerned when Sam was ready to start school but Mrs. Tao and the Excelsior school is amazing. We get email status updates on a regular basis and are able to dialog with the teacher whenever it is needed. Sam is learning so much. I observed his class one day last month and the whole class was conducted in Chinese. We don’t want Sam to get behind in his English curricula so we work hard at home to help Sam with reading and arithmetic. Sam says 圣诞节快乐 to everyone.

Audrey

Audrey enjoys posting humiliating pictures of me on Facebook. Luckily for her, I won’t stoop to the same behavior on my blog, it wouldn’t be…. Christmas like. Audrey has had a lot of great opportunities and experiences this year. She recently started a new job at CF Moto where she is moving into marketing. She also shot a PSA commercial in Los Angelos and will be on a TV show that has something to with hair salons. She also has taken to attending Ruby Users of Minnesota (RUM) with me. I don’t know why. Audrey says ‘because it’s awesome’ but I think she likes to walk around in heels and distract the rest of the geeks there.

Hannah

Hannah is living in Ames. She’s been gaining experience as a waitress this year and hoping to find a better job. She and Lisa made a trip to Conifer Colorado to pick up the newest member of our family, Gus the dog.

Lisa

Lisa finally admitted that she likes it here. She has been taking advantage of many of the wonderful shopping and educational opportunities that we enjoy here in the Twin Cities, learning how to make stained glass and currently learning how to knit. Lisa brought her job with Principal with us, and has been working from home. This has provided welcome income for us, but unfortunately Principal is getting out of the health care business and Lisa will be losing her job along with 1500 others. She will be done second quarter 2011. On the bright side, getting a few months severance just as the weather starts to warm up around here could make for a nice summer.

John

It’s been a great year for me. As always, I’m grateful for fabulous Lisa and my new family. It’s never a dull moment around here. Sam keeps me busy and Audrey is always an entertaining companion. I’ve been able to see a lot more of my family this year and it’s great to spend more time with my brothers and sisters. I love you all.

November 10, 2010

Sick of Virii? Get Linux.

Filed under: Uncategorized — John Murphy @ 10:17 am

Recently I’ve noticed a rash of Facebook based attempts to get you to install malware on your system. These strategies masquerade as a message from one of your friends that try to get you to click on a link that will then run a program on your system. Do you want to know a sure fire way to avoid these exploits? Don’t run Windows, use Linux instead. I know some people will think that you have to be some sort of tech guru to use Linux or they may not even know what Linux is. For these folks I’ll say that Linux is easy to use. It has lots of free software that let you create documents, browse the web, and do pretty much anything that you commonly do on your Windows system and, most importantly, it’s immune to pretty much all of the bad things that hackers perpetrate on unsuspecting Windows users. No anti virus software needed! Here are some links for various Linux distributions to find out more:

Feel free to contact me if you have questions.

September 29, 2010

GAE is Better than EC2

Filed under: Uncategorized — John Murphy @ 11:25 am

Recently, my friend Josh got me interested in Google Application Engine. I’ve been building distributed applications for a number of years now and have always assumed that if I were deploying to a cloud platform, it would be on EC2 because of choice of operating systems, and support for environments that I know well like Rails. GAE doesn’t support the same environments (at least not out of the box). It also abstracts the OS away from you almost entirely. That is the reason that I think GAE is better. I like the idea of not dealing with the OS at all. OS is complicated. To do a Unix application right you need to understand shell scripting, daemons and security. I usually like to set up a user with limited privileges for my applications to run under (no login, limited file system access, etc.) I also like to have a group for users who can admin the application and another group for a more limited set of users who can admin the machine. This of course implies that you set up sudoers correctly so an application admin can start the application as root (the app is then demoted to run as a user with limited privileges after it’s gotten access to all resources it needs to run). And of course you need to be cognizant of things you want the application administrators to have access to like read access to /var/logs. Anyway, it’s complicated to get right. GAE abstracts the OS away from you so you don’t have to worry about any of this stuff which is a good thing. You just focus on the application logic and let Google worry about the OS which is a big win in my opinion.

September 24, 2010

λ + concurrency = evil

Filed under: Uncategorized — John Murphy @ 8:52 pm

I ran into an awful bug in some JavaScript the other day that I thought I’d share as one more reason that non-functional programming languages are really awful in concurrent or asynchronous execution environments. Without further ado, here’s the code:


function update_watchlist() {

    var selected_instruments = $('div#instruments').data( 'selected_instruments');

    for( var selected =  0; selected < selected_instruments.length; ++selected ) {
    
        $.post( '/getquote',
            selected_instruments[selected],
            function( quote ) {
                $('div#quote_last' + selected ).html( quote.last );
                $('div#quote_volume' + selected).html( quote.volume );
                $('div#quote_datetime' + selected).html( quote.datetime );
            },
            'json'
            );    
    }
  
}

This code is supposed to use JQuery and ajax to update a watch list of quotes. Data values for each quote are stored in numbered divs where the div number matches the index in selected_instruments which is an array of information needed to look up a particular quote. In other words we update div id=’quote_last0′ with a quote that we look up using information in selected_instruments[0]. Can you spot the problem?

What is the value of selected in the lambda function passed to $.post? We don’t really know because post is an asynchronous call, the lamda function


            function( quote ) {
                $('div#quote_last' + selected ).html( quote.last );
                $('div#quote_volume' + selected).html( quote.volume );
                $('div#quote_datetime' + selected).html( quote.datetime );
            },

is only called after the http post to the remote server returns. By the time this has occurred, selected has passed out of scope. The fix for this problem would have been to make lambda functions in JavaScript more like first class functions so in this case, the only way to pass the index data to the lambda function illustrated above would be to pass it in the post data, and then have the server return it in the argument passed in the lambda function as illustrated below.


function update_watchlist() {

    var selected_instruments = $('div#instruments').data( 'selected_instruments');

    for( var selected =  0; selected < selected_instruments.length; ++selected ) {
    
        $.post( '/getquote',
            {
                // selected is a valid variable here
                instrument : selected_instruments[selected],
                index : selected
            },
            function( result ) {
                // result.index = selected passed to post target and returned
                $('div#quote_last' + result.index ).html( result.quote.last );
                $('div#quote_volume' + result.index).html( result.quote.volume );
                $('div#quote_datetime' + result.index).html( result.quote.datetime );
            },
            'json'
            );    
    }
  
}

Older Posts »

Powered by WordPress