Skip to content

Instantly share code, notes, and snippets.

View allanlei's full-sized avatar
:shipit:
What's up?

Allan Lei allanlei

:shipit:
What's up?
View GitHub Profile
@allanlei
allanlei / dns.tac
Created August 20, 2015 07:16
Custom Twisted DNS server with dict record storage
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
An example demonstrating how to create a custom DNS server.
The server will calculate the responses to A queries where the name begins with
the word "workstation".
Other queries will be handled by a fallback resolver.
$ aws iam upload-server-certificate \
--server-certificate-name bryce_fisher-fleig_org \
--certificate-body file://bryce_fisher-fleig_org.crt \
--private-key file://bryce_fisher-fleig_org.key \
--certificate-chain file://PostivieSSLCA2.crt \
--path /cloudfront/
@allanlei
allanlei / webcam.py
Created August 7, 2015 09:31
Outputs numpy frames from webcam via FFmpeg
import shlex
# ffmpeg -f v4l2 -video_size 640x480 -i /dev/video0 -c:v libx264 -map 0:v:0 -s 640x480 -dn -sn -hls_list_size 0 -hls_time 10 webcam/prog_index.m3u8
# ffmpeg -i input.flv -f image2 -vf fps=fps=1 out%d.png
# pixel_format, pixel_depth ='rgb24', 3
# ffmpeg('-i "{input}" -s {size} -r:v {fps} -pix_fmt {pixel_format} -c:v rawvideo -an -f image2pipe {output}'.format(
# input=src, output='pipe:1',
# fps=fps, pixel_format=pixel_format, size='{w}x{h}'.format(w=width, h=height),
@allanlei
allanlei / verify.py
Last active August 29, 2015 14:25
Google Play In-App Billing using cryptography package
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, unicode_literals, print_function
import base64
import json
# pip install cryptography
import cryptography
import cryptography.hazmat.primitives.hashes
import cryptography.hazmat.primitives.asymmetric.padding
from twisted.web.server import Site
from twisted.web.resource import Resource
from twisted.internet import reactor
from largerequest import LargeRequest
import hashlib, os, time, json, shutil, socket, boto
# Override tempdir to place temp files in same FS as destination
# this allows for better performance using mv rather than copying
# or re-writing the file.
import tempfile
@allanlei
allanlei / server.py
Last active August 29, 2015 14:17
OAuth2 Hybrid Client Auth
@app.route('/clients/login/<string:backend>/', methods=('GET', 'POST',))
@psa('social.complete')
def complete(backend):
g.backend.STATE_PARAMETER = g.backend.REDIRECT_STATE = False
g.backend.redirect_uri = request.args['redirect_uri']
user = g.backend.auth_complete()
return jsonify(**{
'username': user.email,
'email': user.email,
@allanlei
allanlei / Dockerfile
Created January 27, 2015 08:20
Streaming a zip file to S3 with Docker and aws CLI
FROM python:2.7
RUN apt-get update && \
apt-get install -y groff && \
pip install awscli==1.7.3 && \
apt-get -y autoremove && \
apt-get -y autoclean
@allanlei
allanlei / archive.sh
Created January 19, 2015 06:50
Stream a git archive to S3
git archive HEAD | aws s3 cp - s3://mybucket/$(git describe HEAD).zip
Index: Lib/distutils/msvc9compiler.py
===================================================================
--- Lib/distutils/msvc9compiler.py (revision 82816)
+++ Lib/distutils/msvc9compiler.py (working copy)
@@ -216,7 +216,7 @@
newVariable = os.pathsep.join(newList)
return newVariable
-def find_vcvarsall(version):
+def find_vcvarsall(version, arch="x86"):
@allanlei
allanlei / stunnel.conf
Created October 22, 2014 06:58
STunnel config
#STUNNEL CONFIG
client = yes
[postgres-serverB]
protocol = pgsql
accept = 0.0.0.0:5432 # host:port to listen to on serverA
connect = SERVER_B_POSTGRES_HOST:SERVER_B_POSTGRES_PORT
options = NO_TICKET
retry = yes