I'm a Floridian web engineer who planted his roots in Paris. Some of my favorite past-times are analyzing and optimizing development processes, building solid APIs, mentoring junior devs, and long walks on the beach.

MongoDB Musings from a Beginner 08-06-2016

Counter Cache

If you are used to the way that SQL databases work, then you are also used to the implementation of a counter cache. In Rails it is a trivial implementation. Essentially, it will internally maintain a cache of the count of associated objects in a relation, this results in more data management but it avoids an extra query every time you need the count of associated rows.

In MongoDB, certain types of associations will get this functionality out of the box. With a HABTM and a many to many relationship, the counts will be stored by virtue of the type of associations. This is because there are no joins in Mongo, so the references to a document must be stored directly on that document. Therefore, you end up being able to do something like document.ref_ids.count.

No Joins

In Mongo, there are no joins, only more queries. This can be kind of annoying if you are used to doing more work directly on the database. This means that if you want to join two tables, you need at least two seperate queries. It also means that you need to think more seriously about where certain data needs to go. Should it be in it's own document or embedded in another? The upside, is that aggregations within a collection are extremely powerful.

N + 1 Fun

A quick note, if you are using something like ActiveRecord you can still easily avoid the N + 1 query problem. A call to include works more or less the same way, but of course it will be done with 2 queries instead of a join.

Schemaless Schema

People tend to think that the fact that MongoDB is schemaless means that you can just add new attributes or change attributes without worrying too much about the ramifications. This will create some of the saddest querytime that you have every had. It's true that you don't have to migrate columns as with a traditional SQL database, but if you change an attribute name and don't migrate the data, be prepared to have your queries handle the old data and the new data. There is no free lunch. :(

Tags: mongodb

The Arrogant developer 05-05-2016

Have you ever spoken with a developer who you thought was arrogant? It's hard not to find at least one person that you work with that doesn't give off a condescending air.

I had always wondered where this comes from, if my field just so happens to enforce this kind of behavior or if maybe the field just attracts a certain kind of person. I had a talk with a friend of mine a while back who had noticed something similar. What's more is he had noticed it coming from himself when talking with junior developers or sometimes people new to the team. As we were talking about some of the situations that came up, we realized what the source was.

You know nothing

The depth and the broad range of subjects within the field tends to influence this kind of thinking, but moreover, coming off as arrogant actually comes from a self-esteem problem. My friend and I realized that when we came in to the field, we were surrounded by people who knew much more than us, we are constantly reminded that no matter how much we know, it is a drop in the bucket.

Here is the kicker, if you always think that you don't know anything, when you meet someone who knows less, there is a knee jerk reaction to say something in the lines of "How could you not know that?" Of course, what you are really saying is, "I know so little and I know that, how do you not know that?"

So that was what he was feeling and of course something much worse gets communicated. I'm not really sure how to fix the problem where developers feel like they know nothing, but I know that its important to try to have a different reaction when dealing with those who are seeing or realizing what you already have for the first time.

Ethereum Part 1: Test Blockchain Setup 02-16-2016


Ethereum is a cryptocurrency like Bitcoin which allows for transactions to take place that are not limited to leger changes but also allow for the running of code known as smart contracts. Their unit of currency is called ether and it is used whenever you want to push code onto the blockchain or you run code on the blockchain that modifies the underlying data in some way. This article from EtherScripter goes more into detail.


The ethereum site says you just need 1-2gb free to start developing. For me, I am using an ubuntu virtualbox with

  • 4 gigs of RAM
  • 2 CPU
  • 8 gigs of HDD // With 2 chains(dev and staging) I’m at 42% capacity


In order to start playing around with ethereum I used the following things:

  • ubuntu - apt-get all the things
  • go-ethereum - geth command line utility to run your own blockchain
  • truffle - A lightweight framework for developing, compiling, and deploying code
  • vim - A command-line editor
  • tmux - A terminal multiplexer because there is a lot going on

Get go-ethereum and build your blockchain

sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo add-apt-repository -y ppa:ethereum/ethereum-dev
sudo apt-get update
sudo apt-get install -y ethereum
mkdir -p ~/dapps/test/data
mkdir -p ~/dapps/test/config/
touch ~/dapps/test/dev_up   # Startup script for development
chmod +x ~/dapps/test/dev_up
touch ~/dapps/test/up           # Startup script
chmod +x ~/dapps/test/up

Create your startup scripts


geth --datadir "data" --trace "data/chaintrace.log" \
     --port 30303 --rpc --rpcport 8101 \
     --rpcaddr --networkid 0 \
     --rpccorsdomain "*" --nodiscover \
     --genesis="config/genesis.json" \
     --rpcapi "eth,web3" \
     --maxpeers 0 --unlock 0 \
     --password ./password \

This file will call geth and specify logging and data directories. It doesn’t look for other network ids to connect with. It is pretty standard for a dev environment. This also attempts to unlock the first account in it’s system and use the password in a local password file. This will be used for development.


geth --datadir "testnet/data" --trace "data/chaintrace.log" \
     --port 30303 --rpc --rpcport 8101 \
     --rpcaddr --networkid 0 \
     --rpccorsdomain "*" --nodiscover \
     --genesis="config/genesis.json" \
     --rpcapi "eth,web3" \

