## Wednesday, December 11, 2013

### How many Friday 13ths in a Year in JavaScript

Inspired by a code golf question on codegolf.stackexchange.com asking for code that counted the number of Friday 13ths in a year I came up with this inefficient NodeJS/JavaScript solution. Both the solutions below can be dropped into a .js file and run from the command line by NodeJS.

```// To run:
// node friday13.js <2013>
// <2013> is the year which you want a count of Friday 13ths in

// Add a day incrementer to the Date prototype
var value = this.valueOf();
value += 86400000 * num;
return new Date(value);
}

var year = process.argv[2];
if(!year){
console.log('Was year the first param? Received: ' + year);
return;
}

var startDate = new Date(year,0,1);
console.log(startDate);

var endDate = new Date(year,11,31);
console.log(endDate);

var counter = 0;
while(startDate <= endDate) {
if(startDate.getDay() === 5 && startDate.getDate() === 13) {
counter++;
}
}

console.log(counter + ' Friday 13ths in ' + year);
```

Someone else came up with another JavaScript solution which takes advantage of some of the idiosyncrasies of JavaScript which I thought was interesting:

```var year = process.argv[2];

var numFridays = function(year) {
var count=0;
for(month=12;month--;) {
count += !new Date(year,month,1).getDay();
}
return count;
}

console.log('Number: ' + numFridays(year));
```

Here are the interesting parts:
1. The for loop on line 5 relies on the fact that when the value of month hits zero it will evaluate to false.
2. On line 5 month will be evaluated for truthiness before it's decremented and that it will be decremented before the body of the for loop is evaluated.
3. We only have to loop through the 12 months of the year as there can only be one Friday 13th in each month so no need to go through every day.
4. The JavaScript getDay() method of the Date object returns a 0 for Sunday, 1 for Monday etc. If the month has a Friday 13th then by definition the first day of the month is a Sunday. i.e. if the value of getDay() on the 1st of the month is 0 (equivalent to false) then count this month. To do that we ! (not) the return value which gives us true which will evaluate as the value of 1 when added to an integer.

### The Turning Point to becoming a Software Engineer

I started my career as an accountant and one of my first jobs was to do the bank reconciliations (by hand) for the 56 bank accounts this manufacturing company had. Three weeks each month were spent doing this.

I asked management for a PC, a modem to connect to the banks, and access to the mainframe where the cash book was stored. Using one of the original C compilers and dBase III to store the data I pulled the statements from the bank and the mainframe. After several evenings and weekends of work I managed to automate the reconciliation process such that I could finish in a morning what had previously taken me three weeks to do. Although I had dabbled in software previously at school and university this was the turning point that I realized that I could really make a difference being a software engineer.

To give context to this I had written software in Apple BASIC and IBM/Microsoft BASIC to create trivial and contrived toy programs and to do college assignments. This was the first time that I saw the power of automation where so much time could be saved.

Since then I've worked for a number of different companies in various software development roles and for the last few years I've been managing teams of software developers. Excluding my family, the only thing I love more than solving complex problems through software is helping my team members develop and reach their full potential.

What took you into software engineering?

## Friday, December 6, 2013

### Useful Git and GitHub Commands

My notebook for Git/GitHub commands that I find useful.

To change where your local repo thinks it originally cloned itself from drop onto a command line in the appropriate directory and:
> git remote set-url origin https://github.com/<new location>
This is useful when working with a forked repo that you want to keep up-to-date with the original repo while you're working on the fork. Allows you to flip between both of them and keep changes from both current.
Follow the above command with a
> git pull
to update from the <new location>

### Useful NPM commands

My notebook for NPM commands that I find useful.

i can be used instead of install

npm -g list
- Shows everything that you've installed globally in a dependency tree graph.

npm list
- Shows everything that you've installed locally in a dependency tree graph.

## Thursday, December 5, 2013

### Understanding ES6 Fat Arrows

I'm going to try and do this explanation by manipulating a very simple line of code and transition an anonymous function to a fat arrow function.

[1,2,3].map(function(x) { return x + 1;});

Switch (swap) function and (x):

[1,2,3].map((x) function { return x + 1;});

This does not work. Just showing that you switch the word "function" with the parameter: (x)
Replace function with => (a fat arrow). You end up with this.

[1,2,3].map((x) => { return x + 1;});

Use Firefox if you want to test this as the fat arrow function hasn't been implemented in Chrome yet.

## Tuesday, December 3, 2013

### Full stack JavaScript is not about sharing code front to back

I'm watching a panel discussion at Node Summit and noticed one of the panelists saying that they found that there was very little benefit to sharing code between the front and back end when developing in a JavaScript full stack environment.

Recently I was touting the virtues of NodeJS and the person I was speaking to said "in reality how much code can you share across the stack?" I had to point out that this was not a virtue that I extolled and I've never thought of this to be a benefit of JS full stack.

In my opinion, shared code across the stack is a bonus and not a benefit. The primary benefit comes from the synergies and efficiencies in working in a single language through the stack. This means that if someone who traditionally worked on the front end has to dive in and do some work on the back end they are not going to be shocked by a different syntax and instead will be somewhat comfortable with what they see.

## Friday, November 15, 2013

### Parsing text for a Credit Card Number

A while back I wrote some code that parses text and looks for credit card numbers embedded in the text and then optionally masks all or some of the credit card in the text. This code is open source and available on GitHub: Credit Card Parsing

The main use case for this code was to remove credit card numbers that customers would email in to customer support when they were trying to buy something. The Payment Cards Industry (PCI) standards require the credit card data be stored under more secure conditions than most default standard storage configurations.

If customers' support tickets are being stored in a regular unencrypted database and they are sending you their credit card numbers then you are not PCI compliant. You have two choices. Make the support ticket database PCI compliant or remove the credit card numbers from the text that you're storing in this database.

The code in this library provides a mechanism to find and then optionally mask the credit card numbers in any block of text.

While I was developing this code I learned something interesting. 0.6% of all UUIDs/GUIDs have a valid credit card number in them. When I say valid I mean that it passes the Luhn Algorithm. I discovered this because our support emails had a lot of UUIDs that were part of URLs and other keys that the customers needed to communicate to us.

The first time I saw this false positive I thought that it was a one in a million chance. Not wanting to rely on that (bad) luck I used Monte Carlo Simulation to determine the probability of this happening and it came out at 0.6%. I had to adjust the credit card finding algorithm to ensure that what it thought was a credit card was not part of a UUID.

Development of this library was an unusual experience in that unit tests were immediately useful and protective. Each time a defect came back from production (i.e. a missed credit card or a false positive) I added that block of text* to a unit test and confirmed that it failed. I then fixed the code to ensure that the unit test passed and every time I did that it broke one of the other unit tests. My adherence to strictly unit test everything I wrote in this project ensured that it never had any regression bugs.

* If it was a missed credit card then that credit card would be replaced by a fake one before it was inserted into the unit test. I used Graham King's Credit Card Number Generator to create these fake credit cards.

## Sunday, October 20, 2013

### Facebook should introduce a clothes tagging feature

The next big feature that Facebook should bring out is clothes tagging. This will allow parents to tag clothes that they've given to friends' kids and track how many times they've been passed on. Recipients of clothes can give clothe-tag-thanks to those who gave the clothes as a gift or a hand-me-down.

