Saturday, August 9, 2014

Do What You Love

Riding Bauline, Newfoundland, 1999
I love a lot of things. My wife, my kids, my music, and my many passions. One of those has been with me as long as I can remember.

That is biking. I still remember one of my first bikes. It was a yellow bike that was branded the Mark II. Pretty sweet and I am sure my parents felt they hit the jackpot when they came across that bike. Boy I loved that hard plastic wheeled bike. Not even inflated tires. It was a tank and had traction about as good as you'd think for hard plasticly (very hard rubber) tires.

Of the many forms of biking, Mountain biking holds a big place in my heart, for things I love.

It's something that sits unloved sometimes. Gathering dust in the garage, tires deflating, oil drying out, forgetting the thrill of the trail.

Then a call or text comes, "Want to go biking?" Hell yes I do!

I get out the gear, I prep the bike, and I go.

The other night I went for a ride.

It was great to get on the trail and hurtle downhill at speeds my Mom would disapprove of and my kids would watch in disbelieve.

Nothing quite beats the sensation of throwing that bike around underneath you as your legs and arms pump it over roots, rocks, around ruts, and then throw the bike (and you) into a turn.

As we speed down a section of trail with beautifully hard packed corners, I saw a rise coming in the middle of the S as the turn I was dipped into, leaning over to the right, was going to transition into a fast left hand turn before switching back to the right. Stupidity came over me and I said, I bet I can jump that rise right into that left turn and swoop through this set of curves.

I write this like I had time to think this out. There was no time, my brain thought it, and I pulled up. The bike and I flew into the air.

Was this a good idea I started to think. But before I could finish the thought, the bike and my body knew what to do. Lean back to the left like I was entering that turn on the ground instead of in the air like I was.

Thump! The tires hit. My legs and arms bent. And my ass and rear wheel threw my bike and I into the turn and we both flew through it beautifully.

We had done something stupid again and both made it through.

Mountain biking is freeing. It frees the mind and the spirit.

Mountain biking is exhilarating. Am I going to fast? Will I make this turn? Phew! Did it.

Mountain biking is pounding. It makes the blood flow and the muscles ache as you drive to go faster and climb the hill back up.

Mountain biking rejuvenates my youth as I slip back into my gear and get to pretend to be a Scout Trooper on his speeder bike, whizzing through the forests of Endor.

What do you love?

Go do it.

Remember why you love it.

Tuesday, August 5, 2014

The Illusion of Expertise

Replacing a section of my front
step. Definitely not my area
of expertise.
How much time does it take to become an expert with a new thing?

Let's pick a language.

I mentored a Junior Engineer on a work term who did some Perl development for our project. He then applied to work with us full-time when he graduated. Hey, I must have done something right to have him want to come back.

When reviewing his resume he had listed Expert Perl Knowledge or some such phrase. He wrote 2 scripts for us based off of scripts I had written. I asked him in the interview if he had done more with Perl after we introduced him to it. Nope.

Expert level knowledge? Sheesh!

As a professional developer I get asked to solved problems I have no idea how to solve every day. It's par for the job.

This is no different than many jobs I am sure. I know I have asked building contractors to build or fix something that they've never built or fixed before. So as a professional your expertise comes from being able to tackle these problems without fear. I am paying them for their past experience and ability to successfully deliver; same goes for being a software developer.

What do I mean by without fear?

I have worked with people that say they can't do something since it is outside the realm of their experience? They are asked to add some new functionality to an existing app or script and they say they can't, they don't know that language. I think this is the wrong attitude.

As an Expert, you are expected to step up and say, "Sure, I don't know that language but the program is already written and it just needs some small changes. I can take that on and learn a bit about the language it is written in at the same time. Thanks."

That's how I like to approach tasks outside my realm of Expertise. With contracting, this has become something I have to say more often. Does it slow me down to learn a new language? Sure, I don't know it off the top of my head but with the wealth of information on the web and help within IDEs, there is no reason not to jump in and try out a new language.

