New Gigs, New Digs

26 May 2015

Started a new gig about three weeks ago. Sad to leave the old team and friends. It was awesome and I grew in a lot of ways. But this new place is probably what I was looking for.

It’s way too early to call or judge or even sum up because it takes me about three months to settle into any new job and place. You might think that’s ridiculous but I’ve unsciencely tracked this and it holds up. Slow burn man. It’s three months.

The new place is Goldstar. We sell discount tickets fill events and have amazing customer service in and around this domain. From the tech side, the app is Rails and mobile with a set of amazing devs and ops peeps. We have expanded the tech team very recently and I’m one of the new recruits.

Learning a codebase is rough. Building a codebase and learning along the way is much more natural and comes with an advantage that needs to be cared for and not abused. “Can you not code?” This isn’t happening at the new place. I’m more amplifying what Katrina Owen said on Ruby Rogues about a book that explains downhill synthesis, uphill analysis. It’s way easier to understand a system when you’ve built it. Not even because the code is fresh in your mind. But because you hold the structure and general layout and design, connected by memories and breadcrumbs. When starting from the outside, it’s code splunking. Even if there are tests. Most of the time, I’ll break the test and see what happens. And then fix it. This simulates the synthesis part! Take it apart and put it back together for the put it back together part. This didn’t really click until Katrina enlightened me. I thanked her on Twitter. She was happy. Happy time.

So let’s talk about something pretty serious. This perceived skill gap. It wasn’t as bad as I thought it would be. I’m hanging with smart people but have a massive case of impostor syndrome. But right before this job, I wondered if the small-shop world had accelerated way past the big-scary enterprise world. And it has. But it’s not a huge deal! Do you know why? Because C, Unix, TCP/IP, Sockets, CAP Theorem, I/O speeds, SOLID, ACID and all the other non-science-laws-this-is-the-best-we-can-do-guys stuff of computer science is forever. It’s the bedrock. It’s what’s really happening. And once you know or even have a previous story/tale about these things then learning today’s Hipsterware™ is no big deal.

What’s Riak? I don’t know! It’s consistent and available? Oh! It must be really slow. Yep! Great! Right there I can knock it out of a few use cases where Redis or Memcached would be put in there. I could blather on about this. It’s really not healthy. It’s pretty arrogant actually. Most of the work is not in the initial introduction and overview. It’s in the deep and long lived implementation where your cherished newlywed tech betrays you in your most dire moment of edge-case mortality. There are so many things that I think are really great because I haven’t seen them blow up in my face in prod. There are lots of things that I used to think are great, which now I say “yeah …” unsurely because I’ve seen them blow up or not be a good fit.

I still have many miles to walk. Here some things that I’m predicting WITH MY MIND POWERS that I’ll learn and or gain from this new gig.

  • vim - My vimfiles and dotfiles have been challenged. Not even an editor war. An editor civil war. Are leader keys evil? Is nerdtree evil? Yes!? What?! I submit. I yield! I see the speed at which you are navigating files. I have thought about your strategy before and not seen it in action. Fine. I will delete my .vimrc and use yours. I’ve done it before with janus. I can start over again. Each time, I learn something new. The goal now is to stay as close to vanilla vim as possible.

  • Ruby - looking forward to pairing with lots of folks. I’ve been hearing a lot of great discussion. Lots of end-game topics. “What is intention revealing? What is this actually doing? What is the difference between these two classes? Let’s measure how fast this runs if we try it this way.”

  • AWS - A bigger setup than I’m used to. VPC I’ve done. But not so many objects. Learning lots of integrations within AWS. Pulling and syncing to buckets and stuff. I’m sure I’ll be flexing the fog gem at some point.

  • Instrumentation - It’s a big deal. There are many cloud services in action. Some are overlapping. It’s neat. It’s real. Retros where we look at code climate scores. Custom dashboards. I donated a raspberry pi for the cause. “Hook it up to the TV! Give me real insight. Get it done. Yay!” Pretty sweet.

  • Automation and CM - Chef is being used in a really nice way. It’s changing and evolving. No sacred cows. Custom tooling. Chef server is a bit slow, so move everything out. Put state somewhere else. We need to beef up the custom bits of this. We’re also working on other tools around containers. There’s no single tool really. It’s very practical. No sacred tools. I’m very impressed with the ops folks. It’s kind of beautiful.

  • The Business - It’s so easy to drown in tech. I’m looking forward to seeing all the pieces come together and watch something real happen. Ernie Miller said it best:

    Humane Development, to me, means the acknowledgement that we are humans working with humans to develop software for the benefit of humans.

    To me, this is where you see the user story get run not by your test suite but by a real customer or person. It’s the best part for lots of reasons.

