Archive for the ‘Programming’ Category

Publishing a Static AngularJS Application with Docker

Saturday, November 29th, 2014

Contents

Introduction

The most common use for JavaScript frameworks is to provide dynamic client-side user interface functionality for a web site. There are situations where a JS application does not require any services from its host server (see example unhosted apps). One of the challenges for this type of application is how to distribute it to end users.

This post will walk through creating a static AngularJS application (i.e. no back-end server) and how to create and publish a lean Docker container that serves the application content.  I will mention some tooling but discussion of setting up a JS development environment is beyond the scope of this article. There are many resources that cover those topics.

Also note that even though I'm using AngularJS, any static web content can be distributed with this method.

Side Note on AngularJS

One of the major advantages of using AngularJS over the many JavaScript framework alternatives is its overwhelming popularity. Any question or issue you may encounter will typically be answered with a simple search (or two).

angularjs-trends

With the recent AngularJS 2.0 controversy it will be interesting to see if this trend continues.

Creating an AngularJS application

The easiest way to create a full-featured Angular application is with Yeoman.  Yeoman is a Node.js module (npm) and along with its Angular generator creates a project that includes all of the build and test tools you'll need to maintain an application.

Generate the Angular application with yo. Accepting all the defaults will include "Bootstrap and some AngularJS recommended modules."  There's probably more functionality included then you'll need, but modules can be removed later.

The yo command will take a little while to complete because it has to download Angular and all of the modules and dependencies.

Start the server with Grunt (which needs to be installed separately).

The application can be viewed in a browser at http://localhost:9000/#/:

yeoman-default

Building the Application Distribution

After removing the 'Allo, Allo' cruft and creating your custom application create a distribution with:

This will create a dist directory that contains the static application content.

Creating and Publishing the Docker Container

The prerequisite is of course to install Docker and create a Docker Hub account (free). See Docker Installation Documentation.

A typical Ubuntu Docker container requires more than a 1GB download. A leaner Linux distribution is CoreOs. The coreos/apache container has a standard Apache server and is only ~250MB.

Add a Dockerfile file to the myapp directory:

The key here is the COPY command which copies the content of the dist directory to the container /var/www directory. This is where the Apache server will find index.html and serve it on port 80 by default.  No additional Apache configuration is required.

Create the docker container:

Output:

docker-build

Now push the container to your Docker hub account:

The dockeruser/myapp Docker container is now available for anyone to pull and run on their local machine or a shared server.

Starting the Application with Docker

The application can be started on a client system by downloading the running the dockeruser/myapp container.

The run command will download the container and dependencies if needed. The -d option runs the Docker process in the background while apache2ctrl is run in the container in the foreground. The application will be running on http://localhost:9001/#/.

To inspect the Apache2 logs on the running Docker instance:

To stop the server:

If you've pushed a new version of the application to Docker hub, users can update their local version with:

This example shows how Docker containers can provide a consistent distribution medium for delivering applications and components.

The Bumpy Road to a New Development Laptop

Saturday, September 6th, 2014

My 6 year old Lenovo T400 finally gave up the ghost. It didn't totally die (it probably never will, thank you IBM), but the screen was starting to flicker and it reliably rebooted itself whenever I was doing something useful. Very annoying.

Grief

I went though the standard 5 stages of grief:

  1. Denial: All T400's do this.
  2. Anger: "Damn it, why does this thing keep crashing? I'm sick of this sh*t!".
  3. Bargaining: Maybe if I update to 14.04 it will stop doing this.
  4. Depression: "This sucks!"
  5. Acceptance: OK, time to buy a new laptop.

I'm fine now, but that was a rough 30 minutes!

Decision Process

I'm not going to detail all of my system requirements or decision making process, but here's a high level outline:

  • I primarily need a Ubuntu development machine. My T400 is a dual boot 12.04/XP.  In recent years I've rarely used Windows, but there are some tools that are nice to have around (e.g. Visual Studio).
  • I looked hard at the MacBook Pro but at the end of the day I just couldn't bring myself to go that route. Besides the higher hardware cost/performance ratio re: the alternatives, I guess I'm just not a Mac person.
  • I really wanted to get an Ultrabook form factor. Not only for the portability, but I'm not ashamed to say that the 'cool factor' played a part in the decision.
  • I looked at all of the standard Ultrabook offerings: Lenovo, ASUS, Dell, System76, Acer, etc. No touch, no 'convertible' (if you need a tablet, buy a tablet), no Windows 8. The deciding factor for me was reliability. Besides the T400, I have a T60 in the closet that still runs fine.
  • So Lenovo it is. The history of the X1 Carbon (see The 2014 Lenovo X1 Carbon: Lenovo Giveth, And Lenovo Taketh Away and Lenovo ThinkPad X1 Carbon 2014 review)  goes back to 2011. The latest version (2014, or Carbon 2) has taken a lot of heat over the keyboard, function keys, and trackpad changes. I'm sure these opinions have merit, but I just want a fast machine that works!

Buying Experience (not good!)

Beware of the Lenovo Outlet. I purchased a 'ThinkPad X1 Carbon 2 - New':

x1-carbon-2-new

Here's the condition definition (my highlight):

Products that are discontinued, overstocked, or returned unopened. These items are in their original factory sealed packaging and have never been used or opened.

Boy was I disappointed when the package arrived! First, the only thing in the box was the laptop. No AC power adapter, no docs, no nothing. To my amazement, the machine was in suspend mode. When I opened the lid it came out of hibernation to a Win7 user password prompt! I didn't even try to guess a password. I couldn't believe it!

The machine was in pretty good shape physically, a little dirty and missing a foot pad, but no dents or scratches. Certainly opened and used!  At least the BIOS confirmed that I got the correct hardware (i7, 8G RAM, 256G SSD).

After many calls to multiple Lenovo service centers I got nowhere. No return, no exchange. Maybe I should write a letter to The Haggler, but even then I probably wouldn't return the machine anyway. I got a great price (much better than what I could find on eBay) and the Lenovo Outlet no longer has any i7 X1 Carbon's listed.  Also, I'm a techie so disk partitioning and re-installed OS's is not a problem.

I'm thinking now that Lenovo might have screwed up a repair shipment and I ended up wiping some poor schmuck's SSD. Oh well.

Anyway, as unpleasant as this was, I now have a development laptop that should meet my needs for many years to come.

Installation Notes

  • Dual boot. Here's the right way: WindowsDualBoot, but because I installed Ubuntu first (mistake) here's what I did:
    1. Used GParted  to partition the disk to my liking. Don't forget to add a Linux swap partition (8G for me). The Ubuntu installer will complain if it's not there and find it automatically if it is.
    2. Created a Ubuntu 14.04 bootable USB stick: How to create a bootable USB stick on Windows. Install Ubuntu on the ext4 partition.
    3. Created a bootable Windows 7 USB stick. The Universal USB Installer above works fine for this. Install Windows 7 on the Windows partition.
    4. After Step #3 the system will only boot Windows. Use Boot-Repair (option #2) to re-install GRUB.
  • Ubuntu 14.04 seems to work flawlessly on the X1. There were only two hardware compatibility issues that I read about:
    1. Not waking up from suspend mode. This is resolved by updating the BIOS firmware.  Upgrading from v1.09 to v1.15 fixed it for me. The Lenovo firmware only comes as a CD image (.iso) or a Windows update application. Because the X1 does not have a CDROM drive the only reasonable way to upgrade is via Windows. People have upgraded the firmware via USB (see BIOS Upgrade/X Series), but it's really ugly.
    2. Fingerprint reader. Haven't tried to use it, and probably won't.

Happy Ending (I hope)

Like most things in life, nothing is ever perfect. This experience was no exception.

I have a JRuby/Rails project with some Rspec tests that take 80 seconds to complete on the T400 and 20 seconds on the X1. I can live with that improvement. 🙂

Hopefully the X1 will last as long the T400 did.

The Zigzag Career

Tuesday, December 31st, 2013

I agree with Udi Dahan's Thoughts on a career in software development premise that developers will eventually be faced with a management "opportunity" at some point in their career.

