Skip to content

Instantly share code, notes, and snippets.

View psobot's full-sized avatar

Peter Sobot psobot

View GitHub Profile
@psobot
psobot / emitter.py
Created January 27, 2013 22:33
An absurdly simple, non-blocking emitter for Square's Cube data collection framework.
"""
Simple, asynchronous, nonblocking UDP emitter for Cube metrics.
"""
import json
import socket
from datetime import datetime
class Emitter(object):
@psobot
psobot / jquery.punchout.js
Created December 16, 2012 19:03
Punching out text with HTML5 canvas
// Some really hacky code being used in my next blog redesign.
// by Peter Sobot (psobot.com) on December 16, 2012
;(function ( $, window, document, undefined ) {
var pluginName = 'punchout',
defaults = {
};
function Plugin( element, options ) {
this.element = element;
@psobot
psobot / plot.py
Created December 9, 2012 06:19
CoreAudio CAShow -> Graphviz Renderer
"""
1) Be someone crazy working with Apple's CoreAudio.
2) Put "CAShow(graph)" somewhere in your Objective-C code.
3) Copy the resulting output from your XCode Console window.
4) Do `pbpaste | python plot.py && open out.png`
5) See a very basic rendering of the crazy audio graph you've made.
"""
import re
import sys
@psobot
psobot / bufferedreadqueue.py
Created November 9, 2012 18:05
Buffered Read Queue for Multiprocessing in Python
import Queue
import multiprocessing
import threading
class BufferedReadQueue(Queue.Queue):
def __init__(self, lim=None):
self.raw = multiprocessing.Queue(lim)
self.__listener = threading.Thread(target=self.listen)
self.__listener.setDaemon(True)
@psobot
psobot / assignment.tex
Created September 19, 2012 14:46
Homework Assignment LaTeX Template
\documentclass[10pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\setcounter{secnumdepth}{0}
\usepackage{fancyhdr, lastpage}
\pagestyle{fancy}
@psobot
psobot / ronf.sb
Created August 25, 2012 21:33
Read-only network-free command sandbox
;; Read-only, network-free sandbox
;; Mac OS X 10.7+
;; Restricts file writes and network access for any command run like:
;; sandbox-exec -f ronf.sb <command>
;; Useful for untrusted programs that should only do computation.
(version 1)
(allow default)
(deny file-write*)
(deny network*)
@psobot
psobot / beatbox.py
Created August 10, 2012 15:25
The Beatbox Machine
"""
"The Beatbox Machine" by Peter Sobot and Borna Almasi
Designed and written in 4 hours on Sept. 25, 2011 at Music Hack Day Montréal
Dependencies:
EchoNest.Remix
Wubmachine.Remixer (https://github.com/psobot/wub-machine)
this file should end up in <wub-root>/remixers/beatbox.py
Honestly, this is just a code-dump to Github. (And the code only sorta-kinda-works, with hardcoded values.)
@psobot
psobot / yaml_file.py
Created August 8, 2012 20:28
Real-time YAML object access in Python
"""
liveyamlfile.py
Live Pythonic attribute access to properties in a yaml file.
by Peter Sobot (hi@psobot.com), August 8, 2012
"""
import os
import time
import yaml
import logging
@psobot
psobot / fmod.py
Created July 8, 2012 18:35
Binary File Change Monitor in Python
"""
Detect exactly which bytes have changed in a file.
Useful for binary reverse engineering:
- Start script
- Save file from program, changing one attribute
- See which byte(s) have changed
"""
import os
import traceback
@psobot
psobot / roundingdict.py
Created June 1, 2012 04:11
Rounded Dictionary Access in Python
class RoundingDict(dict):
def __getitem__(self, key):
if key in self:
return dict.__getitem__(self, key)
try:
values = [abs(x - key) for x in self.keys()]
return self.values()[values.index(min(values))]
except (TypeError, ValueError):
raise KeyError(key)