Murphy Bytes

December 22, 2012

Santa Detector

Filed under: Technical — John Murphy @ 12:52 pm

Sam doubts that Santa Claus exists so we thought we’d build a motion detector that would alert us if he actually shows up. The parts required for this first pass at a Santa Detector are an Adafruit PIR Sensor, an Arduino UNO microcontroller, and an LED.

The first thing we need to do is to wire up the motion detector. The Adafruit PIR sensor doesn’t come with jumpers so the first thing I did was to solder three jumpers to the sensor. I then connected the 5V and ground jumpers to the corresponding pin on the Arduino board and the out jumper to digital pin 2. I need some feedback to indicate when the motion detector is triggered so I attach an LED to the Arduino board attaching the anode (long wire) to digital pin 13 and the short wire to the adjacent ground pin. Now that we’ve wired everything together we’ll need to write a sketch for the microcontroller to make it all work.

For this next step you’ll need to fire up your Arduino IDE and enter the following sketch. Compile the sketch and upload it to the Arduino. If you did everything correctly the PIR sensor should detect movement in the immediate vicinity. When this happens the LED that we attached to the Arduino board will come on for a few seconds. Of course we need something more dramatic than a flashing LED to wake us up in the middle of the night when Santa shows up so in my next post I’ll describe how to play a WAV file when motion is detected.

September 22, 2012

Bird Feeders and Morning Coffee

Filed under: Uncategorized — John Murphy @ 9:07 am

I was up working until about 12:30 AM. It’s cold and cloudy this morning. Sam is asleep and I’m having a quiet cup of coffee and watching birds on my feeders. It just occurred to me that it has been so dry they probably aren’t able to find a lot of the seeds that they normally eat. That’s probably why my feeders have been so busy this year. As I write to you I have two flickers, blue jays, chickadees, a cardinal and assorted house finches swirling around. The flickers are not frequent visitors. I think they like the peanuts. Oh and there is the squirrel named
‘Squirrely’ by Sam. We, and by we I mean me, raised Squirrely after his mother got squashed in the road. I raised a couple of squirrels when I was a kid and I thought it would be good to help connect Sam a bit more with nature so I succumbed to his begging and promises to take care of the baby squirrel and let him keep it. Sam was interested in the squirrel for about two hours and I ended up feeding Squirrely 5 or 6 times a day with warm puppy formula until he was weened. Then I moved his cage outside and nailed it up in a tree and made sure he had food for a while. Now he lives in our back yard. He’ll still take peanuts from my hand with a bit a patience.

June 28, 2012

ETags for Ruby in Emacs (On a Mac)

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

Some developers cling to their bloated IDE’s because they erroneously believe thats the only way to get extended code navigation. Wrong. It’s easy to do the same thing in Emacs. All you need is ctags. Here’s how to set it up for a Ruby project on a Mac. This example will run ctags automatically when you navigate to your project if you are using RVM. First install exuberant ctags


brew install ctags-exuberant

Then add the following to your project .rvmrc

ctags -e -a -R --languages=Ruby .

Now, M-. will jump to definitions of symbols in your code.

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.

Older Posts »

Powered by WordPress