Tuesday, January 7, 2014

Iterative solution to the Fibonacci sequence in COBOL

I've decided to learn cobol by contributing to Rosetta Code, a site that aims to show each as many different programming language's solution to a given problem.

Below is the iterative solution to the fibonacci sequence, which takes in input from the user's standard input keyboard.

View on Rosetta Code

Program-ID. Fibonacci-Sequence.
Data Division.
Working-Storage Section.
  01  FIBONACCI-PROCESSING.
    05  FIBONACCI-NUMBER  PIC 9(36)   VALUE 0.
    05  FIB-ONE           PIC 9(36)   VALUE 0.
    05  FIB-TWO           PIC 9(36)   VALUE 1.
  01  DESIRED-COUNT       PIC 9(4).
  01  FORMATTING.
    05  INTERM-RESULT     PIC Z(35)9.
    05  FORMATTED-RESULT  PIC X(36).
    05  FORMATTED-SPACE   PIC x(35).
Procedure Division.
  000-START-PROGRAM.
    Display "What place of the Fibonacci Sequence would you like (<173)? " with no advancing.
    Accept DESIRED-COUNT.
    If DESIRED-COUNT is less than 1
      Stop run.
    If DESIRED-COUNT is less than 2
      Move FIBONACCI-NUMBER to INTERM-RESULT
      Move INTERM-RESULT to FORMATTED-RESULT
      Unstring FORMATTED-RESULT delimited by all spaces into FORMATTED-SPACE,FORMATTED-RESULT
      Display FORMATTED-RESULT
      Stop run.
    Subtract 1 from DESIRED-COUNT.
    Move FIBONACCI-NUMBER to INTERM-RESULT.
    Move INTERM-RESULT to FORMATTED-RESULT.
    Unstring FORMATTED-RESULT delimited by all spaces into FORMATTED-SPACE,FORMATTED-RESULT.
    Display FORMATTED-RESULT.
    Perform 100-COMPUTE-FIBONACCI until DESIRED-COUNT = zero.
    Stop run.
  100-COMPUTE-FIBONACCI.
    Compute FIBONACCI-NUMBER = FIB-ONE + FIB-TWO.
    Move FIB-TWO to FIB-ONE.
    Move FIBONACCI-NUMBER to FIB-TWO.
    Subtract 1 from DESIRED-COUNT.
    Move FIBONACCI-NUMBER to INTERM-RESULT.
    Move INTERM-RESULT to FORMATTED-RESULT.
    Unstring FORMATTED-RESULT delimited by all spaces into FORMATTED-SPACE,FORMATTED-RESULT.
    Display FORMATTED-RESULT.

Monday, January 6, 2014

How to ping a site or address with Java

Java does not natively have the ability to send ICMP messages, so we need to send them using the system's built in ping tool.

I added a simple ping utility to JavaUtils, which you can download the jar from SourceForge and GitHub:

JavaUtils JAR and source download on SourceForge
JavaUtils JAR and source download on GitHub

Then, you can test ping reliability with the built in isNetworkAddressReachable(String);

Here is how to use the JavaUtils class with NetBeans:

Select Properties of your project:

Under Libraries, select Add JAR/Folder

Select the javautils.jar, and click Choose.

Then, click OK.

Now, you're ready to use JavaUtils. Below is an example of its use:

import java.io.IOException;
import javautils.network.Ping;

public class Testing {
    
    public static void main(String[] args) {
        try {
            System.out.print("Is google.com reachable? ");
            System.out.println(Ping.isNetworkAddressReachable("google.com"));
        } catch (IOException ioe) {
            // Something is wrong with the network
        } catch (InterruptedException ie) {
            // The system waitFor process was interrupted
        }
    }
}

The output:

run:
Is google.com reachable? true
BUILD SUCCESSFUL (total time: 0 seconds)

Friday, January 3, 2014

Network Ping Tester

Network Ping Tester is based on a previous application I developed and mentioned in a previous post, Simple Network Tester. The first revision of this graphical ping tool was rough around the edges and had some errors that I ran into. This version is a much cleaner implementation, and has a few additions.

Download at SourceForge.com


Features

  • Uses system ping utility
  • Ping results displayed
  • Latency information and averages
  • Average deviation
  • Variable number of connections

The tool as it stands now is complete. If there is interest in it, I would be happy to develop it further. It could use graphs and data dumping to a .csv or similar. 


If anyone finds the tool useful, let me know. I'll also be glad to develop any features you would find useful.

Thursday, November 15, 2012

Create MD5 and SHA checksums easier with EzDigest (JAVA)

Creating a simple MD5 checksum in Java is a multistep process. I created a simple java class called EzDigest that should make the process much simpler.