The data collected from the clothes lineage (assuming you can identify the label) could be used to calculate the hardiness of the clothes and manufacturing quality. The more kids that were able to wear the same t-shirt or shorts will be the ultimate vote in quality. You could also determine which kid treats their clothes the roughest if there's no lineage from them onwards.

This will also help track when friends and siblings don't return clothes they borrowed. Tag that blouse in a photo of you on Facebook and then link-tag it in your your sister's photo. The public humiliation will ensure that she returns it to you.

### NodeJS Express Automatic Content Type

Try this in a NodeJS Express application. Add a route as shown below and take a look at what the web page shows:
```app.get('/mytest', function(req,res){
var testdata = {
segment: 'Five',
value: '42',
environment: 'development'
};
res.send(testdata);
});```
Before you go to this page in your browser, probably something like http://localhost:3000/mytest you should bring up the Developer Tools, on Chrome you can do this by hitting F12 or Ctrl+Shift+i.

In the browser you will see:
```{
"segment": "Five",
"value": "42",
"environment": "development"
}```
In the Developer Tools take a look at the Response Headers in the Headers section. You will see that Content-Type is set to application/json; charset=utf-8

Now let's change the mytest function to the following:
```app.get('/mytest', function(req,res){
res.send('this is my data');
});```
The browser will now show you:

this is my data

If you look at the developer tools you'll see that the Content-Type is now text/html; charset=utf-8

NodeJS/Express detected the type of data that you're sending back to the browsers and adjusted the Content-Type appropriately.

## Saturday, October 5, 2013

### Audit Controls or People

In my senior year at college I took Auditing along with a number of other accounting majors. I was on track to become an accountant, and in fact became an accountant, until I mainlined some source code and was unable to turn back.

The only thing that I really remember from that auditing class was our professor telling us about controls and people. His comment was: "You can put in as many controls as you want to enforce or prevent something from happening and someone will always find a way around them. At the end of the day you need to hire the right people who don't need those controls in place."

When I heard this it made absolute sense and have always sought to surround myself with the right people and by default trust everyone. There have been occasions when I've been let down which is what you'd expect with a large enough sample size. As I mature and become better at accessing people the disappointments have dropped.

This ties in nicely with the Agile Manifesto and the autonomy that you give to teams to self form and determine what they can get done in a sprint. If you have the right developers on the team the controls can be minimal or none. Trust is the key. Awesome results are the end products.

## Wednesday, October 2, 2013

### A Dozen JavaScript Libraries

Just spent a couple of hours this evening listening to Rob Richardson give an awesome presentation on A Dozen JavaScript Libraries.

He covered:
1. jQuery
2. Lo-Dash
3. Handlebars
4. Modernizr
5. Moment
6. Normalize.css
8. jQuery UI
9. Backbone
10. Angular
11. JSHint
12. Jasmine
13. RequireJS
14. Rafael
in enough detail to arm you with the ability to select one of them for a future project. It also looks like he's extended the Baker's Dozen (13) metaphor to a JavaScript Dozen (14). I'm guessing that JavaScript has the math library to do that.

Also love that he's using reveal.js for his presentations.

Good work Rob!

## Thursday, September 26, 2013

### MongoDB for Node.js Developers

mongoDB.org, the makers of MongoDB, run an great online course called M101JS: MongoDB for Node.js Developers.

The course is 7 weeks long. Each week will take you about 5 to 12 hours to complete and they deal with:
1. Introduction
2. CRUD
3. Schema Design
4. Performance
5. Aggregation
6. Application Engineering
7. Mongoose/Final Exam
Overall I scored 90% for the course. Each concept is well presented in bite sized chunks with a good video clip of 2 to 10 minutes long and usually followed by a quiz to help solidify the concept. They build on each other from easy to difficult.

If you want to get credit for the course you have to keep up and do it as each week becomes available as the homework credits only stay active for one week. This, in my opinion is a good thing as it focuses you to dedicate time every week to getting this done.

The course has great explanations on replication and sharding, makes it seem obvious and simple.

The final exam covers everything you've done in 10 moderate to difficult questions. You'll get a great sense of accomplishment once it's complete.

MongoDB Education provide you with a database of 120,000+ emails from the Enron Corpus which makes for an entertaining set of questions (about 3 of them) that use this database to test your query and update skills.

Of the 7,599 students enrolled, 1,482 students completed the course successfully, a completion rate of 20%.

## Friday, July 26, 2013

### OSCON Clientside MVC

The Clientside MVC page on the OSCON site

Tom Cully (BigCommerce Ltd Pty)
11:50am Friday, 07/26/2013

http://mozart.io/

Clientside MVC provides:
- scalability
- clientside apps exist mostly as static assets allowing greater use of CDN tech

SEO Problem
- webcrawlers and other automated clients that don't run JS
- implementing graceful degradation is possible...
- only early solutions exist e.g. Mozart Concerto

BigCommerce created Mozart to address their deficiencies in the other MVC frameworks. Mozart is written in CoffeeScript.

BigCommerce currently have their Operation Slick running in A/B testing with a 60% probability that a customer will get it at this point.

Mozart Demos
todomvc.com

github.com/tomcully/mozart

HTML5 Unreal Engine

### OSCON The Google Open Source Update

The Google Open Source Update page on the OSCON site.

11:00am Friday, 07/26/2013

A bunch of updates around Google's summer of code. I attended this because of the Git Update in the schedule.

Git Dev over last year
- 3,037 commits
- release about every 6 weeks
- 248 contributors

Hosting Linux Kernel
- time taken is 2m30s to clone Linux Kernel from google's hosted servers
- GitHub takes 5m37s
- Kernel.org takes around 6m

Google has improved speed by changing the algorithm.

JGit 3.0 ("jgit debug-gc")
Gerrit Code Review 2.6 ("gerrit gc")

Android OS project
548 repos

Gerrit Code Review appears to be a competitor to GitHub but perhaps only for an intranet. Not sure if it's hosted.

### OSCON Town Hall

The OSCON Town Hall page on OSCON.

Edd Dumbill (Silicon Valley Data Science), Sarah Novotny (Meteor Entertainment), Matthew McCullough (GitHub, Inc.), Gina Blaber (O'Reilly Media, Inc.), Simon St. Laurent (O'Reilly Media, Inc.)
10:00am Friday, 07/26/2013

Feedback session for OSCON organizers. I attended this because I'm interested in speaking at next year's OSCON so wanted to hear what the pain points were and what works and what they are looking for.

BOFs (birds of a feather) sessions appeared to be problematic.

I suggested that they take advantage of the Improv Troupe and have an evening performance from them and other participants.

This session was just to provide feedback to the organizers. I was hoping to hear something from them as well but we ran out of time.

## Thursday, July 25, 2013

### OSCON Developing full stack Javascript applications

The Developing full stack Javascript applications page on OSCON

Grant Shipley (Red Hat)
5:00pm Thursday, 07/25/2013

IaaS, PaaS, SaaS

PaaS example: OpenShift

OpenShift is free (will pay for EC2 time)

SampleApp will have:
strongloop
mongodb
twilio
openshit
appcelerator (titanium)
- eclipse based ide
- integrated with OpenShift
- build, test and deploy mobile apps from a single ide
- debugger

https://github.com/gshipley/OSCON2013

created a templated app in titanium studio
standardized on commonJS

### OSCON New Rules For JavaScript

