Skip to content

Instantly share code, notes, and snippets.

## calling this url will return a QR code which encodes the str_in parameter:
url = 'chart.apis.google.com/chart?cht=qr&chs=300x300&chl={str_in}&chld=H|0'.format(str_in='')
## find a str_in such that the generated QR code, when scanned, returns the url which generated it
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from contextlib import contextmanager
from functools import wraps
class dummy_statsd_connection(object):
def __init__(self, *args, **kwargs):
self.data = []
self.log_data(args, kwargs)
def log_data(self, *args, **kwargs):
self.data.append({'args':args, 'kwargs':kwargs})
@capttwinky
capttwinky / mnt_ssh.py
Created August 13, 2013 19:38
make and manage sshfs mounts
#!/usr/bin/env python
import sys
import os
import subprocess
import json
import shlex
MODULE_SETTINGS = type("MODULE_STATE", (object,), {
"base_dir": "/home/mcgrady/ssh_mounts",
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
GLOBALS=type('GLOBALS',(object,),{
'my_d': 0
}
)()
@capttwinky
capttwinky / exceptionprofile.py
Created July 11, 2013 01:07
try / except is slllloooooowwwww for key checking. use the built in membership test instead.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
import timeit
import string
import pprint
def exfn(d_in, key):
try:
@capttwinky
capttwinky / inline_callback_task_queues.py
Created June 11, 2013 04:11
uses twisted inlinecallbacks generator to make simple task pools.
from twisted.internet import reactor, defer, task
import random
from contextlib import contextmanager
def dummyLRP(choices, max_wait = 30):
"""
dummy long running sort and select proces.
"""
d = defer.Deferred()
to_wait = random.uniform(0, max_wait)
def powerSet[A](s: Set[A]) =
s.foldLeft(Set(Set.empty[A])) {
(set, element) =>
set union (set map (_ + element))
}
@capttwinky
capttwinky / hfonottest.py
Created August 13, 2012 21:24
test conditions for HFO object
with openHDFS('/my/path/filename','w') as HFO:
HFO.write('string A')
### on inpect /my/path/filename == 'string A'
with openHDFS('/my/path/filename','w') as HFO:
HFO.write('string B')
### on inpect /my/path/filename == 'string B'
with openHDFS('/my/path/filename','a') as HFO: