Skip to content

Instantly share code, notes, and snippets.

View igor47's full-sized avatar

Igor Serebryany igor47

View GitHub Profile
igor47 / chef_to_hash.rb
Created July 15, 2013 02:01
a recursive to_hash for chef 11; also handles arrays inside the hash.
class Chef
class Node
class ImmutableMash
def to_hash
h = {}
self.each do |k,v|
if v.respond_to?('to_hash')
h[k] = v.to_hash
elsif v.respond_to?('each')
h[k] = []
igor47 /
Last active June 4, 2016 06:47
another solution to the problem found in this post about twitter interviewing: this was on hacker news: the original post author solved it here: i use a state machine. this seemed like …
def water(levels, second_pass = False):
# sanity check
if len(levels) < 2:
return 0
# state machine
filling = False
h = 0
igor47 /
Created October 31, 2013 20:09
services guide from airbnb

Smart Stack

We connect our REST services together using smartstack. Smartstack is mainly the combination of nerve and synapse. Nerve lets your service be discovered by other services, and synapse lets you discover services you yourself need.


In order to play well with smartstack, you need to define two special resources in your service. Both should return Content-type: text/plain.

igor47 /
Created November 5, 2013 16:53
The haproxy configuration manual contains a matrix listing configuration keywords and their applicability by haproxy section (defaults, listen, backend, frontend). This code parses the manual and produces a json hash of sections and the keywords that apply in those sections.
#!/usr/bin/env python
from collections import defaultdict
import json
import requests
config_url = ""
longest_keyword = 42 #works for haproxy 1.5 docs, but might need to be adjusted
# first, get the lines that pertain to the matrix
igor47 /
Created January 21, 2014 19:13
airbnb's chef-solo converge script
#!/bin/bash -eu
origin=`cat /etc/chef/origin`
branch=`cat /etc/chef/branch`
role=`cat /etc/chef/role`
env=`cat /etc/chef/environment`
# create temporary files
git_clone=`mktemp -d`
igor47 / sre.json
Last active August 29, 2015 13:57

Keybase proof

I hereby claim:

  • I am igor47 on github.
  • I am igor47 ( on keybase.
  • I have a public key whose fingerprint is 9F5D ADC0 1FB0 4BE0 9AA4 8808 5725 5CA7 693C 0FF9

To claim this, I am signing this object:

from collections import defaultdict
import random
def left_or_right():
return 'l' if random.randint(0, 9) == 0 else 'r'
def make_group():
d = defaultdict(lambda: 0)
for i in range(45):
d[left_or_right()] += 1