This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Terminal greeting. | |
# Whenever you open a terminal, it will show a man page of randomly selected command. | |
# [useful for beginner.] | |
# source : efytimes.com | |
#append this line to ~/.bashrc | |
man `ls /usr/bin | shuf -n1` | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# chunk given list | |
# | |
from itertools import islice | |
def chunked_list(lst, n): | |
itr = iter(lst) | |
return iter(lambda: list(islice(itr, n)), []) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://stackoverflow.com/questions/4203163/how-do-i-design-a-class-in-python/4203836#4203836 | |
#TLDR: | |
How to design a class. | |
Write down the words. You started to do this. Some people don't and wonder why they have problems. | |
Expand your set of words into simple statements about what these objects will be doing. That is to say, write down the various calculations you'll be doing on these things. Your short list of 30 dogs, 24 measurements, 4 contacts, and several "parameters" per contact is interesting, but only part of the story. Your "locations of each paw" and "compare all the paws of the same dog to determine which contact belongs to which paw" are the next step in object design. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find . -iname '*py' -exec sed -i 's/foo/bar/g' {} \; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CheckHttpMethod(object): | |
""" | |
Decorator check whether HTTP request is as per your need, | |
if not it redirects to '/'. | |
This is a decorator with *mandatory* argument, a HTTP method | |
you want to check. | |
>>>@CheckHttpMethod('POST') | |
...def handler(*args, *kwargs): | |
... pass | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TRUE=0 | |
FALSE=1 | |
held_futex(){ | |
tot=`ps -eo "%p %u %a"|awk '{ print ($2=="user") ? $0: ""}'|grep -c -i '[p]rocess'` | |
i=0 | |
for pid in `ps -eo "%p %u %a"|awk '{ print ($2=="user") ? $0: ""}'|grep -i '[p]rocess'|awk '{ print $1 }'` | |
do | |
cnt=`cat /proc/${pid}/wchan|grep -c -i 'futex_wait_'` | |
if [ $cnt -gt 0 ];then | |
i=$((i+=1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Generate Mercurial diff and save in `diffs' subdir. | |
generate_diff(){ | |
diff_dir="diffs" | |
mkdir -p ${diff_dir} | |
branch=`hg branch` | |
now=`date +"%F_%T"` | |
file_path="${PWD}/${diff_dir}/${branch}_${now}.diff" | |
`hg diff > ${file_path}` | |
[ $? -eq 0 ] && echo "created diff ${file_path}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def extract_cert_key(certpath=None): | |
""" | |
Extracts private key & certificate and returns as pem string. | |
params: | |
certpath = Valid P12 certificate file path. | |
returns: | |
(certificate, privatekey) | |
""" | |
import os | |
import getpass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = { | |
"a": 123, | |
"b": 456 | |
} | |
l = [a, a] | |
print l | |
remove_dups = [dict(t) for t in set([tuple(d.items) for d in l])] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> import uuid | |
>>> mac="%12X" % uuid.getnode() | |
>>> mac | |
'48D224921B7C' | |
>>> mac[::2] | |
'4D2917' | |
>>> mac[1::2] | |
'8242BC' | |
>>> map(None, *(mac[::2], mac[1::2])) |
OlderNewer