Skip to content

Instantly share code, notes, and snippets.

@cdunklau
cdunklau / .gitignore
Last active January 3, 2016 10:09 — forked from habnabit/chatserver.py
Chatserver Nightmare! Now with flake8 compliance!
*.py[co]
class IndexProxy(object):
"""
Proxies access to a multidimensional sequence.
When the constructor is provided with a sequence of dimension N,
item access with iterables of length <= N will retrieve the subsequence
or item at the depth corresponding to the distance. For example:
ip = IndexProxy(multiseq)
ip[1,4] == multiseq[1][4]
@cdunklau
cdunklau / extract_attachments.py
Last active August 27, 2021 22:14
A simple (and probably naive) script to extract attachments from .eml files for those of us who don't use software email clients.
#!/usr/bin/env python
"""
Extract all attachments from MS Outlook '.eml' file EML_FILE into
directory OUTPUT_DIR. If OUTPUT_DIR does not exist, it will be
created.
Usage: extract_attachments.py EML_FILE OUTPUT_DIR
"""
from __future__ import print_function
import sys
@cdunklau
cdunklau / python-bitly-links.py
Last active January 29, 2017 20:05
Short links to good texts and presentations about Python, from a few of the denizens of #python
@cdunklau
cdunklau / spacepasteit.py
Created May 28, 2014 11:50
Pastebin a file to bpaste.net
#!/usr/bin/env python
import argparse
import requests
SPACEPASTE_URL = 'http://bpaste.net/'
parser = argparse.ArgumentParser()
parser.add_argument(
'file',
@cdunklau
cdunklau / registry_pattern.py
Last active August 29, 2015 14:02
Registry pattern - avoid magic, be (reasonably) explicit
registry = {}
def registered(cls):
registry[cls.__name__] = cls
return cls
@registered
class Foo(object):
def introduce(self):
@cdunklau
cdunklau / release_me.txt
Last active August 29, 2015 14:02
Great reggae song
Release Me (The Fear)
as performed by Cas Haley (arrangement, maybe song?)
https://www.youtube.com/watch?v=zRgvtu62sYQ
A#m Ddim7 D#m9 G# F# D#m C# Fm
e|---1------x-1----x------4------2------6------4------1---|
B|---2------6-0----6------4------2------7------6------1---|
G|---3------4-1----6------5------3------8------6------1---|
D|---3------6-0----4------6------4------8------6------3---|
@cdunklau
cdunklau / OpenCV_transform.py
Last active June 4, 2017 09:00
One use case for staticmethod
class _Transform:
transform = None
transargs = ()
def __call__(self, image):
"""
Run the transformation and return the tranformed image data
"""
args = [getattr(self, arg) for arg in self.transargs]
return self.transform(image, *args)
@cdunklau
cdunklau / hobbes_and_bacon.txt
Created August 3, 2014 19:54
Hobbes and Bacon: all four comics. Tribute to Calvin and Hobbes
http://www.pantsareoverrated.com/archive/2011/05/10/hobbes-and-bacon/
http://www.pantsareoverrated.com/archive/2011/05/12/hobbes-and-bacon-002/
http://www.pantsareoverrated.com/archive/2011/10/11/hobbes-and-bacon-03-2/
http://www.pantsareoverrated.com/archive/2011/10/13/hobbes-and-bacon-04-2/
@cdunklau
cdunklau / .gitignore
Last active August 29, 2015 14:08
SQLite3-backed mutable set
*.py[co]