Everyone is really good. That’s the job. The digs part is, our rental is coming to a close and we’ve bought a house. The next time I post might be from a different location. But not so far from where I’m at now. We love Portland. I miss friends/family but we’re staying.

I hope this town becomes a tech sanctuary for Bay Area and Seattle burnouts.

Finding a Tree

01 May 2015

When I moved to Portland, I saw this tree on I-5 outside the city. It kind of stands by itself. Pokes out before you hit downtown. I always wondered where it was. Was it huge? Was it normal? How would I find it?

Since I’m trying to explore the city and I had a week off between jobs (oh yeah, that news), I thought I’d take a break from the tech blogging and tell you about this tree I finally found after all these months.

First, I can’t believe my luck on this new Google Maps feature. I had used the Google Earth desktop app before but I didn’t realize it’s the satellite view now. It’s pretty intense on the graphics card. My mac was overheating while my gaming PC was yawning. So it’s not laptop or old mac friendly. :)

So here’s a picture of the tree as you’d see it from I-5. tree_from_i5

Here’s the dead give-away shot from Google Earth. After that, it was easy to track down. All I had to do is zoom and pan to the tree poking out in the orange circle here: tree_from_google_earth

I went to the street it’s on and took a few photos. It looks just like it does from the highway. And it’s lined up with the city. tree_found

It actually turned out to be a bunch of trees all clumped together. tree_found_close_up

Awesome. What a fun use of the google earth view in google maps.

How to Run the Docker Registry 2.0

19 Apr 2015

The docker registry is a daemon/service that you can run privately to push and pull images locally. This is fantastic for sharing images within a team, caching images locally and hacking on docker without polluting the world. There’s been a python version of the docker registry for some time but recently there has been work to rewrite it in golang. I’ve been waiting for the golang port because go projects are usually very easy to install and provide binaries.

Running the docker registry 2.0 (hereafter called Distribution) isn’t intuitive. Typically on github you’ll do something like this:

git clone https://github.com/bleh/bleh
cd bleh
# ./configure && make | go run bleh.go | bundle && rake | pip install -r requirements.txt | bower
# or something ...

That doesn’t work here. Distribution is expecting to be in a go workspace. That means that this doesn’t work:

cd ~/src/vendor
git clone https://github.com/docker/distribution
cd distribution
# oooh there's a Makefile!
make

../../go/src/github.com/docker/distribution/manifest/verify.go:6:2:
cannot find package "github.com/Sirupsen/logrus" in any of:

Oh! It’s using godep. We’ll just grab the dependencies.

$ godep get
  can't load package: package ~/src/vendor/distribution: cannot find package "~/src/vendor/distribution"
  in any of:

Hmm. That doesn’t work either. Well I know we could probably go get the whole thing but that’s going to put binaries in a golang workspace path. I kind of just want binaries in the current working directory. I’m not really sure what the intent here is. Distribution comes with a Dockerfile so I’m assuming that this is the best option to getting it up and running on a server somewhere without having to set up a temporarity golang dev environment (language runtimes as program distribution anti-pattern).

More Than One Way To Do It

We can run docker build Dockerfile

$ git clone https://github.com/docker/distribution
$ cd distribution
$ docker build .

The problem with this approach is that it gives us an image that we have to further customize. The binary registry isn’t in the path and godeps is in a special work dir as specified by the Dockerfile.

$ ls /go/src/github.com/docker/distribution/Godeps/_workspace/bin
godep

So we could go down that road but you’ll have to commit the changes and tag it yourself.

We can go get it

If we do this:

$ go get github.com/docker/distribution

This will put a binary in our path somewhere but then we’ll have to put it on a server. This also requires us to cd into our gopath workspace and copy a binary. Alternatively we could clone Distribution into a tmp golang workspace but this is effectively the same thing just in a different location.

Originally this is how I tried but later realized it’s worse than below (thoughts anyone?).

