Skip to content

Instantly share code, notes, and snippets.

version: '2'
services:
# Start messaging broker
rabbitmq:
image: tutum/rabbitmq
dns: ["8.8.8.8"]
environment:
- "RABBITMQ_PASS=Phaish9ohbaidei6oole"
@kampta
kampta / simpleBool.py
Created September 28, 2016 14:58
Code to evaluate simple boolean logic in python using pyparsing
#
# simpleBool.py
#
# Example of defining a boolean logic parser using
# the operatorGrammar helper method in pyparsing.
#
# In this example, parse actions associated with each
# operator expression will "compile" the expression
# into BoolXXX class instances, which can then
# later be evaluated for their boolean value.
@kampta
kampta / simple_boolean_logic.py
Created September 28, 2016 14:56
Code to evaluate simple boolean logic in python
"""
Code to evaluate simple boolean logic in python
Taken from: http://stackoverflow.com/a/2472414/2353472
Examples
>>> print nested_bool_eval('(True and False) or (True and False)')
False
>>> print nested_bool_eval('(True and False) or (True and (True or False))')
True
"""
"""
An OrderedSet is a custom MutableSet that remembers its order, so that every
entry has an index that can be looked up.
Based on a recipe originally posted to ActiveState Recipes by Raymond Hettiger,
and released under the MIT license.
Rob Speer's changes are as follows:
- changed the content from a doubly-linked list to a regular Python list.
Seriously, who wants O(1) deletes but O(N) lookups by index?
- add() returns the index of the added item
- index() just returns the index of an item
"""
An OrderedSet is a custom MutableSet that remembers its order, so that every
entry has an index that can be looked up.
Based on a recipe originally posted to ActiveState Recipes by Raymond Hettiger,
and released under the MIT license.
Rob Speer's changes are as follows:
- changed the content from a doubly-linked list to a regular Python list.
Seriously, who wants O(1) deletes but O(N) lookups by index?
- add() returns the index of the added item
- index() just returns the index of an item
@kampta
kampta / docker-machine-rename
Created August 26, 2016 07:09 — forked from alexproca/docker-machine-rename
Rename docker-machine
#!/usr/bin/env bash
#copy this in a folder from path ex: /usr/local/bin
#usage: docker-machine-rename default my-default
OLD_MACHINE_NAME=${1:-default};
NEW_MACHINE_NAME=${2:-my-default-2};
STORE_PATH=`docker-machine inspect $OLD_MACHINE_NAME | grep -m 1 StorePath | cut -d ':' -f 2 | cut -c 3- | rev | cut -c 3- | rev`;
mv "$STORE_PATH/machines/$OLD_MACHINE_NAME" "$STORE_PATH/machines/$NEW_MACHINE_NAME";
cp "$STORE_PATH/machines/$NEW_MACHINE_NAME/config.json" "$STORE_PATH/machines/$NEW_MACHINE_NAME/config.json.bak"
@kampta
kampta / digitalocean-addswap.sh
Created August 23, 2016 16:07
Add swap space in all digitalocean docker-machines when you run out of them
for i in $(docker-machine ls | grep digitalocean | awk '{print $1}'); do docker-machine ssh $i -- ls /swapfile || docker-machine ssh $i "fallocate -l 512M /swapfile && chmod 400 /swapfile && mkswap /swapfile" && docker-machine ssh $i "swapon /swapfile && echo '/swapfile none swap defaults 0 0' >> /etc/fstab" &>/dev/null; done
@kampta
kampta / docker-machine-upgrade.sh
Last active August 23, 2016 17:36
script for docker-machine upgrade, when local driver and remote driver are not in sync (borrowed from https://github.com/docker/machine/issues/3308). I was getting the following error ```Error response from daemon: client is newer than server (client API version: 1.24, server API version: 1.23)```
mcn_name=MACHINE_NAME
apt_url='https://apt.dockerproject.org'
lsb_dist='ubuntu'
dist_version='trusty'
arch=$(docker-machine ssh ${mcn_name} dpkg --print-architecture)
repo='main'
docker-machine ssh ${mcn_name} "echo deb [arch=${arch}] ${apt_url}/repo ${lsb_dist}-${dist_version} ${repo} | sudo tee /etc/apt/sources.list.d/docker.list"
docker-machine ssh ${mcn_name} sudo apt-get update
docker-machine ssh ${mcn_name} sudo apt-get install -y docker-engine
docker-machine regenerate-certs ${mcn_name}
@kampta
kampta / queries.md
Created August 23, 2016 10:58
postgreSQL - handy queries

Find all indexes in a postgres table

select
    t.relname as table_name,
    i.relname as index_name,
    array_to_string(array_agg(a.attname), ', ') as column_names
from
    pg_class t,
 pg_class i,
@kampta
kampta / utils.py
Last active August 23, 2016 10:28
day to day utilities
# -*- coding: utf-8 -*-
import string
import random
import os
import re
from unicodedata import normalize
from datetime import datetime
import tempfile