Skip to content

Instantly share code, notes, and snippets.

View tkhoa2711's full-sized avatar

Khoa Le tkhoa2711

View GitHub Profile
@tkhoa2711
tkhoa2711 / apache2-fix-env.sh
Created September 22, 2015 15:08
Apache config variable not defined..
# > apache2 -V
# results in error like this:
# ... AH00111: Config variable ${APACHE_LOCK_DIR} is not defined
#
# we need to source the envvars file to create the configs in which apache2 relies on
source /etc/apache2/envvars
@tkhoa2711
tkhoa2711 / fix-make-error-configure-no-such-file.txt
Created July 8, 2015 04:11
Error during compilation from source - bin/sh: line 2: ./configure: No such file or directory
If you happen to see this error during compilation for programs, for example that's nginx in my case:
...
./configure --disable-shared
/bin/sh: line 2: ./configure: No such file or directory
...
In this case I already configured nginx with my custom-built PCRE library:
./configure --with-pcre=<path-to-lib-containing-pcre>
@tkhoa2711
tkhoa2711 / fix-discoveryd
Created July 3, 2015 16:28
To rescuse your Mac when the infamous discoveryd misbehaves
#!/usr/bin/env sh
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.discoveryd.plist
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.discoveryd.plist
@tkhoa2711
tkhoa2711 / multipledispatch.py
Created June 8, 2015 02:42
A barely simple implementation of multiple-value dispatch for Python
def valuedispatch(func):
"""
A simple decorator for multiple dispatch based on values, not types.
Transform a function into generic function, which can have different behaviours
depending upon the values of its keyword arguments.
"""
registry = {}
def register(**kwargs):
"""
@tkhoa2711
tkhoa2711 / throttle.py
Last active August 29, 2015 14:20
A simple decorator for throttle functionality in Python
import time, platform
from collections import defaultdict
from functools import wraps
get_time = time.clock if platform.system() == 'Windows' else time.time
__nop = lambda: None
__throttle_last_time = defaultdict(__nop)
def throttle(duration=1, **kw):
@tkhoa2711
tkhoa2711 / loop.lisp
Created December 18, 2014 13:40
Tutorial for loop construct in Common Lisp
; http://www.ai.sri.com/pkarp/loop.html
@tkhoa2711
tkhoa2711 / parse-line-to-chars.lisp
Created December 18, 2014 07:44
Parse a line into list of characters
(coerce (read-line) 'list)
@tkhoa2711
tkhoa2711 / reverse-nested-list.lisp
Last active August 29, 2015 14:11
Reverse nested list in Common Lisp
(defun reverse-nested-list (list)
"reverse nested list"
(mapcar #'(lambda (l)
(if (not (consp l))
l
(reverse-deep l)))
(reverse list)))
@tkhoa2711
tkhoa2711 / read-line-into-list.lisp
Created December 18, 2014 07:37
Read a line and parse it into a list of items
(defun read-line-into-list ()
(with-input-from-string (in (read-line))
(loop for x = (read in nil nil) while x collect x)))
@tkhoa2711
tkhoa2711 / timing.py
Created December 17, 2014 17:15
An utility module for timing code execution in Python
"""
An utility module for timing code execution in various ways.
"""
import time
import platform
from functools import wraps
from contextlib import contextmanager