2013-05-29

GeoGuessr as an Interview Question

geoguessr_thumb
Today somebody (it might have been an xkcd comic) pointed me to the addictive game GeoGuessr. I didn’t link it because if you click on it you’ll never come back to finish reading this blog post. The idea of the game is that they drop you into street view somewhere on the planet and you have to guess where you are. The closer you are to being right the more points you get. It is a very simple concept for a game but at the same time real good fun. I was playing it when somebody came into my office and asked about it. We spent 5 minutesdissectinga series of photos using logic and best guesses to figure out where we were. The whole exercise got me thinking about how I’m going to use this game as an interview tool the next time I interview somebody.

What?

Stay with me on this one. One of the more popular interview techniques for tech companies is to present a puzzle and have people solve it. A lot of people look down on puzzle interviews because it is such a gotcha style of interview. If you’ve seen the puzzle before or you guess the trick then you can get it quickly and you win the interview. I don’t mind puzzle interview questions. It isn’t because I think being able to figure out the puzzle is important it is because it gives me some insight into how well the interviewee will approach a problem. We’ve all worked with that developer who gives up in the face of a difficult problem. Throwing ideas against the wall and seeing what sticks is a hallmark of good programming problem solving. I don’t expect people to have the answers to difficult problems right away but I do expect them to puzzle out the problem.

I think that playing a round or two of GeoGuessr(I linked it there because you got this far and deserve a reward) during the interview would allow for a quick evaluation of how the programmer thinks. Just have them puzzle out loud or play with their potential team mates. In the brief time I played with somebody we said things like

“Well look, they’re driving on the left side of the road so that eliminates a lot of places. The language on the signs seems to be English. So UK, South Africa or Australia.Seems prettyarid, perhaps Australia?”

and

“Right, there is a truck. A dodge truck so North America is pretty much for sure. There is a highway marker for an in-state highway 45. So we know US for sure. I bet most states have a highway 45, it is a good number 45. No mountains so that cuts out a few places. There is a train, looks like it has grain cars ““ a lot of grain cars. Bread basket somewhere? Hey, hey look! A sign for interstate 69. Google it! It goes North/South through Arkansas and Kentucky. Let’s try Kentucky.”

This demonstrates that we’re working though a difficult problem and that we’re doing it as a team. Also this sort of thing is a great ice breaker during an interview. If you try this out before me drop me a line and let me know how it works.

2013-05-28

My First Windows 8 App

I have been putting off building a Windows 8 app for ages. I actually don’t have a a computer in the house which runs Windows 8 on bare metal but I do have a couple of VMs. Well the impending end of the developer movementfinally got me going(it ends on the 15th of June, BTW). I had read something a few months back about an open source Windows 8 app which republished your WordPress blog as an app. Perfect!

Source: http://technogerms.com/windows-8-review/Windows 8: the wettest windows not found on a submarine.

Ideapressis the project and they have a pretty simple HTML/JavaScript app which pulls down your posts and republishes them. On their site is even a wizard for creating the app. I ran through the wizard and gave it various images and an API key for wordpress.com. At the end of the process(which finished neither late, nor early butpreciselywhen it meant to) I had a zip file with a VS2012 project in it.

I threw it on a Windows 8 box (as you can only develop for Windows 8 on Windows 8) and hit F5 to run it. I ended up with a pretty darn good app. I was just about to call it good enough and publish it when I realized that none of the source code on my blog was showing up.

I use embedded gists to show source code an provide syntax highlighting. WordPress has built in support for gists. It isn’t actually difficult to do as if you append .js to the end of a gist you can get a javascript version of the gist which injects styling and a div onto your page. Pretty smart. This wasn’t working on the app for some reason, likely security related. The security model for injecting content into the page in Windows 8 is more restrictive than on a browser.

