Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / showBigOrLittleEnd.c
Created August 31, 2015 03:54
查看机器是大端还是小段
#include<stdio.h>
typedef unsigned char * byte_pointer;
int showBigOrLittleEnd()
{
int i = 0x01;
byte_pointer bp = (byte_pointer) &i;
if (bp[0] == 0x01)
return 1;
#coding:utf-8
from gevent import monkey
monkey.patch_all()
import os
import tornado
import logging
import tornado.wsgi
import tornado.httpserver
#coding:utf-8
def quick_sort(sort_list):
if len(sort_list) <= 1:
return sort_list
m = sort_list[0]
return quick_sort(filter(lambda x: x<=m, sort_list[1:])) + [m] + \
quick_sort(filter(lambda x: x>m, sort_list[1:]))
#coding:utf-8
def insert_sort(array):
if len(array) <= 1:
return
for i in range(1, len(array)):
j = i
@ls0f
ls0f / bubble_sort.py
Last active September 14, 2015 02:05
#coding:utf-8
def bubble_sort(sort_list):
length = len(sort_list)
while length > 1:
for i in range(1, length):
if sort_list[i] < sort_list[i-1]:
sort_list[i], sort_list[i-1] = sort_list[i-1],sort_list[i]
#coding:utf-8
# https://gist.github.com/opensourcegeek/9822127
from gevent import monkey
monkey.patch_all()
import logging
import gevent
from gevent.queue import Queue, Empty
import pymysql as db
@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