The New Rules For JavaScript page on OSCON site.

Kyle Simpson (Getify Solutions)
4:10pm Thursday, 07/25/2013

54y.geti.fi/slides/js-rules/oscon

Kyle is writing youdontknowjs.com

html5hub.com

linters - jslint, jshint, eslint
- use for checking and agreeing on style

stop thinking JS (as a dynamic language) doesn't have types

!! same as Boolean(a)

7 types:
null, undefined, boolean, string, number, object, function
can get type by using typeof  except for null which will return object

stop thinking JS variables have types

values have types, and those types can't change but vriables can hold any value at any time

== allows coercion
=== disallows coercion

null == undefined // true

stop using anonymous functions
- improves readability of stack when debugging
- also name IIFE
- named functions are always better

don't assume the JS engine optimizes away mistakes

stop abusing function scope

block scoping is better than manually hoisting variables

let() {}
- does not exist yet
- can use blockscope.js on GitHub

stop using this until you really understand how it gets assinged
is the call-site new-invoked? use that
is the call-site binding overriden with call/apply?

stop using new Something() "constructors" to "instantiate" ...

OO vs OLOO (Objects Linked to Other Objects)
class vs delegation oriented code

delegation oriented programming

The Adventures in Node.js page on OSCON.

Faisal Abid (Dynamatik, Inc.)
2:30pm Thursday, 07/25/2013

node.js is built around "events"
event loop is always running checking for new events
fires callbacks when new events are received

http.createServer(function(request, response) {
// request has all information about request
// response allows packaging of what will be returned to client.

}

use EventEmitter class to write custom events
- can help with callback hell

require is used to import modules to your application.
- modules are like classes
- http module is stored in the node_modules folder
- require returns a JSON object

in examples using nodemon

npm is used to get modules
npm.org -
run from cmd line:
npm install socket.io
npm install nodemon
npm install -g coffee-script

package.json is a manifest for node
use * in package to get latest version otherwise specify version number
npm install --save hbs - adds to package.json?

Express.js
- framework like sinatra
- REST API for node
- great support for templates

restangular - simplify rest on angular

node has 32k modules out there, huge community support

### OSCON Rebooting the Team

The Rebooting the Team page on OSCON site.

Fran Fabrizio (Minnesota Population Center, U of Minnesota), Peter Clark (Minnesota Population Center, U of Mn)
1:40pm Thursday, 07/25/2013

POV manager in the private sector

a reboot is a conscious decision to engage in deeper more radical change than just incremental improvements
typically impacts staff structure, work implications...

purpose: wetware doesn't lend itself to engineering-style solutions. i.e. reboot tough for engineers to solve
reboot in between incremental and fire everyone.

Happy teams are very similar. unhappy teams are each unhappy in their own unique way

symptoms of requiring a reboot
- too quiet
- people are quiting
- you've been committed to things without your knowledge
- nothing ever ships
- no 1:1 meetings
- sick time spikes
- build is always broken
- people doing' take pride in their work

- etc.

Like "code smells' there is an "org smell":
patterns in a team or organization which hint at deeper flaws. usually not catastrophic themselves, but indicatieve of weakness in team...

getting to the root: (switch speakers)
the cubicle story
- e.g. complain about noise and distraction
- translates to "i'm bummed out because management doesn't seem to be listening to or valuing my needs."
- exposes a communication disconnect between engineers and management

organizational debugging
- when organizational debuggign is done collaboratively and with humility, respect and trust 9hrt) it prodcues momentum for change.

Big Secret - wetware problems land in one of these 3 buckets:
- communcation
- trust
- process

engage dev team
- create dedicatid time/space to focus on these problems (e.g. focus fridays)
- squishy book discussion. e.g. Team Geek
- meet privately with individuals regulary

1:1
- do you feel fulfilled when you leave work at the end of the day
- do you feel that your career has direction?

engage management
- provide visibility to the smell
- gain buy-in from the top

solutions
- find easy wins mixed in with longer-term fixes
- make it collaborative

exampe:
underinvestment in individuals
early wins
- do a job study across the dev team to clarify roles
- leverage org strengths (e.g. robust prof dev support)
long-term work
- address harder-to-sovle recruitemnt and retuntion issues

lack of focus on mission
early wins
- make all hidden work visible to management
- distration managemetn: prioritize work and outsource or kill fringe projects and other distractions. align effort to core mission

lack of team cohesiveness
early wins
- hipchat: persisten group chat tool
- monthly thinking thursdays: group lunch then gathering
long term work
- cross-project standardization (e.g. tiger teams)

operational deficitis
early wins
- evolve tools: svn to jenkins
- management support for our version of 20% time
long term work
- ongoing technical debt reduction

lack of customer-developer transparency
early wins
- formalize a quarterly planning process
- open work trackign tool to customers
long term work
- refactoring the communications model

measruing outcomes
most important one is qualitative
- ie..e it smells better now

not all solutions work out as planned
- solution doesn't work - symptoms don't go away
- fix to problem creates a new problem

### OSCON Deal with multiple types of input in your HTML5/JavaScript code

The Deal with multiple types of input in your HTML5/JavaScript code page at OSCON.

Olivier Bloch (Microsoft)
11:30am Thursday, 07/25/2013

Pointer Events

average finger width
threshold for finger is 11mm which is 40px

avoid hiding content behind :hover

use HTML5 input types
switches keyboard based on input type

Pointer Events
an event model for touch, pen, mouse, and more
- simplicity of mouse events
- with support for multiple device types
including multi-touch (even multi-user)
device-specific peroperties like pressure or touch contact size
hand.js - pointer events pollyfill

touchcontrol.js
example of single canvas with virtual joystick

Example of node server communicating with copter

resources:
w3.org/TR/pointerevents/
bit.ly/win8touchguidance
docs.webplatform.org/wiki/concepts/PointerEvents
github.com/jacobrossi/PointerPaint/

### OSCON Getting Started with 3D Programming in Three.js

The Getting Started with 3D Programming in Three.js page on OSCON site.

Chris Strom (EEE Computes), Robin Strom (EEE Computes)
10:40am Thursday, 07/25/2013

gamingjs.com/ice is sample site.

Book: 3D Game Programming for Kids - Create Interactive Worlds with JavaScript

Three.js
Low Complexity (for dummies)
Lightweight JS Library
Modern browsers
Canvas, SVG, CSS, and WebGL

Code-a-long with above ice editor

esh: Core 3D Object
combination of
Shapes -

Animation
requestAnimationFrame()
- callback to update the scene
- stube for window.requestAnimationFrame(), if available.

group object together
create a new frame of reference

WebGL vs Canvas
WebGL is better
nicer graphics
beter animation
bettera meterial
better effects
Canvas is better support

Physics with Physisja
dropin replace for three.js

## Wednesday, July 24, 2013

### OSCON Translated Strings and Foreign Language Support in JavaScript

The Translated Strings and Foreign Language Support in JavaScript Web Apps on the OSCON site.

Ken Tabor (Sabre Holdings)
5:00pm Wednesday, 07/24/2013

Translating:
what - date/time formatters
where - single page app

Basic solution
- string table, disconnects string from code

Never hard code text string
string-tables must be easily accessed throught the application
language string-tables must be demand-loadable resource.

- Combine duplicating strings
- Stop nearly duplicated string
- Easier word-smithing
- Setup for translation services
- Abstract away date/time formatting

