Skip to content

Instantly share code, notes, and snippets.

@liaoyw
liaoyw / restore-root-filesystem
Created July 12, 2017 05:35
restore accidently moved root files system
https://stackoverflow.com/a/11910583/5797497
Old thread, but got exactly the same stupid mistake. /lib64 was moved to /lib64.bak remotely and everything stopped working.
This was a x86_64 install, so ephemient's solution was not working:
# /lib64.bak/ld-linux.so.2 --library-path /lib64.bak/ /bin/mv /lib64.bak/ /lib64
/bin/mv: error while loading shared libraries: /bin/mv: wrong ELF class: ELFCLASS64
In that case, a different ld-linux had to be used:
# /lib64.bak/ld-linux-x86-64.so.2 --library-path /lib64.bak/ /bin/mv /lib64.bak/ /lib64
@liaoyw
liaoyw / close_fd.py
Last active February 16, 2017 08:59
close deleted file fd
# gdb -ex 'set print thread-events off' --batch -q -x ~/df.py
import os
import os.path
import sys
import gdb
pid = open('/var/run/docker.pid', 'r').read()
print 'attach to ' + pid
gdb.execute('attach ' + pid)
os.chdir('/proc/%s/fd'%pid)
git_branch() {
gb=$(git branch 2>/dev/null | grep '^*' | tr -d '* ')
[[ ! -z $gb ]] && echo "($gb)"
}
export PS1="\\W\$(git_branch) $"
@liaoyw
liaoyw / latency.markdown
Created October 9, 2016 01:10 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

ping cn.bing.com | while read pong; do echo "$(date): $pong"; done
# open macdown from terminal
# from https://github.com/MacDownApp/macdown/wiki/Advanced-Usage
macdown() {
"$(mdfind kMDItemCFBundleIdentifier=com.uranusjr.macdown | head -n1)/Contents/SharedSupport/bin/macdown" $@
}
# encoding: utf-8
import zlib
"""
copy from:
https://github.com/afirel/consistent_hashr/blob/master/lib/consistent_hashr.rb
http://www.tom-e-white.com/2007/11/consistent-hashing.html
"""
class ConsistentHash(object):
# copy from http://www.tldp.org/LDP/abs/html/sample-bashrc.html
function extract() # Handy Extract Program
{
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname