csaunders

 

Maybe it would be appropriate to title this “how our government shows respect for workers rights”.  This of course in response to the Honourable Lisa Raitts’ continuous threats to legislate unionized workers back to work, this time being Air Canada flight attendants.

We are told this is because our economy is in a terribly fragile state and everyone needs to work, otherwise everything will crumble.  This is really a quite entertaining argument, especially since we have several other airlines that we can choose to go with instead if the flight attendants decide to go on strike.  So, as consumers there isn’t anything major to worry about if there is a strike.  We may be slightly inconvenienced because of this, but we do need to give the workers their right to fight for better terms in their collective agreement.

It’s extremely frustrating to see our members of parliament, let alone the Conservative party getting involved in private affairs like that of Air Canada or Canada Post.  In forcing these workers back to work we are taking away a strong part of their bargaining power.  The strikes are supposed to put pressure on an employer to make a better agreement since every day on strike is lost profit on their part.  Meanwhile, we have our government stepping into places they shouldn’t be involved with and passing laws that truly only benefit the employer.  Perhaps another benefit is it keeps canadians complacent despite the extremely damaging chilling effect this could have on other unions that will have lasting effects.

I’d like to thank Hon. Raitt for getting the union crushing snowball rolling.

 

I’ve realised that I haven’t posted about any of my homebrewing results in the last few months. To date I’ve made approximately 5 batches now, none of which are the same.

I’ve learned a fair amount and am far more prepared before I even begin boiling water. I’ve found the biggest part of making brewing an enjoyable experience is simply having a plan. What’s great about it, is that it doesn’t need to be anything complicated.  It just has to be enough to keep you from getting too stressed out.  For me, it typically consists of ensuring that I separate the tasks over several days so that I am able to focus on the task at hand.  Then brew day becomes a 2 hour event with little left to do after.

I’ve felt that each brew has gotten slightly better, with one exception…  It was a recipe for a wheat extract based beer.  We (my partner and I) figured it would be a good idea to give this a try since our thought process went something like this.

It’s going to have lemon in it, and honey, oh and it will be somewhere near 8%.  It’s going to rock!

It was a terrible idea.  From what I’ve discovered from other homebrewers; using honey has some pretty explosive results. In my case, because of all the sugar in the brew from  the malt extract and honey, the yeast went on a field day.  This resulted in the airlock getting gunked up, and the lid popping off leaving behind a wonderfully sticky mess to clean up.  If we look at it positively, at least we knew the yeast was working properly

The end result though, lead to a beer that had a high A.B.V. as we had expected but also still contained lots of sugars.  So it’s sweet, burns as it goes down, and has this really strange after taste.

Thankfully we have an ESB in the primary fermenter and I just bottled an IPA this morning so we’ll be back into familiar territory within a week or so.  Keep posted for the results!

 

Keeping up with my typical not at all on the subject mentality I did a presentation about Clojure at Septembers OGRE meeting.  There was some interest in getting the slides, as well as the resources I mentioned.  You can get the slides here (zipped up if you’d prefer that) and this is the list of resources I talked about.

 

  • Leiningen – https://github.com/technomancy/leiningen
  • Emacs Starter Kit – https://github.com/technomancy/emacs-starter-kit
  • 4Clojure – http://4clojure.com/
  • Intro Book: Programming Clojure – http://pragprog.com/book/shcloj/programming-clojure
  • Intermediate/Advanced: The Joy of Clojure – http://joyofclojure.com/
  • Lighter Approach: Land of Lisp – http://landoflisp.com/
  • “Clojure – Functional Programming for the JVM” – http://java.ociweb.com/mark/clojure/article.html
 

Last week at Shopify we had a this thing called FedEx Days (or something similar) where we were given 2 days to work on any project we wanted.  After having looked at the Jhopify library, and trying to patch it, I figured that API bindings for Shopify could be solved better.  I had worked with the Shopify API before when I first started working at Shopify while I was still doing Android dev there.  Since then though, nothing really came of it.

I had taken a few lessons from that experience and decided to use that knowledge to create a tool so that Android devs could spend less time writing boilerplate API code, and more time solving problems.  I also wanted to ensure that I could provide as much of a one-to-one mapping to the API as possible.  This meant one thing, Java Beans.  I looked at the API and looked at a blank Article.java file and cringed.  There has to be a better way to do this; and of course there is!  You see, I remembered reading something from the Pragmatic Programmer.  It’s something along the lines of “If you have to write repetitive garbage, why not have a computer do it instead? Voila! Code Generators!”.

Thankfully, the Shopify API provides some pretty good example output and I figured I would use this as a tool.  With the Shopify examples that I had so gracefully copy-pasta’d into some ‘fixtures’ that I was intending on using for tests I then proceeded to use them as training data.

So I fired up my default system text editor (TextMate, though emacs would’ve been preferable… no time!) and started hacking out some ruby.  First step was to get all the POJOs/beans written up, then I’d tackle actually getting the API to work.  This was pretty straightforward; read in the data, turn it into a hash, infer the data types and apply the various private members and their getters/setters, add annotations, etc.

