Skip to content

Instantly share code, notes, and snippets.

View ryanwitt's full-sized avatar

Ryan Witt ryanwitt

  • New York, NY
View GitHub Profile
@ryanwitt
ryanwitt / README.md
Created October 10, 2012 22:38 — forked from kaa/carbon.init.sh
Installing graphite 0.9.10 and statsd on Amazon Linux

Installing

If you trust me, do this:

curl https://raw.github.com/gist/3868967/30ed8db63ea701e1ad18dabbecfc8df0ffd8b195/install.sh > install.sh

sh install.sh

@ryanwitt
ryanwitt / intro.js
Created September 8, 2012 19:51
Textphile interative introduction
// requires ace editor + https://github.com/creationix/step
/* INTERACTIVE INTRODUCTION */
var sec = 600;
var typewriter_pauses = [
{match:/[,\-(]/, pause:0.2*sec}
, {match:/[.!?:]/, pause:0.4*sec}
, {match:/[\t]/, pause:0.8*sec}
, {match:/[\n]/, pause:0.4*sec}
, {match:/.*/, pause:0.035*sec}
@ryanwitt
ryanwitt / server.js
Created September 5, 2012 22:23
data generation server for csh week-10 (summer 2012)
var http = require('http');
var choices = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam erat augue, molestie accumsan vulputate ut, imperdiet ut nunc. Nunc convallis magna sed dolor suscipit placerat faucibus felis tempus. In in odio arcu, a fringilla tellus. Mauris molestie, nibh non pretium condimentum, lacus mi hendrerit erat, ac ornare dui arcu ut ipsum. Pellentesque luctus venenatis orci et feugiat. Praesent dictum bibendum fermentum. Integer aliquam erat ut dolor semper auctor. Ut sed justo sit amet orci convallis ultrices. Maecenas egestas aliquet diam. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.'.split(' ');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
var no = false;
console.log(req);
req.on('close', function() {no=true; res.end();});
//req.on('end', function() {no=true; res.end();});
if (req.url == '/') {
import urllib2
try:
d = {}
for line in urllib2.urlopen('http://192.168.201.133:1337/6'):
split = line.split(',')
d[split[2]] = d.get(split[2], 0) + 1
except KeyboardInterrupt:
for v,k in sorted(((v,k) for k,v in d.items()), reverse=True):
print k,',',v
@ryanwitt
ryanwitt / lcs.py
Created September 2, 2012 23:51
a naïve longest common substring impl
def static_lcs(one,two):
lcs, candidate = '', ''
for o,t in zip(one, two):
if o == t:
candidate = candidate + o
if len(candidate) > len(lcs):
lcs = candidate
else:
candidate = ''
return lcs
@ryanwitt
ryanwitt / request.py
Created August 14, 2012 03:32
fun simulating django request objects
class Request(object):
def __init__(self, host, path):
self.get_host = lambda:host
self.get_full_path = lambda:path
@ryanwitt
ryanwitt / dijkstra.py
Created August 3, 2012 05:46
Dijkstra for the CSH in-class graph
#
# Version 1
#
# - data stored as node and edge sets
# - frontier is set of (src, dst, weight)
# - far too many O(n) loops
#
# Load graph
nodes = set()
@ryanwitt
ryanwitt / huffman.py
Last active November 29, 2016 14:41
silly huffman coding example
__all__ = (
'frequency_histogram',
'endode_simple',
'decode_simple',
'huffman_tree',
'encode_character',
'encode_huffman',
'hist2dot',
'tree2dot',
)
@ryanwitt
ryanwitt / gist:2911560
Created June 11, 2012 17:46
Confusion matrix for a logistic glm model in R. Helpful for comparing glm to randomForests.
confusion.glm <- function(data, model) {
prediction <- ifelse(predict(model, data, type='response') > 0.5, TRUE, FALSE)
confusion <- table(prediction, as.logical(model$y))
confusion <- cbind(confusion, c(1 - confusion[1,1]/(confusion[1,1]+confusion[2,1]), 1 - confusion[2,2]/(confusion[2,2]+confusion[1,2])))
confusion <- as.data.frame(confusion)
names(confusion) <- c('FALSE', 'TRUE', 'class.error')
confusion
}
from django.core.exceptions import ImproperlyConfigured
from django.core.management.base import BaseCommand, CommandError
from django.core import serializers
from django.utils.datastructures import SortedDict
from optparse import make_option
class Command(BaseCommand):
option_list = BaseCommand.option_list + (
make_option('--format', default='json', dest='format',