In order to fix that I pulled in a handy library called gist-embedded. This library made us of jQuery which is where I ran into my first problem. I guess that before jQuery 2.0 there were somecompatibilityissues between jQuery and the Windows 8 runtime. These have been resolved in jQuery 2.0. However, my application failed validation due to the jQuery file which nuget added. I was confused because I failed in two sections. The first was that the code didn’t run and the second was that the encoding was wrong. The encoding was easy enough to fix. You just resave the jquery file with UTF-8 encoding.

Changing the encodingChanging the encoding

But I was totally flumoxed by thecompilationerrors. I could not manage to duplicate them in the app or in IE10. Eventually I ran the validation again and found everything now worked. I guess the incorrect encoding was causing more than one issue.

Now that I had the application working the way I wanted and passing the validation I signed up for the windows store. I had to give Microsoft $49 of my hard earned dollars for the privilege of giving away a freeapplication. It is so funny that companies likeMicrosoftand Apple have tricked us into paying for the right to release software on their platform. If he wasn’t a mildly insane toe nail eater I would beinterestedto hear what RMS would say about it.

Weirdly Microsoft validate your credit card by charging a small amount then refund it and use it as a method of validating your account. They require that you enter the amount charged to validate your account. This means that if, like me, your bank sucks at posting charges with any rapidity you’ll be stuck waiting.

When setting up the application you have to enter a stunning amount of meta-data about where you want your app advertised, which age groups, what category, whether it contains cryptography”¦ it wasoverwhelming and at least half the stuff could have been replaced by setting some reasonable defaults.

At last I got to the point where I could submit my app for publishing.Yay! Now I can sit here and wait. And wait.

StepsSteps

The phase which was suppose to take an hour took a day. I’m now into hour 20 of the 3 hour security testing. I’m obviously more excited about getting this app out than I should be. No amount of refreshing seems to speed the process along. It is superunfortunatethat this process is so time consuming.

I can’t comment on the rest of the process because I’m still waiting.

Overall I think that building and distributingWindows 8 apps is more painful than it needs to be. I suppose you do get access to a global distribution channel and a place in the Windows store for your $49 but if uptake on Metro apps has been as bad as reportedthen cleaning up app submission should be high on a priority list at Microsoft.

The submission process needs to get faster. I know that the process is far better than Apple’s but it still sucks. I’m use to hitting publish in my CI system and 5 minutes later everything is up and running on my site. I don’t expect updates to be pushed out to clients with that rapidity but I do expect the app to at least be published in less than a day. App stores are the antithesisof the continuous deployment model.

Actually programming an app using JavaScript is great. I really like the JavaScript and HTML model so, so much more than dealing with XAML and C#. I’ll write more about then when I talk about writing my first Windows Phone 8 app. The security model take some getting use to and I haven’t tried a framework like AngularJS out yet so I can’t comment much on that.

Is it worth making Windows 8 specific apps? That’s a firm maybe. I don’t think it should be the default for any company but if there is a customer base asking for it then you might as well. It is no more difficult than building a normal application.

2013-05-27

Surrogate Keys are King

Choosing keys in a database can be a pretty difficult process. In university it was very simple, we came up with superkeys and compound keys and made sure things were in BCNF. In the real world that doesn’t work. Dealing with normalized databases is a huge pain. The other thing which is painful is dealing with compound keys where a record is referenced by two or more fields. I always recommend adding a unique identifier for each row of data. That key can be either an integer or a GUID, I know of arguments both ways and that isn’t what this post is about.

Iwas recently sitting in on the evaluation of a piece of software. It was the standard CRUD sort of application with a few additional features. However one of the things which was permitted was allowing users to set the value of the primary key field. As soon as the presenter mentioned it hand shot up all over the room.

“What if we have the same object ID for multiple things?” “Err, well that would never happen.” “Not true, we have 8 examples of it right here off the top of our head” “Err, well I guess we don’t support that situation”

We talked it around for half an hour and the consensus was that this was a serious design flaw in the application. The developers had assumed that a certain piece of user generated data was certain to be unique but, as it turns out, it wasn’t. Things got worse the further we pushed into the problem. There were other restrictions which further limited users’ ability to enter the data they wanted in the primary key field.Unfortunately,the work needed to change the constraints was considerable as the primary key was, as primary keys are, heavily used throughout the application.