JavaUtils JAR and source download on SourceForge
JavaUtils JAR and source download on GitHub

EzDigest can handle the following one way message digests:
MD2
MD5
SHA
SHA1
SHA256
SHA384
SHA512

It currently the only member of the JavaUtils package. If you have any ideas or requests for similar utilities (or additional digests/hashes), let me know in the comments!

Here is how to use the JavaUtils class with NetBeans:

Select Properties of your project:

Under Libraries, select Add JAR/Folder

Select the javautils.jar, and click Choose.

Then, click OK.

Now, you're ready to use JavaUtils. Below is an example of its use:

import java.security.NoSuchAlgorithmException;
import javautils.digest.EzDigest;

public class Testing {

    public static void main(String[] args) {
        try {
            System.out.println("SHA256: " + EzDigest.getSHA256String("Test"));
            System.out.println("MD5 : " + EzDigest.getMD5String("Test"));
        } catch (NoSuchAlgorithmException ex) {
            System.out.println(ex.getCause());
        }
    }
}

The output:

run:
SHA256: 532eaabd9574880dbf76b9b8cc00832c20a6ec113d682299550d7a6e0f345e25
MD5 : 0cbc6611f5540bd0809a388dc95a615b
BUILD SUCCESSFUL (total time: 0 seconds)

Monday, July 30, 2012

6 Terminal Easter Eggs and Tricks that work in Linux, Unix, and OS X!

Emacs Tetris

I like to keep Tetris available on all my devices, phones, tablets, calculators, and computers.  But if you are running a Unix based Operating System, chances are pretty good that you already have Tetris available to be played!

Open the terminal and type "emacs". Press the escape key, and then "x". Finally type "tetris", and enjoy!


Emacs Psychotherapist

Following the example above, there is another absolutely unbelievable feature of emacs, the psychotherapist.  If you've never tried this before, I would highly recommend it. It is a little scary though on how well it does interpreting your problems.

Just like above, open the terminal and type "emacs". Press the escape key, and then "x". Finally type "doctor", and let your emotions flow freely.

Run Nyan Cat!

If you're looking to score some serious nerd-cred, look no further.  Enter the following command into terminal:
telnet miku.acm.uiuc.edu


Enjoy your non-stop nyan cat!

Start a Webserver From Any Directory

If you are too busy (lazy) to install xampp, you can use this command to start a very simple web server!
python -m SimpleHTTPServer 8000
[More Information | Source]

Watch Star Wars Episode IV

If you are a die hard Star Wars fan, and have some free time and imagination, you can watch the entirety of Star Wars Episode IV from your favorite terminal application.  You will need to telnet using the following command:
telnet towel.blinkenlights.nl


[More Information]

More Emacs Games

There are a TON of Emacs games so if you've already seen everything on this list before, and you have some time to play some classic games, here is a list!  The instructions for these games are the same for the first two on this list.  Enter "emacs" in the terminal, hit the escape key, then the "x" key, followed by anything on the list below.
  • 5x5
  • animate
  • blackbox
  • bruce
  • cookie1
  • decipher
  • dissociate
  • doctor
  • dunnet
  • fortune
  • gamegrid
  • gametree
  • gomoku
  • handwrite
  • hanoi
  • landmark
  • life
  • meese
  • morse
  • mpuz
  • pong
  • snake
  • solitaire
  • spook
  • studly
  • tetris
  • yow
  • zone
This is the list of games available on my machine, but your listing may be different! To see what is on your machine, enter this command:
ls /usr/share/emacs/22.1/lisp/play/
 Enjoy! Comments are welcomed as always, as well as more suggestions!  I'll be glad to add them and credit you for your additions.

Monday, July 9, 2012

How-to Launch a Weather Balloon for Aerial Photography

Over July 4th, 2012 I decided to launch a weather balloon with a camera attached.  I've always been interested in aerial photography, and the timing seemed right.  Below is a short 3 minute video showcasing some of the amazing shots the small camera took.


While I was very pleased with how the video turned out, I also learned several lessons for future launches.  In the hopes that you don't make the same mistakes as I made, I have put together this guide.  I hope it answers some of your questions, but if it doesn't, feel free to contact me!

How-to Launch a Weather Balloon for Aerial Photography

Step 1: Acquire Equipment

While I always try to keep a do-it-yourself mindset, there are some things I don't have the ability to make myself.  Here is a list of the equipment I purchased, and some small notes on what it does and doesn't do.

This weather balloon was incredible.  If there was one part of this project that went 100% to plan, it was the weather balloon.  The latex balloon carried my payload and camera 100,000 feet into the air, and then burst exactly as it should have.  This is one part that I will not change in the future, and it's something I highly recommend.

Video Camera - Kodak PlaySport HD Video Camera
The video camera survived more than I thought it ever would.  I was only hoping the SD card would come back in one piece, but was surprised instead to find the camera was in perfect working order. There was one problem I experienced with the camera: at around an altitude of 15,000 meters (~50,000 feet) the camera shut off because the batteries died due to the extreme cold.  For my next launch, I plan to solve this by putting a device like this into an insulated cooler.  The cooler should keep the batteries at a reasonable temperature, so they can continue to power the camera well beyond its previous flight time. You certainly don't have to buy the Duracell product I linked to, but whatever you buy, it should be lithium-ion, so that it can survive in the cold.

GPS Tracking Device - Micro-trak AIO High-Altitude
This is the one device that saved my project.  The Micro-trak AIO is a radio equipped with a GPS so that you can track your balloon in real time, on the internet! It uses APRS (Automatic Packet Reporting System), which requires an Amateur Radio license from the FCC.  Getting your HAM radio license is extremely easy, it just requires a night or two of studying and then taking the test.  For more information on getting your amateur radio license, and where to take the test, visit arrl.org. The Micro-trak AIO allowed me to track my balloon in real time with updates every 2 minutes.  Sadly, it suffered the same fate as the camera though, and when it got extremely cold in the high atmosphere, it stopped reporting its position.  Thankfully on its descent the batteries warmed up again and the radio turned back on.  I was able to watch it drift into an abandoned lot, where I later found and recovered it!  It was only inches away from where aprs.fi was reporting it to be. The next time I launch the weather balloon, I will definitely use lithium-ion batteries in hopes of keeping the radio powered on throughout the entire flight. If you purchase your Micro-trak AIO from Byonics, it will come pre-configured.  You only need to add batteries and turn it on!

Helium - 100 - 150 Cubic Feet
Filling a weather balloon the as large as the one listed above takes a lot of helium.  I rented a large tank from a local welding supply store.  They charged me around $50 for the tank rental and helium, and an additional $50 as a security deposit, which I got back when I returned the tank.  I've always found welding supply stores to be helpful, especially if you share with them what you are doing.  The tank that I got was 120 cubic feet of helium, and was just enough to fill the balloon to get the lift I needed.  I would advice getting a tank with similar ratings or larger.  Some of the helium will leak out during the fill process, which I will talk about later in the article. Make sure you also pick up a regulator with the tank, so you will have some pressure control.  A standard nozzle used to fill party balloons will be handy as well.

Kite String / Rope - 75 - 100 Feet
I used 50 pound kite string to connect the balloon to the payload (the parachute was tied in between the two).  It is extremely important that you use kite string rated under 50 pounds, so that you do not fall under the rules of FAA's F.A.R. 101. It is much easier to do a launch like this if you do not fall under those regulations.  I will talk later about the FAA's rules and things to consider. I purchased my rope at Lowe's.

5 Centimeter Flexible Plastic Tubing (2 Inch Tubing) - ~2 meters long
I used 2 inch tubing to connect the regulator's nozzle on the helium tank to the weather balloon.  I prevented major leakage by using duct tape to connect the regulator to the helium tank. To get a snug fit around the 2 inch tubing I placed the stem of the balloon on to the tubing and then wrapped duct tape around both, and then secured it with a couple of zip ties (over the top of the duct tape, you don't want it so tight that you cannot remove the tubing!).

Soft Cloth Tarps or Painter's Tarps - Quantity of 2, around 2 meters squared
You want to avoid even the smallest of trauma to the balloon, including pebbles, stones, weeds, etc... so you should put a cloth or other soft tarp on the ground before opening the balloon's box and protective packaging. A second cloth can be used to hold the balloon on the ground before it is buoyant.

Latex Gloves - Amazon Link
Everyone who is touching the balloon in any way should be wearing latex gloves.  No sharp rings should be worn around the balloon, and no one with excessive hair spray or hair gel should be near the balloon.  If you're going to put all this money into it, you definitely want the balloon to reach its maximum height!

Step 2: Make the Parachute

Your recovery system is key to getting everything back, but it can also be extremely simple.  The parachute made for my balloon was made using fabric purchased at Walmart. I purchased 2 yards of fabric, and cut it into a circle. I also cut a hole in the middle of the parachute, about 4 inches in diameter. It was through this hole that the rope connecting the balloon to the payload was run.  Eight very small holes were cut evenly spaced throughout the parachute, and the holes were hemmed, and reinforced with a liquid stitch product. It looked something like the diagram below.


I was very happy with the way this parachute worked for my balloon.  The payload had only extremely minor damage, and there were no scratches or signs of damage on the camera.

Step 3: Things You Need to Know About Contacting the FAA

