Skip to content

Instantly share code, notes, and snippets.

{
"cards": [
{"p": 0.23, "s": true, "e": 35, "n": "A Display of My Dark Power"},
{"p": 1.8, "s": true, "e": 14, "n": "Abbot of Keral Keep"},
],
"editions": [
"", "Shards of Alara", "Morningtide", "3rd Edition", "Commander's Arsenal",
"Duel Decks: Phyrexia vs. The Coalition", "Planar Chaos", "Dissension",
"Duel Decks: Garruk vs Liliana", "Duel Decks: Heroes Vs. Monsters",
"Homelands", "Duels of the Planeswalkers", "Unlimited", "Portal 3K",
@numberoverzero
numberoverzero / profanity.py
Created March 26, 2014 22:34
Filter delimited profanity - does not handle character substitution
'''
Character substitution
====
Not handled at all. Should be reasonably straightforward to plug into the existing code.
Roughly:
def expand_substitutions(wordlist, sub_map):
for word in wordlist:
for substitution in expand_word(word, sub_map):
yield substitution
@numberoverzero
numberoverzero / worker.html
Last active August 29, 2015 14:00
Basic web worker
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
</head>
<body>
<div>Type some stuff and click send (or hit enter)</div>
<input type='text' id='input' onkeyup="onKeyUp(event)" autofocus="autofocus"></input>
<button onclick='send_text()'>Send</button>
<div id='output'></div>
@numberoverzero
numberoverzero / worker-transferrable.html
Created April 29, 2014 01:18
WebWorker showing off transferrables
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
</head>
<body>
<div>Transferring an array</div>
<button id='bPopulate' onclick='populateArray()'>Populate Array</button>
<button id='bSend' onclick='sendArray()'>Send Array</button>
<div id='output'></div>
@numberoverzero
numberoverzero / volume.sh
Last active August 29, 2015 14:01
Control pulseaudio volume
#!/bin/bash
#=================
# commands:
# volume : get volume
# volume [0,100] : set volume, unmute
# volume [up|down] : step volume up or down by small pct, unmute
# volume mute : toggle mute
# volume muted : exit 0/print true if muted, else exit 0/print false
#=================
@numberoverzero
numberoverzero / chain.py
Last active August 29, 2015 14:01
Use functools.partial to nest function calls
"""
# First argument to the function should be the next
# object to invoke (next_handler below)
class EventHandler(object):
def __init__(self, name):
self.name = name
def handle(self, next_handler, event, data):
print("ENTER: Handler {} Event {}".format(self.name, event))
@numberoverzero
numberoverzero / chain_v2.py
Created June 10, 2014 21:41
Chain class with special-casing for __call__, which __getattr__ won't handle (same with __getattribute__)
"""
Why is __call__ a special case?
https://docs.python.org/3.4/reference/datamodel.html#object.__getattribute__
> Note: This method may still be bypassed when looking up special methods as the result of implicit invocation via language syntax or built-in functions. See Special method lookup.
> In addition to bypassing any instance attributes in the interest of correctness, implicit special method lookup generally also bypasses the __getattribute__() method even of the object’s metaclass
"""
class Chain(object):
@numberoverzero
numberoverzero / multi_index.py
Last active August 29, 2015 14:06
Simple indexing into a list or iterable by name
def build_index(*fields):
'''each arg is (field_name, length) tuple'''
index = type('Index', (object,), {})
start = 0
for field, offset in fields:
s = slice(start, start + offset)
setattr(index, field, s)
start += offset
return index
@numberoverzero
numberoverzero / HomelessPack
Last active August 29, 2015 14:07
Approximate list of HomelessPack contents
SUMMARY
=============================
bartell's gift card
toothpaste
thermos
soap dish
chapstick
tictacs
shower gel
shaving cream
@numberoverzero
numberoverzero / Markdown Regex
Created October 31, 2014 06:05
Scratchpad for a simpler markdown-inspired language for compilation to a subset of regex
"[name] is [age:int] years old." -> "(?<name>[^ ]) is [(?<age>\d+) years old \."
----------------------------------------
Examples
"search [service]/[region] [metric]"
"search (?<service>[^ ^/]+)/(?<region>[^ ]+) (?<metric>[^ ]+)"
"stock (?<name>[^ ]) (?<op>((<|>|=)=?)) (?<value>[^ ]+)"