As a general rule I never allow users to enter key information because they may make mistakes. Mistakes are made all over the place by users but these tend to have more direconsequencesas they cross from user data over into system data. Think about what would happen if the user wants to change the value they entered in that field. You now need to crawl through countless other tables and data structures looking for places where that key was used and change it.

I consider there to be a division in the application between data used by the system and data used by users. You wouldn’t want users seeing your application’s routing tables because it isn’t an abstraction about which they should have to care. Equally the IDs of records should not be visible to users. Just as you keep this data away from users you should keep the user data away from the application. I can’t count the number of problems I’ve seen which, when you drill down, turn out to be a result of the system relying on user data which becomes inconsistent.

2013-05-24

How Netflix Unblockers Work

Note: I’m totally guessing at how a lot of this stuff works so maybe don’t use it as the basis of building a space ship or anything important.

Here in Canada we get Netflix but it isn’t the same as the US Netflix. If it wasn’t for the fact that Canadian Netflix has Startgate SG-1 and US doesn’t I would be much angrier about the whole thing. None the less there are times when I want to watch something which isn’t available in Canada. I was always aware that there were services and ways of watching US Netflix in Canada but I hadn’t really bothered looking into until a friend of mine mentioned Blockless. Their service is really simple, you just need to change the DNS settings on your router and away you go. This was way easier than the SSH backed VPN tunnel to an Amazon virtual machine I had envisioned.

Blockless use cool DNS tricks to get you Netflix

Well that got me thinking, how the heck does this work? Well if I was going to set up a geographically specific service I would check theincomingIP addresses of connections and then block or allow them as I saw fit or serve out different content. This doesn’t, however, seem to be the way that Netflix works. Instead they seem to use a technology called GeoDNS. This is the same technology which is behind CDNs which deliver content from the nearest node.

When you ask the DNS server to give you an IP address for a name it usually just blindly hands you back an address. With a GeoDNS service the server will first look up your location and then return the IP address of the node which is closest. Netflix uses this to ensure that if you’re in Canada you get Canadian content.

When you change your DNS server with Blockless or Unblock Us they intercept the DNS request and substitue the US location in for the Canadian IP address. With that you now get US Netflix. The same thing can be done to simulate being in any country you want.

This is a really great solution to the pain of geolocking, but it only works if the service you’re talking to take a naive approach to their filtering. IF Netflix also checked the incomming IP address when they were serving the content then you would need to go with a fully fledged VPN. With a VPN the actual end point accessing Netflix would be in the US and there would be no real way for Netflix to filter it.

2013-05-23

Excel Dates

I love hearing stories of how things came to be in computing. One of my favorite stories is about date in Microsoft Excel. I stumbled across this story while writing some spreadsheet import code.

The first thing you need to know is that Excel stores date as a number of days since January 0th 1900. So a date with a value of 1 is January 1st 1900. You can see this by selecting a date field and changing the format to general. You’ll get a number like 41408 which is the 14th of May 2013. So that’s pretty simple except for leap years. As we all know in a leap year (every 4 years) there is an extra day in the year. However just adding a day every 4 yearsisn’tquite right. Every 100 years we skip a leap year. Every 400 years we have an extra leap year. That’s why the year 2000 was a leap year even though it is divisible by 100 (because it is also divisible by 400). Keep these leap year rules in mind, we’re coming back to them later.

Back in the mid-1980s a little company named Microsoft was trying to build a new spreadsheet program. Spreadsheets were the killer applications of the 1980s, heck they probably still are the most used applications on business computers. VisiCalc was the first consumer spreadsheet and its influence can be seen to this day. The A1 style of addressing cells waspopularizedby VisiCalc, although you can probably trace the origins further back than that. VisiCalc was released in 1979 but by 1983 it had beensupplantedby the vastly superior Lotus 1-2-3. Microsoft had already tried to compete with VisiCalc and Lotus 1-2-3 with a program called Multiplan. It did not go well.