If you think you need to be trained in a language or domain to work in it, then you are missing out on being more useful to your team. Being willing to jump in and work in any language is a plus for you in your career that will make you more valuable as an employee.

Don't fear your lack of expertise. Dive in and take on challenges. You grow more from them than staying in your comfortable shell.

Saturday, August 2, 2014

Building Web Services Quickly

Haven't We Been Here Before?
Seattle from the harbour.

The last time I built a web service was back in 2009. I figured out Google App Engine (GAE), it was great since it used Python (my pet language at the time) and with free hosting at the level I was going to use it, that was the platform for me.

I built Hockey Tweet with GAE and then designed Tweety10, a Cocoaheads Ottawa app, which a team of 6 built in 3 weeks in 2010 for the 2010 Olympics to use GAE as well. I ramped up one of the guys on GAE and he built out our web service while I worked on whatever needed my help.

What's This Web Service For?

I have a team that is interested in hiring me, possibly on contract, for their app. They would like a portfolio to see what I have done; which is hard to show when you work for large companies. So I am building a demo app, that will have a web service backend. As such I need to build a web service to simulate some of the features they mentioned. So I am cooking up a web service to simulate the backend service they want to build. I figure this is a good portfolio piece.

You see, I have worked for many teams/companies but those have been larger teams that had many people building the end-to-end solution. For this, I need to show I can build the app end-to-end. They are looking for their own on-site web services programmer but I need something to build my app against for the demo.

I also want some experience with technologies/framework/APIs I have not used yet. There are a lot of frameworks and APIs available to use in modern mobile apps and as such it is hard to find time to learn stuff you don't need for your day to day job. So, I want to try out some stuff I would need for this project, if the team decide to go with me, and also that will help me improve my portfolio to show that I can build an app from scratch with various technologies to meet a clients needs.

Tonight I laid out the storyboards for the app based on the initial use cases the team told me about. The storyboards let me get an idea of what data I will need to support the app. With that in mind I can also think about what the API calls should be. I see the storyboards as a visual walkthrough of the user stories, a kind of overview of the apps back-end.

Deciding on the Web Service Framework

I did some research an evening or two ago on various web frameworks so I could figure out what to mockup the backend web service in. I decided on sinatra, which is built on ruby. It is an alternative to Ruby on Rails and instead of following a Model-View-Controller design it is geared towards quickly developing a web application. So in other words, throw good design to the wind and hack up that web service fast. Perfect.

With Sinatra, you get the basics, but there are some additional features I want which were easy to add. I have added the following gems:
  • gem install sinatra
    • Basic sinatra framework
  • gem install sinatra-authentication
    • Adds authentication framework for your apps. I want to simulate adding users, login, logout, and then mapping users to resources (i.e. events for a user)
  • gem install sinatra-jsonp
    • To add json data payloads.
  • gem install shotgun
With that I have a basic web service running that I can talk to.

Next I will start to build up the API and write tests to hit the web service. I will then start to fill in the app by populating the UI with the data I am pushing from the web service.

I could skip the web service and do this with dummy data in the app but I want some current experience building a web service and so I am approaching the demo app this way.

Monday, July 28, 2014

Today's Challenge: Move

I took a couple weeks off from running. Studying for an interview, a trip, my wife on a business trip (solo Dad with 2 kids), and working on my house meant I had to cut something. So I cut running.

Thankfully, the house has been a good physical activity that has included a bit of movement to keep me happy. You see, I am happy when I am physical.

For me, running, swimming, biking, and everything else I do is not just to stay in shape, it's to stay happy. Read any number of studies and think about our past. Humans were meant to move.

So this morning I got in a run and I feel awesome. The thing is, before the run, and last night I knew I would go for a run today but I did not want to. I am sure you probably don't want to either.

Here was my thinking yesterday:

  • I am too sore from house work (painting, caulking, scraping paint).
  • I have put on weight not working out the past 3 weeks.
  • My sneakers are probably too old and I will be sore.
  • I'll probably get blisters.
  • Blah Blah Blah
RUN!

