Skip to content

Instantly share code, notes, and snippets.

import difflib
def diff(old, new, limit=False):
matcher = difflib.SequenceMatcher(None, old, new)
actions = []
size = 0
for tag, old_from, old_to, new_from, new_to in matcher.get_opcodes():
if tag == "insert":
new_line = new[new_from:new_to]
actions.append(("+", new_line))
@HelloZeroNet
HelloZeroNet / diff_undiff.py
Last active March 31, 2016 10:53
Fast diff and undiff in python
def diff(old, new):
# via https://github.com/paulgb/simplediff/blob/master/python/LICENSE by Paul Butler
# Create a map from old values to their indices
old_index_map = dict()
for i, val in enumerate(old):
old_index_map.setdefault(val,list()).append(i)
# Find the largest substring common to old and new.
# We use a dynamic programming approach here.
#
@HelloZeroNet
HelloZeroNet / bench_translate.py
Created March 13, 2016 11:28
bench_translate.py
import re, time
data = open("all2.js").read()
translate = {
"Please, choose your account before creating a topic.": "TRANS1",
"Please, choose your account before upvoting.": "TRANS2",
"Comments requires at least ZeroNet 0.3.0 Please upgade!": "TRANS3",
"Every new user has limited space to store comments, topics and votes.\\n": "TRAN4",
"This indicator shows your used/total allowed KBytes.\\n": "TRANS5",
@HelloZeroNet
HelloZeroNet / test_max.py
Last active March 5, 2016 12:34
Test and change max open files limit
fdb = []
for i in xrange(10000):
try:
fdb.append(open('test_max.py', 'r'))
except Exception, err:
print "Max open files without changing settings: %s" % i
break
fdb = []
import sys
import urllib2, re, json, os, time, sys, HTMLParser
html_parser = HTMLParser.HTMLParser()
auth_address = "1KbV1e1u6P6AsY8XNBydgtbtN8iSB5WMyG"
auth_privatekey = "xxxx"
site = "1TaLkFrMwvbNsooF4ioKAY9EuxTBTjipT"
zeronet_dir = ".."
os.chdir(zeronet_dir)
import time
import urllib
import urllib2
import hashlib
import struct
import socket
import bencode
import gevent
import os
import re
@HelloZeroNet
HelloZeroNet / detect_indent.py
Last active August 29, 2015 14:23
Detect tab or space indent for Sublime text
import sublime, sublime_plugin, re
class ExampleCommand(sublime_plugin.EventListener):
def on_activated(self, view):
self.on_load(view)
def on_load(self, view):
import msgpack
import cStringIO as StringIO
print "Msgpack Version", msgpack.version
print "Testing simple data"
data = "A"*10
for i in range(1,20):
print "- %skb..." % len(data),
print "Packing",
@HelloZeroNet
HelloZeroNet / gdb-backtrace.log
Created May 22, 2015 10:08
python-bitcoinlib random SIGSEGV
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff62452eb in BN_bin2bn () from /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
#0 0x00007ffff62452eb in BN_bin2bn () from /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
#1 0x00007ffff484e834 in ffi_call_unix64 () from /usr/lib/python2.7/lib-dynload/_ctypes.so
#2 0x00007ffff484e2af in ffi_call () from /usr/lib/python2.7/lib-dynload/_ctypes.so
#3 0x00007ffff483bfd1 in _call_function_pointer (argcount=3, resmem=0x7fffffffa8e0, restype=<optimized out>, atypes=<optimized out>, avalues=0x7fffffffa8b0,
pProc=0x7ffff62452a0 <BN_bin2bn>, flags=4353) at /home/jmm/py/python2.7-2.7.3/Modules/_ctypes/callproc.c:827
#4 _ctypes_callproc (pProc=pProc@entry=0x7ffff62452a0 <BN_bin2bn>, argtuple=argtuple@entry=
("TC\xdb\xc6_(8\x0ct\xdf\xc3i\xb5\xb9e\x03\x9f\x1c'\x07\xc2kg\xb5\x89\x99\xc8\xee\x10\xdc\x15\x1e", 32, -334573824), flags=4353, argtypes=< at remote 0x8d30a0>,
# via http://pastebin.com/H1XikJFd
# -*- Mode: Python -*-
# This is a combination of http://pastebin.com/bQtdDzHx and
# https://github.com/Bitmessage/PyBitmessage/blob/master/src/pyelliptic/openssl.py
# that doesn't crash on OSX.
import ctypes
import ctypes.util
import hashlib