Skip to content

Instantly share code, notes, and snippets.

@adoc
adoc / auth_client.js
Last active January 4, 2016 11:09
auth_client.js: REST API Authentication Client using HMAC.
/*
auth_client.js
REST API Authentication using HMAC.
Author: github.com/adoc
Location: https://gist.github.com/adoc/8613025
Python server counterpart:
[py-rest-auth](https://github.com/adoc/py-rest-auth)
@adoc
adoc / gist:8613254
Created January 25, 2014 08:00
temp: api call outside of backbone
// api calls outside of backbone.
var apiCall = function(uri, data, success, method) {
data = data || {};
method = method || 'GET';
$.ajax({
method: method,
url: opts.apiRoot + uri,
data: method == 'POST' ? JSON.stringify(data) : data,
dataType: 'json',
@adoc
adoc / gist:8613268
Created January 25, 2014 08:01
temp: tightenauth
// Update the time provider and ip address.
// Called on every page, cause.
var tightenAuth22 = function() {
apiCall('/ping', {}, function(data) {
authApi.timeProvider.reset(data._time);
authApi.clientIp = data._addr;
authApi.tight = true;
if (opts.success) {
opts.success();
@adoc
adoc / backbone_auth.js
Last active January 4, 2016 11:09
backbone_auth.js: Provides bi-directional HMAC hooked in to Model and Collection.
/*
backbone_auth.js
Provides bi-directional HMAC hooked in to Model and Collection.
Author: github.com/adoc
Location: https://gist.github.com/adoc/8613376
*/
define(['underscore', 'backbone', 'config', 'events', 'auth_client', 'persist'],
@adoc
adoc / thredis.py
Last active August 29, 2015 13:57
"""Just some simple threaded redis pool classes. Also some useful
primitive data models.
"""
# Date: 2014/03/19
# Author: https://github.com/adoc/
# © 2014 Nicholas Long. All Rights Reserved.
import logging
log = logging.getLogger(__name__)
@adoc
adoc / __init__.py
Last active August 29, 2015 13:57
safedict: A threadsafe dict-like object.
"""
"""
import threading
__all__ = ('SafeDict', )
class SafeDict:
"""A threadsafe dict-like object.
@adoc
adoc / __init__.py
Last active August 29, 2015 13:57
orderedset: Ordered set implementation. (src: http://code.activestate.com/recipes/576694/)
"""Ordered set implementation.
http://code.activestate.com/recipes/576694/
"""
import collections
__all__ = ('OrderedSet', )
class OrderedSet(collections.MutableSet):
@adoc
adoc / qbytes.py
Last active August 29, 2015 13:59
def qbytes(*args):
"""Accepts argument list of variables that might be bytes and
decodes, otherwise passing the value through."""
# This is a bit hackish and the static-typers are throwing their
# hands up. :P
return tuple([arg.decode()
if isinstance(arg, bytes)
else arg
for arg in args])
@adoc
adoc / ex_unique.py
Created April 25, 2014 00:06
Unique constraint
"""
Python Pseudocode implementation of a unique constraint.
uniques - Set of unique KEYS. Ex: {'username'}
obj - Dict object being persisted. Ex: {'id': 12345,
'username'}
obj_set - Set of `obj` key/val pairs.
all_ - Set of ID of every record.
id_ - ID of object we are checking
@adoc
adoc / __init__.py
Created April 27, 2014 16:20
threadutils: Threading utility functions.
import time
import threading
THROTTLE = 0.01
class KillableThread(threading.Thread):
"""Subclass of threading.Thread with kill signal functionality.
"""