Skip to content

Instantly share code, notes, and snippets.

@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 time
import urllib
import urllib2
import hashlib
import struct
import socket
import bencode
import gevent
import os
import re
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)
@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
@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 / 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.
#
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 / handler.py
Created May 8, 2016 08:44
Http version check disabled gevent websocket handler
# Modified: Werkzeug Debugger workaround in run_websocket(self):
import base64
import hashlib
import warnings
from gevent.pywsgi import WSGIHandler
from .websocket import WebSocket, Stream
from .logging import create_logger
import time
import json
import os
import sys
import re
import socket
from subprocess import call
from bitcoinrpc.authproxy import AuthServiceProxy
import zipfile, time
import cStringIO as StringIO
data = StringIO.StringIO()
req = open("archive.zip@ref=master", "rb")
while True:
buff = req.read(1024)
if not buff:
break
data.write(buff)