We can pull the registry from docker hub

# create some directories - change to your tastes
$ mkdir /opt/docker_data/registry
$ cd /opt/docker_data
$ wget https://raw.githubusercontent.com/docker/distribution/master/cmd/registry/config.yml
$ mv config.yml registry.yml

$ docker run -d -p 5000:5000 -e STORAGE_PATH=/registry -v \
  /opt/docker_data:/data -v /opt/docker_data/registry:/registry \
  --restart=always --name docker_registry registry:2.0 /data/registry.yml

# set it to autostart, bob's your uncle
# see below for usage with boot2docker

This is pretty nice. We have to be careful to specify the registry:2.0 tag in order to get the golang version. Latest will grab the python version. You can see this if you run the image interactively (not sure the 2.0 can be run interactively because of ENTRYPOINT – but there’s your clue).

Boot2Docker and insecure-registry

Once you are running a private registry, it’s up to you to generate an SSL cert. If you are on mac, you don’t even have a docker daemon locally so this part is confusing. When you push to your registry, you’ll get a warning/error.

FATA[0000] Error response from daemon: v1 ping attempt failed with error: Get https://hostname:5000/v1/_ping: tls: oversized record received with length 20527. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry hostname:5000` to the daemon's arguments. In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag; simply place the CA certificate at /etc/docker/certs.d/hostname:5000/ca.crt

This is like your browser warning message on a unknown self-signed cert. But how do we add an exception? The official boot2docker docs have an answer but I have an addition. Add the port number to the hostname. If your server is called bleep then add bleep:5000 to the boot2docker image file at /var/lib/boot2docker/profile

# on your mac
$ boot2docker ssh "echo $'EXTRA_ARGS=\"--insecure-registry bleep:5000\"' | sudo tee -a /var/lib/boot2docker/profile && sudo /etc/init.d/docker restart"

# now you can push
$ docker push bleep:5000/busybox
The push refers to a repository [bleep:5000/busybox] (len: 1)
8c2e06607696: Image already exists
6ce2e90b0bc7: Image successfully pushed
cf2616975b4a: Image successfully pushed
Digest: sha256:3cc6b183efb34ff773f81ce230362ef67288375fdeb9cc8d50c221820fbe5e3b

# testing
$ docker run -it --rm bleep:5000/busybox /bin/busybox env

# on the host
$ ls /opt/docker_data/registry/docker/registry/v2/repositories
busybox

Deleting Images

I couldn’t get this to work. I commented on an issue, someone had the same question as me.

$ curl -XGET http://private-host:5000/v2/busybox/manifests/latest
# GET included for effect only  :)

The API doc says that DELETE should work. So I just substitute http verbs above and get an unexpected error:

$ curl -XDELETE http://private-host:5000/v2/busybox/manifests/latest
{"errors":[{"code":"UNSUPPORTED","message":"The operation is unsupported."}]}

So I’m not sure what’s up there.

Sidenote

I ran into a weird issue while testing Distribution on ubuntu.

FATA[0000] Error response from daemon: Cannot start container
aa2a7765d5c67625fea17f1c5f0d8b90216418d44db95df5268822d8e3bcf21e: write /sys/fs/cgroup/cpu/docker/
aa2a7765d5c67625fea17f1c5f0d8b90216418d44db95df5268822d8e3bcf21e/cgroup.procs: no space left on device

My disk has plenty of space. docker info shows it using aufs which I believe doesn’t have the same disk space limits that devicemapper (like CentOS) has. By that, I mean the docker host + kernel combination. I’m actually not sure of where that interaction lies. I just know that docker info on different kernels show different output.

So how do I start over? I have my docker data in a docker directory. For this case, when all your data is safe and secure then you can just blow away everything and start over. For me, this was the fix. I had some package garbage (docker.io and lxc-docker packages installed). So I apt-get remove --purge-d everything and installed docker 1.6 through apt-get. That fixed this croup problem and kept my containers/data in tact. I feel like this was an edge case.

Conclusion

The docker image is the best way to run the registry but it requires a tiny bit of setup beforehand. There’s also some things that aren’t covered here:

  • SSL cert
  • Logstash support is mentioned as an output format
  • Redis caching
  • Authentication / reverse proxy / webgate

Regardless, happy to see a golang version of the registry.

Nil, If and Collect in Ruby

18 Dec 2014

Ruby’s if statement returns the return value when matched. If it falls through, it returns nil. I sometimes forget this. It’s not a big deal until it bites you.

Here’s an overly simple example where this works very well.

numbers = [1,2,3,4,5].collect do |number|
  if number % 2 == 0
    "#{number}: even"
  else
    "#{number}: odd"
  end
end

numbers
# => ["1: odd", "2: even", "3: odd", "4: even", "5: odd"]

This is really handy because we don’t have to create like a temporary variable somewhere and use each. But this is also a really clean case because there’s only odd and even. In other words, our if statement never falls through to return nil. Nil is a pain in Ruby. Avdi’s book Confident Ruby is not just about nil but it talks about nil. Avdi’s screencasts about nil are a good place to learn more (and I often refer back to Avdi’s work).

Ok, back to our collect. When possible, I try to use collect to avoid mutation. Maybe it’s my concession to functional programming languages. Maybe it’s because state mutation in Ruby causes headaches. I think the most important reason for exploring this is so we know of one other way to skin a cat. So let’s look at a more real example.

users = [
  { name: "Jay", enabled: false },
  { name: "Joan", enabled: false },
  { name: "John", enabled: true }
]

# enable everyone!
users.each do |user|
  user[:enabled] = true if user[:enabled] == false
end

# users
# {:name=>"Jay", :enabled=>true}
# {:name=>"Joan", :enabled=>true}
# {:name=>"John", :enabled=>true}

Meh. Mutation. It’s good to know just one more way for us to do this. Return a new collection.

users = [
  { name: "Jay", enabled: false },
  { name: "Joan", enabled: false },
  { name: "John", enabled: true }
]

# enable everyone!
enabled = users.collect do |user|
  user.merge({enabled:true}) if user[:enabled] == false
end

# enabled
# {:name=>"Jay", :enabled=>true}
# {:name=>"Joan", :enabled=>true}

Whoops. Where did John go? Here’s that thing I was talking about. Our collect needs to handle the fallthrough from the if.

users = [
  { name: "Jay", enabled: false },
  { name: "Joan", enabled: false },
  { name: "John", enabled: true }
]

# enable everyone!
enabled = users.collect do |user|
  if user[:enabled] == false
    user.merge({enabled:true})
  else
    user
  end
end

# enabled
# {:name=>"Jay", :enabled=>true}
# {:name=>"Joan", :enabled=>true}
# {:name=>"John", :enabled=>true}#

# users
# {:name=>"Jay", :enabled=>false}
# {:name=>"Joan", :enabled=>false}
# {:name=>"John", :enabled=>true}#

Great! You can see we didn’t mutate state. Now the problem with doing this all the time in Ruby is tail call optimzation. If you go to the ends of the earth with this your stack will explode. But I still like this style when I can do it because I avoid changing state.

The end-game to this line of thinking is switching to or at least playing with a functional language like Clojure, Rust or Scala.

Mocking in Golang

28 Nov 2014

This was originally a stackoverflow but it got down voted and suggested it be a blog post. Ok! Here’s my toy program. I had it separated into package files but I figured that would be harder for you guys to run it yourself. Please bear with me while I step through this.

The first iteration:

charge.go

package main

import "fmt"

type VisaGateway struct {
    Name string
    Url  string
}

func NewVisaGateway() *VisaGateway {
    return &VisaGateway{
        Name: "Visa",
        Url:  "visa.com...",
    }
}

func (v *VisaGateway) Charge() {
    fmt.Println("I am charging Visa -->")
}

type PaymentGateway interface {
    Charge()
}

func ChargeCustomer(g PaymentGateway) {
    g.Charge()
}

func main() {
    gateway := NewVisaGateway()
    ChargeCustomer(gateway)
}

Running it.

$ go run charge.go
I am charging Visa -->

So we can test this with a mocking library (separate question) maybe but for now let’s just use this interface and make a test that passes in a fake gateway so our test suite doesn’t hit a real system.

charge_test.go

package main

import (
    "fmt"
    "testing"
)

type MockGateway struct {
    Name string
    Url  string
}

func (m *MockGateway) Charge() {
    fmt.Println("This is a fake gateway.  --> [no-op] <---")
    fmt.Println("Yay!  :) ")
}

