Skip to content

Instantly share code, notes, and snippets.

View fungusakafungus's full-sized avatar

Ilya Margolin fungusakafungus

View GitHub Profile
@fungusakafungus
fungusakafungus / gist:466d9448feddf0617c28fa560317dd7b
Last active July 27, 2018 07:56
Wait for kubernetes pods to reach running state
```
$ kubectl run --image nginx nginx ; while kubectl get pod --no-headers | grep -v Running ; do sleep 2; done
deployment "nginx" created
nginx-701339712-wpg0v 0/1 ContainerCreating 0 0s
nginx-701339712-wpg0v 0/1 ContainerCreating 0 2s
nginx-701339712-wpg0v 0/1 ContainerCreating 0 4s
nginx-701339712-wpg0v 0/1 ContainerCreating 0 6s
nginx-701339712-wpg0v 0/1 ContainerCreating 0 8s
nginx-701339712-wpg0v 0/1 ContainerCreating 0 10s
```
@fungusakafungus
fungusakafungus / gen-mod-from-diff.sh
Last active April 1, 2018 16:49
gen-mod-from-diff.sh
#!/bin/bash
test -z "$1" && {
cat >/dev/stderr <<-HELP
Usage: $0 mod-name
Use this script from top level of Cataclysm checkout, with your changes to data/json not added to git.
It will try to make a mod out of those changes instead.
The script needs:
- python (2?)
- jsondiff from jsonpatch python package (https://python-json-patch.readthedocs.io)
def process_dict_item(k, v):
try:
return k, int(v)
except (TypeError, ValueError):
if k == 'EbsOptimized' and v == 'true':
return 'EbsOptimized', 1
if k == 'NoEcho' and v == 'true':
return 'NoEcho', 1
return k, replace_quoted_ints_in_values(v)
@fungusakafungus
fungusakafungus / prepend_with_path.py
Last active December 31, 2015 22:49
Prepend every substructure of a nested dict/list structure with its path
def prepend_with_path(j, path=''):
"""
>>> prepend_with_path({})
[('', {})]
>>> prepend_with_path([])
[('', [])]
>>> prepend_with_path({1:2})
[('', {1: 2}), ('[1]', 2)]
>>> prepend_with_path({'a':'b'})
[('', {'a': 'b'}), ("['a']", 'b')]
from collections import defaultdict
def _maj(counts_to_items, items_to_counts, max_count, sequence):
if not sequence:
return counts_to_items, items_to_counts, max_count, sequence
item, new_sequence = sequence[0], sequence[1:]
count = items_to_counts[item]
counts_to_items[count].discard(item)
count += 1
counts_to_items[count].add(item)
from tornado.web import asynchronous, RequestHandler, Application
from tornado import gen
from tornado.testing import AsyncHTTPTestCase, gen_test
from tornado.httpclient import AsyncHTTPClient, HTTPRequest, HTTPResponse
from mock import patch, Mock
from tornado.concurrent import Future
import StringIO
class FooHandler(RequestHandler):
@fungusakafungus
fungusakafungus / format-bash.sh
Created July 22, 2013 18:20
Use `type` builtin to format bash code. Give it a bash file as an argument, it will overwrite it with formatted bash. Kinda useful for one-liners, but adds useless semicolons and strips comments. At least.
#!/bin/bash
eval "function $1() { $(cat $1); }";
type $1 2>&1 | sed -n 's#^ ##p' > "$1"
@fungusakafungus
fungusakafungus / .bashrc
Created February 24, 2012 18:21
create ... aliases
for i in `seq 2 10`; do
dots=`printf '% *s' $i '' | tr ' ' .`
alias $dots=cd\ `printf '../%.0s' $(seq $((i-1)))`
done
@fungusakafungus
fungusakafungus / gist:1026804
Created June 15, 2011 09:42 — forked from unakatsuo/gist:1026755
bash retry function
function retry {
local retry_max=$1
shift
local count=$retry_max
while [ $count -gt 0 ]; do
"$@" && break
count=$(($count - 1))
sleep 1
done