Skip to content

Instantly share code, notes, and snippets.

:shipit:
What's happening?

Allan Lei allanlei

:shipit:
What's happening?
Block or report user

Report or block allanlei

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View diff.py
# -*- coding: utf-8 -*-
MISSING_KEY_VALUE = None
def diff(d2, d1={}, missing=MISSING_KEY_VALUE):
for key, val in d2.items():
if key not in d1:
yield key, (missing, val)
@allanlei
allanlei / dh.py
Created Apr 24, 2014
Diffie Hellman
View dh.py
#!/usr/bin/env python
from binascii import hexlify
import hashlib
# If a secure random number generator is unavailable, exit with an error.
try:
import Crypto.Random.random
secure_random = Crypto.Random.random.getrandbits
except ImportError:
@allanlei
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
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;
server_name example.com www.example.com testing.example.com;
root /path/to/static/files
# Include SSL stuff
@allanlei
allanlei / Dockerfile
Created Jun 10, 2014
Command line boto docker container
View Dockerfile
FROM dockerfile/python
RUN pip install boto
View fetchIAMKeys.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
import urlparse
import click
@click.command()
@click.argument('iam_role')
@click.option('--metadata-url', default='http://169.254.169.254/latest/meta-data/iam/security-credentials/')
View motion.py
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
allanlei / motion.py
Created Jun 12, 2014
Motion detection using OpenCV with Differential Images technique. Source http://www.steinm.com/blog/motion-detection-webcam-python-opencv-differential-images/
View motion.py
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"
View forward.py
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
View procfile.py
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('#'):
continue
process_name, command = process_line.split(':', 1)
yield process_name.strip(), command.strip()
You can’t perform that action at this time.