Skip to content

Instantly share code, notes, and snippets.

Avatar

Roy Binux binux

View GitHub Profile
@binux
binux / logging_receiver
Created Apr 22, 2011
logging receiver for python logging module
View logging_receiver
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import cPickle
import logging
import logging.handlers
import SocketServer
import struct
View byr-bbs-ip2location.user.js
// ==UserScript==
// @name BYR BBS ip2location
// @namespace http://bbs.byr.cn/
// @description 使北邮人论坛用户发贴IP地址后附加物理地址信息
// @include http://forum.byr.edu.cn/*
// @include http://forum.byr.cn/*
// @include http://bbs.byr.edu.cn/*
// @include http://bbs6.byr.edu.cn/*
// @include http://bbs.byr.cn/*
// @include http://bbs6.byr.cn/*
@binux
binux / background.html
Created Apr 23, 2011
ip2loc for byr forum (http://bbs.byr.cn) chrome extension
View background.html
<html>
<head>
</head>
<body>
<script>
function fetchLocation(callback,ip) {
var req = new XMLHttpRequest();
req.open("GET","http://www.youdao.com/smartresult-xml/search.s?type=ip&q="+ip,true);
req.onload = function() {
var response = req.responseText;
@binux
binux / pool.py
Created May 26, 2011
使用threading+queue的线程池封装,使用对象在每个对象中保存独立的连接,可以安全地使用ctrl-c打断
View pool.py
# !/usr/bin/env python
# -*- coding:utf-8 -*-
import sys
import time
import Queue
import threading
import traceback
class ExitException(Exception):
@binux
binux / gist:1369949
Created Nov 16, 2011
call any function asynchronous in tornado
View gist:1369949
class AsyncProcessMixin(object):
def call_subprocess(self, func, callback=None, args=[], kwargs={}):
self.ioloop = tornado.ioloop.IOLoop.instance()
self.pipe, child_conn = Pipe()
def wrap(func, pipe, args, kwargs):
try:
pipe.send(func(*args, **kwargs))
except Exception, e:
logging.error(traceback.format_exc())
@binux
binux / gist:1384677
Created Nov 22, 2011
a diff function base on Advanced Dynamic Programming
View gist:1384677
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Created on 2011-6-7
Modified on 2011-11-22
a diff function base on Advanced Dynamic Programming
http://www.avatar.se/molbioinfo2001/dynprog/adv_dynamic.html
@author: binux
View baidu_fanyi.py
# -*- encoding: utf-8 -*-
# author: binux<17175297.hk@gmail.com>
import re
import time
import json
import requests
class BaiduFanYiAPI(object):
"""
@binux
binux / jsfunctionParser.py
Created Dec 14, 2011
xunlei lixian plugin for flexget
View jsfunctionParser.py
# jsonParser.py
#
# Implementation of a simple JSON parser, returning a hierarchical
# ParseResults object support both list- and dict-style data access.
#
# Copyright 2006, by Paul McGuire
#
# Updated 8 Jan 2007 - fixed dict grouping bug, and made elements and
# members optional in array and object collections
#
@binux
binux / mem_cache.py
Created Jan 6, 2012
一个通用的python function cache
View mem_cache.py
# -*- coding: utf-8 -*-
#
# Copyright(c) 2010 poweredsites.org
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@binux
binux / proxyheader.php
Created Jan 6, 2012
请求信息输出
View proxyheader.php
<html>
<head>
<title>CS_ProxyJudge ver 1.0</title>
</head>
<body bgcolor="#808080">
<font color="#FFFFFF"><B>
<PRE>
<?
//=======================================================================
// 修改记录: