Monday, April 11, 2016

Running GUI Apps in Docker on Mac OS X

I've been trying to figure out how to run GUI apps in a Docker container on my Mac running OS X El Capitan. As a developer, I try out many different software packages and configurations. I would love to be able to try out certain things in a well-contained environment where I won't leave bits and pieces lying around if something doesn't work or if I get bored with the package. I have also been enamored with using Docker for development environments to make them portable and self-contained. After many searches and experiments, I finally stumbled on what I needed to do.

I am using the Docker Toolbox to run Docker on my Mac. I have also used Boot2Docker, but the Docker Toolbox experience is a little smoother. Either option will work to get Docker containers running on your system.

One of the required pieces I had to install was XQuartz. This is an X11 windowing system that runs on the Mac. I was originally worried about installing this package, concerned that it would interfere with the X11 windowing system built into OS X. So far, I haven't had any trouble with it.

To try out a GUI app, I wanted a basic Linux container with an obvious GUI app that is not installed on my Mac. I created a basic Dockerfile defining an image based on the latest distribution of Ubuntu. I then install Firefox into the image. The image starts up at a bash prompt, which allows me to run programs. Here is that docker file:

FROM ubuntu:latest

RUN apt-get update && apt-get install -y firefox

CMD /bin/bash

Getting Docker to create an image and run a container based on that image was pretty straightforward with the Docker Toolbox for Mac OS X. The hardest part was trying to get the running container to bind the DISPLAY environment variable to the XQuartz server. This link finally broke things open for me. A comment from slobo on January 22, 2015 has the secret sauce. In an xterm window started under XQuartz, run the command

socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"
Then, when starting the container, set the DISPLAY environment variable to the IP of the Docker virtual machine. (This IP address is usually a 192.168.x.x value.) I found this IP address on my Mac by typing
ifconfig
and locating the vboxnetn entry (where n is 0 - 9). For me, it looked like:

Using the IP address 192.168.99.1, I ran the following command to start a running container:

docker run -it -e DISPLAY=192.168.99.1:0 firefox
(firefox is the image name for the Ubuntu image running Firefox I defined with the Dockerfile above.) When I got to the bash prompt inside the running container, I ran Firefox, and the UI appeared like another window in OS X!

I am just starting my journey with Docker, but I'm excited about the possibilities it offers.

UPDATE:

Benny Cornelissen (@whieee) has a blog post that does a really good job integrating XQuartz and the instantiation of containers into the bash shell.

Tuesday, April 5, 2016

Setting Future File Permissions in Linux

Here is a link to a StackOverflow article outlining how to do this.

I actually found something that so far does what I asked for, sharing here so anyone who runs into this issue can try out this solution:

sudo setfacl -Rdm g:groupnamehere:rwx /base/path/members/
sudo setfacl -Rm g:groupnamehere:rwx /base/path/members/

R is recursive, which means everything under that directory will have the rule applied to it. d is default, which means for all future items created under that directory, have these rules apply by default. m is needed to add/modify rules.

The first command, is for new items (hence the d), the second command, is for old/existing items under the folder. Hope this helps someone out as this stuff is a bit complicated and not very intuitive.

Monday, February 22, 2016

Traversing TFS Links

Recently, Team Foundation Server (TFS) has added some new features that my team is using. One of these features is the new Epic work item. We are using epics to track high-level business initiatives, with features underneath the epics to track user requirements. Underneath the features, we have user stories, which are self-contained units of work that can be tested and deployed independently. My team works with user stories and tracks everything through user stories. I need to drive my reporting by user stories but relate the data to the epics that they are under.

The built-in reporting capabilities of TFS are pretty good, but they don't handle the kind of roll-up reporting I need. A consultant friend shared some code snippets with me that use the TFS API to pull data from the TFS database. I'm building out my custom reporting using the TFS API. One of the first challenges I've run into is starting with a user story and determining the epic that contains that story.

I struggled trying to understand how to follow the links that are available on a TFS WorkItem object. This link pushed my understanding forward quickly. It helped me understand how to identify the "type" of link that I was seeing.

"The tricky bit" for me is identifying the type of link I'm dealing with. Here is the code snippet to do that:

if (link.LinkTypeEnd.Name == "Parent")
In this code snippet, I am filtering on links that are of type "Parent." One could easily filter on other types of links based on need.

As I develop my TFS reporting capability, I will document what I'm doing to make it less mysterious for others.

Monday, February 15, 2016

Pinewood Derby and Arduino Coding

My middle son's Pinewood Derby for Cub Scouts was about a month ago. His pack usually has an "outlaw" division for dads, siblings, and other family members to submit cars. Usually I don't submit a car for the derby, but this year I decided to create a car powered by Arduino.

My original idea was to put a motion sensor on the car, have the Arduino detect that the car was moving, and start up a motor with a propeller. The way the project played out, I got the Arduino kit about 3 days before the Pinewood Derby, so I had to throw something together very quickly.

I cut the car into a basic platform, with a cut-out intended for the motor. I slapped some black paint on it to cover the wood and mounted the wheels. I didn't put any time into making it faster or straight because my intention was not to win a race.

Next I had to do something with the Arduino. I purchased the Arduino Uno with a basic electronics kit. The kit came with jumper wires, resistors, and numerous sensors. It was perfect! I spent a few hours installing the Arduino IDE and playing around with sample sketches. Now I was ready for my project.

My initial idea of driving a motor with the Arduino was doomed to fail. First off, I needed a 5V battery to power the Arduino. I really didn't have room on the car for the Arduino board, battery, and motor. (If I had more time, I would have used an Arduino micro.) Second, not being an electrical engineer, I didn't realize I needed a relay switch to power the Arduino and the motor from the same battery. This realization put my whole project in jeopardy.

At this point I was frantically scrambling to come up with something I could do for this project. I settled on mounting the active buzzer component, with a ball switch. I found a sketch that set up all the notes on the scale and played a melody repeatedly through the buzzer. I wired the buzzer into the Arduino board with the ball switch so that the melody only played when the car was angled downward. (This ensured that the car wasn't annoying everyone unless it was perched for a race.)

The project came together as a family effort. My oldest son helped me mount the board to the car while I figured out how to get the electronic components mounted. My middle son helped me figure out the first few notes of the Imperial March (think Darth Vader theme song) so I could program that into the sketch. I used the space for the motor to mount the battery, and was able to get something together. Here is a picture of the car.

The code I downloaded and modified to play the Imperial March is here on Github.

Even though the project didn't come out as I expected it, it had the desired effect. Numerous adults and scouts asked me about the car. They were all interested in how it worked and what it did. This was exactly the purpose of the project.

I wanted to show the scouts that something like the Pinewood Derby could be looked at through a different lens. I wanted to show the kids that technology can be used in different ways, even on a wooden block with wheels. Although it wasn't perfect, I'm still proud of my first IoT project!

Saturday, February 6, 2016

Evangelization

The St. Ferdinand Men's Club has been reviewing the four signs of a Dynamic Catholic from the book by Matthew Kelly. I was supposed to do a brief presentation at our February meeting, but it got bumped due to a full schedule. Since I'm not sure if it will get rescheduled or not, I thought I would convert it into a blog post.

The first sign we covered was prayer. We covered it first because it is the first sign in the book, and because I feel it is the basis for everything we do as Catholics. The next sign I was going to cover is evangelization. I skipped ahead because I think this is the toughest of the four signs, and I think it is one of the most critical for our parish at this time.

What is evangelization? Fundamentally, evangelization is sharing our faith with others. It is being open to opportunities to talk about our faith, our faith journey, and our practice of the faith. Evangelization is also about sharing our faith with our faith community (parish) and helping to bolster our fellow parishioners.

When I want to understand how to evangelize, I turn to the saints. The first saint I look to is St. Rose Philippine Duchesne. She is the dedicated religious that founded St. Ferdinand school and helped bring Catholicism west of the Mississippi river. She evangelized by working for the poor, building schools to teach the faith, and by supporting the missionaries in any way she could.

Another person I look to for help understanding evangelization is Fr. Pierre De Smet. He was a Jesuit missionary in America, whose "home base" was St. Louis. He was instrumental in establishing missions in Florissant, MO, Kansas, and Oregon. He made great strides converting Native American tribes by learning their language, understanding their customs, and adapting his approach to their particular needs. Fr. De Smet's peaceful approach to evangelization earned him the respect of most of the Native American tribes west of the Mississippi.

Stories of holy people moving thousands of miles from home to start missions and teach poor kids are exciting and romantic. They make evangelization seem intimidating for most ordinary people. The key is to understand that St. Rose and Fr. De Smet had particular callings that spoke to their characters, allowing them to do these things. Most of us are called to evangelize in simpler ways.

St. Rose, despite her accomplishments starting schools, was most known for her prayer life. She was known by the Native Americans as the Woman-Who-Prays-Always. Her contemporaries were convinced of her holiness because of her diligence in prayer.

Fr. De Smet gained the respect of the Native Americans he worked with in several simple ways. He learned their language and customs, helped broker peace between tribes, and treated them with respect. His success came from simply living as a Christian.

So, who should evangelize? The short answer is: EVERYONE! We should all feel called to share our faith with others. If we have truly embraced Christianity and its way of life, we should be eager to share it with others.

How should we evangelize? First and foremost, we should evangelize through the example of our lives. We should live as Christians are called to live by Jesus Christ. That example was compelling enough to draw thousands to the church in the days immediately after the Ascension. It is good enough to work today.

We are also called to evangelize by telling our story. A great way to to get people curious about the faith is to share with them what drives you in your faith. The compelling personal story goes a long way to drawing people to the Lord.

A critical way we evangelize is by supporting our faith community. My cousin always signs his emails with the tag line "Keep the faith." I used to think it was a catchy platitude, but now I see the brilliance of it. Keeping the faith is difficult, and it needs the support of a strong faith community. By participating in our faith community, we bolster the faith of others and make them strong to evangelize too.

So how do we, as modern Christians, draw others to Jesus?

Tuesday, October 27, 2015

Exercises for New Developers

Over the course of my career, I have needed to guide newer developers learning either general programming practices or a specific topic. I usually have the developer work through a sample project with some specific instructions intended to push that person along a path. I was recently asked to find my notes from one of these exercises to share with another individual. Instead of just emailing the instructions, I wanted to capture them more permanently.

These write-ups are not very detailed. They are written with the assumption that a more experienced programmer is "administering" the exercise to someone, so the instructions are more like teacher's notes. The only comparison I can come up with are the Spiritual Exercises of St. Ignatius Loyola. He wrote a manual of sorts for spiritual directors to guide retreatants through spiritual "exercises" to improve their relationship with God.

As I write up these exercises, I will link them here.


Calculator Project

Calculator Project

This is the first write-up of a software development exercise that I have used to help train developers. This post should be viewed as instructions for the instructor, more than a step-by-step guide for someone trying to learn.

In this project, the user will create a basic calculator application. The specific project steps are written to encourage the user to create a program that interacts from the command line. This is done to keep the focus of the project on Test Driven Development and good programming practices. After the main exercise is described, alternate variations are mentioned.

Phase 1

Create a command-line application that will prompt the user for two numbers, add the numbers together, and return the result.

The program flow should look like:

C:\> calculator.exe
Please enter the first number: 3
Please enter the second number: 4
The sum of 3+4 is 7.
C:\>

The main() method should call the Calculate() method on another object. The program should be able to accept and correctly add any integer less than half of the max integer available on the system.

Phase 2

Modify the existing calculator program to be able to perform subtraction. The user should enter two numbers just as with addition, but will be prompted to select an operation. All of the constraints from the first phase still apply.

Phase 3

Modify the existing calculator program to be able to perform multiplication and division. If the user enters a 0 as a divisor, the program should return a message indicating that division by 0 isn't possible.

Phase 4

Modify the existing calculator program to accept floating point values (decimal values) as well as integers.

Alternate Phase A

Using the calculation code developed in the first 4 phases, implement the entire application as a web site using MVC. The scope of this approach could be expanded to have the user interface mimic a calculator's interface with number and operation buttons.

Alternate Phase B

Using the calculation code developed in the first 4 phases, implement the entire application as a REST API, with a single page application (SPA) framework such as AngularJS as the user interface.