Skip to content

Instantly share code, notes, and snippets.

View thomasyip's full-sized avatar

Thomas Y thomasyip

View GitHub Profile
@thomasyip
thomasyip / jQuery Plugin Factory
Last active December 21, 2015 15:28
Skeleton of jQuery plugin
;(function($, undefined) {
var PLUGIN_NAME = 'plugin';
var DEFAULT_OPTIONS = {
optionA: true,
optionB: false,
'callbackC': function() {
}
};
function plugin(options) {
@thomasyip
thomasyip / middleware.py
Last active March 17, 2017 11:42
Accept Tastypie API Key authentication for regular django app.
class TastypieApiKeyUserMiddleware(object):
"""
Middleware for per-request authentication with tastypie
"""
# Name of request header to grab username from. This will be the key as
# used in the request.META dictionary, i.e. the normalization of headers to
# all uppercase and the addition of "HTTP_" prefix apply.
header = 'HTTP_AUTHORIZATION'
method = 'apikey'
apikey_auth = ApiKeyAuthentication()
@thomasyip
thomasyip / gist:5eec33abfb4fa4b588f6
Created December 1, 2014 02:57
Python Utilities -- Save a few line of typing
## Print stack trace
def exception_printer(sender, **kwargs):
import sys, traceback
print >> sys.stderr, ''.join(traceback.format_exception(*sys.exc_info()))
raise
## Set breakpoint
import pdb
pdb.set_trace()
@thomasyip
thomasyip / settings.py
Last active August 29, 2015 14:14
django-pipeline configuration (a SASS / Compass folder per app)
STATICFILES_STORAGE = 'pipeline.storage.PipelineStorage'
PIPELINE_COMPILERS = (
'pipeline_compass.compass.CompassCompiler',
)
PIPELINE_CSS = dict(zip(PROJECT_APPS, [{
'source_filenames': (
(app + '/sass/*.scss'),
),
@thomasyip
thomasyip / Gruntfile.js
Last active August 29, 2015 14:14
Grunt Multi Task: configmerge
module.exports = function(grunt) {
grunt.initConfig({
compass: {
// see configmerge.compass
},
watch: {
// see configmerge.watch
}
configmerge: {
compass: {
@thomasyip
thomasyip / gen.sh
Created July 4, 2015 22:52
Generate self-signed alternate dns (wildcard) ssl certificate with a single script
#!/bin/bash
# file: gen.sh
# usage: ./gen.sh [name]
ROOT=rootCA
NAME=${1:-device}
EXTS=( key cnf csr crt )
ROOT_NAME=rootCA
ROOT_EXTS=( key pem )
@thomasyip
thomasyip / pictiles
Created February 25, 2017 05:46
A simple html to combine a number of photos into one
<html>
<head>
<style>
* {
margin: 0;
padding: 0;
}
.row span {
display: inline-block;
position: relative;