func TestCharging(t *testing.T) {
    m := &MockGateway{}
    ChargeCustomer(m)
}

Great!

$ go test
This is a fake gateway.  --> [no-op] <---
Yay!  :)
PASS
ok      github.com/squarism/credit_card 0.010s

What I’d probably want to do is use a library to help with the mocking setup. Previously I was trying to use a dependency injection style without interfaces and it didn’t work out.

Imagine that my Charge() method signature looks more like this (from joneisen.tumblr.com.

func ChargeCustomer(args ...interface{})
// code to init args and defaults -- see blog post linked above

This doesn’t work because type checking args breaks when you pass in a mock object with no interface. I’m not even sure if interfaces would fix this.

I was hoping to have a default value of the real type/struct and then in my test pass in a mock object. This is one nice side effect of default parameters and dependency injection. But that’s dynamic language style that I have to teach myself to let go of.

Ok. Let’s now using testify for mocking. Let’s add a return value so we can test something.

charge.go

...

func (v *VisaGateway) Charge() bool {
    fmt.Println("I am charging Visa -->")
    return true
}

type PaymentGateway interface {
    Charge() bool
}

func ChargeCustomer(g PaymentGateway) bool {
    return g.Charge()
}

func main() {
    gateway := NewVisaGateway()
    ChargeCustomer(gateway)
}

...
charge_test.go

package main

import (
    "github.com/stretchr/testify/assert"
    "github.com/stretchr/testify/mock"
    "testing"
)

type MockGateway struct {
    mock.Mock
}

func (m *MockGateway) Charge() bool {
    args := m.Mock.Called()
    return args.Bool(0)
}

func TestCharging(t *testing.T) {
    m := MockGateway{}
    m.On("Charge").Return(true)

    r := ChargeCustomer(m)
    m.Mock.AssertExpectations(t)

    assert := assert.New(t)
    assert.True(r, true)
}

The run result:

$ go test
PASS
ok      github.com/squarism/credit_card 0.018s

In the mocking example we also added m.Mock.AssertExpectations there. That is additional test that captures and remembers the calls. If the wiring is wrong and the expected call is not called, the test will fail. For a while I was not testing this and I would have had a test coverage gap. Another mistake I made while figuring out the AssertExpectations test was not passing by reference. I continue to make this mistake because I’m pointer-nooby. For more information on this see my question on stackoverflow.

Ok, so that’s my first foray with mocking in Go. So here are some questions:

  • Do you use a mocking library?
  • Do you see how default arguments wouldn’t work to help with mocking? You can’t really DI. I’m ok with this. I just need to learn.
  • Do you like interfaces for (not only) testing reasons?
  • Do you like the interfaces version more than the mocking version?
  • It seems that mocking really needs an interface somewhere? Otherwise won’t you get a cannot use gateway (type *VisaGateway) as type PaymentGateway in argument to ChargeCustomer. I might have gotten this wrong from the testify docs. It wasn’t obvious until I wrote this question.

If you have anything to say or answers to this question tweet me at @squarism.

… and once again, rubber ducking on stackoverflow. Writing the question made me figure it out.

Follow Through and Fundamental Immovables

15 Nov 2014

You can imagine an end result without knowing about fundamental problems. If those fundamentals are core to your business or idea and they are immovable then you probably can’t pivot without fudging what pivot means.

Stay with me for a second and take this lead and gold atom.

alchemy atoms

Now if we could just remove three protons from the lead nucleus then three electrons would just float away it would turn to gold. How useful! How wonderful! Gold has many industrial applications. Lead is poisonous although it also has industrial applications. We could create a lead recycling center! My imagination is running wild with ideas even before we’ve gotten anywhere!

Hmm. So what if we had tiny tweezers? Oops, there’s our tweezers.

alchemy tweezers

Oops! Our tweezers are made of atoms too!

Our tiniest breakthrough, patent winning, best mankind could produce tweezers. Imagine you haven’t gone through any class / book / information that would give you a keyword like “Alchemy” or chunked knowledge like “Alchemy is bogus”. Wouldn’t it seem tempting to try these tweezers? To build these tweezers? When the tweezers don’t work, try pliers?

alchemy pliers

Pliers aren’t the problem. We have an fundamental immovable.

Here’s a wall. You can imagine walking up it can’t you? Well, how would that work exactly? Do you put your first foot on the wall and now you feel like you are doing splits? Or can you remove your foot as easily as a handshake? See, in physics there’s something called perpendicular force (relative to gravity). If I push a car, it’s easy. If I lift a car it’s hard. So are you stepping onto the wall? How hard is it to step up on a table? What transition is there? If you don’t strain like stepping up on a table, could you fall off the wall onto the floor? If you could, wouldn’t that create energy?

walking up a wall

We don’t know. Let’s find out together. This is why I like the TDD loop. Not just testing or test-first but actual TDD. I feel that it guides me. It allows for team discovery. How many more complicated problems like this are there? TDD is a like a science that mitigates human fallacies. More than TDD. Many things do. Science, Agile (whatever that meant before it died), feedback loops, Kanban. They are feedback systems that correct human bias.

It’s not about testing really, it’s about iterating and least-complexity. I really like this picture of shipping a minimum viable product.

agile car

I think this is also a function of diversity. If our team is made up of pliers, we’re in a tight spot. And I don’t even mean racial or gender diversity specifically. Think of this like a portfolio. Don’t put all your eggs in one basket but also make your eggs happen fast while not caring about eggs.

Where Do You Put Your Go Code?

14 Nov 2014

One of the most confusing parts of starting Go was learning the project layout or what Go calls the workspace. It’s changed a little bit in past releases (eschewing $GOROOT etc) but the confusion I think remains if you come from other languages and tools.

Internalize these things:

  1. Your code will go in a folder next to all the libraries you download.
  2. You probably cannot put your Go code next to your Java/Python/Ruby/Javascript/… unless you luck out on naming conventions that you’ve already started.
  3. If you are starting out and you don’t put stuff in ~/bin then just set $GOPATH to your home.
  4. If you don’t like that last rule, just create ~/gocode and set $GOPATH to that.
  5. You probably should not put your Go code in Dropbox.

You also do not need to create a github.com account to put your projects in ~/gocode/src/github.com/{username}/hello_world. You can just go ahead and start your project. It’s just a namespace. If something else needs github.com/{username}/hello_world then it will import it. If it can find it in the GOPATH then it will work. That’s all this is.

When I started Go, I was worried that I was polluting system paths by starting projects in $GOPATH/src/github.com/{my_username}. You’re not. Don’t think about it.

I can’t put my crap code next to the likes of Docker!

It’s impostor syndrome. Just start your project. Just do it.

YAML and Maps in Go

13 Oct 2014

This wasn’t exactly clear. When using the gopkg.in/yaml.v2 (or gopkg.in/yaml.v1) packages, I was confused as to what to do with my data structure.

Let’s say we start off with this file.yml:

description: fruits are delicious
fruits:
  apple:
    - red
    - sweet
  lemon:
    - yellow
    - sour

Here’s a complete example to read this file in and you get a parsed data structure out of it:

package main

import (
  "fmt"
  "gopkg.in/yaml.v2"
  "io/ioutil"
  "path/filepath"
)

type Config struct {
  Description string
  Fruits map[string][]string
}

func main() {
  filename, _ := filepath.Abs("./file.yml")

  yamlFile, err := ioutil.ReadFile(filename)
  check(err)

  var config Config

  err = yaml.Unmarshal(yamlFile, &config)
  check(err)

  fmt.Printf("Description: %#v\n", config.Description)
  fmt.Printf("Fruits: %#+v\n", config.Fruits)
}

func check(e error) {
  if e != nil {
    panic(e)
  }
}

What is Fruits map[string][]string in the Config type? It’s foo: ['a', 'b', 'c'].

This is roughly equivalent to what I would do in Ruby. Of course the Ruby code is much shorter because in Ruby, typically we abuse hashes. :) The surprise I had is this: when the YAML changes, we have to update our type Config. I’m ok with this. I was just surprised by a few things.

