Friday, April 8, 2016

Deployment to OpenShift

Today I had the day off from work, so I decided to get back to some of the mobile app development that was been slowly wasting away.  A couple of things that bugged me that I wanted to fix today were: 1) paid GitHub account for private repos, 2) paid AWS account for hosting LDS Temples web service.

In order to get around these issues, I first moved all of my private GitHub repos to Bitbucket.  I didn't realize that Bitbucket was provided by Atlassian (same folks who do Jira, Stash, Confluence, etc.).  I found it extremely easy to import my GitHub projects.  They did a great job with that feature.  

Then, onto moving the LDS Temples web service.  For this, I decided to go with OpenShift since they allow 3 free "gears" indefinitely.  This was a little more challenging, but since my app was already deployed as a WAR, it wasn't too bad.  The only part that really bugged me is that they do not support apps written in Java 8 for their Tomcat 7 deployment feature.  However, once I downgraded to Java 7, things worked smoothly after that.  The webservice is now running here: 

Anyway, that was my fun for the day.  Now I need to update the app to use the new REST endpoint, since we no longer own the blinkdroid.com domain.  It was costing too much.


Sunday, October 4, 2015

Writing to an NTFS drive from a Mac

If you have ever tried to write to an NTFS drive from a Mac, you may have been frustrated. NTFS is sometimes chosen over FAT32 since it support files larger than 4GB. However, a common misconception is that Macs cannot write to NTFS. However, this is in fact supported by Apple, you just have to know how to do it. All you need to do is add one line to your /etc/fstab file (create it if it does not exist):

LABEL=drivename none ntfs rw,auto,nobrowse

Replace with the name of the drive you are mounting. Make sure that the drive name does not contain any spaces. After editing the file, then remount the drive and you are good to go. Just a little tip for you, and for me, when I forget what I did.

Saturday, August 1, 2015

Bubble Sort Java Implementations

Out of curiosity, I decided to implement the Bubble Sort to refresh my memory, and play around with Generics. At a really high level, the bubble sort is performed by iterating over an array of elements and comparing adjacent elements. If the adjacent elements are in the wrong order, then you swap them. You continue to iterate over the array until no changes are made to the order of the elements within an iteration. This sort is essentially brute force, and not as performant as other sorts such as quick sort, merge sort, etc.

1. Here is my initial implementation which sorts the characters within a String in lexicographic order:
2. Here is my follow-up implementation which sorts a List:
3. Finally, I decided to implement a version which uses Generics to sort a List of Comparables:
4. Here are some example scenarios and output:
Example output: Thank you for reading this far through the post! If you are curious, the full code example is in GitHub here: https://github.com/jmartin127/InterviewQuestions

Saturday, June 14, 2014

Thread Interruption in Java

This week a question came up at work about the best way to handle an InterruptedException thrown from Thread.sleep(...). Often times, developers will simply catch this exception, and then just print a stack trace, or leave the block completely empty. However, this is not good practice, since you are essentially ignoring the fact that your app has been interrupted:

For example, say you have a thread which processes a given number of records, with a configurable sleep in between each record to allow you to throttle the speed. If not handled properly, the thread will never exit gracefully. For example:

Note that simply calling Thread.currentThread.interrupt() will not kill the running thread. In this case, the thread will continue to run, interrupting itself over and over again. A better way to handle the InterruptedException is to gracefully discontinue processing records, for example:

In this example, the private sleep method properly throws the InterruptedException up the stack to a piece of code which knows how to handle it properly.

To run an example of the non-interruptable runnable and the interruptable runnable, you can clone the project from GitHub Here.

Monday, May 14, 2012

The beginning of the gobbledygook

This is the start of my Gibberish Code blog.

Gibberish: a generic term in English for talking that sounds like speech, but carries no actual meaning (wiki)

While typically gibberish refers to speech, I am extending it here to mean "letters that look like code, but carry no actual meaning". In a past life (4 years ago) I was a software engineer for a small non-profit in Utah. However, since then I obtained a master's degree in Bioinformatics in Georgia, and then worked for the DOE in Northern California. I recently decided to make the jump back to Software Engineering and have accepted a position as a Software Developer.

I started this blog to track my journey back into the world of Java, Oracle, Hibernate, etc. We'll see where the journey ends up...