Lotus 1-2-3. I totally remember this.Lotus 1-2-3. I totally remember this.

To be competitive with Lotus 1-2-3 Microsoft needed something new. Excel was the answer to this. To compete with the dominant player, Lotus,they needed to be able to open up Lotus 1-2-3 files, edit them and save them back again as Lotus 1-2-3 files.One of the problems they encountered enabling that was that there was a bug in Lotus 1-2-3 in how it handled dates. Lotus 1-2-3 thought that the year 1900 was a leap year so it had 366 days in that year. To maintain compatibility Microsoft included that bug in Excel. Even to this day you’ll find you can enter February the 29th 1900 despite the fact that day never existed.

The bug in Lotus 1-2-3 has survived long after the death of Lotus. It’s been 30 years but we still see the influence of one minor mistake. Amazing.

All this means that when you’re converting an excel date to another date format you actually have to take the number of days Excel tells you, subtract 2 (one for the leap year and one for the fact there is no 0th of January) then add that to 1900-01-01.

2013-05-22

Ford Sync

A few months back I bought a new car from Ford and it came with the Ford Sync system. For theuninitiatedthis system is evolution of the car radio combined with climate control, navigation and a phone interface. I took a look at a lot of systems when I bought this car because, from my perspective, the technology stuff in the car is the most important part. Years ago the quality of cars from different manufacturers was highly variable but these days they all have wheels, they all have gas tanks which don’t explode when you crash them. Of the systems I examined Sync was head and shoulders above the rest.

What do you get with Sync? First off you get navigation. There is nothing too special about the navigation system. I know it’s crazy to say that considering how amazing it is to have an encyclopedia of maps and locations at your fingertips in a vehicle. However times are a changing and GPS is common place even on $300 phones. On an expensive car I expect no less.

The entertainment system is really good and the one place where I feel like the voice control works well. My version of sync allows for the regular radio frequencies as well bluetooth and USB. And it actually works! Even with my crummy Windows phone which I’ve never managed to get working on another car. I can even tune the radio to a frequency just by talking to it.

Climate control is a total disaster of user interface design. Look at all these buttons!

Climate control disasterClimate control disaster

Still it works just fine and I’m pretty sure that there is a button in there somewhere to turn the inside of the car into one of those hurricane booths you see in the mall. I’m going to find it eventually.

The phone interface is the best part though. I mentioned earlier that it works with my phone and in fact it even reads text messages to me. That’s impressive because it doesn’t do that with my wife’s iPhone. I’ve never looked into it but I imagine there are a series of bluetooth protocols which govern how phones and cars interact. Seems strange that there would be a defect which would mean that the iPhone doesn’t work as well as the WP7 phone.

So for all this is the sync system good? Yes! Is the system amazing? Nope. There is a long way to go with these systems. What kills me is that I’m going to keep this car for a decade by which time the built in system will be so comically out of date I’ll be able to sell the interface as being the same one used on the Nina and the Pinta(not on the Santa Maria, though, that ship used PalmOS).

This sort of thing is difficult for car companies. The steering wheel in a 1982 Volvo is about the same as the steering wheel in a 2013 Volvo. Nobody is coming back to Volvo and asking for a steering wheel update. They have no experience with the rapid product cycles of technology.

If I was designing a car computer I would make it modular andplug-able. Heck, I would make it a tablet. So long as there was a consistent interface to the car (USB) then the human interface is pluggable. Why is nobody doing that? There must be smart technical people inside car companies who have come up with this approach. I wish that somebody would let them free to innovate. It had better be done before all the smart folks move over to Tesla.

2013-05-21

Missing the Hidden Costs - Metrics