First, the keys are significant. If we change the YAML to be:

description: fruits are delicious
tambourines:
  apple:
    - red
    - sweet
  lemon:
    - yellow
    - sour

It won’t work. But HOW it won’t work is confusing.

Description: "fruits are delicious"
Fruits: map[string][]string(nil)

You’ll get an empty map until you change your type to have Tambourines in it. You can’t just access .Tambourines either. The type/struct won’t have a method on it. So this is the trick and benefit the package gives you. You just model your YAML and it maps the keys for you. But you have to “know” what your YAML (dare I say schema?) is. So would you then validate that it loaded correctly by checking lengths etc?

Now what happens when you get it really wrong?

Continue Reading →

Ruby Slop Example

25 Sep 2014

One of my favorite features of slop is the automatic help generation. But it’s not intuitive. It doesn’t print out the help when the parsing fails. This isn’t very unix-y. So every time I want to use slop, I have to look up this snippet I saved for myself. So I’m posting it here. This is the only slop example you’ll ever need.

Unix style CLI program in Ruby

require 'slop'

opts = Slop.new(strict: true, help: true) do
  banner 'Usage: slop_test.rb [options]'

  on 'resume=', 'Your resume file', required: true
  on :s, :skill=, 'Skill Name', as: Array, arguments: :optional
  on 'v', 'verbose', 'Enable verbose mode'  # same as adding required: false
