Upgrading my Mac Pro (In Pictures)

I’ve always dreamed of having a do it all high end workstation to do my experiments on. Something with fast storage, lots of ram and at least one fast GPU. As you may have gathered from my blog, I tend to dabble in different things so having a powerful machine allows me the flexibility that my laptop (A retina Macbook Pro) lacks. So a year ago, I bought a 2009 Mac Pro off my friend fairly inexpensively with the intention of turning it into a power machine. »

TIL(oved): destructuring in Coffescript

I’ve talked about destructuring before on this blog, I think it’s a pretty useful langauge feature and use it where I can. So today, I was writing a CSV importer which returns each row as an array like [thing1,thing2,thing3] so I started writing processRow: (argsArray)-> firstName = argsArray[0] lastName = argsArray[1] when I had a thought, what if I could break the array elements into function arguments? I could do something janky like this »

Michael Francis

Awesome SASS: Mixins

I’ll be the first to admit, that despite considering myself a fullstack developer, my CSS knowledge is pretty limited. I know enough to say, assign a div a background color, and give it appropriate styling, but I shy away from the idea of writting CSS skeleton code from scratch and thus always rely on something like Bootstrap or Foundation for my projects. Up until recently, every project I had worked on with bootstrap used the compiled bootstrap CSS. »

Michael Francis

Ruby parameter expansion

If you’re familiar with ruby, you probably have seen multiple assignment before which looks like first, second = 1,2 or first, second = [1,2] but did you know you could do multiple assignment in method params like so: def test yield [1,2] end test do |(first, second)| "First is #{first} and second is #{second}" end Say for example you have an method that returns an array of tuples (something that’s unfortunately pretty common) such as »

Michael Francis

Abusing Reduce

As someone who enjoys functional programming languages (ruby, scala, javascript) one of my most used commands is reduce. The canonical example of reduce is summing a bunch of numbers such as [1,2,3].reduce(function(sum, number) { return sum+number }) or elegantly in ruby [1,2,3].reduce(:+) which would produce 6 However, I see reduce as more of a function you can use to build other functions from. For example, I recently wanted to write my own version rubys . »

Michael Francis

Moving to Containers Part 1: Building a PaaS

I’ve done my research and I’m mostly ready to build my dream PaaS, most of the pieces are assembled. So far we have Dokku as the PaaS layer NodeJS build pack for app(s) TokuMX for persistence (experiemental) Redis Graylog2 (for system and app logging, experiemental) Elasticsearch (for graylog2 mostly) I’ll begin by talking about setting up Dokku. First you’ll need a host for dokku, (preferably a clean Ubuntu 13. »

Michael Francis

Moving to containers part 2: Redis & mongo

Installing and setting up Redis is a breeze, you just follow the instructions here, once done, create a redis container for your app using dokku redis:create then push it’ll automatically be linked to your app. Inside your app a new enviroment variable will appear, REDIS_URL which will be in the format redis://:. I’m using redis inside the sample app for session storage but it expects host and port to be seperate, like so »

Michael Francis

Inline string formatting with Javascript

One thing I miss in javascript coming from Ruby and Python is a quick and easy way to format strings. It’s quite common in javascript to see developers doing things like var str = 'my name is ' + name; Which I find messy and unintuative. Therefore, here’s something I use in my node apps to make string formatting a bit easier var format = require('util').format; /** * Formats a string by replacing the placeholds with * with the specified variables */ String. »

Michael Francis

How to quickly remove duplicates from MongoDB

The fastest way to remove duplicates from Mongo is to fix whatever is adding them to mongo, but if you’re reading this you probably want to remove the duplicates that are already there. I had this problem as well and google wasn’t much help so here’s my solution. From here on I’m assuming you’re using MongoDB and NodeJS but if not you can apply this concept to any language; Hash your documents So as a human to find duplicates I would find documents that have exactly the same content, the easiest way for a computer to do this is to hash the document. »

Michael Francis

Joys of Embedded day 2

Well it’s that time again, it’s the second day since I decided I should blog about my (mis) adventures is embedded hardware development. Today’s adventure was implementing a few common functions without the use of stdlib or the math libraries. Most people would argue against rewriting functions that already exist. Existing packages have been vetted, have had all their bugs worked out and hey they exist to be used right? Well unfortunately these existing libraries are designed to cover everyones use case and most (if not all) corner cases. »

Michael Francis