I woke up at 6:15 AM this morning and felt great. Surprising since last night I went to bed about 10 after taking some Advil since I was aching all over. I was painting the house this weekend and spent a solid two days working on the house. It is coming along great but I did not expect to wake up feeling good.

So, I ignored my few aches and pains. I stuffed my fat ass into a pair of running shorts. I laced up those old sneakers. And I pounded the pavement.

As I ran I felt free. I felt alive. I felt good.

Ya, it was not my best run, my fastest, or my cleanest. But I did it.

As I thought about this I realized we are just meant to move. This movement can come in many forms. For example, if you are like me you don't wake up thinking, how can I squeeze in some time to paint the house today? But these days I think that. Is it just the fact that house is going to look good? Maybe a bit but a lot of it is climbing up and down that ladder. It is movement.

When I bought our current house I had many people tell me it was a mistake. They said, "You should have gotten a new house so you don't need to do any work on it for 5-10 years."

You know what those people were telling me? You need to find more ways to not move.

Screw that.

I think you should buy that house that needs a coat of paint. It needs some work done. Don't know how to do it? Great, learn. I sure as sunshine don't know how to do a lot of what I do. I just figure it out.

The best part of figuring it out and doing it is you get so many intangible benefits. You get exercise. You get a sense of accomplishment. And you get to know you just paid yourself first since you never paid some contractor to do a job you won't be happy with since it took longer than you expected and cost more than you wanted to pay.

So, for me. I say, find more ways to move. Find more ways to learn. Find more ways to work with your hands. Even though you think that it will suck, you'll thank yourself in the end for having done it.

Your challenge today? Move.

Friday, July 25, 2014

Snooping On Mac OS X Apps

On iOS an app is limited in scope to it's sandbox (unless you are on a jailbroken device) and so you can take a quick look at the apps filesystem within Xcode to see what it is storing. This is not so for the keychain but you can guess the keychain is in use if the app links the Security.framework.

Now, for Mac OS X, since the app may have access to more resources it can be harder to track down what resources the app you are testing is using. There are a couple ways to figure this out though. Here are the ways I use to get an idea what resources a Mac OS X app is using:

  • Activity Monitor.app
    • Launch Activity Monitor
    • Find your app
    • Double click it
    • Choose the "Open File and Ports" tab.
    • See what the app has open currently
  • Use Dtrace
    • This is the long bread method of finding out what your app is doing.
    • Even better you can trace all file opens on a specific process (meaning you get a trace of the opens int eh terminal).
    • To do this open Terminal.app
    • This command must be run as root so I will show you the command with sudo at the front which will prompt the terminal to ask for your root password to complete the command:
      • sudo opensnoop
Here is sample output from opensnoop:
sudo opensnoop
  UID    PID COMM          FD PATH                 
   89  72769 mdworker       7 /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/System/Library/Frameworks/OpenGLES.framework/glp_sh_interposer.dylib.dSYM/Contents 
   89  72769 mdworker       7 /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/System/Library/Frameworks/OpenGLES.framework/glp_sh_interposer.dylib.dSYM/Contents/Resources 
   89  72769 mdworker       7 /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/System/Library/Frameworks/OpenGLES.framework/glp_sh_interposer.dylib.dSYM/Contents/Resources/DWARF 
   89  72769 mdworker       7 /Developer/Applications/Xcode.app/Contents/Library/Spotlight/uuid.mdimporter

Notice that you get the User ID, the Process ID, the Process (COMM), the File Descriptor, and the Path to the file that was opened.

You can play with opensnoop to limit by process name, process id, etc.  Here is the usage output:
USAGE: opensnoop [-a|-A|-ceghsvxZ] [-f pathname]
                 [-n name] [-p PID]
       opensnoop                # default output
                -a              # print most data
                -A              # dump all data, space delimited
                -c              # print cwd of process
                -e              # print errno value
                -g              # print command arguments
                -s              # print start time, us
                -v              # print start time, string
                -x              # only print failed opens
                -Z              # print zonename
                -f pathname # pathname name to snoop
                -n name # process name to snoop
                -p PID # process ID to snoop
  eg,
       opensnoop -v             # human readable timestamps
       opensnoop -e             # see error codes
       opensnoop -f /etc/motd   # snoop this file only

