Monday, September 29, 2014

jargrep Bash Script

When I work with Java it can be handy to grep for a string in a JAR, so I have created an executable script called "jargrep".

# Greps a jar file for a string.

if [ $1 ] ; then
  find . -name "*.jar" -a -exec bash -c "jar tvf {} | grep $1" \; -print
  echo "Usage: jargrep [string]"
  echo "  Example: jargrep \"string to grep for\""

Create a text file called jargrep, copy the contents above, then run "chmod +x jargrep" to make it executable.

Friday, September 26, 2014

Bash Security Hole

There is a pretty serious bug in bash that you can read about in more detail in this article: In short, you are currently vulnerable and can test it by running this:

env x='() { :;}; echo vulnerable' bash -c "echo you are vulnerable"

If you see:

you are vulnerable

Then you are vulnerable. I tried it on all of my systems including OS X Mavericks and Ubundu!

Thursday, September 25, 2014

Underwater Camera

Recently we took a vacation/work trip to Hawaii. How could that be work you ask. The Missus needed to get photos of things that can only be found in a tropical place like Hawaii. Shucks! Turns out Hawaii was less expensive than other tropical places so that's good on the bottom line. But we also needed an underwater camera. Housings for an SLR while awesome are expensive and overkill so we picked up a point and shoot underwater camera and I am super happy with it.

The choices were between the Panasonic TS4 and the Nikon AW110. At the time of writing this the Panasonic was $150 more than the Nikon so we went with the Nikon. I've used the Panasonic TS3 before and it's great but the Nikon holds its own at a much lower price. However, as of writing this they are virtually the same price on Amazon since it appears the price of the Panasonic TS5 has come way down in price from it's predecessor.

One really huge advantage to these cameras is there is no protruding lens. On a normal point and shoot when it is turned on a little motor will push the lens out. If you bump it every so lightly it will break off. I've had this happen more times than I can count. Be more careful you say. Well, that's true, but it's happened by accident every single time and with this camera you don't have to worry about it. All optical zoom is internal so no external moving parts!

In good light the pictures are very good. An SLR will always outperform it but in good light it's real close. Convenience is key. In dark rooms it leaves much to be desired but that's the same with any point and shoot. The speed at which the shutter release is pressed and the picture is taken is also very impressive and surpasses many regular point and shoots in the same price range or even the Canon G series. I had a Canon G but I sold it because I preferred the Nikon AW110.

My only complaint is the battery life. Buy a second battery.

Also when going in a pool with chlorine or in the ocean with salt water, before opening the doors to the camera to replace the SD card or the battery, fill a small bowl with fresh clean water and soak the camera for 30 minutes. This will keep the seals clean. Also you will want to oil the seals once in a while so they don't become brittle.

Update: Turns out we like it so much it's with us almost all the time over our SLR!

Nikon now has the AW120. It looks even better.

Wednesday, September 24, 2014

Random Numbers

Generating random numbers isn't the most straight forward. Here is the correct way to do it in C/C++:


int randomNumber;

if (rand_s(&randomNumber))
    return randomNumber;

    //TODO error


int randomNumber;
int fd = fopen("/dev/random", O_RDONLY));

if (fd > 0 && read(fd, &randomNumber, 4))
    return randomNumber;
    //TODO error

NOTE: On Linux don't call this too many times because the pool of numbers is limited.

Friday, September 19, 2014

Talk Like a Pirate Day

Friday, September 19 is International Talk Like a Pirate Day 2014.

Check out the Original Talk Like a Pirate Day website:

I know this is one of my favorite holidays!

Thursday, September 18, 2014

Can you Depend on Cloud Solutions?

Cloud solutions are great. They usually are free, or pretty inexpensive for what you get. However you do give the company access to your data which is how they are making money most of the time. But my point of this post isn't too discuss the nuances of how the companies make money or whether you should give the companies your data for free in exchange for a useful tool. My point is should you even depend on them? Most of them are touting themselves as more reliable than your desktop and your own backup system. It's true that the best backup is the one that you do, but you also have to be able to get to your data. Obviously the choice depends on what you are putting into the cloud because of reliability of the service and the sensitive nature of the data.

If you are a student writing a term paper for instance, Google Drive, Apple iCloud, or Microsoft office 365 are all free and are very compelling. However OpenOffice and Apple Pages are also free, and if something goes wrong your term paper won't be bit dust.

What made me think of this is Apple just rolled out iOS 8, and in doing so upgraded iCloud to iCloud Drive. Brilliant because now it's more on par with Google Drive, however the fine print says that when upgrading to iCloud dries only iOS 8 and OS X Yosemite support iCloud Drive. Only developers are running Yosemite so this seems like a rather odd thing to do. So until Yosemite is out I guess I won't be using iCloud.

Apple Calendar Stuck in Unusable State after Changing Password

After changing my password for my CalDAV server I started getting this error: "The server responded with an error. The server did not recognize your user name or password for account "." Make sure you enter them correctly." Typing in the new password just displays the dialog again, but I was able to successfully fix this issue by resetting the Keychain. Go t0 > Utilities > Keychain Access > Preferences > Reset My Default Keychain It also works to remove all keychain entries for that specific server to be more selective about it. Note: I'm running Mavericks, but I've run into this with Lion and Mountain Lion.

Wednesday, September 17, 2014

I'm Still Here (and Alive)

I haven't posted in some time so a few readers (and friends) have contacted me to see if I'm still alive. I'm happy to report that I am alive and I'll be posting more often. The last few years have been, well they've been extremely busy and a lot of things have come up that have been, well, more important than this blog. But, that's about to change so stay tuned!

