asu () { user=$1; shift; su $user -c “$*”; }
print the arguments joined with a comma
python -c ‘import sys; print(“,” .join(sys.argv[1:]))’ 1 two trois
python case insensitive word lists comparison
commonwordsinlist1=[i for i in list1 if i.upper() in map(str.upper,list2)]
Is a perl module installed on multiple servers
for i in server{1,2,3,4};do ssh $i perl -e ‘use Debug::Trace’ && echo $i yes || echo $i no;done
execute multiple commands on multiple servers from the shell command line
for i in host{1,2,3}.{east,west}.serverdomain.net;do ssh -t $i ‘for i in this that;do ls $i;done’;done
custom css to add to custom.css for your ipython notebook to make chrome stop zooming on input focus
textarea{font-size:18px!important;}
python interleave iterators of mismatched length without adding None placeholders
python -c ‘reduce(lambda x,y:x+tuple(i for i in y if i is not None),map(None,range(0,6,2),range(1,8,2)))’
python interleave iterators of mismatched length
python -c ‘print reduce(lambda x,y:x+y,map(None,range(0,6,2),range(1,8,2)))’
j search and replace and example usage
srep =: 4 : ‘; (> {:x)&, each (#>{.x)&}. each ((>{.x) E. y) <;. 1 y'
('abc';'xyz') srep 'abc123abc456'
python interleave two iterators
python -c “print reduce(lambda x,y:x+y,zip(range(0,10,2),range(1,10,2)))”
gnu smalltalk one liners read standard in
gst – <<<“‘hello’ printNl”
haskell list comprehension and local scoping
ghc -e 'let hw = let zhw = zip "hello" "world"; h = [fst x | x <- zhw]; w = [snd y | y <- zhw] in h ++ " " ++ w' -e 'hw'
haskell factorial function
ghc -e 'let {factorial 0 = 1; factorial n | n > 0 = product [1..n]; factorial n | n < 0 = (-1) * factorial (-n); factorial -n = (-1) * factorial n; }' -e 'factorial 5' -e 'factorial -6' -e 'factorial (-7)'
haskell one liners begin with -e
ghc -e 'let hw (x,y) = x ++ " " ++ y' -e 'hw (unzip (zip "hello" "world"))'
grep git the last commit hash
git log -n1|head -n1|grep -o '[[:xdigit:]]\{7,\}'
cut git the last commit hash
git log -n1|head -n1|cut -d' ' -f2
awk git the last commit hash
git log -n1|awk '/commit/ {print $2}'
launching emacs as a shell
emacs -e 'shell'
sed cut replacement everything in a csv except second field
sed -ne 's/[^,]*,//2p'
sed as grep and cut replacement
sed -ne '/key=/{s/^.*=//,s%/%\\/%g;p}'