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 / si_prefix.js
Created November 8, 2010 17:32
si_prefix.js
function si_prefix(size) {
var suffixes =['', 'k', 'M', 'G', 'T', 'P', 'E'];
if (size === 0) return '0';
base = Math.log(size) / Math.log(1000);
return suffixes[Math.floor(base)];
}
#!/usr/bin/python
# -*- coding: utf8 -*-
import hashlib, random, timeit
def generate_it(bytes):
return ''.join(chr(random.getrandbits(8)) for x in xrange(bytes))
def hash_it(stuff):
return hashlib.md5(stuff).hexdigest()
# $Id: pcap.py 26 2006-11-21 01:18:55Z dahelder $
"""Libpcap file format."""
import sys, time
import dpkt
TCPDUMP_MAGIC = 0xa1b2c3d4L
PMUDPCT_MAGIC = 0xd4c3b2a1L
#!/usr/bin/python
#jh- pasted from:
# http://peerit.blogspot.com/2007/07/multipartposthandler-doesnt-work-for.html
####
# 02/2006 Will Holcomb <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
function setupValidation(field, timeout) {
var input = $('#id_'+field);
var input_tr = $('#id_tr_'+field);
check = function () {
var t = this;
if (this.value != this.lastValue) {
if (this.timer) clearTimeout(this.timer);
input_tr.removeClass('error');
$('#id_tr_errors_'+field).remove();
this.timer = setTimeout(function () {
"""
Classes for a dynamic, templated settings environment.
By "environment" we just mean a dictionary where keys can be accessed as
object attributes. The _AttributeDict class comes from Fabric.
The _RecursiveAttributeDict class takes this idea one step further, and lets
you refer to other keys in the dictionary using new-style python formatting
syntax (PEP 3101). See the class docstring for examples.
"""
We couldn’t find that file to show.
@ryanwitt
ryanwitt / samp.py
Created April 14, 2010 16:30
Sample program inspired by the todo in kriskowal/xbin
#!/usr/bin/env python
"""usage: %prog [-n N]
Returns a random uniform sample of the lines on stdin using a technique
called reservoir sampling [VITTER '85]. Preserves input ordering."""
import sys
from optparse import OptionParser
p = OptionParser(usage = __doc__)
p.add_option(
@ryanwitt
ryanwitt / gist:305695
Created February 16, 2010 17:18
slides for @kriskowal's vim presentation @fastsoft
^w hjkl move to windows
^w HJKL move windows
^w +- horizontal resize
^w = even splits
^w10<> vertical resize
O
I ia A
<script language="javascript" type="text/javascript">
SHARETHIS.addEntry({
title:'Share me',
summary:'Sharing is good for the soul.',
icon: 'http://path.to/icon'
}, {button:true} );
</script>