Skip to content

Instantly share code, notes, and snippets.

sudo -i
/opt/aws/opsworks/current/bin/chef-zero &
cd /var/chef/runs/*/
opsworks-agent-cli get_json > attributes.json
/opt/aws/opsworks/current/bin/chef-shell -c client.rb -j attributes.json -z -S http://localhost:8889
docker stats $(docker ps|grep -v "NAMES"|awk '{ print $NF }'|tr "\n" " ")
@vsudilov
vsudilov / fetch_latest_gh_commit.py
Last active August 29, 2015 14:25
Fetch latest commit from target repo on github, check if that image is on dockerhub
import requests
import argparse
API_ENDPOINT = "https://api.github.com/repos/adsabs/{repo}/branches/master"
DOCKERHUB = "https://registry.hub.docker.com/v1/repositories/adsabs/{repo}/tags"
parser = argparse.ArgumentParser()
parser.add_argument(
"--repos",
nargs='*',
dest='repos',
@vsudilov
vsudilov / gist:6f2b1a6d2086b14ad941
Created June 22, 2015 17:35
change directory context manager
class ChangeDir:
"""Context manager for changing the current working directory"""
def __init__(self, newPath):
self.newPath = os.path.expanduser(newPath)
def __enter__(self):
self.savedPath = os.getcwd()
os.chdir(self.newPath)
def __exit__(self, etype, value, traceback):
@vsudilov
vsudilov / gist:cc25a6eee101a375bfed
Created June 5, 2015 18:15
in-memory tarfile with in-memory contents
tar_fileobj = io.BytesIO()
with tarfile.open(fileobj=tar_fileobj, mode="w|") as tar:
my_content = "abdef".encode('utf-8')
tf = tarfile.TarInfo("my_file_name")
tf.size = len(my_content)
tar.addfile(tf, io.BytesIO(my_content))
tar_fileobj.seek(0)
@vsudilov
vsudilov / gist:ff5598d07de1fe9d412f
Created May 18, 2015 18:59
python-retry decorator
def with_retry_connections(max_tries=3, sleep=0.05):
"""
Decorator that wraps an entire function in a try/except clause. On
requests.exceptions.ConnectionError, will re-run the function code
until success or max_tries is reached.
:param max_tries: maximum number of attempts before giving up
:param sleep: time to sleep between tries, or None
"""
def decorator(f):
@vsudilov
vsudilov / gist:b970efbcf4837f998933
Created April 1, 2015 18:57
curl+sed to check+parse public ip addr
curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//'
@vsudilov
vsudilov / gunicorn.conf.py
Created November 13, 2014 14:30
gunicorn.conf.py
import multiprocessing,os
APP_NAME = 'foobar'
bind = "0.0.0.0:5000"
#bind = "unix:/tmp/gunicorn-%s.sock" % APP_NAME
workers = multiprocessing.cpu_count() * 2 + 1
max_requests = 200
preload_app = True
chdir = os.path.dirname(__file__)
@vsudilov
vsudilov / gist:eda0a23338a69bb728cd
Created October 10, 2014 13:52
pika/rabbitMQ basic worker pattern
import pika
class GenericWorker:
def __init__(self,url='amqp://admin:password@localhost:5672/%2F'):
self.connection = pika.BlockingConnection(pika.URLParameters(url))
self.channel = self.connection.channel()
self.channel.exchange_declare(exchange='TestExchange',exchange_type='direct',passive=False,durable=False)
self.channel.queue_declare(queue='TestQueue')
self.channel.queue_bind(queue='TestQueue',exchange='TestExchange',routing_key='TestQueueRoute')
def run(self):
@vsudilov
vsudilov / docker_cleanup.sh
Created June 30, 2014 15:22
Docker cleanup containers+images
docker rm $(docker ps -a -q)
docker rmi $(docker images | awk '/^<none>/ {print $3}')