Skip to content

Instantly share code, notes, and snippets.


Igor Serebryany igor47

View GitHub Profile
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

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:

View sre.json
igor47 /
Created Jan 21, 2014
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 /
Created Nov 5, 2013
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 Oct 31, 2013
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 /
Last active Jun 4, 2016
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 / chef_to_hash.rb
Created Jul 15, 2013
a recursive to_hash for chef 11; also handles arrays inside the hash.
View chef_to_hash.rb
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] = []
You can’t perform that action at this time.