Skip to content

Instantly share code, notes, and snippets.

View keenhenry's full-sized avatar

Henry Huang keenhenry

  • Veldhoven, Noord Brabant, The Netherlands
View GitHub Profile
@keenhenry
keenhenry / git.rst
Last active October 30, 2016 20:51
Git workflow document
@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 / 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 / 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 / array_iteration_thoughts.md
Created January 14, 2017 11:36 — forked from ljharb/array_iteration_thoughts.md
Array iteration methods summarized

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it much simpler to think about both the old list and the new one, what they contain, and

@keenhenry
keenhenry / gist:e3e86c8563808f3fdfdb8687d078c295
Created February 5, 2017 19:40 — forked from rduplain/gist:2149194
PyCon 2012 Digest for WillowTree Apps

PyCon 2012 Digest

from DevOps team {rduplain,mattd,teebes}, to mobile developers at WillowTree Apps

Pronunciation

@keenhenry
keenhenry / test_runner.py
Created February 17, 2017 09:21
Use file storage on the local filesystem in Django unit tests
import shutil
import tempfile
from django.conf import settings
from django.core.files.storage import FileSystemStorage
from django.db.models import FileField
from django.db.models.loading import get_model, get_models
from django.test.runner import DiscoverRunner
@keenhenry
keenhenry / supervisord.conf
Created June 15, 2017 13:28 — forked from CMCDragonkai/supervisord.conf
Upstart: Upstart Init Script for Supervisord
# supervisord - Upstarts the supervisor as service
# Put this file into /etc/init/supervisord.conf
# sudo service supervisord start
# sudo service supervisord stop
# Service gets started as root
# Needs `pgrep` available to root
description "Supervisord - Upstart"
stop on runlevel [016]
@keenhenry
keenhenry / supervisord.sh
Created June 15, 2017 13:35 — forked from danmackinlay/supervisord.sh
an init.d script for supervisord
#! /bin/sh
### BEGIN INIT INFO
# Provides: supervisord
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
@keenhenry
keenhenry / trie.py
Last active July 30, 2017 09:05
Python Trie implementation
#!/usr/bin/env python
class Node(object):
__slots__ = ('letters', 'children', 'num_occurs')
def __init__(self, letters=None):
self.letters = letters # only leaf nodes have non-None letters
self.children = {}