Skip to content

Instantly share code, notes, and snippets.

@mydreambei-ai
mydreambei-ai / urlparse.py
Created June 22, 2017 07:29
Python url parser
import re
class UrlParser(object):
def __init__(self, url):
self.url = url
self.schem = self.zone = self.domain = self.port = self.path = self.query = self.params = None
def parse(self):
match = re.match(r"((\w*)://)?([^:/\?]*):?(\d+)?(.*)?", self.url)
if match:
self.schem = match.group(2)
@mydreambei-ai
mydreambei-ai / compare_files_lines.py
Last active June 7, 2017 08:17
Compare files line by line like linux command comm
import argparse
"""
usage:
python compare_files_lines.py -a inter <file1> <file2> == comm -12 <file1> <file2>
python compare_files_lines.py -a union <file1> <file2> == comm <file1> <file2> | sed 's/[\t ]*//g'
python compare_files_lines.py -a diff <file1> <file2> == comm -23 <file1> <file2>
python compare_files_lines.py -a rdiff <file1> <file2> == comm -13 <file1> <file2>
python compare_files_lines.py -a sydiff <file1> <file2> == comm -3 <file1> <file2> | sed 's/[\t ]*//g'
@mydreambei-ai
mydreambei-ai / compare_files_lines.py
Created June 7, 2017 08:03
Compare files line by line like linux command comm
import argparse
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-a", "--action", dest="action", required=True,
choices=["inter", "union", "diff", "sydiff", "rdiff"])
parser.add_argument(
"A", type=argparse.FileType("r"), help="the base file")
parser.add_argument(
"B", type=argparse.FileType("r")
@mydreambei-ai
mydreambei-ai / compare_files_lines.py
Created June 7, 2017 08:03
Compare files line by line like linux command comm
import argparse
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-a", "--action", dest="action", required=True,
choices=["inter", "union", "diff", "sydiff", "rdiff"])
parser.add_argument(
"A", type=argparse.FileType("r"), help="the base file")
parser.add_argument(
"B", type=argparse.FileType("r")
@mydreambei-ai
mydreambei-ai / pycurl_mul_example.py
Created May 31, 2017 07:22
epoll and pycurl multiple example
import pycurl
import select
URLS = ["https://www.douban.com/", "http://mail.163.com", "http://www.sina.com.cn", "http://google.com"]
SOCKETS = set()
TIMEOUT = 10
epoll = select.epoll()
def start_timeout(msecs):
@mydreambei-ai
mydreambei-ai / compile.md
Created May 15, 2017 07:26
linux kernel comiple
@mydreambei-ai
mydreambei-ai / compile.md
Created May 15, 2017 07:26
linux kernel comiple
@mydreambei-ai
mydreambei-ai / compile.md
Created May 15, 2017 07:26
linux kernel comiple
@mydreambei-ai
mydreambei-ai / sed_example.sh
Created May 9, 2017 07:29
three useful sed function
function join_lines()
{
local delim=${1:-,}
sed 'H;$!d;{x;s/\n/'$delim'/g;s/'$delim'//}'
}
function reverse_lines()
{
sed '1!G;h;$!d'
}
@mydreambei-ai
mydreambei-ai / data.json
Last active May 5, 2017 09:58
Import data from json file into Postgresql table
{
"data":[
{
"city_code": "411800",
"domain": "jiyuan.gov.cn",
"id": 11849
},
{
"city_code": "410500",
"domain": "anyang.gov.cn",