With most scientific weather balloon launches, the balloon will fall under the FAA's F.A.R. 101. There is more paperwork associated with FAR 101, so I decided to keep my balloon under its specifications.  It was significantly more simple.  That being said, I strongly advise you to read over FAR 101 and become intimately familiar with what it says.  Read it over several times to make sure that you are following the law.  The last thing you want is your balloon to wind up on the news because someone suspects it to be dangerous.

While my balloon did not apply to FAR 101, I was advised to contact the FAA about it anyway.  The last thing I want to do is surprise some poor pilot and cause him to take evasive action because of my aerial balloon project.  When I called the FAA, the process was extremely simple because I had knowledge of what types of questions they would ask.  I would also advise you to call the FAA and file a NOTAM (notice to airmen).  The phone number I was advised to call was for the US NOTAM office at 1-877-487-6867.  Here are some questions you should have answers to before you call:
  • When do you plan to launch (Date/Time)?
  • Where do you plan to launch from?
    • Coordinates in Degrees, Minutes, Seconds (I used Google Earth)
    • Elevation of launch site
  • What is the rate of ascent of the balloon?
  • When do you expect the balloon to be on the ground (landed)?
  • Where do you expect the balloon to land?
  • How large in diameter is the balloon on the ground?
  • What is the weight of your payload?
  • Where are the nearby airports to your launch and landing sites?
  • How long do you expect the balloon to be under 60,000 feet above sea level?
  • Do you have a cut down mechanism? (Balloon bursting counts)
If the representative you are talking to isn't aware that your balloon doesn't fall under FAA's FAR 101, politely remind them that your balloon isn't applicable.  The person you are talking to is going to send out a notification to the local airports, so they are only trying to get the most detailed and useful information from you.

Most of these questions can be easily answered using some basic math, Google Earth, and the EOSS' extremely helpful calculator.

Step 4: Create the Payload

The payload is where you can become somewhat creative.  Keeping rule #1 in mind, be sure to make it as light as you possibly can.  I created my payload out of a small sheet of styrofoam.  I cut it into a 12 inch square box, held together with epoxy, duct tape, and a few screws. The radio's antenna stuck straight up out of the top, and the camera was attached to the side.  I cut out a small section in the side so that the camera would fit in and then "sandwiched" it using 2 flat pieces of plexiglass.  It was very simple, and very light, but able to withstand the tug and pull of the rope.  4 strings connected it to the main rope; they were tied off at the bottom and top, and were designed in an attempt to distribute some of the force that the balloon and parachute would exert.

I also labeled the payload in several places with the phrase "NOT DANGEROUS!", and the details of the project including my phone number.  While APRS was able to take me to the balloon, I did get a phone call confirming that it was safe on the ground!




Step 5: Launch Day

This is the day you've waited for.  Be sure that you start early in the morning so you'll have time to chase after the balloon if necessary. As long as you've got a bright day and a clear sky, you are all set to launch your balloon! Make sure you put down your tarp before unwrapping your weather balloon. Attach the helium tank's regulator to your balloon using the 5 centimeter tubing.  When filling the balloon, first put duct tape above the end of the balloon's stem to make the balloon fit snugly around the tubing.  Further secure the balloon by putting a zip tie around the duct tape region of the balloon and tubing.  Connect the parachute between the balloon and the payload, going directly through the hole in the middle of the parachute.  Then when the balloon has been filled, secure the rope holding the parachute by using a reasonable amount of duct tape and zip ties.  Make sure the parachute has been tied off at all 8 outside points at approximately 6 feet above the payload.  It should look something like the diagram below (when launched!)


Step 6: Tracking and Recovery

Now comes the fun part! Track your balloon on aprs.fi, and travel with it to its destination! Good luck to you, and be sure you post the video it takes online!  Below is a video showing the full launch and video to give you some idea of the launch process.



If you have any questions, feel free to leave them as comments here, or post on the amateur radio reddit for more help!

Thanks to the following people for helping out!

  • Ashley Hollenback
  • Mark Hollenback
  • Ryan Girven
  • Justin Girven
  • Marilyn Burke
  • Larry Burke
  • Joseph Mauceri
73s!
KB3VFE

Monday, June 11, 2012

Microphone Placement and Selection for a Grand Piano

Every once in a while a few audio technicians I know and work with get into a debate on what is the best microphone(s) to be used on a grand piano. For the most part, when we need to do live sound reinforcement we use two of Shure's SM81s.  We don't typically do any recording work, so we are somewhat limited in what microphones we have on hand.

Today we had a couple hours of free time and some extra ambition, so we recorded the same short section of a piano piece using 5 different microphones. Below are the recordings.

SM57



SM81



PCC



PZM



ME35



I'll let you make your own decisions on which one was best, and please comment if you have any suggestions!  You'd be helping out fellow audio technicians!