But it dawned on me.  What if the Shopify API for say, Articles were to ever change? I could just manually add the new changes, but that sucks.  This reminded me of another problem I had when doing some iOS/core data work about a year ago which has much of the same problem, which was solved.  The tool that solved the iOS problem is known as MOGenerator.  The way the tool works is by inspecting your data model and creating intermediate classes with all the boilerplate, then adds a subclass where you can add custom code.  It makes the promise that if you ever put custom code in the _yourModel (or whatever syntax it uses), MOGenerator will gladly come in and overwrite all of it.  So I figured that taking a similar approach for the Shopify models would be fine, and would also save a bunch of time/worry.

With all that working and tests running green on some simple and more complex data types, I then proceeded to create the API bindings.  I decided to go with a tool called CRest which makes mapping API endpoints far simpler.  After writing the first endpoint I again realized that this could be generated as well, mind you not as elegantly.  Not all endpoints map out in a manner that is as simple as the beans, but I figured this is the best way to get at least some form of API wrapper working.  So making some really basic assumptions, I also generated all the endpoints.  These probably won’t work as elegantly as the beans did, but it should be a starting point for anyone wanting to work with the API.

So all in all, I was able to get hundreds of lines of code written up in about 200 lines of ruby.  Though we need to keep in mind that much of that ruby code consists of huge blocks of text and not actual logic.  If I were to remove all of that, I’d say this was accomplished in even fewer lines, perhaps 100?  I’m hoping to have the code publicly available on GitHub soon.  Just need to get a tutorial/demo app written up, unless you don’t care, then I may be able to convince some people to release it as is.

 

From the Playstation update v 3.70 release notes

Exclusively for Playstation(R)PLus members, [Automatic Update] is a convenient feature that automatically takes care of daily chores for you.  When you use this feature, the system will start automatically at the scheduled time and will perform the following operations.

* Download content such as game patches, system software update data and video items we recommend to you
* Upload new saved data from your gameplay to online storage
* Sync trophy information with the server

Yep, 50 bucks a year to run a daily CRON job. Thanks Sony!

 

As I mentioned earlier I decided to start playing around with Clojure on my Windows box. This was an excellent way to get a quick introduction to the language, although there were aspects of the Windows platform that made going any further than toying around somewhat pointless. Although, this could simply be my bias towards Unix style systems.

When I decided to set up clojure on my Ubuntu installation, it felt like there was a huge wall in my way that made absolutely no sense. This was really because I had made a few mistakes when installing my editor of choice (emacs) from apt. That being, I had installed various emacs plugins such as swank and slime which caused some really frustrating problems to arise when running swank-clojure. I found in the end, the easiest thing to do is get a full install of emacs going, without any extra bells and whistles; that’s what the ELPA is for, and it does a damn good job at it.

Once my emacs was back to a good state, I was able to get the clojure-jack-in function to work the way I was expecting it to. Finally I was able to get hacking! On the windows box, I was (and still am) doing a text adventure game from the Land of Lisp book. I’ve found this to be an excellent way of stepping into the language, especially since the book assumes you are using common lisp. This has lead to a fair amount of research into finding out clojure equivalents to CL macros. Meanwhile, on my Ubuntu machine I’m working on a project that I’m hoping will make one part of my life a bit easier.

I’ve found that when it comes to doing tasks, such as groceries, it can often be a pain. My partner and I use our phones for entering our grocery list and each time it’s excruciating. These keyboards are annoying to use, our Nexus ones have those poorly placed heat sensitive buttons that your thumbs always manage to hit, and the program we are using doesn’t learn very well. So I’ve decided that the first step in making this better would be to have an application that makes at least entering the data easier. I’ve decided that I’m going to implement this tool using Clojure, because I’ve found I’m loving the way you do things in the language (it feels more mathematical). I also feel that since I’m extremely green with the language that I’ll be required to keep things simple (I still cannot get [& args] working for whatever reason!).

In an attempt to keep things simple, I’m avoiding the database… well that’s a lie. I’m avoiding the Relational database. I’ve always found that when I use a tool like Rails I tend to over-complicate my models for whatever stupid reason and it just leads to me abandoning the project.  I’m also interested in playing with document stores (in my case MongoDB) since I love to use hashes/JSON.  It just so happens that there is a library called congomongo which is pretty easy to setup and start playing with MongoDB. Once I’m done getting this part of the application working, my next plan is to play with the Noir microframework (similar to Sinatra or Flask) to implement my web app.  If I decide to continue working on this, it probably won’t scale all that well, but at least it’s simple enough to not overwhelm me at first.

 

I’ve been mentioning to people that I’ve been collecting bixi usage data for the last few months. Well I went to check out the dataset, and it would appear that most recently there’s been a loss in some data. Either their site is down, they are blocking my requests, or something else… not too sure. But I’ve managed to collected around 7.5 megs (110kB gzipped) worth of data from them, so I’d say that’s pretty good.

Personally, I’m going to be bringing this dataset with me to the Hack/Reduce event that’s coming up in August. I’d really love to figure out some neat statistics about usage, perhaps generate some heatmaps or something.

Anyway, I figure that others may be interested in running some of their own data analysis on the dataset as well. So here it is!

