Skip to content

Instantly share code, notes, and snippets.

View tkhoa2711's full-sized avatar

Khoa Le tkhoa2711

View GitHub Profile
(defun flatten (lst)
"flatten nested list"
(labels ((flatten-rec (lst acc)
(cond ((null lst) acc)
((atom lst) (cons lst acc))
(t (flatten-rec
(car lst)
(flatten-rec (cdr lst) acc))))))
(flatten-rec lst nil)))
@tkhoa2711
tkhoa2711 / print-lisp.lisp
Created December 17, 2014 16:56
Print a list in Common Lisp
(defun print-list (list)
(format t "~{~A ~}~%" list))
@tkhoa2711
tkhoa2711 / Singleton.py
Created October 25, 2014 16:51
A thread-safe implementation of Singleton in Python
import threading
# A thread-safe implementation of Singleton pattern
# To be used as mixin or base class
class Singleton(object):
# use special name mangling for private class-level lock
# we don't want a global lock for all the classes that use Singleton
# each class should have its own lock to reduce locking contention
__lock = threading.Lock()