It's too bad that this is usually a "fork in the road" decision. I don't think companies are necessarily trying to pigeonhole developers, but they certainly have specific roles (with associated job descriptions) they are trying to fill.  It makes sense though. For large software projects, being a manager (and probably a scrum master) is a full time job.  Put another way, if you try to split your time between being a contributor and a manager, you'll probably do both jobs poorly.

My advise is to make this type of decision with your eyes open. If you have a management opportunity and it's something you're interested in, take it. Treat it like the career change that it is. Get the additional training and improve your skills just like you would be doing if you were learning a new technology. Management isn't easy. It takes time and work get good at it.

Also, good companies do not pigeonhole technical managers. You will probably have the ability to switch back to a development or architect role as business needs and priorities change in the future.  This could mean moving to a different company, but both you and your current employer know this.  Switching from management back to a technical track will require yet another skills learning curve and a mindset change.

The way to create a Zigzag career is to go with the flow.

Whether you experience success, failure, or somewhere in between, each one of these transformations involves significant personal and professional growth.  Also, no matter what you do always stay at the top of your game: Continuous Learning: 14 Ways to Stay at the Top of Your Profession.

VirtualBox Ubuntu Guest Auto Re-size Display Problem

Sunday, June 23rd, 2013

Oracle-VM-VirtualBoxOracle VirtualBox version 4.2.12 was released on 12-Apr-2013 and caused the following problem: VirtualBox Guest Additions 4.2.12 breaks Ubuntu 12.04 guest. The solution of reverting back to GA 4.2.10 allowed the VM to run but I lost the ability to re-size the guest display.

On 21-Jun-2013 version 4.2.14 was released with a fix to this problem.

GA 4.2.14 does not cause graphics problems but it did not resolve the re-size issue for me. The Ubuntu VM starts up okay, but the display would still not re-size when the host (Windows 7 x64) window size was changed.

The solution to this problem was to change /etc/X11/xorg.conf back to its original configuration (this is the complete un-commented file content):

The xorg.conf this replaced had device/monitor/screen sections with specific driver details, e.g.:

I've been using this VM for a number of years and I suspect that older versions of the guest additions made this change.  Apparently newer GAs no longer require this.

Anyway, if you're having a Ubuntu guest display re-size problem give this a try.

Design Patterns for EMR/EHR Performance

Saturday, March 31st, 2012

Healthy Architectures - Using CQRS and Event Sourcing for Electronic Medical Records presents a couple of interesting patterns for the management of healthcare data. The two patterns are:

  • Command Query Responsibility Segregation (CQRS)
  • Event Sourcing (ES)

Here's another article that provides further clarification on the CQRS pattern and how it compares to ES and Task-Based UIs: CQRS, Task Based UIs, Event Sourcing agh!

These are high level design patterns that result in non-traditional and more complex system architectures when implemented.  The healthcare domain is complex and alternate approaches for providing robust solutions are worth consideration.

Binary Waveform Data in SQL Server 2008

Tuesday, March 8th, 2011

As Shahid points out in Consider MySQL ‘Archive’ storage engine to store large amounts of med device structured or waveform data, saving physiologic waveform data from a medical device in a MySQL database for archive purposes is a reasonable alternative to using flat files.

In SQL Server 2008 you can have it both ways.  In addition to saving binary data directly in the database you have the option to have a varbinary column stored as a file stream. From the article How to store and fetch binary data into a file stream column:

File stream data can be used from the .NET Framework using the traditional SqlParameter, but there is also a specialized class called SqlFileStream which can be used with .NET Framework 3.5 SP1 or later. This class provides mechanisms, for example, for seeking a specific position from the data.

There are pros and cons to this approach. The backup and transactional issues, along with the performance considerations, all have to be evaluated against your specific system requirements.  Having the SQL Server engine manage the database relationship to the binary files seems like a big advantage over maintaining flat files yourself.

Read the MSDN article FILESTREAM Storage in SQL Server 2008 for all the gory details.

UPDATE (3/25/11): Who's Got Access to your FileStream Directories?

