Skip to content

Instantly share code, notes, and snippets.

@ls0f
ls0f / phone2.lua
Last active August 29, 2015 14:28
手机号码归属地库lua解析脚本
#!/usr/bin/env lua
local phone_dat = "phone.dat"
function getPhoneType(a)
if a == 1 then
return "移动"
elseif a == 2 then
return "联通"
elseif a==3 then
@ls0f
ls0f / phone.lua
Last active August 29, 2015 14:28
手机号码库lua解析脚本
#!/usr/bin/env lua
function byteToUint32(a,b,c,d)
local _int = 0
if a then
_int = _int + bit32.lshift(a, 24)
end
_int = _int + bit32.lshift(b, 16)
_int = _int + bit32.lshift(c, 8)
_int = _int + d
@ls0f
ls0f / python-count-time.py
Created August 15, 2015 10:29
python-count-time
#coding:utf-8
import time
__author = 'haifang'
def count_function_time():
def wraps(function):
function.CUR_TIME = time.time()
def log_time(point):
@ls0f
ls0f / python-yield-socket.py
Last active August 29, 2015 14:27
python-yield-http.py
#coding:utf-8
# http://stackoverflow.com/questions/2719017/how-to-set-timeout-on-pythons-socket-recv-method
# http://stackoverflow.com/questions/16745409/what-does-pythons-socket-recv-return-for-non-blocking-sockets-if-no-data-is-r
import select
import socket
def receive(s):
@ls0f
ls0f / install-vpn-on-ubuntu.sh
Last active September 23, 2015 08:58
install vpn on ubuntu
#!/bin/bash
default_user="vpn"
default_password="123456"
read -p "Input VPN username:(default is ${default_user})" user
read -p "Input VPN password:(default is ${default_password})" password
if [ $user=="" ];then
user=$default_user
@ls0f
ls0f / python-producer-consumer.py
Last active August 29, 2015 14:26
python-producer-consumer
import sys
def producer():
while True:
line = sys.stdin.readline()
yield line
def consumer(p):
line = p.next()
@ls0f
ls0f / gist:85817aaedbabea7e6cf6
Created August 6, 2015 18:27
lua-producer-consumer
#!/usr/local/bin/lua
function producer()
return coroutine.create(function()
while true do
local line = io.read()
coroutine.yield(line)
end
end)
end
@ls0f
ls0f / lua
Created August 6, 2015 18:23
lua-yeild-http
#!/usr/local/bin/lua
local socket = require "socket"
function receive(c)
c:settimeout(0) --> 不阻塞
local s,status,partial = c:receive(2^10)
if status == "timeout" then
coroutine.yield(c)
end
@ls0f
ls0f / block-ip.py
Last active August 29, 2015 14:20
block ip
#coding: utf-8
import os
## block cc攻击 的ip
CMD = "netstat -ntup | grep -v SYN |awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr"
MAX_CONN = 50
@ls0f
ls0f / tornado-redis-cache
Created April 27, 2015 01:34
tornado-redis-cache
#coding:utf-8
from tornado.web import RequestHandler
import redis
def getRedisObj(rdb=0):
pool = redis.ConnectionPool(
host='127.0.0.1', password='', port=6379, db=rdb, socket_timeout=3)
r = redis.Redis(connection_pool=pool)