You may look at the dataset and think it’s a bit messed up. When I wrote the script I really didn’t want to waste time trying to figure out how best to represent the data so I decided the best thing to do was to keep it as raw as possible. Each line represents a single entry taken at a certain time, and is in JSON, so you can easily parse the data. All I really added was a timestamp so you can know when the data was collected.

Feel free to use this data though if you could give credit to me for the data set that would be great!

 

A while back a friend of mine suggested I should get into programming some clojure. I figured I would, but wanted to get my environment working. This included all of the setup for emacs to get slime, swank, leiningen, etc working, which I still cannot really get working.

I was looking around for something that would at least get me knocking out some clojure code before I commit any efforts to actually getting my environment working on. I discovered this awesome prebuilt package called Clojure Box. I don’t really know what is all there, but at least it got me up and running with clojure so I can play around in the REPL while learning the language.

I am a bit bummed that the tool is windows only, but it’s not a big deal for now since all I’ve really been doing is writing snippets in buffers I’m probably going to throw away.

As for learning the language I’m starting to follow this introduction to clojure guide I found. It *really* covers the basics, but every time I try to jump too far ahead in new languages I just get lost and confused anyway.

 

I’ve recently started using spine for a project I’m working on at Shopify and I realized that there were some deficiencies in the framework. These were primarily around dealing with prefixed API responses and finding items that weren’t necessarily available locally (yet). I had been working on fixing the prefix issues several times, though I was informed by Alex (the maintainer) that he was going to be dropping support for prefixed responses anyway. Also, for finding items Spine made an assumption that on your fetch call everything would be retrieved from the server. This works for tiny applications, but when dealing with large datasets (such as those that can be retrieved in the Shopify API), you may not get everything you want in a single call. This required being able to defer a call off to the server to see if it exists there before reporting an item as unknown/not found.

Hence, bring on the plugins project that I’ve started. Currently the only plugin is the ajax.find plugin that solves the problems mentioned above. Hopefully it will help anyone using spine with any issues they may be having in the future when their server responses are non-standard (in the rails sense) or simply legacy from old rails applications.

The code is available on github and I really hope that it helps with any problems you may have been having. I’m definitely willing to accept contributions, though it would be preferable that they are tested.

 

As part of my day job at Shopify I’ve been implementing a new front end using the language CoffeeScript. Originally, the front-end was regular JavaScript, but since Rails 3.1 will be supporting CS we might as well start using it.

As a whole, the language isn’t that bad. I do appreciate many of the helpers it provides for enumerating hashes and arrays, and bindings (aka fat arrow) are awesome. It’s made writing some complex client code that relys on context far easier, especially since the new features like .bind aren’t available on most (if any) mobile devices (although this is easily fixed with something like 5 lines of code).

My main complaints about CS are with some of the edge cases it has. For example, I needed to have a bound anonymous function within a setTimeout. In JS I would typically perform something similar to:

setTimeout(
  // May be a little bit off here, but I think that's how to do ECMA5 binds
  function(){ this.doSomething(); }.bind(this),
  150);

The above is fairly straight forward, and the language doing anything I’d consider unexpected. Though if we were to do the same thing in CS, I’d expect it to be something like this:

setTimeout( => @doSomething(), 150)

This actually doesn’t work, the coffee compiler will complain. It’s somewhat understandable, there some weird stuff going on here and it’s difficult to parse. A solution I often used was this:

setTimeout( (=> @doSomething()), 150)

Now I have all these extra brackets that I shouldn’t need, and it’s frustrating because I’m trying to use th language the way it seems to have been designed. Now this had been bothering me for some time now, and decided to twitter rage/complain about it. This did get some attention from someone who runs the CS twitter account who gave me some suggestions. Those of which I found to be somewhat hacks, or wouldn’t work in my case.

One solution was to have (in my case) the fetch method bound to the products instead of having a fat arrow function declaration. Now, since the actual model that products Points to is a Spine model, I really don’t feel like going in and hacking something (that already works the way I want/expect) for such a minor (but annoying) problem with CS. Another solution was to essentially create a function that is in essence setTimeout but reversed, so it’s something like:

delay = (delay, function) ->
  setTimeout(function, delay)

Which I’m also not super keen on, once again it’s going through a bunch of extra steps to fix an inherent problem with the language itself. Now I often do mix up the arguments used in setTimeout, and I would love to see that get fixed/added in the future.

I mentioned the problem I was having to one of our awesome (and way smarter than me) interns about it and he actually came up with an almost perfect solution.

setTimeout( =>
  @doSomething()
,150)

Aside from that preceding comma and needing to remember to un-indent, it’s not a big deal and I like that I’m not having to go in and hack apart Javascript to fix minor issues.

Although I do seem to be a bit bitter about my experience with CoffeeScript, I do have to say that I like what the language is bringing to the table, I just hope it gets some improvements for CS 2.0 or something. Perhaps having some kind of explicit scope declaration (like begin end or curly brackets), would help out a fair amount. Though, I think I can keep dreaming for having curly brackets, there seems to be some kind of aversion towards them.

© 2011 Christopher Saunders Suffusion theme by Sayontan Sinha