Local High School Visit

Friday May 17, 2013, Haley and I went to the local high school to speak with the computer science class. We did a small presentation followed by any questions the students had. We presented some myths in the industry, best practices, things we like and don’t like, and some tools we use.

I was very nervous at the beginning of the presentation. It had been over four years since I gave a presentation. My voice was a little shaky until I got through the first joke. Once everyone started laughing, I settled in and did the presentation well (at least that’s what everyone told me). Haley answered questions and added comments to the presentation.

The students asked a wide variety of excellent questions. Things like “where do you find clients?”, “what programming language do you mainly use?”, and “why are we typing (null,null) here?”. One question that was an unexpected surprise was when we mentioned we create windows phone apps. One student asked if we create apps for Windows Phone 7 or Windows Phone 8. I thought that was awesome! I had just assumed all the students had iPhones or Androids.

It was a very fun day for Haley and me to go and speak with the students. We look forward to doing it again.

WP8: Linq to Sql MissingManifestResourceException

I was making a major overhaul of a windows phone 8 application yet to be released. It was my own fault, I made a lot of changes in a short time. I did make sure all my tests still passed. Running the application in the emulator gave me a MissingManifestResourceException. I never had this problem before. The error would occur in the base constructor for the DataContext.

The full error message was:
Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "Microsoft.Phone.Data.Resources.resources" was correctly embedded or linked into assembly "Microsoft.Phone.Data.Internal" at compile time, or that all the satellite assemblies required are loadable and fully signed.

I did the usual checks for Neutral Language setting in the Assembly Information. I made sure the Supported Cultures were correct. I added a resource file to the project. I thought maybe the template I had used to create the app didn’t include the appropriate resource file. Still nothing.

I couldn’t find anything that would confirm or deny the fact that linq to sql required cultural resource files.

After much thrashing, I found the cause of my issue. It was in the connection string. Can you see the problem?
"Data Source=isostore;/children.sdf"

It’s the semi-colon. The connection string should have been:
"Data Source=isostore:/children.sdf"
My typo in the connection string gave me an obscure error which lead me on a wild goose chase down the wrong path.

So, lesson learned. Always double check you are using a colon ":" in your connection string.

Raspberry Pi and Adafruit Starter Pack: Ambient Light Warning

Let me start by saying I am not an expert nor an engineer.

I received my adafruit start pack and proceeded through the tutorials with the parts I had available.

This is the result of combining the Basic Resistor Sensor Reading and Raspberry Pi E-Mail Notifier Using LEDs tutorials. You should read/do those tutorials.

I made this system that would turn on the green led when there was ample light, blue for the transition between light and dark, and red for when there is minimal or no light. The reason for doing this? I had no other sensors to connect at the time.

So, let’s begin.

* I assume you already have the Pi Cobbler inserted in the breadboard.
* Warning: Don’t have your Raspberry Pi connected to the breadboard or don’t have power to your Raspberry Pi. We really don’t want to fry something while setting things up.

  • Connect the GND pin (ground) to the blue power rails (-ve).
  • Connect the 3V3 pin (3.3 Volts) to the red power rails (+ve).
  • Use jumper wires to relocate pins #23, #24, and #25 to individual and easily accessible rows on the breadboard.
  • Add resistors (any values from 330 ohm up to 1000 ohm should be fine) to each of the jumper wire rows, connecting to the other corresponding side.
  • Connect your LEDs where the short leg (-ve) connects to the blue rail and the long leg (+ve) connects to the same row as an inserted resistor. (On my board, the Green LED is on #23 and row 24, Blue LED is #24 and row 27, and Red LED is #25 and row 30).
  • Connect a jumper wire from pin #22 to an available and accessible row.
  • Connect the 1uF capacitor’s -ve leg to the blue rail and the other to the row with the newly attached jumper wire for pin #22.
  • Connect one side of the photocell to pin #22 and the other to the red power rail (3V3).

The overhead shot of my setup:
ambient_setup

Now to program the Raspberry Pi. The OS I used was adafruit’s occidentalis.

Getting the necessary packages: (If you already have them you may skip this part)

$ sudo apt-get install python-dev
$ sudo easy_install rpi.gpio

Once those packages are installed we can write the program.

$ sudo vi ambient_warning.py
#!/usr/bin/env python

import RPi.GPIO as GPIO, time, os
# The levels required changing based on the type of light I was in.
# In sunlight, the photocell readings ranged from 15 to 105. In 
# artificial light the readings were much higher.

# Artificial light
#LEVEL1 = 160
#LEVEL2 = 300 

# Sunlight
LEVEL1 = 30
LEVEL2 = 60

DEBUG = 1
GPIO.setmode(GPIO.BCM)
GREEN_LED = 23
BLUE_LED = 24
RED_LED = 25
GPIO.setup(GREEN_LED, GPIO.OUT)
GPIO.setup(BLUE_LED, GPIO.OUT)
GPIO.setup(RED_LED, GPIO.OUT)

def RCtime (RCpin):
	reading = 0
	GPIO.setup(RCpin, GPIO.OUT)
	GPIO.output(RCpin, GPIO.LOW)
	time.sleep(0.1)

	GPIO.setup(RCpin, GPIO.IN)

	while (GPIO.input(RCpin) == GPIO.LOW):
		reading += 1
	return reading

def ResetWarningLights ():
	GPIO.output(GREEN_LED, False)
	GPIO.output(BLUE_LED, False)
	GPIO.output(RED_LED, False)

def SetWarningLight (level) :
	ResetWarningLights()
	if (level <= LEVEL1) :
		GPIO.output(GREEN_LED, True)
	elif (level <= LEVEL2):
		GPIO.output(BLUE_LED, True)
	else:
		GPIO.output(RED_LED, True)

ResetWarningLights()
while True:
	level = RCtime(22)
#	print level
	SetWarningLight(level)

Save your file, double check your board layout, connect the raspberry pi to the breadboard, and run your program.

$ sudo ./ambient_warning.py

If everything is correct you should have an LED on based on the amount of ambient light.
full lighthalf_lightdark

A Different Thought Process: OOP to Erlang

I’ve been dabbling in functional programming lately, more specifically in erlang. I am familiar with recursion. I do use recursion on occasion when code simplicity outweighs the possible performance cost. I am reading Erlang Programming by Francesco Cesarini & Simon Thompson. I am enjoying the book, although I’ll admit I’m not very far into it. I would like to share a realization that I had during one of the exercises: don’t think in objects, think pattern matching.

The exercise consisted of creating a simple database. The underlying structure was a key/value pair contained in a list. The interface consisted of new, destroy, write, delete, read, and match. I am going to focus on the read(Key, Db) function, where Db is the list obtained from calling new. After adding data consisting of key/values, I would call the read function with the specified Key.

My initial implementation was as such:

read(_Key, []) -> {error, instance} ;
read(Key, Db) -> 
  [Head | Tail] = Db,
  case Head of
    {Key, Data} -> {ok, Data} ;
    {_,_} -> read(Key, Tail)
  end.

I want it to be known that this does work. It looks horrid, but it does work. Imagine if this were a more complex operation? My problem at the time was thinking the Db argument was a list. I would then pull out the Head (first item in the list) and Tail (remaining list items) once in the function. This was so wrong of me. I was thinking OOP and not pattern matching.

When I remembered Pattern Matching can be used for deep matches. I refactored the read operation to three lines.

read(_Key, []) -> {error, instance} ;
read(Key, [{Key, Data} | _Tail]) -> {ok, Data} ;
read(Key, [_ | Tail]) -> read(Key, Tail).

The first implementation was using pattern matching. The matches were based on an empty list and a non empty list. The refactored code pattern matches on an empty list, a non empty list where the first item contains the key we were looking for, and a non empty list where the first item’s key did not match.

When pattern matching with functions in erlang, it seems less about what the arguments are, and more about what you want them to be.

ActiveRecord and MySQL Setup on Ubuntu 12.04.1

As a .Net developer I thought I would give Ruby and ActiveRecord a try for a simple web application. When I say simple I mean it’s only two operations. One consists of non-authenticated data entry and the other of data retrieval. Install of everything went fine, or so I thought. It turns out that there are some intricacies in getting the right activerecord to work on Ubuntu.

This is a quick blog post of getting activerecord to work with MySQL on Ubuntu 12.04.1 LTS. This is a result of me searching a bunch of other blogs and tutorials to figure out what I was doing wrong.

Getting the files

>sudo apt-get install mysql-server
>sudo apt-get install ruby
>sudo apt-get install rubygems
>sudo gem install activerecord
>sudo apt-get install libmysqlclient15-dev
Note: this may install “libmysqlclient-dev” instead, which should be fine.
>sudo gem install activerecord-mysql2-adapter

You should now have all the required files.

Setup test database

Connect to MySQL and create a database and table.

>create database dummy;
>use dummy;
>create table tests(id bigint primary key auto_increment, text varchar(100));

A test ruby file: atest.rb

#! /usr/bin/ruby
require ‘rubygems’
gem ‘activerecord’, ‘=3.2.9’
require ‘active_record’

class Test < ActiveRecord::Base
end

ActiveRecord::Base.establish_connection( :adapter => ‘mysql2’,
  :host => ‘localhost’,
  :username => ‘username’,
  :password => ‘password’,
  :database => ‘dummy’
)

Record = Test.create(:text => ‘new record text’)
Inserted_records = Test.where(:id => 1)
# It is recommended to use “find” instead of “where“ when selecting by the primary key.
# I used where as a test to make sure I had everything installed and working
Puts inserted_records[0].text

Make sure you have a reference to the gem in your ruby file. If you don’t, when you go to use the ”where” method you will receive a method_missing error. As of writing, the active record gem version was 3.2.9.
Also make sure the adapter in the establish_connection method is ‘mysql2’. Using the older ‘mysql’ adapter will also cause issues.

Note

I did skip creating a new user and granting access to the mysql database as that was an easy web search.

Initial thoughts on the HTC 8x 16GB WP8

I recently picked up two Windows Phone 8 devices. The HTC 8x 16GB and a Nokia Lumia 920. Out of the kindness of my heart, I gave the Nokia to my wife and I kept the HTC. I am giving my thoughts after using the HTC 8x for a few days.

Now, let me preface this by saying the HTC 8x is a very nice device. I do like it. There are a couple of issues that I am going to have to get used to. These issues may go away when I get a case for the phone. It also may sound like I am envious of my wife’s Lumia 920. This may be the case, but there are things about my phone that she is envious of. To be honest, if I had the choice again… to hell with being nice. I would keep the Nokia Lumia 920 for myself.

Starting with what came out of the box. The phone, of course. A micro usb cable, a 5v 1A charger, and documents. This is the basics. I was a little surprised there were no earbuds and mic. I thought for sure there would be considering it has Beats Audio. My wife’s Nokia Lumia 920 had head phones. Maybe I received a box where the earphones were missing? It’s ok though. I can use the ones that came with my Samsung Focus. Basics out of the box are phone, micro usb cord, charger, and documents.

I do like the sound the phone is able to reproduce. The HTC 8x automatically enables Beats Audio when you plug headphones in. I was testing using earbuds from my old Samsung Focus. I thought the music sounded pretty good. The speaker itself did well providing I didn’t have it muffled on my desk. I was going to test the audio for movies, but that will have to wait until we are allowed to load movies purchased through Zune. Overall, I thought the speakers and Beats Audio were very well done.

The HTC 8x had four custom apps out of the box. The HTC came with a flashlight app, unit converter app, photo enhancer app, and the HTC app (this includes local weather, news, and stock quotres). My wife is envious of the unit converter app. The app is elegant, fast, and easy to switch unit types. Photo enhancer is for adding effects to your pictures, such as making them look vintage. The Lumia 920 on the other hand came with an array of apps. I think there were four camera apps alone for the Lumia 920. There are a modest number of apps for the HTC 8x compared to the Lukia 920.

I haven’t had a chance to tinker with all the settings on this phone. There is a setting for those with hearing aids. This will increase the volume while you are talking on the phone. There is also attentive phone. This allows the phone to adjust to external actions during ringing. When enabled, the phone can quiet the ring on pickup, mute the ringer if you flip over your phone, or use a loud ring when the phone is in your pocket or purse. I don’t get many phone calls, that’s why I haven’t gotten to all the settings.

The phone is a good size and aesthetically pleasing. It is smaller and lighter than the Lumia 920. The HTC 8x has a nice feel to it. There are issues for the way I hold my phone. I prefer holding the phone using three edges instead of using a death grip on two. I hold the phone with my pinkie finger supporting the bottom edge of the phone. The phone has rounded edges on all sides and the micro usb port is located on the bottom edge. I find that because the phone is rounded, the edges of the usb port rub against my finger. This will probably not be an issue once the gel cover case arrives. The screen is very clear and the phone looks very nice.

Now, here is my main gripe with the phone. The power button is located on the top edge. I am finding it very inconvenient since I hold the phone using the bottom edge. Whenever I want to turn on the phone I either have to adjust the phone in my hand (fingers aren’t quite long enough) or use my other hand. Two hands to turn on your phone is non-optimal. This is where the Lumia 920 is really better suited for me. All three buttons are on the right edge of the phone. Ideal for one handed access and use of all three phone buttons. I may get used of it, or become more eficient of one handed turn on using my face (chin works well. I may look stupid in public though). The power button on the top is kind of a deal breaker for me.

Results so far: If I had known then what I know now. I would have gone with the Lumia 920. Just so I could have the power button on the side. Other than that, the HTC 8x is a very nice phone. At 16GB it is less than what the Lumia 920 has, but I never filled my old Samsung Focus with only 8GB. Am I happy with this phone? Yes, for the most part.

I know what people are thinking, “don’t hold it like that”.

CodeStock 2012: Good Books Open Space

I wanted to share the list of good books that were suggested during the open space.

  • Life of Pi by Yann Martel
  • Go Tell It on the Mountain by James Baldwin
  • Ender’s Game by Orson Scott Card (Aside from Ender’s Shadow, apparently the rest of the series is not all that great)
  • AWOL on the Appalachian Trail
  • A Walk in the Woods by Bill Bryson
  • Blood Meridian by Cormac McCarthy
  • Atlas Shrugged by Ayn Rand
  • The Fountain Head by Ayn Rand
  • Anthem by Ayn Rand
  • River of Doubt by Candice Millard
  • Wool by Hugh Howey
  • Ready Player One by Earnest Klein
  • Selarial’s Song by Brewer
  • Hunger Games Trilogy
  • Dragon Tattoo by Stieg Larsson
  • The Monster Hunter Series by Larry Correia
  • After America by John Birmingham
  • 1632 by Eric Flint
  • Fuzzy Nation by John Scalzi
  • Old Man’s War by John Scalzi
  • Iron Druid Chron by Kevin Hearne
  • MetaGame by Sam Landstrom
  • Song of Ice and Fire by George R. R. Martin
  • Daemon by Dan Suarez
  • Blindness by Jose Saramago
  • Death Interrupted (Death with Interruptions) by Jose Saramago
  • Leadership and Self Deception
  • Flash Forward by Robert Sawyer
  • Color of Magic by Terry Pratchett
  • Lies of Locke Lamora by Scott Lynch
  • Troy Rising by John Ringo
  • The Mote in God’s Eye by Larry Niven
  • Saga of 7 Suits by Kevin J. Anderson
  • Pastwatch: The Redemption of Christopher Columbus by Orson Scott Card
  • First & Last Men by Olaf Stapledon
  • I am Legend by Richard Mathison
  • Mistborn by Brandon Sanderson
  • Now Habit by Neil Fiore
  • Name of the Wind by Patrick Rothfuss

Late to the Game

This is my first foray into blogging. Be forewarned this is TL;DR and it’s about me and how I got to where I am now. I am an independent consultant located in a small town in Canada. Be gentle in the comments, again, this is my first time.

If you had told me in high school I was going to be a software developer, I would have laughed. My hopes and dreams were a hockey star or basketball star. I knew nothing about computers. It was around 1993 when a lot of my classmates had computers and I was marveling at the idea only having to type an essay once. They could save, edit, and reprint their essays with ease. I thought that was a fantastic idea. I asked my parents for a computer to help with writing essays. I got a typewriter. In all fairness to my parents I was a huge gamer and would spend countless hours on my Sega/Nintendo in the basement. Almost every weekend my buddy and I would pool our money and rent a Super Nintendo and Street Fighter II: The World Warrior. I completely understand my parents’ reasoning for not buying a computer. At the end of high school I still had no knowledge of computers.

University, the first time, is when I really got introduced to computers. My roommate had a computer. There were three of us sharing this one computer. Really we just took turns playing games, usually Civilization II. Three guys, one computer, eight hour shifts. I got the midnight to eight am shift. Let’s just say classes were not regularly attended by me. I was always tired and the classes were really uninteresting. I was majoring in chemistry. By the end of the first year I was placed on academic probation for a low GPA. Not much changed in the second year, except I took one computer course. I did really well in that course because I was interested in it. However, it was not enough to bring my GPA up. I was on academic suspension for one year. Those two wasted years at University gave me an introduction and a passion for computers.

Immediately after being suspended, I enrolled into a community college. This time would be different. I had a direction and a purpose. I enrolled into a Computer Technician course. I learned the inner workings of computers and was introduced to programming for the first time. It was Turbo C and assembler. It was very minimal programming as this was a course on how to repair computers. Still, the problem solving involved in programming got me hooked. After this ten month course I graduated with flying colors. I was now a computer technician.

I got a job fixing computers in a small city. Things were going well. Over time though, my job evolved. Not in the direction I wanted. I worked in a small office equipment repair shop. We started seeing fewer computers and more photocopiers. We were the Sharp dealer in town. We then also became the Pitney Bowes dealer for the area. This meant an influx of photocopier repairs. I learned how to repair and maintain photocopiers. I saw this as a step backwards from where I wanted to go. I wanted into software development. I enrolled back into University, this time for a Computer Science degree.

As a side note, in the 2002 NHL Stanley Cup playoffs I joined a hockey pool. I bet big on the Carolina Hurricanes as the underdogs. They did well that year and made it to the finals losing to the Detroit Red Wings. I won the playoff pool, and with the money I bought Microsoft Visual C++ .Net Standard.

This second time in University was again different. I still had a goal and a direction. I was focused, determined, and working full time. The first year back in 2002 went great. I was excited things were going extremely well. In 2003, I enrolled again in University, but couldn’t fix photocopiers anymore. I got a new job, in a different city as a support person for a software company. This posed a problem as it was too late to transfer to another university. I didn’t want to give up the entire year, I was disappointed. Luck was on my side as the course I was enrolled in decided to change their time slot to being once a week on Wednesday night. I was thrilled. I didn’t have to give up my entire year. Yes, I was only taking one course, but it was something. It was a difficult year. Every Wednesday I would leave work early, drive two and a half hours to make it to class for 6pm to 9pm, and then drive two and a half hours home. There were a couple of times I didn’t go due to snow storms and there was one time I did go through the snow storm only to find out when I got there class was cancelled.

After that year of traveling, I transferred to the new and my final University. I worked and went to school part time for a few years. I was able to work my way into being a part time developer, but mostly support person at that software company. Then my girlfriend (now wife) gave me a chance to finish my degree faster. She let me quit work and go to school full time. She was already a software developer, an independent consultant with two clients. I took her up on that offer and promised to make it up to her. I finally finished my degree in 2008. Twelve years after my initial entry to University.

The reason I am telling you this is I was late to getting into computers, but it really is never too late. I go to conferences, they are the greatest thing a software developer can do. You meet so many awesome people, hear so many stories, and gain so many new friends. You do hear a similar story, a lot. They grew up with computers, what their first computer was at the age of ten to fourteen, what they started programming with and so on. I didn’t get really into computers until I was twenty. I didn’t really get into software development until I was twenty four. I was late to the game. I’m sure my story is not unique. It’s just a little different. I’m sure there are others out there like me that had a later start and a difficult road to get into software development. I’m proud of what I’ve accomplished and where I am in the development game. I also look forward to where I am going, and what other accomplishments I haven’t achieved yet.