Skip to content

Instantly share code, notes, and snippets.

View psobot's full-sized avatar

Peter Sobot psobot

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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):

So you want to use Node.js…

Current status: incomplete draft.

Speed

  • Computation: V8 very fast; significantly faster than most interpreted languages. The one very big exception is PyPy, which is in the same ballpark
@psobot
psobot / bad_scoping.py
Created March 12, 2013 21:27
Python Scoping Pitfalls
class MyClass(object):
def __init__(self):
self.foo = "I'm the correct variable!"
def do_something(self):
# Whoops, I forgot to write this as "self.foo".
print foo
if __name__ == "__main__":
foo = "Herp derp, I'm the wrong variable."