It’s the same as the previous file but you can use this one without having any accounts. If you want more information on this setting up a test chain, you can use this as a reference: Ethereum Testing.

Genesis block

The next thing is to create a genesis file to seed the blockchain with. This file is needed for creating the base of the blockchain. A little more information about the production chain can be found on the Bitcoin wiki page and the Ethereum blog.


    "nonce": "0xdeadbeefdeadbeef",
    "timestamp": "0x0",
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "extraData": "0x0",
    "gasLimit": "0x8000000",
    "difficulty": "0x400",
    "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "coinbase": "0x3333333333333333333333333333333333333333",
    "alloc": {

Create an Account

You can spool up your new test blockchain and access the console with ~/dapps/test/up

> personal.newAccount()
Repeat passphrase:

Ok. A word to the wise, don’t lose your password or your account hash. When they are gone, they are gone.

In the console, you can find a list of your accounts with the command personal.listAccounts. Now take the password you just entered and put it in ~/dapps/test/password. Now when you run ~/dapps/test/dev_up it will bring up your test chain and unlock the first account in personal.listAccounts with the password in the password file.

Exit the console and start up the dev_up version. Now we need to grab some ether by starting a miner in the console.

miner.start(10) // Starts 10 miner threads.
I0216 20:13:20.229458 miner/worker.go:349] 🔨  Mined block (#1 / 67af97f2). Wait 5 blocks for confirmation
I0216 20:13:20.230321 miner/worker.go:570] commit new work on block 2 with 0 txs & 0 uncles. Took 358.013µs
I0216 20:13:20.235390 miner/worker.go:349] 🔨  Mined stale block (#1 / 7feeeaa9).

This will go on forever unless you stop it. So just run miner.stop(10) to stop the miner threads. You can see your ether balance by running web3.fromWei(eth.getBalance("0xYourAccountHash"), "ether"). With that you will be ready to start making a dapp.

A Controller for Disabled Gamers 02-11-2016

A while back I went to my home city and played some Xbox with a friend. He has one arm and while he was very interested in playing an FPS with me it was heart crushing to see how impossible it was for him. I decided to try to modify an Xbox controller and I started to look into how I could make modifications to it.

Here is my initial plan:

New Xbox controller

The idea was to lay out all of the buttons so that he could use them with the controller sitting down. After taking apart an old Xbox controller, de-soldering all of the buttons and playing around with some alternatives, I decided to trash the idea.

A friend at Le Petit Fablab had recommended Makey Makey as a possible solution, but since it wasn't made for Xbox I didn't want anything to do with it. Later on I decided that the system didn't matter and ended up taking the Makey Makey route after all.

Board Construction

I decided to base the board out of plexiglass, with 6 smaller squares of plexiglass fixed onto it for the buttons. The decision to go with plexiglass was because other materials are a little more harsh.

  • Metal wasn't great since the base board needed to be an insulator and it's harder to work with.
  • Wood wasn't great because over time it might break down or get splintery.

Here is a shot of what I created:

Sorry for the potato quality

I covered the squares with metal tape to make them conductive and attached Makey Makey's alligator clips to the buttons. After everything was assembled, I covered it in as much duct tape as I could get my hands on. Now it really has that prototype feel. :)

The board can then be controlled with your bare feet. While it was a little awkward for me at the start, it was possible to use it to take the place of my other hand. This setup gives you the directional buttons and then two miscelleneous buttons. Makey Makey comes with certain connectors hardwired for certain buttons. WASD, F, G, space, and mouse click being the presets. You can extend what they give you but for my purposes it is just easier to override the buttons in a game.

It is funny that when I started the project, I had thought that my biggest problems would be technical ones. In retrospect, it ended up being more questions of ergonomics and materials.

Tags: hardware xbox pc

Create an Object and Its Associations in Django 04-08-2015

I just added a bit of code for creating an object with an association in Django. I saw quite a few tutorials that mix the setting of associated data directly into the view. In general, this is not recommended as django views should be for handling the passing of of data that will be rendered and the likes. Form processing should be handled in the Form classes. Here is an example of a not so great solution:


def some_view(request):
    obj_form = ObjectForm.new(request.POST)
    other_obj = OtherObj.objects.find(pk=request.POST['other_obj_id'])
    obj = obj_form.save()
    obj.other_obj = other_obj
    return render(request, 'object.html')

Association Support

Django supports the setting of associations with ModelChoiceField. However there is a caveat in that you must specify a queryset. I wanted the associated object other_obj to be able to be any row from the table that represents OtherObj, but this table will grow with time. For my needs I don't need to limit my associations to the queryset and what's more, as the table grows, the queryset will become less manageable.

Therefore, I modified the form class as follows:


class ObjectForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):

        super(ObjectForm, self).__init__(*args, **kwargs)
        self.other_obj_id = self.data['other_obj_id']

    def save(self, *args, **kwargs):
        self.instance.other_obj_id = self.other_obj_id
        return super(ObjectForm, self).save(*args, **kwargs)

In this way, I can keep everything relative to the manipulation of the Object class within ObjectForm instead of having it spread between the view and form classes.

Tags: django