This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Ordered set implementation. | |
http://code.activestate.com/recipes/576694/ | |
""" | |
import collections | |
__all__ = ('OrderedSet', ) | |
class OrderedSet(collections.MutableSet): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
""" | |
import threading | |
__all__ = ('SafeDict', ) | |
class SafeDict: | |
"""A threadsafe dict-like object. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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'], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Just some functions to help out with byteArrays. | |
Authors and Inspiration: github.com/adoc and Various Others. | |
*/ | |
// Converts an integer to bytes. | |
var intToBytes = function(n) { | |
var result = ''; | |
while (n) { |