Skip to content

Instantly share code, notes, and snippets.

View tianweidut's full-sized avatar
🎯
Focusing

tianwei tianweidut

🎯
Focusing
View GitHub Profile
@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 sys
from multiprocessing import Process, Pipe
import traceback
class SubprcessException(Exception):
pass
#coding: utf-8
import gevent
import gevent.monkey
import urllib2
import time
def stop():
print '---start stop'
@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 sys
import os
import mmap
def get_mmap(filepath):
with open(filepath, 'r+b') as f:
mm = mmap.mmap(f.fileno(), 0)
@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
@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 / inherit.py
Created November 18, 2015 12:38
python 继承的小例子,使用子类的key
#coding: utf-8
class Base(object):
def __init__(self):
print 'Base __init__'
def update(self):
print 'Base update'
#coding: utf-8
class Solution(object):
def fullJustify(self, words, maxWidth):
"""
:type words: List[str]
:type maxWidth: int
:rtype: List[str]
@tianweidut
tianweidut / nth_percentile.py
Created April 1, 2016 06:09 — forked from ageron/nth_percentile.py
Explanation of 90th percentile
def nth_percentile(dataset, percentile = 90):
sorted_dataset = sorted(dataset)
new_length = len(sorted_dataset) * percentile / 100
return sorted_dataset[0:new_length]
def mean(dataset):
return sum(dataset)/float(len(dataset))
dataset = [5, 9, 7, 101, 4, 8, 109, 104, 6, 1, 110, 106, 3, 107, 105, 2, 102, 10, 103, 108]
percentile_90 = nth_percentile(dataset)