Skip to content

Instantly share code, notes, and snippets.

View igor47's full-sized avatar

Igor Serebryany igor47

View GitHub Profile
@igor47
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
igor47 / walls.py
Last active June 4, 2016 06:47
another solution to the problem found in this post about twitter interviewing: http://qandwhat.apps.runkite.com/i-failed-a-twitter-interview/ this was on hacker news: https://news.ycombinator.com/item?id=6639839 the original post author solved it here: https://gist.github.com/mkozakov/59af0fd5bddbed1a0399 i use a state machine. this seemed like …
#!/usr/bin/python
def water(levels, second_pass = False):
# sanity check
if len(levels) < 2:
return 0
# state machine
filling = False
h = 0
@igor47
igor47 / smartstack.md
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.

Resources

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
igor47 / parse_haproxy_matrix.py
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 = "http://haproxy.1wt.eu/download/1.5/doc/configuration.txt"
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
igor47 / converge.sh
Created January 21, 2014 19:13
airbnb's chef-solo converge script
#!/bin/bash -eu
repo="/etc/chef/src"
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
igor47 / sre.json
Last active August 29, 2015 13:57
[
{"kScreenSaverURL":"https://app.datadoghq.com/screen/board/2582?fullscreen=true","kScreenSaverTime":"5"},
{"kScreenSaverURL":"https://rpm.newrelic.com/accounts/7358/applications/2237","kScreenSaverTime":"5"},
{"kScreenSaverURL":"https://dashboards.airbnb.com/screens/1","kScreenSaverTime":"5"}
]

Keybase proof

I hereby claim:

  • I am igor47 on github.
  • I am igor47 (https://keybase.io/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