Technical Debt in Medical Software

Wednesday, August 4th, 2010

Software development is software development. Most of the life cycle and quality issues faced in medical software are the same challenges for any software product. Technical Debt in Medical Software points out what technical debt is:

  • Complexity
  • Code Duplication
  • Documentation Debt
  • Testing Debt
  • Architectural Debt

A Martin Fowler article is referenced that nicely identifies the source of technical debt:

The benefits of paying down the debt are:

  • Increased R&D efficiency and improved time to market
  • Hitting commitment dates
  • Performance and technology upgrades

Of course if you don't want to pay it off, there's always the option to go bankrupt. This may have long-term advantages, but it will surely be a more expensive route. There is one statement in this regard that I think needs some qualification:

In this case the technical debt can be retired along with the legacy system, and like filing Chapter 11, you are no longer responsible to address all the sins of the past.

I know this refers to code sins, but just because you decide to do a re-write doesn't mean you no longer have responsibility for the legacy product. You still have customers using the old software that you're obligated to continue to support.  For FDA approved medical software, this is a legal requirement. Most of the time this means that the legacy code will need to be maintained and periodically updated in the field, sometimes even after the "new" product is released. This just makes the cost of bankruptcy even higher.

The Challenges of Developing Software for Medical Devices

Monday, February 8th, 2010

Developing Software for Medical Devices – Interview with SterlingTech gives a good overview of the challenges that especially face young medical device companies. In particular (my emphasis):

Make sure that your company has a good solid Quality System as it applies to software development. Do not put a Quality System into place that you can not follow. This is the cause of most audit problems.

I couldn't have said it better myself, though I think that focusing on the FDA may distract you from why you're creating software quality processes in the first place. The real purpose of having software design controls is to produce a high quality, user friendly, robust, and reliable system that meets the intended use of the device.  If your quality system does that, you won't have to worry about FDA audits.

Since Klocwork is a static analysis tool company I also want to point out a recent related article that's worth reading -- and trying to fully understand:

A Few Billion Lines of Code Later: Using Static Analysis to Find Bugs in the Real World

Note the user comment by Bjarne Stroustrup.

UPDATE (2/9/10): Here's another good code analysis article:

A Formal Methods-based verification approach to medical device software analysis

Stackoverflow Overflow Update

Sunday, February 7th, 2010

In Stackoverflow Overflow I predicted 500,000 questions on 2/7/2010 at 5:31. When I checked (after the Superbowl -- congratulations to NO!) at 19:42 this evening:

Not bad. Only 14 hours off on a three month linear extrapolation from only two weeks of data!

Stackoverflow Overflow

Thursday, November 19th, 2009

I really like SO. It's quickly become an invaluable resource for finding and getting programming answers.

I generally browse the new questions to see if there's anything I might be able to a answer.  Even when you find a question you already (think you) know the answer to, it still requires  some research.  Answering questions is a great exercise.

A couple of weeks ago I started to take notice of how fast the question count was increasing.  So I decided to track it and quantify the growth. Here's what I found:

SO-Count-L

So on average there are about 1472 new questions every day! That means when I browse through my 50 or so new questions, there are more than 1400 other ones that I'm not seeing. And that's if I visit every day.

Yeah, yeah -- I know about searching, using the tags, unanswered questions, etc.  What's remarkable to me is the shear volume of questions.  Two things strike me about this:

  1. There seems to be a lot of question duplication. You can see that when you go to a question and look at the related questions on the right hand column.
  2. My sense is that the number of views per question is also going down.  I don't know for this sure, but it would follow that there must also be fewer answers per question.

These are just anecdotal observations on my part.  I didn't mean this to be an exhaustive analysis of SO, and I'm not trying to be critical. It just seems to me that the "weight "of SO is bound to become an issue in the future.

SO is a great site and I'm sure Jeff and Joel are very aware of these patterns and are plotting solutions while the rest of us sleep.

So based on 14 days of data - 🙂 -  here's about when the number of questions will hit future milestones:

SO-Count-Future

We'll have to wait and see if these predictions become true.