RequireJS
RequireJS has 'i18n' plugin
At the cost of user control

Testing
- test entire app in Englsih
- native speaker confirms translations
- wait on bug reports

Automate testing with Jasmine and Selenium

Server-side errors - return codes and not string

### OSCON Getting Hadoop, Hive and HBase up and running

The Getting Hadoop, Hive and HBase up and running in fifteen minutes page on OSCON.

Mark Grover (Cloudera)
4:10pm Wednesday, 07/24/2013

Hadoop is a distributed batch processing system
Installation and configuring hadoop projects is hard
Integration testing not done across versions.

- generates packages of various Dadoop ecosystem componenets for various distros
- provides deployment code for various projects
- convenience artifacts available e.g hadoop-conf-pseudo to fake multiple nodes on local workstation
- integration testing of latest project releases

Hive
- allows SQL syntax query into hadoop
- don't claim to be SQL complaint but are very close. do not support correlated sub-queries.

Code for demo:
github.com/markgrover/oscon-bigtop

### OSCON Server-Side Push: Comet, Web Sockets, and Server-Sent Events

The Server-Side Push: Comet, Web Sockets, and Server-Sent Events on the OSCON site.

Brian Sam-Bodden (Integrallis Software, LLC.)
2:30pm Wednesday, 07/24/2013

Polling - classic "are we there yet?" to allow the server to communicate updates. Self-DDoS attack

iFrame Streaming -
- embed an invisible iFrame (using jQuery)
- server returns chunks of data in a loop
- bind iFrame JS to parent page JS

XHR Streaming
- XMLHTTP request
- uses an AJAX call in background and sends JSON
- complexity now on client. need to watch the stream and determine the delta

Long polling
- most commonly used
- still used as a fallback
- blocks on server until something available then returns
- reestablish the request after server timeout
- thread of execution is blocked on the server

Flash streaming
- XML Socket
- creates a 1 pixel movie in page and uses a streaming movie's socket

Above are the less optimal

Push Frameworks

Comet
- previously associated with long polling
- now frameworks will interrogate the browser and pick the most appropriate technique
- provide both client and server side components
- many use a pub-sub protocol
- protocol is Bayeaux
faye.jcoglan.com
(faye is good for ruby)

Web Sockets
- Two way communications (tcp/ip socket)
- dedicated socket
- works with security, firewalls and proxies

Server-sent events
- from server to client
- unidirectional
- typically use UDP
- BOSH

WebRTC
-

Use a framework, allows graceful degradation

### OSCON JavaScript Framework Face Off

The JavaScript Framework Face Off page on the OSCON site.

Nathaniel Schutta (ntschutta.com)
1:40pm Wednesday, 07/24/2013

The Seven Frameworks

Going to discuss three frameworks.

MIT is the most popular license for these.
The code is on GitHub.

Library vs. Framework is mostly semantic but....
Library works in existing code.
Framework forces you to work with them.

1. Backbone.js
Likes: small because there's no UI stuff
Designed for MVC JS applications
Has models, events, collections, views, controllers, persistence
Influenced by Ruby on Rails
Data lives in models instead of DOM
Changes to models trigger change events, views are notified.
Code structure: multiple files get confusing but can do in one file.
Event wiring kept in a single JSON data structure.
Doesn't take over the entire application
backbonejs.org

2. Knockout.js
MVVM
Likes: small, no dependencies
Supports all browsers
Uses declarative binding
Built in templates
Works with jQuery
Built by a Microsoft employee
knockoutjs.org

3. Angular.js
MV-whatever
Shim to make-up for the fact that browsers don't support apps
Declarative binding
dependency injection
Custom attributes: ng-
data binding updates view or model automatically
controllers abstracting away the dom
includes form validation
xhr wrapper: promises and exception handling
supports creating components via directives
supports localization
strong focus on testing, chrome, jasmine plugins
works with other libraries
documentation is excellent
angularjs.org

Help selecting an MVC JavaScript framework:
todomvc.com

### OSCON 10 Reasons You'll Love Dart

The 10 Reasons You'll Love Dart page on OSCON site.

Chris Strom (EEE Computes)
11:30am Wednesday, 07/24/2013

Compiles to JavaScript.
Attempts to normalize the compiled code for all browsers.
All browsers supported but for IE 10+

A language that doesn't affect the way you think about programing, is not worth know. Alan Perlis

primer on functions in Dart:
say_hi(name) {
return "hi, \${name}";
}

say_hi("Bob");

Must have ; at end of statement in Dart, in JS this is optional

syntactic sugar for above:
say_hi(name) => "hi, \${name}";

anon functions:
var say_hi = (name) => "hi...

magic instance variables:
var num;
num = number;
}
}

Also, quick assignment in constructor:

precede the variable name in the class with an _ to make that variable private and inaccessible from outside the class.

get and set are Dart keywords used for getters and setters of private _ variables.

parameters can be optional, named, required and default

..mix_it()
..stir_it()

Can be used for setting methods, e.g. in CSS:
bg.style
..position = 'absolute'
....

