Skip to content

Instantly share code, notes, and snippets.

What's happening?

Allan Lei allanlei

What's happening?
View GitHub Profile
# -*- coding: utf-8 -*-
def diff(d2, d1={}, missing=MISSING_KEY_VALUE):
for key, val in d2.items():
if key not in d1:
yield key, (missing, val)
allanlei /
Created Apr 24, 2014
Diffie Hellman
#!/usr/bin/env python
from binascii import hexlify
import hashlib
# If a secure random number generator is unavailable, exit with an error.
import Crypto.Random.random
secure_random = Crypto.Random.random.getrandbits
except ImportError:
allanlei / gist:300602157a54153b754b
Last active Aug 29, 2015
docker + etcd - Command to read all keys from a directory of etcd and set as env in a docker run command
View gist:300602157a54153b754b
docker run $(etcdctl ls $ETCD_ENV | while read e; do etcdctl get $e > /dev/null 2>&1 && echo --env $(echo $e | rev | cut -d/ -f1 | rev)=$(etcdctl get $e); done) busybox env
allanlei / python-site
Created May 26, 2014
Sample python backend for nginx
View python-site
server {
listen 80 default_server deferred;
listen 443 default_server deferred ssl;
listen [::]:80 ipv6only=on default_server deferred;
listen [::]:443 ipv6only=on default_server deferred ssl;
root /path/to/static/files
# Include SSL stuff
allanlei / Dockerfile
Created Jun 10, 2014
Command line boto docker container
View Dockerfile
FROM dockerfile/python
RUN pip install boto
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
import urlparse
import click
@click.option('--metadata-url', default='')
import StringIO
import subprocess
import os
import time
from datetime import datetime
from PIL import Image
# Motion detection settings:
# Threshold (how much a pixel has to change by to be marked as "changed")
# Sensitivity (how many changed pixels before capturing an image)
allanlei /
Created Jun 12, 2014
Motion detection using OpenCV with Differential Images technique. Source
import cv2
def diffImg(t0, t1, t2):
d1 = cv2.absdiff(t2, t1)
d2 = cv2.absdiff(t1, t0)
return cv2.bitwise_and(d1, d2)
cam = cv2.VideoCapture(0)
winName = "Movement Indicator"
from twisted.internet import reactor
from twisted.protocols import portforward
def server_dataReceived(self, data):
print 'Server received data:', data
portforward.Proxy.dataReceived(self, data)
portforward.ProxyServer.dataReceived = server_dataReceived
def client_dataReceived(self, data):
print 'Client received data:', data
def procfile(filepath):
with open(filepath, 'rb') as fp:
for process_line in fp.readlines():
process_line = process_line.strip()
if not process_line or process_line.startswith('#'):
process_name, command = process_line.split(':', 1)
yield process_name.strip(), command.strip()
You can’t perform that action at this time.