end

begin
  opts.parse

  # validation passed
  puts "Here's the data"
  puts opts.to_hash
rescue Slop::Error => e
  puts e.message
  puts opts
end

Calling it like this will fail:

$ ruby ./slop_test.rb
Missing required option(s): resume
Usage: slop_test.rb [options]
        --resume       Your resume file
    -s, --skill        Skill Name
    -v, --verbose      Enable verbose mode
    -h, --help         Display this help message.

Great! Then using it correctly will do this:

$ ruby slop_test.rb --resume hechicero-del-relámpago.doc
Here's the data
{:resume=>"hechicero-del-relámpago.doc", :skill=>nil, :verbose=>nil, :help=>nil}

The resume flag is the only required one, so in this case that’s how it’s run correctly.

Update: I was very happy that @lee_jarvis (the slop author) accepted my pull request to put this example into the README.

Redis and 595 Timer States

24 Sep 2014

I wanted to learn about how a 595 timer chip works. I’m a code dude. So when I see this integrated chip and all its pins, it’s scary. I’m sure an EE major is giggling right now but that’s just Impostor Syndrome. For no reason beyond this, I wanted to visualize and grok a 595 timer’s state at any given point by having it’s pins mapped to Redis key/value pairs.

Here’s a quick video explanation of the project.

Continue Reading →

Positive Change

17 Aug 2014

I’ve been in Portland for a week. So far, it’s amazing. I really don’t want to blather on about how great it is because, to be honest, I’m afraid of boyish optimism. This town, like college, will probably give back whatever I put into it. So I’m pacing myself. I think it will be good though.

Our house is completely empty while we wait for our movers to arrive and that’s ok. I’ve been getting a lot done without all the distractions. One of my favorite pictures of Steve Jobs is where he is sitting in an almost empty room with nothing but books. I’m not trying to be Steve Jobs but I appreciate the minimalism because my house looks very similar to this picture right now.

Continue Reading →

Default DC Tech is Just Bad

06 Jun 2014

The opinions of this blog, but especially this post are mine and not my employers’.

I’m done with DC. I need to archive the reasons why for myself. I hope this serves as a free field trip to the DC area for anyone outside the beltway.

TL;DR

If you move to DC for the tech jobs, you are going to have to prune a lot of C-minus government work if you are good. All the while, you will be paying for local benefits you are not taking advantage of. This is the land of politics, military, intelligence, big government and lobbyists. I tried to influence from within but now it’s time for me to GTFO and move to Portland to try to find “actual reality” jobs.

dc_capitol

I’ve Been Here Too Long

I’ve lived in the DC area for 30 years. I’ve been working for 14. You might as well say I’ve lived around DC my whole life. I went to School and College in Northern Virginia. Northern Virginia and Maryland are part of the DC metropolitan area or what we would call the “DC Metro”. This is a little bit confusing because if you say “The Metro” then you mean the subway. I’ve traveled around and lived other places but you could say I’ve been here for a long time. Recently, I’ve concluded that DC isn’t all bad but I’ve been here too long. Also I feel like a slow learner in that it has taken me so long to realize these things. I’m doing something about it and I’ll talk about that later.