Unit Tests
- built into language
test_create() {
group("new DBs", () {
setUp(removeFixtures);
tearDown(removeFixtures);
....

test("creates a new DB", () {
...

Client-side libraries, declare:

Use:
import 'dart:html';

Pub packages:
pub install
- pulls in dependencies

inheritence:
super(attributes

PubPackages
pub.dartlang.org
public git repos
great for local dev

Statically Typed Language
int num;
...
You can assign a string to an int and it will compile and run. However, if your run dartanalyzer then it will pick up your intention and complain. Can put this into the build process. Dart editor has this built in.

Dartdocs
Tools to generate HTML about code.
Accepts /// for comments to be extracted into the documentation.
Client side search in docs

Chris Strom @eee_c does a #pairwithme!!! on Tuesdays at 7:30pm PST.

### OSCON GitHub Power Tools

The GitHub Power Tools page on the OSCON site.

Tim Berglund (GitHub, Inc.)
10:40am Wednesday, 07/24/2013

git ls-remote origin
gets all refs
refs are names for commits which are created in the root repo
use if pull requestor has deleted their fork
github has pull's

teach.github.com

## Tuesday, July 23, 2013

### OSCON Improve Your Team With Improv

The official Improve Your Team With Improv page on the OSCON site.

Andrew Berkowitz (TeamSnap), Wade Minter (TeamSnap)
1:30pm Tuesday, 07/23/2013

There was a great selection of sessions to attend in this time slot so I was deeply torn. The other top contender was Real-time: HTML5 and Node.js however that and the others can be done asynchronously by myself (not as effectively). You can't do Improv by yourself, or at least not in a meaningful way.

The session was great. These guys have identified a bunch of Improv exercises and techniques that directly apply to work situations and have cut out all the other Improv activities that would be appropriate for only Improv.

Some good techniques on how to get the team to know each other which is especially useful for teams that aren't collocated who need to quickly get to know each other in a short time frame on those rare occasions when they come together. They were also very cognizant of the fact that most people aren't touchy feeling and kept the "touch" exercises that way.

At the end of the session they ask us all to write down one item that we thought would make OSCON a better conference. The ideas included swag, free beer, a million dollars for everyone (top voted), free laptops, free conference, and rides on the animals on the covers of the O'Reilly books.

People swapped their card and then found partners to divide 7 points between the two cards they had which they then swapped again. The score was written on the back. This was repeated five times and then those five scores added up for a maximum of 35 points.

I believe that the winning idea was a million dollars for each person with 31 points.

My idea was "A unicorn ride from the hotel to the conference each day. The unicorn would have cup holders and unlimited beer and its horn would be shined each day." This scored in the middle of the range at 21 points. What were those guys on? Who would rather have a million dollars when you can ride on a unicorn?

### OSCON Introduction to Clojure

The Introduction to Clojure page on the OSCON site.

Neal Ford (ThoughtWorks)
9:00am Tuesday, 07/23/2013
bit.ly/clojureinsideout

My notes from the Introduction to Clojure session.

Clojure is Functional, Dynamic, Hosted, Open Source, has an Atomic Succession Model, Lisp

The most enjoyable part of this presentation was that I was back in Lisp land again. Although I only spent 6 to 12 months working in Lisp I love the radically different structure and syntax of this language.

Data:
EDN Extensible Data Notation
data is immutable
nil - nil, null, nothing
booleans - true or false
strings - double quotes, can span multiple lines,, include \t \r \n
char - same as JVM
integer - same
double - same

Two syntaxes for naming things
symbols - e.g. variable names and namespaces, should map to something

Collections
lists - a sequence of values, zero or more elements within () like lisp
vectors - in [] like an array, supports random access
maps - key/value associations, looks like JSON, can have a vector as key, keys are unique
sets - {} collection of unique values

Clojure syntax is edn + language syntax
println("Hello World") becomes (println "Hello, world")

Operators: (+ 1 2 3 4 5)

Infix
int x = 40 - (5 + 10 * 2) becomes:
(def x (- 40 (* 2 (+ 5 10))))

Defining functions
(defn greet     <- name
"some text"  <-
[your-name]
(str "Hello, " your-name))

(defn larger [x y]
(if (> x y) x y ))

Anonymous Functions
(map (fn [x] (* x 2)) (range 10))
i.e. pass functions as parameters
result (0 2 4 ... 18)
syntactic sugar for above:
(map #(* % 2) (range 10))

Namespaces
(ns com.example.foo)
- maps to JVM as you'd expect
Can wrap requires:
(:require...
Use :exclude to override (e.g. override + for vector math)
Don't use :use

Platform Interop
java Math.PI
Clojure sugar: Math/PI

java dot notation

Clojure is a homoiconic language. i.e. it's a language that's represented by its data structure. Languages that you might have heard of that exhibit homoiconicity:
Curl
Julia
Lisp
Scheme (Lisp dialect)
Clojure (Lisp dialect)
Racket (Lisp dialect)
Mathematica
Prolog
SNOBOL
Tcl
XSLT

Functional Programming
- Easier to reason about - higher level of abstraction
- Easier to test
- Easier to compose
- Essential at scale

Persistent Data Structures
Composite values - immutable
'Change' is function of value to value
Collection maintains performance guarantees

uses Bit-partitioned hash tries

Constructing Values
Looping via recursion (recur)
prefer higher-order library fns when appropriate

Recursive Loops
No mutable locals in Clojure
No tail recursion optimization in the JVM
recur op does constant-space recursive loping
Rebinds and jumps to nearest loop or function frame

Loop alternatives
(loop
(reduce
;apply data constructor fn
(apply
;map into empty (or not) structure
(into
;get lucky
(zipmap

Benefits of Abstraction
Better to have 100 functions operate on one data structure than to have 10 functions operate on 10 data structures - Alan J. Perlis
All Clojure collections have (seq available.

Sequences
(seq coll)
(first seq)
(rest seq)

In Lisp the first and rest functions used to be called car and cdr.

Lazy Seqs
Evaluated at execution
Very similar to LINQ in C#, same type of syntax

Operations on sequences:
(drop
(take 9 (cycle
(interleave
; splits collection into param partitions
(partition 3
; create key values
(map vector
; use like String.Join():
(apply str (interpose \, "asdf"))
-> "a,s,d,f"
(reduce + (range 100)) -> 4950

(for
is a macro and not an imperative loop

Seq Cheat Sheet
http://clojure.org/cheatsheet

Vectors
(def v [42 :rabbit [1 2 3]])
(v 1) -> :rabbit
(peek v) -> [1 2 3]
(pop v)
(subvec v 1)
(contains? v 0) -> true
(contains? v 42) -> false ; last param is index

Maps
(def m {:a 1 :b 2 :c 3})
(m :b) -> 2 ;also (:b m) will work
(keys m) -> (:a :b :c)
(assoc m :d 4 :c 42) ->
(dissoc m :d)
(merge-with

Nested Structures
(def jdoe {:name "John Does", :address {:zip 27705, ...}})
(get-in
(assoc-in
(update-in

Sets
(use clojure.set)
(def colors #["red" "green" "blue})
(disj
(difference
(intersection
(union

(def v [1 2 3]) ;vector
(def l '(1 2 3)) ;list
(conj v 42) -> [1 2 3 42]
(conj l 42 -> '(42 1 2 3)

(into v [99 :bottles])
(into l [99 :bottles])

Destruction
Pervasive Destructuring
DSL for binding names
Works with abstract structure
sequential (vector) map (associative)

Special Forms
(def symbol init?)
(if test then else?)
;do returns the last value executed:
(do exprs*)
(quote form
(fn name? [params*] exprs*)

(let [binding
(loop
(recur
(throw
(try expr* catch-clause* finally-clause?]

Macros
(->
Do everything from inside out - i.e. first statement is inside statement

(->>

Boids
github.com/relevance/boids
Algorithm in Clojure
Cross compiled to ClojureScript

Example: perfect #

Break exercises
clojure.org - install clojure
leiningen.org - build tool
github.com/functional-koans/clojure-koans -> for beginners
projecteuler.net -> if you know the syntax of clojure

Second part of session

Leiningen
run a REPL etc.
"Maven meets Ant (withou the pain)"
RubyGems/Bundler/Rake

Compojure
Lightweight web framework - most popular
MVC based
github.com/abedra/shouter - example compojure app

objects are mutable
encapsulate change & info
polymorphism lives inside object
extend via inheritance
interfaces are optional

Clojure
expose immutable data
encapsulate change (not data types)
polymorphism a la carte
interfaces are mandatory
extend by composition

defrecord
(def stu (Person. "Stu" "Halloway" (Address...

defrecord Details:
Type fields can be primitives
Value-based equality & hash
in-line methods defs can inline
keyword field looks can inline
protocols make interfaces

Protocols
(defprotocol AProtocol
"A doc string for AProtocol abstraction"
(bar [a b] "bar docs")
(baz [a] "baz docs"))
named set of generic functions
polymorphic on type of first argument
no implementation
define fns in the same namespaces as protocols

Extending Protocols
(extend-type
Like extension methods in .Net but more extensible
(extend-protocol

ClojureScript extension
; extends JS array
(extend-type array ISequable

Reify
(let [x 42 r (reify AProtocol ; implement 0 or more protocols or interfaces

deftype
use defrecord for information
use deftype

Concurrency - done at the same time
Parallelism - the execution of items in parallel

Values
immutable
maybe lazy
cacheable forever
can be arbitrarily large
share structure

What can be a value?
42
{:first-name "Stu"...}
anything...

References
refer to values or other references
permit atomic, functional succession
model time and identity
compatible with a wide variety of update parameters

API
(def counter (atom 0))
(swap! counter + 10)

Shared Abilities
@some-ref
(deref some-ref)

Atoms
(def a (atom 0))
(swap! a inc)
=> 1
(compare-and-set! a 0 42)
=> false
(compare-and-set! a 1 7)
=> true

! - mutates
? - returns true or false

Software Transactional Memory (STM)
refs can change only within a transaction
provides the ACI in ACID (Atomic Consistent Isolated)
(defn transfer
[from to amount]
(dosync
(alter from - amount)
(alter to + amount)))

(alter from - 1)
=> IllegalStateException No transaction running

STM details
uses locks, latches internally to avoid churn
only Haskell and Clojure have transactional memory

Pending references
work not done yet

Future
(def result (future...
(defef result 1000 or-else) ; timeout
@result deref result) ; wait without timeout

Delay
(def result (delay dont-need-yet))

Promise
(def result (promise)) ; no-org constructor

Java API
all work in Clojure
thin wrapper over Java API

Summary
Clojure is a 21st century Lisp
popular with framework designers
most interoperable with underlying platform
powerful abstractions
active community
"a programming language beamed back from the near future" -Stuart Halloway

### OSCON 6 Minute Apps

The 6 Minute Apps! Build Your First Modern Web App page on OSCON.

James Ward (Typesafe)
1:30pm Monday, 07/22/2013

### OSCON Introduction to Scala

The official Introduction to Scala page on the OSCON site.

Dianne Marsh (Netflix), Bruce Eckel (Mindview, LLC)
9:00am Monday, 07/22/2013

Great presentation by Bruce and Dianne. They covered a lot of material in an easy to digest manner. After each nugget of information they had a great set of exercises that stretched the mind well beyond what they had explained. i.e. explain a concept and the accompanying syntax and then ask you to apply it to a typical real world problem.

(They call the nuggets atoms because it's the smallest amount of information you can explain about a corner of Scala without it being overwhelming and still being complete. I believe that this is the format that their book has followed.)

This was the first time that I've ever seen Scala and my immediate impression was that this is a language that is building on Java to play catchup with C#. Due to the lack of features being added to Java over the years C# had moved ahead with a great set of new features and to address this on the JVM Scala took up the challenge. Remember that I've spent all of 3 hours on Scala so this could be completely wrong.

My notes on what I've picked up so far.

All objects are either a val or var. Vals are called const or constant in most other languages and are immutable. A var is variable that can be changed. Val and var declaration take data types as optional parameters otherwise the type is inferred.

val myNumber:Int = 1
val myFloat:Double = 1.1
val myBool:Boolean = false
val myWord:String = "A string"
val myLines:String = """Triple quotes let you have quotes" and
multiple lines under a another trifecta of quotes"""

Use semicolons to put multiple expressions on the same line:
var age=42; val color="blue"

Unit is the same as void in most C based languages or Nothing in Visual Basic.

The last line of code executed inside curly braces will be the value assigned to the variable, for example:

val area = {
val pi = 3.14
}

Comments are the same as Java and other modern C languages: // and /* comment */

If statements are the same as Java:
if(x) {
}
if(!x) { // if x is not true
}

A difference with Scala is that the result of an if (and else) statement evaluation can be assigned to a val or var.

e.g.
val result = {
if(99 > 100) { 4 }
else { 42 }
}

In Java/C# this would be:
int result = 99 > 100 ? 4 : 42;

Boolean && and || are as you'd expect.

...Unfinished...

### O'Reilly Open Source Convention (OSCON) 2013

This blog post will be an index into my notes from the sessions that I attended at OSCON 2013 from July 22 to July 26.

Monday July 22, 2013
Tuesday July 23, 2013
Wednesday July 24, 2013
Thursday July 25, 2013
Friday July 26, 2013

## Wednesday, July 17, 2013

### Ship It Day #2

On Friday July 12, 2013 our team, held our second Ship It day with the judging taking place the following Monday, July 7/15.

At the previous ship it day we focused all the prizes on the demonstrations that were given. In both instances we asked a panel of judges to submit a score, based on their own criteria, from 0 to 10 for each team/demo.

Initially the judges wanted guidance on how to score the submissions. Several attributes were suggested but I resisted this because I felt that each judge already has a different viewpoint of what they like to see in a demo and what is important to them. The selection of a wide range of judge types was more important than giving them attributes to score on that might not make sense to each individual. The judges were Business Analysts, User Experience (UX) Engineers, Product Managers, and Senior Software Engineers.

At this Ship It Day we changed the focus to emphasize the importance on creating something that was actually shippable at the end of the exercise. Small prizes have been established around the demo but the biggest prizes are around who can ship in the week immediately after Ship It Day and then the prize size decreases for week two and week three. Given that we are in the middle of week one nothing has been given out yet but there are indications that at least one of the teams will ship in the two weeks immediately following Ship It Day. I'll update this blog post with more details in around three weeks.

In total we had fourteen self-organized teams at this event which is up six (+75%) from the eight we had at the last event. As usual we provided lunch for the team and snacks and drinks throughout the day and at the end of the day we had adult beverages for everyone.

## Monday, July 8, 2013

### TypeScript as a better JSLint

TypeScript, if you haven't heard of it, is Yet Another JavaScript Transpiler (YAJST). Their marketing pitch:
TypeScript is a language for application - scale JavaScript development. TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. Any browser. Any host. Any OS. Open Source.
Apart from using the language for its added benefits you can also use the TypeScript Compiler (tsc.exe) as a very powerful and better form of JSLint that can catch "compile time errors" in a language that isn't compiled, in this case JavaScript.

A compiled language like Java, C, C++, or C# benefit from a first round of implicit unit tests which is the compilation of the code. i.e. before deploying the code it's been validated by the compiler and we know that syntactically it is "clean." Of course it may still be very buggy.

JavaScript doesn't have this benefit. We can run unit tests against the JS we write and if not syntactically correct we can catch some of those syntactic errors. However, if we don't have exhaustive, comprehensive and high quality unit tests we won't catch everything. We also can't test for intent.

Here's a trivial JavaScript example that works and is valid but may be a bug:

function getDivisor() {
return "5";
}

function myTest() {
console.log(10 / getDivisor());
}

If you run this through the TypeScript Compiler then you'll get this error:

TypeScriptTest.ts(3,17): error TS2112: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.

JavaScript will execute this code correctly. It coerces the "5" in a string into an int and everything works as expected. However, TypeScript knows that the only type that can be returned by the getDivisor() function is string and by using implicit typing it knows that you can't (or shouldn't) try and divide by a string.

We can fix this by changing getDivisor() to look like this:

function getDivisor() {
return parseInt("5");
}

Even if you don't use any of the features of TypeScript, your code quality can improve by inserting TypeScript as part of your build process. I'd suggest that you add this immediately after any other code in your system has been compiled and just before you run any unit tests.

As a note, TypeScript will not accept a .js file as an input, it will only accept .ts files. As such you will need to copy your .js files to a temporary location, renamed them to .ts files, run tsc.exe against them and capture the output.

## Sunday, July 7, 2013

### Scott Guthrie Event 2013

On 16 May 2013, Scott Guthrie along with Damian Edwards and Joshua Twist came the Valley of the Sun for Scott Gu's tenth annual technical presentation.

I was lucky enough to be on-stage at 4pm for a ten minute presentation. The event took place at the Scottsdale Center for the Performing Arts, 7380 E. 2nd Street, Scottsdale, AZ. There were around 800 attendees but I estimate that there were probably 400 left by that time.

Below is the content of my speech.

Good afternoon ladies and gentlemen. My name is Guy Ellis. I’m the director for software development for the presence and commerce team at Go Daddy. This is my sixth year as an employee at Go Daddy. I started off at Go Daddy as a .Net developer working with the internal tools team. I then moved to our SEO product called Search Engine Visibility which I managed before moving onto the Presence and Commerce team which is responsible for creating our Website Builder and Quick Shopping Cart products.

Over the years I’ve been to almost all the Scott Guthrie events and like this one they’ve all been fantastic and I’d like to thank Scott Cate and everyone else involved for making this available to us at no cost.

I’d like to share with you how I explain SSL to the layperson, or as I sometimes say "SSL for your grandmother."

As developers you most likely know how SSL works but how do you explain to a non-geek that Secure Sockets Layer uses asymmetric public key encryption to prevent a man-in-the-middle attack? How do you explain to them how their username, password and financial data that’s traveling over the ether when they’re accessing their bank account cannot be used if it’s intercepted. They see the green address bar in the browser and the S at the end of HTTP and they know they want it but don’t understand how it works.

To help us understand this I need to take you back in time. A very long time ago. Before the internet. Before television. Before phones where invented. I was a very young man. I lived in a small village on the banks of river. One day I was walking next to the river and on the other side I saw the most beautiful woman I’d ever seen. I couldn’t help myself, I waved and shouted across to her. She took one look at me and headed off. You may notice that men still try and use this technique today except they are usually hanging out of a car window but the impact is generally the same.

I had to get to know this woman so I rushed back to the village and asked around and found out that she lived in the village on the other side of the river. Unfortunately, back then I was afraid of water and unable to take the ferry across the river to meet her. My only choice was to write her a letter and win her over with my romantic prose.

I spent all night writing a letter and in the morning I gave it to the ferryman to deliver to her. I watched from the dock as he paddled across the river disappeared into a house. About an hour later a young man, about the same age as me, came out of the house and went off to her house with the letter and delivered it to her house. She opened the letter and read it and appeared very excited by it but then hugged and kissed the man who had delivered it.

I hired an investigator to find out what had happened and soon it became apparent that this other young man was the ferryman’s son and he had taken my letter and rewritten it from himself and was using my carefully crafted masterpiece to win her heart for himself.

I knew I had to work out a way to get my letters to her without the possibility of interception. I got myself a box, put my next letter in it, put a padlock on it and sent it across the river. I included instructions for her to attach her padlock and send it back to me. Once I received the box back I removed my padlock and then sent it back to her knowing full well that she was the only one that could open the box. My plan was infallible, or so I thought. I later discovered that the ferryman’s son had attached his padlock to the box and stolen my letter again.

I then recruited the help of a man who referred to himself as Mr. Authority. I sent the box with padlock and letter and it came back with an old rusty padlock on it in addition to mine. Mr. Authority took a look at the other padlock and shook his head. This isn’t her lock he said. I rejected the box and the next time it came back it had a beautiful pink padlock that smelled of roses. Mr. Authority confirmed that this was her lock and I removed mine and she finally started receiving my letters.

Several letters later she took the ferry across the river and we met and fell in love and she is now my wife and that, ladies and gentlemen, is how SSL works.

This is the view from the stag when the lights are not switch on. When the lights are on you can't see anybody or any of the seating. It's just a blazing glow.

Photos courtesy of Richard Kimbrough Photography.

## Thursday, June 27, 2013

### 8 reasons you should become a JavaScript expert

As a developer you should always be looking at other languages and striving to be a polyglot programmer. Learning a second language will make you a better developer in your primary language. This seems like a strange statement but what happens is that you see a strange construct or pattern being applied in the second language you say "hey, that's not available in my primary language." On further investigation, something like that or a clever workaround is usually available and that then gets added to your arsenal of tricks in your primary language.

No computer language is more important to learn today that JavaScript. Becoming an expert at JavaScript paves your way for future success.

1. C-based

JavaScript's syntax is influenced by the language C. Most developers have used a C-based language in the past (Java, C, C++, C# etc.) so this immediately gives you a good chunk of the syntax and keywords used in JavaScript. Almost all developers who have worked with a C-based language and then look at JavaScript think that they know JavaScript. This is a mistake. Unlike traditional C-based languages JavaScript is prototype-base, dynamic, and weakly typed.

2. Programming styles

JavaScript supports object-oriented, imperative, and functional programming styles giving the developer the flexibility to experiment with different programming styles in the same language.

3. Full stack

With Node.js it is now possible to use one language to develop web applications on both the client and the server. If there's one language to rule them all then this is it.

4. They all compile to JavaScript

On the client side you have other options than JavaScript to develop in. For example, CoffeeScript, TypeScript, and Google's Dart. However, at the end of the day they all compile down to JavaScript. If they stop maintaining that transpiler then you need to get stuck into the JavaScript code.

In 2006 Google Web Toolkit (GWT) created a way to compile Java to JavaScript

In 2007 we had pyjamas to transpile Python into JavaScript.

List of languages that compile to JavaScript.

5. JavaScript is the only standards-based language that runs in all web browsers

There is no other language that will run in all browser and that has a committee defining and developing standards for it.

6. More JavaScript code is being created each day than any other language

Okay, I just made this one up. However, it might be true. I have no idea how you would measure this but I bet that if it's not true today it will be one day soon.

7. Expert JavaScript developers are tough to find

Want to bullet proof your prospects of finding a job? Then become an expert JavaScript developer. I've been interviewing developers for a number of years and most recently been looking for expert JavaScript developers and I can tell you that they are the hardest type of developer to find. (Drop me a note if you're an expert JavaScript developer and you want to work at Go Daddy.)

8. Legacy JavaScript is going to be with us for decades

Just like COBOL programmers make comebacks every now and then because there is so much legacy written in COBOL, JavaScript programmers will be in demand for a very long time because of the amount of JS that's being written today.

## Wednesday, June 26, 2013

### Changing the JSON object in an API

Interesting discussion with the development team today about a bug that recently surfaced. The JSON object that was being sent back and forth between the client (browser) and the server changed in structure. For a few hours after the deployment a bunch of exceptions showed up in the logs but as users of the site left and rotated out for new users the exceptions became fewer and finally disappeared.

What had happened was that Ajax calls pages on browsers that had been loaded before the deployment were still communicating with the server using the previous JSON structure while the server was expecting the new JSON object. The code to handle the old JSON object had been removed from the server and not knowing how to deserialize the old object the server was throwing and logging (thankfully) exceptions.

The lesson from this is that you should always provide backward compatibility for one version (iteration) of the code base and then remove that backward compatibility.

The best and easiest way to provide backward compatibility is to have a version key/value pair in your JSON object. Increment the version when you change the JSON structure and perform a switch on the server to handle the previous and current versions. This does, however, require that you thought about this ahead of time and your current live object has a version key/value pair in it.

If not, then you can inspect the object for the known change (e.g. new or removed key) and use an if/else to switch which deserializer you're going to use.

The reason that you want to remove the old code after one iteration is because you want to get rid of dead code as soon as it's dead because it becomes a maintenance nightmare. The longer the dead code is in the code base the more worried everyone is about removing it because nobody can remember if it does anything. While the memory of the previous version is still fresh in your head make sure that old code is killed off. Create a work item in the next project that includes the removal of this code.

Incidentally if you have code that you think is dead but can't be certain (e.g. some code uses reflection to call it or it's an entry point to the application like an API endpoint or web service) then I usually put a log statement in there. Then I put a reminder in my calendar, usually a month out, to search the logging database for that string to see if anything has called it and then I remove it.

## Tuesday, June 18, 2013

### Graffiti Redirect 404

This is an unusual blog post as it's the destination for unredirectable 404 pages for the old Graffiti CMS that used to host this blog.

A couple of blog posts back I wrote that I had migrated this blog from Graffiti CMS to Blogger. I changed the domain of the blog from a non-www version (guyellisrocks.com) to the www version (www.guyellisrocks.com) so that I could host a redirector on the non-www version.

The redirector receives a request for the original URL and then using a bunch of rules and pattern matches attempts to redirect to the new page on Blogger, this blog that you're reading now. However, before it redirects the visitor it checks to see if the blog page exists in this blog. If Blogger returns 404 then it logs this missing lookup and sends the user to this blog post.

At this point, you should type your query again in the search box above and to the left and it will search just this blog for the missing post.

If, in final desperation, you still can't find what you're looking for then feel free to reply to this post and I'll try and help you.

## Tuesday, May 28, 2013

### Stream ended unexpectedly (got X bytes, expected Y)

I was trying to clone the nopCommerce repository from codeplex (https://hg.codeplex.com/nopcommerce) to my local drive and the first two attempts failed with stream ended unexpectedly (got X bytes, expected Y)

The definition of stupidity is trying the same thing twice and expecting a different result right? In this case I was running it a second time to see if it failed at exactly the same point. If that happened then it was most likely a corrupt source/repo on the server. If the values were different (which they were in this case) then it indicated that it could have something to do with the network.

By checking the "Do not verify host certificate" option in TortoiseHG's close function to I managed to complete the download successfully.

## Thursday, May 23, 2013

### Migrating from Graffiti CMS to Blogger

I set this blog up in 2008 and have blogged on and off for the last 5 or so years on technology. I selected Graffiti CMS after Rob Howard from Telligent, its creator, gave a talk at our local AZ Groups .Net user group and he gave out a bunch of licenses to a this product which was then going to be sold at \$150. It has since become open source.

Graffiti CMS has treated me very well and is a remarkably good product. However, these were the drawbacks that made me decide to move my blog off Graffiti:
• Very small number of users and one very kind and competent developer maintaining it.
• I hosted it on my dedicated server. This meant that it was eating up resources that other web apps needed.
• I had to upgrade it and maintain it and patch it myself and a security vulnerability might impact other applications on the server.
I moved it to Blogger because I already have a blog on Blogger and as such I'm familiar with the tools but I'm sure that other blogging platforms like Wordpress would have had as much as I needed as well.

The migration process went like this:
• Found some code that someone had written to export the blog into BlogML and tried it out. This failed as Blogger couldn't read it in.
• Spent a few hours modifying the code to get the export format I wanted but was unsuccessful. Knowing that I don't have much time on my hands to do this type of thing I threw some money at it and asked the Graffiti developer to create an export for me.
• He kindly did this and here I am, 300 or so migrated posts in Blogger.
The original blog ran off http://guyellisrocks.com/ (no www) and I've migrated it to http://www.guyellisrocks.com/ so that I can redirect to the new url pattern. I've written a web app which is now sitting at the non-www version and when it gets a request it then reaches into the database and pulls out the date for that post and generates the new url. This is then used for redirection to the new (this) site.

What's still to be done?
• Some of the URLs did not migrate in the predictive fashion I'd expected. I'm logging those and will make changes to the redirection code as I go along.
• Images have not come across so I'll do that manually as I find time.
• There are references to the non-www version in the new www version and even though they will redirect correctly they should be fixed as eventually I'd like to get rid of the redirector. I'll do this by checking the referrer header and if it's from the www version I'll log this so that I can find the posts with those links.

## Tuesday, May 14, 2013

### ShipIt Day at Go Daddy

I manage a team of developers in the Presence and Commerce division of Go Daddy. We're responsible for providing small businesses with their Digital Identity. Our two main products are Website Builder and Quick Shopping Cart. Last Friday, May 10, 2013 we had our first ShipIt Day.
ShipIt Days were created by Atlassian. In their words:

Every quarter, we give employees the chance to work on anything that relates to our products, and deliver it during ShipIt Day, our 24-hour hackathon. Been wanting to build that plugin, redesign that interface, or completely rethink that feature that’s been bugging you? You’ve got 24 hours...go!

Our first ShipIt Day pretty much followed the format described by that statement.

We picked a Friday to do it because Fridays are usually less busy than other days because we try and avoid them for deployments. The teams self-organized which included the skill sets of Quality Assurance, Developers, DBAs and Business Analysts. We found a room where everyone could come together and work. Tip: When you do this bring power strips, duct tape and extension cords to make sure everyone has power throughout the day. Also make sure that the wireless is working well and has the bandwidth needed.

During the day we made sure that the team was sugared up on sodas and snacks and brought in lunch and towards the end of the day we brought in some adult beverages when the brain numbing complexity of the coding was done. This allowed everyone to relax and celebrate their work and cruise into the weekend.

We delayed the judging and demos until first thing on Monday morning to allow weekend travelers to get home.

Each team had six minutes on Monday morning to show what they'd created and the Product Managers and other non-participating managers joined in the judging. As score collector I asked the judges to use whatever criteria they through appropriate but to roll it all up into a single score from zero to ten and give that to me. Decimal places were allowed and one of the judges used five criteria and sent me scores to two decimal places.

Based on the generally high scores given out by all the judges, the quality and usefulness of the work done was exceptionally high. I cannot list the features because we will probably ship all of them in one of the two products already mentioned. However, once they're shipped I'll come back here and talk about them some more.

All of the members of the top three teams each received a prize to recognize their innovation. It was a tough call because the scores were close together as all the features were awesome.
Tips for a successful ShipIt Day (not saying we did all of these but in future ShipIt Days we hope to cover them all):
• Make sure you have power, wireless and a comfortable place for everyone to work.
• Make sure the team understands what they're doing. (i.e. a feature to enhance the product that they're working on but it doesn't have to come from the backlog.)
• Let the team know the ShipIt Day date well ahead of time so they can start forming their teams and ideas around what they'll work on and cancel that vacation to Hawaii so they can be there.
• Make sure they have drinks, snacks, and lunch during the day and of course an adult beverage at the end of the day.
• Get a budget for prizes, who doesn't like to be recognized?
I'm very lucky to be working with such an awesome team of developers. They are constantly going above-and-beyond in their efforts to make world class products and it's a privilege to be part of this team.

## Tuesday, February 19, 2013

`static int equi(int[] A){    for (int i = 0; i < A.Length; i++)    {        if (A.Take(i).Sum() == A.Skip(i + 1).Sum())        {            return i;        }    }    return -1;}`
`static IEnumerable<int> equi2(int[] A){    for (int i = 0; i < A.Length; i++)    {        if (A.Take(i).Sum() == A.Skip(i+1).Sum())        {            yield return i;        }    }}`