Skip to content

Instantly share code, notes, and snippets.

def test19():
src_fpath = "gbk.txt"
dst_fpath = "utf8.txt"
dstf = open(dst_fpath,"w")
for line in open(src_fpath):
try:
dstf.write(line.decode("gbk").encode("utf8"))
except Exception as e:
print "error when handle '%s': '%s'"%(repr(line),e)
@zhangchunlin
zhangchunlin / tcping.py
Created June 20, 2016 10:08 — forked from defnull/tcping.py
TCPing
def ping(server, port):
''' Check if a server accepts connections on a specific TCP port '''
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((server, port))
s.close()
return True
except socket.error:
return False
@zhangchunlin
zhangchunlin / drun
Created August 18, 2016 05:04
drun
#! /usr/bin/env python
#coding=utf-8
def main():
from optparse import OptionParser
import os
import logging
import sys
import time
@zhangchunlin
zhangchunlin / prun
Created August 5, 2014 08:11
prun, a little tool to run cmds parallel.
#! /usr/bin/env python
#coding=utf-8
import gevent
from gevent.subprocess import Popen, PIPE
import sys
def run(cmd,name="",index=1,color=True):
fc = 32 + index%5
if name:
@zhangchunlin
zhangchunlin / time_strftime.py
Last active February 16, 2017 07:31
time and strftime
import time
tstr = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))
print tstr
@zhangchunlin
zhangchunlin / nginx.conf
Created May 9, 2017 23:42
nginx.conf , openresty, redirect, ip
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
server {
listen 6699;
location / {
from subprocess import Popen, PIPE, STDOUT
import os
def runcmd(cwd,cmd):
oldcwd = os.getcwd()
os.chdir(cwd)
runcmd_timeout = 3600
p = Popen(cmd,stdout=PIPE,stderr=STDOUT,shell=True,preexec_fn=os.setpgrp)
p.wait(runcmd_timeout)
if p.returncode==None:
@zhangchunlin
zhangchunlin / emojis.json
Created December 18, 2017 02:42 — forked from oliveratgithub/emojis.json
Emoji-list with emojis, names, shortcodes, unicode and html entities [massive list]
{
"emojis": [
{"emoji": "👩‍👩‍👧‍👧", "name": "family_mothers_two_girls", "shortname": "", "unicode": "", "html": "👩‍👩‍👧‍👧", "category": "p", "order": ""},
{"emoji": "👩‍👩‍👧‍👦", "name": "family_mothers_children", "shortname": "", "unicode": "", "html": "👩‍👩‍👧‍👦", "category": "p", "order": ""},
{"emoji": "👩‍👩‍👦‍👦", "name": "family_mothers_two_boys", "shortname": "", "unicode": "", "html": "👩‍👩‍👦‍👦", "category": "p", "order": ""},
{"emoji": "👨‍👩‍👧‍👧", "name": "family_two_girls", "shortname": "", "unicode": "", "html": "👨‍👩‍👧‍👧", "category": "p", "order": ""},
{"emoji": "👨‍👩‍👧‍👦", "name": "family_children", "shortname": "", "unicode": "", "html": "👨‍👩‍👧‍👦", "category": "p", "order": ""},
{"emoji": "👨‍👩‍👦‍👦", "name": "family_two_biys", "shortname": "", "unicode": "", "html": "👨&zw
@zhangchunlin
zhangchunlin / command.py
Created January 3, 2018 10:09
python command line file template
#!/usr/bin/env python
from __future__ import print_function
def main():
pass
if __name__=='__main__':
main()
@zhangchunlin
zhangchunlin / master.py
Created April 1, 2014 03:26
gevent master slave example
#! /usr/bin/env python
#coding=utf-8
import gevent
from gevent.server import StreamServer
from gevent.queue import Queue
import json
def sendmsg2fobj(fobj,msg):