When I was a teenager I worked for one week at a local supermarket as a cashier. I only lasted a week because I found a “better” job at Tim Hortons. As it turns out it was probably a far worse job but it did have the advantage that when you worked the closing shift all the donuts would have to be thrown out. From time to time a clean garbage bag full of donuts would make its way into somebody’s car instead of the dumpster. Anyway this article isn’t about how that is a greatmetaphorfor illegally downloading music, its about incorrect metrics.

The supermarket, called Superstore, had a goal of getting people through the checkout as quickly as possible. This was anoblegoal as nobody, except the English, likes spending time in a queue. They had identified that a checkout consisted of a few steps: unloading the cart, ringing the items up, paying, and packing. As this was a discount store the customer unloaded their own cart and packed their own groceries. The customer was typically the limiting factor on the speed of paying for the groceries too. This only left ringing the items up as an optimization point over which they had control.

superstoreAt the end of every shift we would be given a print out of the number of items a minute we were scanning. The goal was to spend no more than 2 second scanning an item so that you would end up with 30 items/minute as your average. These numbers were all rolled up and the store would report back to corporate with an average number. 30 items/minute seems pretty low for just passing a barcoded thing in front of the scanner. I had forgotten all about this metric until I was in a Superstore last week and they had left out a graph with the averages for that store.

22.45 items/minute.

I was greatly amused to see that the metric was still in force and even more amused to see the number was so low. See in my one week at the job I had averaged well over 30 items/minute, I think it was closer to 40 items/minute. It wasn’t because I was a cashier savant or because I entered into atranscendentstate and became a scanning machine. It was because I knew how to game the system and break the metrics.

First I took advantage of the multiple items button. If you buy 10 tins of cat food the cashier is suppose to hit 10 QTY and then scan the item. This is a quick way to ring in many items and is designed to get people out of the store quicker: a great idea. However in the metrics it was only counted as one scan. If, instead, you scanned each item individually it would count as 10 items. I would scan the same item 10 times in rapid succession. In this way I could get 10 scans in about 4 seconds.

The second trick was the Total button. This is the button which is pushed at the end of the transaction and denotes moving from the ringing in phase to the payment phase. Because we cashiers couldn’t control the length of time a customer would take to pay us we weren’t measured on this phase. However you could get out of the payment mode and back into the ringing in mode by just pressing Exit. I took advantage of this by hitting the Total button any time I had an item with a code on it that I had to look up or a stack of items to move from one side of me to the other. It acted as a sort of pause button.

Any scanning averages they got from me were just about useless. What’s worse is that I was not at alloptimizingfor customer experience, I was optimizing for the benchmark.

Any time you set up key performance indicators(KPIs) in a business you have to be aware that in so doing you might not beoptimizing for the things you want. You may very well be teaching people to optimize for your KPI. If your KPI is not very well thought out then the result could be a less efficient businessprocess. I’m not saying don’t measure, measurement is key. What I’m saying is continually examine not just the results of your measurements but also the process you use to take measurements.

2013-05-20

Missing the Hidden Costs - Crowdsourcing

One of the things I see quite frequently in business is that new,supposedlyoptimal processes are introduced without a full examination of the cost. It is a difficult problem because figuring out the full cost is shockingly difficult. One of the big culprits is offloading work to the crowd.

Twenty years ago nobody filled out their own expense reports. There was some person who was expert at filling out expense reports and you took that person a bunch ofreceiptsand they dealt with it. Magically a few days later your expenses were paid. Those days are gone, instead you file your own expense report through some piece of software.

I am totally incapable of correctly filling in an expense report correctly. Last time I did one it took five tries to get the report right. I’m kind of dumb but I bet that most of the expense reports which go into that system are rejected the first time. But because the system is in place there is no need to employ that expense report specialist who existed 20 years ago. Cost savings! Right? Probably not because most of the people who are now filling in expense reports are earning more than that specialist, they’re taking more time to do the reports and they’re having to redo the reports.

