This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# $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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__all__ = ( | |
'frequency_histogram', | |
'endode_simple', | |
'decode_simple', | |
'huffman_tree', | |
'encode_character', | |
'encode_huffman', | |
'hist2dot', | |
'tree2dot', | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Request(object): | |
def __init__(self, host, path): | |
self.get_host = lambda:host | |
self.get_full_path = lambda:path |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |