Skip to content

Instantly share code, notes, and snippets.

View munhitsu's full-sized avatar

Mateusz Łapsa-Malawski munhitsu

  • cr3.io
  • London, UK
View GitHub Profile
@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: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: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: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: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 / 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: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 / 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:22609bf1e51ad0be9fa2
Created July 7, 2014 13:00
get elastic search cluster configuration (i.e. to check logstash protocol version)
curl -XGET localhost:9200/_nodes/_all/process?pretty
@munhitsu
munhitsu / gist:f79735df67fb6c9fddd2
Created August 8, 2014 17:22
reverse dns from dig
dig +noall +answer -x 8.8.8.8
dig -x 8.8.8.8