Skip to content

Instantly share code, notes, and snippets.

@thepaul
thepaul / forwarding.py
Created January 9, 2013 00:16
Simple cross-protocol forwarder (Twisted). Run under twistd -y with FWD_LISTEN and FWD_CONNECT set according to the rules for serverFromString (http://twistedmatrix.com/documents/current/api/twisted.internet.endpoints.html#serverFromString) and clientFromString (http://twistedmatrix.com/documents/current/api/twisted.internet.endpoints.html#clien…
import os
from twisted.internet import protocol, reactor, endpoints, error
from twisted.application import service
from twisted.python import log
class Forwarder(protocol.Protocol):
def __init__(self):
self.peer = None
self.peer_queue = []
@thepaul
thepaul / levenshtein.py
Created January 6, 2013 01:00
Levenshtein distance between two sequences
def _LevenshteinDistance(str1, i, len1, str2, j, len2, cache):
key = (i, len1, j, len2)
if key in cache:
return cache[key]
if len1 == 0:
return len2
if len2 == 0:
return len1
@thepaul
thepaul / runnable-pyc
Created January 2, 2013 20:23
make byte-compiled python code into an executable
#!/usr/bin/env python
#
# runnable-pyc
usage_info = \
"""runnable-pyc - make compiled Python code into an executable file
Usage: runnable-pyc <pycfile> [<outputfile>]
If no outputfile is specified, and pycfile ends in '.pyc', then the default
@thepaul
thepaul / git-pbuilder-fix.diff
Created November 9, 2012 04:22
git-pbuilder argument splitting fix
--- /usr/bin/git-pbuilder 2012-09-28 12:18:15.000000000 -0600
+++ /usr/bin/fixed-git-pbuilder 2012-11-08 21:07:37.123999784 -0700
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
# $Id: git-pbuilder,v 1.27 2012/01/13 04:12:35 eagle Exp $
#
# git-pbuilder -- Wrapper around pbuilder for git-buildpackage
@@ -75,7 +75,8 @@
fi
@thepaul
thepaul / config.log
Created July 27, 2012 21:48
brew install quvi configure output
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by quvi configure 0.2.19, which was
generated by GNU Autoconf 2.68. Invocation command line was
$ ./configure --disable-dependency-tracking --prefix=/usr/local/Cellar/quvi/0.2.19 --enable-nsfw --enable-todo --enable-nlfy
## --------- ##
## Platform. ##
@thepaul
thepaul / knapsack.py
Created July 5, 2012 23:49
dynamic programming generic 0-1 knapsack problem solver
def solve_knapsack(items, maxcost, cost=lambda n:n, value=None):
"""
Generic dynamic-programming knapsack problem solver. Takes time
O(len(items) * maxcost), so it can be helpful to reduce the costs
and maxcost by the greatest common divisor if possible. Costs for
all items must be nonnegative integers.
Returns the set of items the sum of whose costs does not exceed
maxcost, and the sum of whose values is otherwise maximal.
"""
import collections
import Queue
class MaxSizeDict(collections.MutableMapping):
def __init__(self, maxsize):
self.maxsize = maxsize
self.valdict = {}
self.keyqueue = Queue.Queue()
def __setitem__(self, key, value):
diff --git a/Library/Formula/nmap.rb b/Library/Formula/nmap.rb
index 8bd1df1..7e06901 100644
--- a/Library/Formula/nmap.rb
+++ b/Library/Formula/nmap.rb
@@ -14,7 +14,7 @@ class Nmap < Formula
def install
ENV.deparallelize
- args = ["--prefix=#{prefix}", "--without-zenmap"]
+ args = ["--prefix=#{prefix}", "--without-zenmap", "--without-liblua", "CFLAGS=-DNOLUA"]
==> Downloading http://nmap.org/dist/nmap-5.51.tar.bz2
File already downloaded in /Users/paul/Library/Caches/Homebrew
/usr/bin/tar xf /Users/paul/Library/Caches/Homebrew/nmap-5.51.tar.bz2
==> ./configure --prefix=/usr/local/Cellar/nmap/5.51 --without-zenmap
./configure --prefix=/usr/local/Cellar/nmap/5.51 --without-zenmap
checking whether NLS is requested... yes
checking build system type... x86_64-apple-darwin11.2.0
checking host system type... x86_64-apple-darwin11.2.0
checking for gcc... /usr/bin/gcc-4.2
checking whether the C compiler works... yes
==> Downloading http://nmap.org/dist/nmap-5.51.tar.bz2
File already downloaded in /Users/paul/Library/Caches/Homebrew
/usr/bin/tar xf /Users/paul/Library/Caches/Homebrew/nmap-5.51.tar.bz2
==> ./configure --prefix=/usr/local/Cellar/nmap/5.51 --without-zenmap
./configure --prefix=/usr/local/Cellar/nmap/5.51 --without-zenmap
checking whether NLS is requested... yes
checking build system type... x86_64-apple-darwin11.2.0
checking host system type... x86_64-apple-darwin11.2.0
checking for gcc... /usr/bin/llvm-gcc
checking whether the C compiler works... yes