Skip to content

Instantly share code, notes, and snippets.

@six8
six8 / test.py
Last active April 29, 2019 15:45
Python chunked base64 encoding
import base64
import os
from binascii import b2a_base64
from math import ceil
from tempfile import TemporaryFile, NamedTemporaryFile
from timeit import timeit
def original_chunked_encode(input, input_size, output, read_size=1024):
"""
"""
Split a logfile by days
"""
import sys, os, re
filename = sys.argv[1]
out_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logs')
"""
Hawk (https://github.com/hueniverse/hawk) Python example
The client attempts to access a protected resource without authentication,
sending the following HTTP request to the resource server:
GET /resource/1?b=1&a=2 HTTP/1.1
Host: api.example.com:443
The resource server returns an authentication challenge.
from pingspot.dal.users import UserService
import uuid
def test_foursquare_auth_token(dal, uniqueuser):
user = uniqueuser()
auth_token = str(uuid.uuid4())
# No need to return anything, an error will be raised if something went wrong
dal.users.set_foursquare_auth_token(user, auth_token)
@six8
six8 / debounce.coffee
Created November 27, 2013 19:21
A debounce that you can cancel
###
Creates a function that will delay the execution of `func` until after
`wait` milliseconds have elapsed since the last time it was invoked. Pass
`true` for `start` to cause debounce to invoke `func` on the leading edge
of the `wait` timeout. Subsequent calls to the debounced function will
return the result of the last `func` call.
###
debounce = (opt, func) ->
if typeof opt is 'number'
opt = {wait: opt}
@six8
six8 / version_compare.js
Created September 28, 2012 20:10
Javascript to compare different software version strings (ex: 1.0.4 vs 1.1.4). Can handle pre, beta, etc prefixes/suffixes.
// Some versions to test [v1, v2, expected result]
var versions = [
['1.2.0', '1.2', 0],
['1.4', '1.7.2', 1],
['1.2pre', '1.2', 1],
['1.7', '1.1.1', -1],
['1.7.9RC1', '1.7.9RC2', 1],
['1.7.9RC1', '1.7.9RC', -1],
['1.7.9RC1', '1.7.9', 1],
['0.4beta', '0.4', 1],
@six8
six8 / gist:1751024
Created February 6, 2012 09:20
git flow finish current branch
[alias]
# Start a feature branch (git start myfeature)
start = !"git flow feature start $1"
# Finish current git flow branch (git finish)
finish = !"git flow $(BRANCH=$(git for-each-ref --format='%(refname:short)' `git symbolic-ref HEAD`); echo ${BRANCH%/*} finish ${BRANCH##*/})"
@six8
six8 / gist:1732686
Created February 3, 2012 21:20
Javascript dependency graph resolution
// Dependency resolution, adapted from https://gist.github.com/1232505/f16308bc14966c8d003c2686b1c258ec41303c1f
function resolve(graph) {
var sorted = [], // sorted list of IDs ( returned value )
visited = {}; // hash: id of already visited node => true
// 2. topological sort
Object.keys(graph).forEach(function visit(name, ancestors) {
if (!Array.isArray(ancestors)) ancestors = [];
ancestors.push(name);
visited[name] = true;
@six8
six8 / margin-zero.html
Created September 22, 2011 03:46
HTML for iOS UIWebView that will show unwanted overlay when touching screen edge
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
<style>
body {
margin: 0;
@six8
six8 / pil-install.md
Created September 20, 2011 05:53
Install PIL in a virtualenv on Mac OSX Lion with minimal dependencies

Perquisites:

brew install jpeg
pip install --upgrade --no-install PIL

Edit setup.py:

vi $VIRTUAL_ENV/build/PIL/setup.py

Change: