Skip to content

Instantly share code, notes, and snippets.

View munhitsu's full-sized avatar

Mateusz Łapsa-Malawski munhitsu

  • cr3.io
  • London, UK
  • 17:03 (UTC +01:00)
View GitHub Profile
@munhitsu
munhitsu / gist:56688bb6a9c7335d3023
Created June 30, 2014 16:58
breaking rabbitmq cluster
"""
Handy when you don't care about data and rabbitmq stopped working
$ rabbitmqctl add_vhost /sensu
Creating vhost "/sensu" ...
Error: {node_not_running,'rabbit@ip-X-Y-Z-A'}
$ rabbitmqctl cluster_status
Cluster status of node 'rabbit@ip-X-Y-Z-A' ...
[{nodes,[{unknown,['rabbit@ip-X-Y-Z-A']}]},{running_nodes,[]}]
@munhitsu
munhitsu / gist:2b499311c9381cac127a
Created June 20, 2014 14:20
ascii secret in python
import os
"".join((chr(ord(os.urandom(1))/2) for x in range(64)))
@munhitsu
munhitsu / pprinttable.py
Created April 19, 2014 22:05
pretty prints list of dictionaries as a table
from __future__ import print_function
def pprinttable(data, headers=None, print=print):
"""
prints data as a table assuming that data is a list of dictionaries (single level)
if headers are provided then they specify sequence of columns
example of data:
[{'slug': u'ams1', 'name': u'Amsterdam 1', 'region_id': 2},
{'slug': u'sfo1', 'name': u'San Francisco 1', 'region_id': 3},
@munhitsu
munhitsu / gist:5153686
Created March 13, 2013 16:14
How to confirm if gevent monkey patch works
from gevent import socket as g_socket
assert g_socket.timeout == socket.timeout
print "gevent monkey patch for socket confirmed"
@munhitsu
munhitsu / gist:5118993
Last active December 14, 2015 16:59
slightly crazy universal base encoder (number to alphabet)
BASE_ALPHABET = "123456789abcdefghijkmnopqrstuvwxyz"
def encode_base_x(n):
base = len(BASE_ALPHABET)
def chars(num):
while num >= base:
num, mod = divmod(num, base)
yield BASE_ALPHABET[mod]
@munhitsu
munhitsu / gist:5089739
Created March 5, 2013 11:42
virtualbox mount shared host folder
mkdir -p /mnt/shared
mount -t vboxsf -o uid=1000,gid=1000 shared /mnt/shared
@munhitsu
munhitsu / gist:5064293
Created March 1, 2013 12:22
class SchrodingerUser :)
class SchrodingerUser(AnonymousUser):
"""
Imagine that you are making the experiment and want to measure your results.
But Greenpeace has just came to the office and claims that 50% of cats life
is better for the cat than certain life or death.
Returned on DB access error.
"""
pass
@munhitsu
munhitsu / gist:5056212
Created February 28, 2013 11:50
demo of context manager and loop break/continue behaviour
class DebugContext(object):
def __init__(self):
print self.__class__, "init"
def __enter__(self):
print self.__class__, "enter"
def __exit__(self, type, value, traceback):
@munhitsu
munhitsu / gist:4162619
Created November 28, 2012 17:15
ipython within lettuce context
# from: http://matelakat.blogspot.co.uk/2012/03/lettuce-and-ipython-interactive-shell.html
#
@step(u'And give me IPython')
def and_continue_here(step):
import IPython
import sys
shell = IPython.InteractiveShell()
ip = IPython.core.ipapi.get()
p = IPython.core.debugger.Pdb(ip.colors)
p.reset()
@munhitsu
munhitsu / gist:4153696
Created November 27, 2012 11:13
to dump Xvfb buffer to png file
setup DISPLAY accordingly i.e.
export DISPLAY=:0
import -window root file.png