Monday, October 28, 2013

Disable Java 7 and 8 in the Browser Manually on Mac

To disable Java 7 and up in the browser on Mac open Terminal and run the following three commands: 1. Change directories to the Oracle Application support directory.

cd /Library/Application\ Support/Oracle/Java
2. Remove the Info.plist (ls -al should show that it points to the Enabled.plist)
sudo rm -r -f Info.plist
3. Create a new Info.plist that points to the Disabled.plist
sudo ln -s /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Disabled.plist Info.plist
This will completely disable the Java plugin from running from within the browser. You can also do this from the Java Control Panel, but there are times when this is preferred. Note that this change will be remembered after upgrades because of how the installer works it will not modify this symlink, it will only create it if it does not exist and point it to the Enabled.plist.

Tuesday, May 21, 2013


This last weekend I went to the Maker's Fair and got a free breadboard Arduino. What a swag score After making a blinky light I decided to order a few parts from SparkFun Electronics and decided to toy around with a 7-segment display (I now wished I had gotten something a bit more challenging, but hey, I haven't done electronics in a long time). I followed the tutorial here and noticed many Arduino examples don't use objects. So, here is a version of the SparkFun 7-segment display example using objects.

/* Serial 7-Segment Display Example Code
    Serial Mode Stopwatch
   by: Jim Lindblom
     SparkFun Electronics
   date: November 27, 2012
   license: This code is public domain.
   This example code shows how you could use software serial
   Arduino library to interface with a Serial 7-Segment Display.
   There are example functions for setting the display's
   brightness, decimals and clearing the display.
   The print function is used with the SoftwareSerial library
   to send display data to the S7S.
   Arduino -------------- Serial 7-Segment
     5V   --------------------  VCC
     GND  --------------------  GND
      8   --------------------  RX

class LED
    // These are the Arduino pins required to create a software seiral
    //  instance. We'll actually only use the TX pin.
    int softwareTx;
    int softwareRx;
    SoftwareSerial *s7s;
      s7s = NULL;
    void initialize()
        softwareTx = 8;
        softwareRx = 7;
        s7s = new SoftwareSerial(softwareRx, softwareTx);
        // Must begin s7s software serial at the correct baud rate.
        //  The default of the s7s is 9600.
        // Clear the display, and then turn on all segments and decimals
        clearDisplay();  // Clears display, resets cursor
        s7s->print("-HI-");  // Displays -HI- on all digits
        setDecimals(0b111111);  // Turn on all decimals, colon, apos
        // Flash brightness values at the beginning
        setBrightness(0);  // Lowest brightness
        setBrightness(127);  // Medium brightness
        setBrightness(255);  // High brightness
        // Clear the display before jumping into loop
      if (s7s != NULL)
        delete s7s;
    void printDisplay(int value)
        char tempString[10];  // Will be used with sprintf to create strings
        // Magical sprintf creates a string for us to send to the s7s.
        //  The %4d option creates a 4-digit integer.
        sprintf(tempString, "%4d", value);
        // This will output the tempString to the S7S
    // Send the clear display command (0x76)
    //  This will clear the display and reset the cursor
    void clearDisplay()
      s7s->write(0x76);  // Clear display command
    // Set the displays brightness. Should receive byte with the value
    //  to set the brightness to
    //  dimmest------------->brightest
    //     0--------127--------255
    void setBrightness(byte value)
      s7s->write(0x7A);  // Set brightness command byte
      s7s->write(value);  // brightness data byte
    // Turn on any, none, or all of the decimals.
    //  The six lowest bits in the decimals parameter sets a decimal 
    //  (or colon, or apostrophe) on or off. A 1 indicates on, 0 off.
    //  [MSB] (X)(X)(Apos)(Colon)(Digit 4)(Digit 3)(Digit2)(Digit1)
    // Example: setDecimals(0b00000100);  // Sets digit 3 decimal on
    void setDecimals(byte decimals)

unsigned int counter = 0;  // This variable will count up to 65k
LED Led;

void setup()

void loop()
  Led.setDecimals(0b00000100);  // Sets digit 3 decimal on
  counter++;  // Increment the counter
  delay(100);  // This will make the display update at 10Hz.

Sunday, September 30, 2012

JavaOne 2012

I'll be at the JavaFX booth and the talks about Java on the Mac so come up and say "hi!" if you're around!

Thursday, July 26, 2012

Make the Apple Magic Trackpad Ergonomic

I've been using the Apple Magic Trackpad and found that it is not terribly ergonomic because it slants up to match the keyboard angle which forces the wrist to slant upwards. The Magic Trackpad can be made much more ergonomic by simply turning it around (I got my directions from here). In order to turn it around the coordinate system must be reoriented. To do that, type this into the terminal:

defaults write TrackpadOrientationMode 1

sudo defaults write ForceAutoOrientation YES
NOTE: Both commands might not be required but I couldn't get it to work otherwise on Lion or Mountain Lion. Then disconnect the Magic Trackpad, shut it off, reboot the Mac, reorient the Magic Trackpad and until the system is booted. Then turn on the Magic Trackpad and rest 5 finger tips spread out (like you are playing piano) on the Magic Trackpad and move them away from you. Viola! I have also found the settings tap-to-click and 3-finger drag to be useful and can be enabled in the trackpad control panel. To Remove the settings type:
defaults remove TrackpadOrientationMode
sudo defaults write ForceAutoOrientation NO