Another great example somebody told me about was adding a card scanner to the office printer. The goal is to prevent people printing things and then leaving them on the printer. Apparently this is a huge cost. Millions of dollars are being wasted byunnecessaryprinting. Now everybody uses their keycard to activate the printer. On the surface this is a great idea but there are hidden costs. People feel like they’re being spied upon, people have to remember to bring their swipe cards to the printer and people can no longer send print jobs to remote printers for somebody else to pick up. There are hidden costs here too.

These are just a coupple example, I see lots of others. Heck, I write lots of others. If you’ve ever seen an initiative with the words “self-serve” in their name then you’ve got a crowd sourcing initiative. It can be great to empower people to solve their own problems through a self-service model but keep in mind that there is a cost. Sure there is no longer a line item in the accounting department’s budget for an expense expert but now that cost is spread out all over thecompany If you get enough of these initiatives then they start to detract from the time people spend on the core functions of the business. Now the cost is not only that you’re paying an expensive engineer to do expenses but that engineer no longer has time to do engineering which is where you earn your money.

Watch out for those hidden expenses!

2013-05-20

Privacy Policy

Visiting this site collects no information about you other than your geographic location. We use this to plot out your location on a map, because that’s kind of cool to see.

When you comment on our site we collect your name and e-mail address. You name we show on the site and the e-mail address we retain. We’ll never send you an e-mail or give you information to anybody, ever. Don’t even worry about it.

If you’re worried drop me a line

[contact-form][contact-field label=’Name’ type=’name’ required=’1’/][contact-field label=’Email’ type=’email’ required=’1’/][contact-field label=’Concern’ type=’textarea’ required=’1’/][/contact-form]

2013-05-17

Fixing Access Result Set Locking

If you’re running an Access front end to a SQL database then there are frequently issues with table locking. From what I can tell when Access encounters a large table or view which is being used to populate a grid it will issue a query to retrieve the entire dataset using a cursor. It will then move the cursor along just far enough to see a bunch of records and hold the cursor open. This has the effect of locking a significant part of one or multiple tables. There are solutions and this blog post will take a look at a couple of them.

The first thing to do is try to identify the query which is causing the problem. In my case I found a reproducible test case in which an update query timed out. In a multi-user system this is the hardest part. I was aware the bug existed but with 40+ people in the database the problem only seemed to show up while I was at lunch and by the time I was back had cleared up. I finally narrowed it down to one screen and to verify it I ran

select cmd,* from sys.sysprocesses where blocked > 0

This query finds all the executing processes on the SQL server which are blocked. The contents of the blocked field is actually the Id of the session which is preventing the query from going through. With that information in hand you can run

with the session Id from the previous query. This will get you the currently running query which is blocking your update. Great, now you have a test case! If you want to know who is running the query you can look up the session Id against the output of

sp_who

But it doesn’t really matter which user it is. Now to fix it.

Fixing with Access

The problem we’re having is that Access, in the interests of showing data quickly, is not pulling the entire data set. You can hook into the form open and have it jump to the end of the result set to have it pull all the records and close the cursor. In the subform with the locking query add this to the form load:

Fixing with SQL Server

The Access based solution isn’t a great one because it can force Access to pull back an entire, huge, result set. This isn’t performant. Okay, Access as a whole isn’t performant but this is particularly bad. Instead we make sure that our form is based on a view instead of a table. If you’ve done anything with Access and SQL Server you’re probably already doing this because of the crippling performance issue with crossing tables retrieved from SQL server. To get rid of the locking contention you can use the table hint with(NOLOCK) in your view definition.

If your view looks like, say

and you’re running into locking issues on tblTags you can change it to look like

There is nothing stopping you from putting NOLOCK on every table in the view but it will increase the frequency of running into inconsistent behaviour. And you will run into inconsistent behaviour. NOLOCK is a terrible idea in general as it changes the isolation level to READ UNCOMMITTED. It is much better to not use cursors or sort out your transactions but such options are not open to us when using Access as it is a black box over which we have no control. There is plenty writtenout there about why NOLOCK is dangerous but it is the best of several bad options.

The real solution is to stop using Access. Please. Just stop.