Skip to content

Instantly share code, notes, and snippets.

View tianweidut's full-sized avatar
🎯
Focusing

tianwei tianweidut

🎯
Focusing
View GitHub Profile
@tianweidut
tianweidut / check_container
Created July 17, 2015 06:31
shell 技巧: 1. exec 一个shell func: export -f func_name; exec bash -c “func_name” 2. 判断命令输出是否为空 if [[ -n $(docker ps -f name=test)]]; 3. 判断命令的返回码是否为0(即是否正确执行exit 0) if docker ps ;
#!/bin/sh
ulimit -n 65536
exec 2>&1
create_container () {
echo 'try to create container'
sudo docker create --name 'gentoo_with_portage' \
-v /usr/portage/ \
-v /var/lib/layman/ \
@tianweidut
tianweidut / iptables_ignore_docker.sh
Last active August 29, 2015 14:11
iptables clear rules ignore docker
function clear(){
table=$1
chain=$2
iptables -t $table -L $chain -n --line-numbers -v | grep -iv 'docker' | grep '^[0-9]' | awk '{print $1}' | sort -nr | xargs -rl iptables -D $chain
}
clear filter FORWARD
clear nat PREROUTING
clear nat POSTROUTING
clear nat OUTPUT
#coding: utf-8
import sys
import os
import mmap
def get_mmap(filepath):
with open(filepath, 'r+b') as f:
mm = mmap.mmap(f.fileno(), 0)
@tianweidut
tianweidut / drs
Created October 10, 2014 14:55
cas:50-29-3 smi:Clc1ccc(cc1)C(c1ccc(Cl)cc1)C(Cl)(Cl)Cl
est863@est863:/var/chemistry/code/chemistry/calcore/fordragon/Clc1ccc(cc1)C(c1ccc(Cl)cc1)C(Cl)(Cl)Cl$ cat Clc1ccc\(cc1\)C\(c1ccc\(Cl\)cc1\)C\(Cl\)\(Cl\)Cl.drs
No. NAME MW AMW Sv Se Sp Si Mv Me Mp Mi nAT nSK nBT nBO nBM SCBO RBN RBF nDB nTB nAB nH nC nN nO nP nS nF nCL nBR nI nB nHM nHet nX H% C% N% O% X% nCsp3 nCsp2 nCsp nCIC nCIR TRS Rperim Rbrid MCD RFDRCI NRS NNRS nR03 nR04 nR05 nR06 nR07 nR08 nR09 nR10 nR11 nR12 nBnz ARR D/Dtr03 D/Dtr04 D/Dtr05 D/Dtr06 D/Dtr07 D/Dtr08 D/Dtr09 D/Dtr10 D/Dtr11 D/Dtr12 ZM1ZM1V ZM1Kup ZM1Mad ZM1Per ZM1MulPer ZM2 ZM2V ZM2Kup ZM2Mad ZM2Per ZM2MulPer ON0 ON0V ON1 ON1V Qindex BBI DBI SNar HNar GNar Xt Dz RamBLI Pol LPRS MSD SPI PJI2 E
#coding: utf-8
import gevent
import gevent.monkey
import urllib2
import time
def stop():
print '---start stop'
#coding: utf-8
import sys
from multiprocessing import Process, Pipe
import traceback
class SubprcessException(Exception):
pass
@tianweidut
tianweidut / remote_pdb.py
Created August 25, 2014 03:18
pdb in subprocess
#ref: http://stackoverflow.com/questions/4716533/how-to-attach-debugger-to-a-python-subproccess
import sys
import pdb
class ForkedPdb(pdb.Pdb):
"""A Pdb subclass that may be used
from a forked multiprocessing child
"""
#coding: utf-8
import os
from os.path import join, exists, splitext
import datetime
import uuid
import string
import random
import shutil
TEST_DIR = '/tmp/xinxin/'
@tianweidut
tianweidut / git-rebase
Created April 20, 2014 03:24
git rebase after sync upstream master
$ git rebase upstream/master
First, rewinding head to replay your work on top of it...
Applying: config test for dae
Using index info to reconstruct a base tree...
M apitests/framework.py
M tests/test_commodity/framework.py
<stdin>:48: trailing whitespace.
dae test -p -- ilmen/apitests/ --junitxml=ilmen/reports/apitest_v2/nose.xml --cov=ilmen.view.commodity.api.v2 || RET=$?
warning: 1 line adds whitespace errors.
Falling back to patching base and 3-way merge...
@tianweidut
tianweidut / visit.py
Last active December 23, 2015 00:09
safe call function in period
#coding: utf-8
import threading
import time
MAX = 8
MIN = 0
TIME_LIMIT = 60
g = 0