I like to use this by process name, start the process, run the app a bit to exercise most of the functionality, and then look at what opensnoop found. Turn on printing of the errno values and you can see if any file opens are failing.

Come to think of it, another Dtrace script I love is errinfo. This one will show you system calls that are returning an error. It is a good one to use when you know the name of a process having a problem. For example, I once worked with a app that was not logging when it launched another process but the process never started. Missed error checking aside, I used this to show that the exec was failing due to a permission error. The permissions on the sub-process were not set correctly and the other process, running as a different user could not exec the process since it did not have the correct permissions. We fixed the missing error checking and the permission error and all was well.

If you want to know what Dtrace scripts your Mac has then run "apropos Dtrace". Here is what my Mac is showing for Mavericks:
Tcl_CommandTraceInfo(3tcl), Tcl_TraceCommand(3tcl), Tcl_UntraceCommand(3tcl) - monitor renames and deletes of a command
bitesize.d(1m)           - analyse disk I/O size by process. Uses DTrace
cpuwalk.d(1m)            - Measure which CPUs a process runs on. Uses DTrace
creatbyproc.d(1m)        - snoop creat()s by process name. Uses DTrace
dappprof(1m)             - profile user and lib function usage. Uses DTrace
dapptrace(1m)            - trace user and library function usage. Uses DTrace
diskhits(1m)             - disk access by file offset. Uses DTrace
dispqlen.d(1m)           - dispatcher queue length by CPU. Uses DTrace
dtrace(1)                - generic front-end to the DTrace facility
dtruss(1m)               - process syscall details. Uses DTrace
errinfo(1m)              - print errno for syscall fails. Uses DTrace
execsnoop(1m)            - snoop new process execution. Uses DTrace
fddist(1m)               - file descriptor usage distributions. Uses DTrace
filebyproc.d(1m)         - snoop opens by process name. Uses DTrace
hotspot.d(1m)            - print disk event by location. Uses DTrace
httpdstat.d(1m)          - realtime httpd statistics. Uses DTrace
iofile.d(1m)             - I/O wait time by file and process. Uses DTrace
iofileb.d(1m)            - I/O bytes by file and process. Uses DTrace
iopattern(1m)            - print disk I/O pattern. Uses DTrace
iopending(1m)            - plot number of pending disk events. Uses DTrace
iosnoop(1m)              - snoop I/O events as they occur. Uses DTrace
iotop(1m)                - display top disk I/O events by process. Uses DTrace
kill.d(1m)               - snoop process signals as they occur. Uses DTrace
lastwords(1m)            - print syscalls before exit. Uses DTrace
loads.d(1m)              - print load averages. Uses DTrace
newproc.d(1m)            - snoop new processes. Uses DTrace
opensnoop(1m)            - snoop file opens as they occur. Uses DTrace
pathopens.d(1m)          - full pathnames opened ok count. Uses DTrace
perldtrace(1)            - Perl's support for DTrace
pidpersec.d(1m)          - print new PIDs per sec. Uses DTrace
plockstat(1)             - front-end to DTrace to print statistics about POSIX mutexes and read/write locks
priclass.d(1m)           - priority distribution by scheduling class. Uses DTrace
pridist.d(1m)            - process priority distribution. Uses DTrace
procsystime(1m)          - analyse system call times. Uses DTrace
runocc.d(1m)             - run queue occupancy by CPU. Uses DTrace
rwbypid.d(1m)            - read/write calls by PID. Uses DTrace
rwbytype.d(1m)           - read/write bytes by vnode type. Uses DTrace
rwsnoop(1m)              - snoop read/write events. Uses DTrace
sampleproc(1m)           - sample processes on the CPUs. Uses DTrace
seeksize.d(1m)           - print disk event seek report. Uses DTrace
setuids.d(1m)            - snoop setuid calls as they occur. Uses DTrace
sigdist.d(1m)            - signal distribution by process. Uses DTrace
syscallbypid.d(1m)       - syscalls by process ID. Uses DTrace
syscallbyproc.d(1m)      - syscalls by process name. Uses DTrace
syscallbysysc.d(1m)      - syscalls by syscall. Uses DTrace
topsyscall(1m)           - top syscalls by syscall name. Uses DTrace
topsysproc(1m)           - top syscalls by process name. Uses DTrace
weblatency.d(1m)         - website latency statistics. Uses DTrace

