Skip to content

Instantly share code, notes, and snippets.

@medecau
medecau / gist:946348
Created April 28, 2011 13:31
Processing controlP5 round button
import controlP5.*;
ControlPad cp;
ControlP5 controlP5;
void setup() {
size(400, 400);
frameRate(30);
smooth();
from sys import argv
from glob import glob
from itertools import imap, chain, ifilter, groupby
from collections import defaultdict
from PyPDF2 import PdfFileReader
from pattern.en import parsetree
def ilen(i):
"""
add_library('Drop')
from drop import SDrop, DropListener
drop = None
img = None
class DropyListener(DropListener):
def dropEvent(self, e):
global img
if e.isImage():
@medecau
medecau / calldict.py
Last active February 20, 2021 08:52
Callable dictionary
class callable_dict(dict):
def __call__(self, **kwargs):
nd = self.copy()
nd.update(**kwargs)
return nd
d = callable_dict(a=1, b=2)
nd = d(b=3, c=4)
print(d)
print(nd)
@medecau
medecau / exc_info_to_db.py
Created July 16, 2018 05:49
Exception > Dict > SQLite
import datetime as dt
import logging
import sys
from playhouse.dataset import DataSet # this can be any DB ;)
params = 'timestamp name level pathname lineno msg args exc_info func sinfo'.split(' ')
db = DataSet('sqlite:///db.sqlite')
@medecau
medecau / mod.py
Created May 18, 2020 05:35
mutation testing with redbaron and pytest
def inc(n):
"""increments n by one"""
return n + 1
def square(n):
"""squares n"""
return n ** 2
@medecau
medecau / insist.py
Created October 22, 2020 02:54
enforce type hinting at runtime with a decorator
from functools import wraps
from typing import get_type_hints
class InputError(Exception):
pass
def make_error_message(arg_name, arg_type, expected_type):
return f"{arg_name} value has type {arg_type} - must be {expected_type}"
@medecau
medecau / interpret.py
Last active November 12, 2020 16:47
Interpret python code and update the caller's locals
import inspect
def interpret(src):
"""Compile and execute provided code as if it was local to the caller"""
# get a decent name
try:
name = __file__
except NameError:
name = __name__
@medecau
medecau / shadow_it.md
Last active March 6, 2021 04:31
Dark IT, Rogue IT, and Stealth IT

Shadow IT

What you are looking for is Shadow I.T..

Dark IT, Rogue IT, and Stealth IT all mean Shadow IT.