I’ve done the DC government contracting circuit and I’ve concluded that I’ve seen enough. It doesn’t really matter what company you work for, it’s the same project with the same people and the same problems. However, a few years ago I found a small life raft. It’s a non-profit R&D shop and it’s the best big tech company I’ve found in DC. It’s not perfect but at the core of it is the non-profit bit. It’s not Beltway Bandit time.

Beltway bandit is a term for private companies located in or near Washington, D.C. whose major business is to provide consulting services to the US government.

Continue Reading →

Passion

19 May 2014

On a Ruby Rogues podcast about Passion, Avdi continued to enlighten and entertain me with his insights. I’ve really been enjoying his speaking style and voice lately through tapas and talks. If he reads this, I hope he understands I don’t disagree with what he is saying; I thought he would enjoy a related story.

Honestly, this topic is so massive I don’t think I can really offer too much more than the Rogues did on the podcast so I encourage you to listen to the episode yourself. It has almost nothing to do with programming or Ruby. I feel that philosophies and stories about passion are so close to the difficult and inevitable goal of “master yourself”, which is both complicated and personal, I can just barely approach the topic and then a rat’s nest of anecdotes and advice explodes all around us.

With that context laid out, here are a few stories.

Continue Reading →

DRY up Methods with Ruby Blocks

14 Sep 2013

Let’s do something terrible by hand. First, here’s our data. It comes from a database.

db_results = [
  { id: 1, login: 'mjay', roles: ['user'], projects: ['muffins'] },
  { id: 2, login: 'rroke', roles: ['admin', 'user'], projects: ['security'] },
  { id: 3, login: 'tpain', roles: ['user'], projects: ['muffins'] },
  { id: 4, login: 'ghaz', roles: ['admin', 'user'], projects: ['muffins', 'cakes'] },
  { id: 5, login: 'bbarker', roles: ['user'], projects: ['pies'] }
]

Now when working with these people, we probably could get away with doing something like this for a while:

# find all admins
admins = db_results.select {|user| user[:roles].include? 'admin' }

Which is fine. Until you want to find out what people are on the Muffin Project:

# find all people working on the muffins project
people_on_muffins = db_results.select {|user| user[:projects].include? 'muffins' }

But as you keep working, you might be getting a feeling of deja-vu. The two methods above are very similar. You might be inspired by other Ruby libraries which give you a tiny DSL or at least allow you to pass blocks into methods to be more expressive.

Continue Reading →

Problems with "The Cloud"

27 Aug 2013

I’ve been thinking about the problems with The Cloud outside it being a raging buzzword. It really comes down to Control and Connectivity. That’s the problem but allow me to elaborate.

Control

Google Wave is a great example of control loss. If you really put a lot of energy, stock and trust into Google Wave as a content store for your team, brain or idea then you might feel deflated by its cancellation. Even as an idea and a disruptive alternative to E-mail or SMTP crappiness, it’s a shame it had to die. So what now? Wait for an open source version? Host your own?

The idea was to “put it in the cloud” and forget about it. But when the cloud changes outside your control, you have to be aware of it again. Now you really have to think about the cloud itself. It’s not such a vague black box which is what the cloud diagram really means.

Another example of control is YouTube. I use YouTube favorites as a persistent list. I see a cool video, I favorite it and I feel like I sort of own it, or at least it’s in a list that I can refer to later. But take a look at this:

youtube_whoops

What were those things? Who knows! Now, I have to think about “the cloud” again. These are temporary videos that someone else ultimately controls. I’m just adding references to a list. I don’t own the clips. They are transient. They are ephemeral. I’m out of control again. I don’t even know what media I’ve lost. Do I mitigate again? Do I suck down a list periodically and do a diff?

Connectivity

I recently got a Roku box for my TV. It’s a great box. During registration it does a bunch of sign up and account creation. But it doesn’t work without uPNP enabled on the router. This isn’t even a connectivity outage thing, it’s a connectivity assumption that I have a certain kind of firewall that can’t have holes punched in it … or that I’m not capable of punching the holes myself. I don’t even really know why Roku does this uPNP thing. All I know is, it wouldn’t even finish the setup until I made this change. Now here’s a device that doesn’t work without connectivity or a clear path to connectivity.

Think about how picky that is for a second. If it’s not picky then think about how many technical barriers there are to pure or uniform Internet. Everyone brings their own quilted environment and it’s a mess.

Hi, I am
Chris Dillon