Skip to content

Instantly share code, notes, and snippets.

View fcicq's full-sized avatar

fcicq fcicq

View GitHub Profile
@fcicq
fcicq / rangefile.py
Last active October 4, 2015 07:37
Range Limited File Class
import os
import sys
try:
file
except NameError:
import io
file = io.FileIO
class RangeFile(file):
@fcicq
fcicq / ed2kHash.py
Last active August 18, 2018 11:54
ed2kHash class for python (you may use it as alcc)
# by fcicq (fcicq at fcicq dot net) @ 2012.5.12, Released under GPLv2
import hashlib
try:
from cStringIO import StringIO
except ImportError:
from io import BytesIO as StringIO
if bytes != str: ord = int
class ed2kHash():
CHUNK_SIZE = 9728000
BLOCK_SIZE = 262144
--- cherokee/connection.c.orig 2011-10-13 02:07:44.000000000 +0800
+++ cherokee/connection.c 2012-05-28 13:02:51.000000000 +0800
@@ -2625,6 +2625,8 @@
ret_t
cherokee_connection_open_request (cherokee_connection_t *conn)
{
+ ret_t ret;
+
TRACE (ENTRIES, "web_directory='%s' request='%s' local_directory='%s'\n",
conn->web_directory.buf,
@fcicq
fcicq / gougou.py
Created June 8, 2012 08:12
Old gougou interface, now obsoleted
# -*- coding: utf-8 -*-
# GPLv2, by fcicq
import urllib2, json, StringIO, gzip, base64
def decodethunderuri(str):
if isinstance(str, unicode): str = str.encode('utf-8')
origstr = str
if str.startswith('thunder://'):
str = str[10:]
if len(str) % 4 != 0: str += '=' * (4- len(str) % 4)
@fcicq
fcicq / socks.py
Created June 13, 2012 08:29
A magical proxy ...
#!/usr/bin/python
# by fcicq, released @ 2011.5.12, MIT License.
# eventlet is required.
import eventlet
from eventlet.green import socket
### SETTINGS ###
SERVER_PORT = 1080
IPV6_ENABLED = socket.has_ipv6
@fcicq
fcicq / pkcs.py
Created June 25, 2012 13:48
pkcs#1 padding, see RFC 3447 7.2.1
import random
def random_bytes(size):
return "".join(chr(random.randrange(1, 256)) for i in xrange(size))
def pkcs1_pad(text, size = 128):
l = size - len(text) - 3
if l >= 8: # see RFC3447 7.2.1
padding = random_bytes(l)
return '\x00\x02' + padding + '\x00' + text
else:
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Converts the specified JSON file with the specified encoding
# (default encoding is utf8 if not specified) into a formatted
# version with the specified indent (2 if not specified) and
# writes to STDOUT.
#
# Usage: jsoncat.py inputfile.json [input_encoding] [indent]
#
@fcicq
fcicq / dice.py
Created July 25, 2012 11:29
fcicq's dice
import random
# E = 129.875
def dice():
s = random.randint(1, 20)
if s <= 2: return random.randint(1, 20)
if s <= 8: return random.randint(21, 50)
if s <= 14: return random.randint(51, 99)
if s <= 17: return random.randint(100, 200)
if s <= 19: return random.randint(201, 500)
return random.randint(501, 1024)
@fcicq
fcicq / dstat-virt-steal.diff
Created August 12, 2012 13:16
Virtualization Env friendly dstat
Virtualization env friendly dstat, hiq + siq -> int, added steal by fcicq
Usage:
cd /usr/bin; sudo patch -p0 < /path/xxx.diff
--- /usr/bin/dstat 2010-06-11 14:08:01.000000000 +0800
+++ /usr/bin/dstat.new 2012-08-12 21:06:56.000000000 +0800
@@ -561,7 +561,7 @@
class dstat_cpu(dstat):
def __init__(self):
@fcicq
fcicq / mywallet.py
Created August 16, 2012 08:49 — forked from anfedorov/mywallet.py
tools to decrypt blockchain.info wallet.json.aes
#!/usr/bin/env python
import base64, hashlib, hmac, json, sys, getpass
from Crypto.Cipher import AES
from Crypto.Hash import RIPEMD, SHA256
base58_chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
def prompt(p):
return getpass.getpass(p + ": ")