Skip to content

Instantly share code, notes, and snippets.

@xixitalk
xixitalk / gist:4969986
Last active December 13, 2015 20:28
为flask_twip添加图片代理
def getimg(self):
imgurl = request.args.get('imgurl','')
if len(imgurl) == 0:
return '<form action="/twip/getimg" method="get"><input type="text" size="50" name="imgurl" /> <input type="submit" value="submit" />'
urlobj = urllib2.urlopen(imgurl)
header = urlobj.info()
headers = {}
headers['Content-Type'] = header.get('Content-Type','image/png')
content = urlobj.read()
status = urlobj.getcode()
@xixitalk
xixitalk / isChinaIP.py
Created March 12, 2013 11:39
算法:判断是否是中国IP
#/usr/bin/python
#coding: utf-8
global_ip_dict = [[[] for col in range(256)] for row in range(256)]
#input:apnic|CN|ipv4|112.0.0.0|4194304|20081215|allocated
#output:addr1,addr2,addr3,addr4,ip_num
def analyseLine(ip_line):
ip_str_list = ip_line.split('|')
if len(ip_str_list) < 7:
@xixitalk
xixitalk / updateDDNS.sh
Created May 29, 2013 11:34
update 3322.org DDNS with API
#!/bin/sh
if [ ! -e /tmp/dnsip.txt ] ; then
ping mydomain.f3322.org -c1 | grep PING | awk '{ print $3 }' | sed 's/[()]//g' > /tmp/dnsip.txt
fi
mydnsip=$(head -1 /tmp/dnsip.txt)
curl -s http://icanhazip.com > /tmp/ip.txt
myip=$(head -1 /tmp/ip.txt)
@xixitalk
xixitalk / base64_block.rb
Last active December 19, 2015 08:39
octopress plugins:base64 encode twice and decode at browser with javascript
# Title: base64 encode content
# Author: xixitalk http://xixitalk.github.io
# Description: base64 encode twice and decode at browser with javascript
#
# Syntax:
# {% base64_block %}
# This text will be encoded twice with base64
# {% endbase64_block %}
#
# Output:
@xixitalk
xixitalk / haproxy.cfg
Last active March 26, 2016 00:24
8877为haproxy对外的端口,8443是多个SS服务器的端口,weight是权重,值越大分配的负载越多,backup是标志后备的服务器。手机上影梭使用haproxy所在的IP和端口8877访问,加密方式和密码使用SS服务器的设置。
global
ulimit-n 51200
defaults
log global
mode tcp
option dontlognull
balance roundrobin
option persist
timeout connect 10000
timeout client 150000
@xixitalk
xixitalk / 0. remote.conf
Created May 8, 2016 02:07 — forked from clowwindy/0. remote.conf
SigmaVPN configure
[peername]
proto = nacltai
proto_publickey = LOCAL_PUBKEY
proto_privatekey = REMOTE_PRIKEY
local = tuntap
local_interface = tunnel
local_tunmode = 1
peer = udp
peer_localaddr = REMOTE_IP
peer_localport = 8000
@xixitalk
xixitalk / deadloop.c
Created July 9, 2016 02:15
UINT32引起的死循环
SINT32 txsem_count_init(Semaphore *ptxSem)
{
UINT32 i = 0;
UINT32 semCount = 0;
UINT32 Count = 0;
semCount = GetSemaphoreCount(ptxSem);
Count = SEM_INIT_NUM - semCount;
if (Count > 0)
@xixitalk
xixitalk / mymalloc.c
Last active July 10, 2016 09:36
malloc封装用于检测内存越界
#define BEGIN_MAGIC 0x3a3a3a3a
#define END_MAGIC 0x5a5a5a5a
void *mymalloc(unsigned int size)
{
char *ptr = (char *)malloc(size+12);
unsigned int *ptmp = NULL;
if(NULL == ptr)
return NULL;
@xixitalk
xixitalk / funcStackCheck.c
Last active July 10, 2016 08:49
函数栈破坏检查
#define STACK_FIND_SIZE 2048 //find from SP to SP+STACK_FIND_SIZE
void funcStackCheck(unsigned long *psp, unsigned long lr)
{
if(psp && (*psp != lr))
{
assert(0);
}
}