Have fun with Dtrace, it can open up your debugging and give you a view into processes you don't own.

Wednesday, July 23, 2014

Breaking Mac Apps

One of the reasons I took my current gig as a Software Development Engineer Test (SDET) was so I could learn more about my craft of software development. Too often as the developer under stress to get something out the door it can be tempting to do the minimum testing possible to get the feature out the door. That temptation is tempered by the fact that you know if you ship crap then you will have more headaches than spending the extra time now to get it right.

So, I wanted to concentrate on breaking a product too see what I learn by finding it's rough spots. This has been fun at times in the sense that I am actually learning ways to more effectively test my own software. I plan to use this knowledge to write better software myself.

I am currently testing a product on both Mac OS X and iOS. As a dev I have some things I learned from writing Mac apps that I have been able to put to use in my job as a tester.

One of those is to always test the First Run case. What is this? The First Run test involves running the app as if you were a new user installing and running the app for the first time.

How to do this on Mac?

  • Does the app use the Keychain to store anything? Find out and make sure to clear it before you run the test.
  • Does the app use the User Defaults to store anything? Probably, so go learn the command line tool defaults. Here is a short primer:
    • Open Terminal.app
    • Run this: defaults
      • Now you have the standard usage (screenshot shown above).
    • If you app's defaults are stored in the domain "com.mycompany.myapp" then type this to view what the app is storing: 
      • defaults read com.mycompany.myapp
    • Now before a First Run test run this to clear the stored setting: 
      • defaults delete com.mycompany.myapp
  • Does your app use any other storage? SQLLite for example? CoreData store?
    • Find out, find out where the files are stored and then delete them before you run a First Run test.
Run the test and see what blows up.

Too often we forget to retest this scenario as we work on features and the simple First Run case can get broken.

Test it often to weed out problems before new users find them.  I always run this on candidate builds for a new release to end users. I am also always surprised when this breaks since we seldom think the simple changes we are making in our app will break the First Run.

Monday, July 21, 2014

Sometimes You Just Have To Get Your Hands Dirty

Hockey Tweet in Landscape iPhone 4s (Landscape
was not in the original)
I have dropped off the radar for a bit as I have been busy with some projects. I took a week off from everything but code as I worked on porting my old 2009 Hockey Tweet app to Swift. I have written about that and will some more as I have major updates.

I was also studying for some interviews I had. One was an all day affair with a 7 hour interview that included a 2 hour pair coding session. We are still talking and no news yet to report on the job.

Outside of that I have been ramping up house work. For several reasons, I might have to sell my house (job), the house needs a new paint job, the deck needs a new paint job (or I will be replacing sooner rather than later), and of course I have all the prep work to do (caulking, 15 tubes Sunday) to even begin to paint.  Sunday I got a solid 8 hours in of caulking and then painting.

I started the painting so that I can begin alternating between caulking and painting. Since they use the hand and arm muscles differently, once I get tired with one I can switch to the other for a while. I also have over half of the house caulked now and wanted to get the front of the house completed. I figure I can do the front first and then continue the back of the house into the fall. Since you won't see if, you won't notice it is half/not done.

So, it's been a week of getting dirty. Dirty with new code as I learn to program in Swift. Dirty with house work.

Now some may ask, why not pay someone to paint your house? Heck, I wish. But at a $25,000 average quote to paint the house including prep work (some would not include prep since the amount of caulking was so daunting); I am sucking it up and being a man (frugal).

This just means I might have less posts for a while since how many blog posts can you do about painting you house? Who knows, but I am sure we will find out ;-)