Skip to content

Instantly share code, notes, and snippets.

View keenhenry's full-sized avatar

Henry Huang keenhenry

  • Eindhoven, Noord Brabant, The Netherlands
View GitHub Profile
@keenhenry
keenhenry / process_states.txt
Created December 11, 2016 20:37
process states codes (try `$ man ps`)
PROCESS STATE CODES
Here are the different values that the s, stat and state output specifiers (header "STAT" or "S") will display to describe the state of a process:
D uninterruptible sleep (usually IO)
R running or runnable (on run queue)
S interruptible sleep (waiting for an event to complete)
T stopped, either by a job control signal or because it is being traced
W paging (not valid since the 2.6.xx kernel)
X dead (should never be seen)
Z defunct ("zombie") process, terminated but not reaped by its parent
@keenhenry
keenhenry / 1) Install
Created December 8, 2016 20:15 — forked from nghuuphuoc/1) Install
Install Redis on Centos 6
// --- Compiling ---
$ wget http://download.redis.io/releases/redis-2.8.3.tar.gz
$ tar xzvf redis-2.8.3.tar.gz
$ cd redis-2.8.3
$ make
$ make install
// --- or using yum ---
$ rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
$ rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
@keenhenry
keenhenry / keyerr.py
Last active November 2, 2016 20:43
How to bypass try-catch block from the inner function ...
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
def inner():
d = {'b': 1}
try:
d['a']
except:
@keenhenry
keenhenry / git.rst
Last active October 30, 2016 20:51
Git workflow document
@keenhenry
keenhenry / mkdir_p.py
Last active October 29, 2016 16:54
The implementation of `$ mkdir -p path` in Python: http://stackoverflow.com/questions/600268/mkdir-p-functionality-in-python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import errno
import os
def mkdir_p(path):
try:
@keenhenry
keenhenry / script.bash
Created April 16, 2016 20:04 — forked from jiaaro/script.bash
Embed Python in a bash script
#!/bin/bash
export FOO=100
python - <<END
import os
print "foo:", os.environ['FOO']
END
@keenhenry
keenhenry / scopes.py
Created March 31, 2016 19:27
Python Scopes Quirks
#!/usr/bin/env python
# name binding always creates a name in the local scope
ng = 'a global'
def f():
# without the following commented out line, UnboundLocalError will throw
# global ng
nl = 2
print ng, nl
ng = 3
@keenhenry
keenhenry / latency.txt
Created March 20, 2016 10:01 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@keenhenry
keenhenry / Print Python's Exception objects hierarchy
Created March 5, 2016 15:44
A small script to print out the Exception inheritance hierarchy. Useful for writing exception handling (Python 2.5+)
#!/usr/bin/env python
def classtree(cls, indent=0):
print '.' * indent, cls.__name__
for subcls in cls.__subclasses__():
classtree(subcls, indent + 3)
classtree(BaseException)
@keenhenry
keenhenry / beautiful_idiomatic_python.md
Created February 14, 2016 20:51 — forked from JeffPaine/beautiful_idiomatic_python.md
Transforming Code into Beautiful, Idiomatic Python: notes from Raymond Hettinger's talk at pycon US 2013. The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]: