Skip to content

Instantly share code, notes, and snippets.

View johndgiese's full-sized avatar

David Giese johndgiese

View GitHub Profile
@johndgiese
johndgiese / transaction.js
Last active August 29, 2015 14:04
Group-level transactional support in javascript using promises.
Q = require('Q');
/**
* Store a promise for each `group` of function calls; the existence of a
* promise for a given key indicates a lock on that group, and subsequent
* calls in that group are delayed until that promise is resolved. After the
* last call is complete, the lock (i.e. key) is cleared.
*/
var groupQueues = exports._groupQueus = {};
@johndgiese
johndgiese / cards.py
Created March 31, 2015 16:21
Analysis of Card Game My Younger Brother Plays
"""
The card game we are analyzing plays as follows:
1. Shuffle a deck of 52 playing cards
2. Player is dealt N cards into the "face down pile"
3. Turn over a card and place it in the "face up pile":
- if it is an ace, deal 4 cards from the deck to the "face down pile"
- if it is a king deal 3
- if it is a queen deal 2
- if it is a jack deal 1
@johndgiese
johndgiese / weird.py
Created April 4, 2015 18:05
Weird stuff about python
a = 10
b = 10
print(a is b)
a = 10000000
b = 10000000
print(a is b)
def func(a):
@johndgiese
johndgiese / apploi-test-script.js
Last active December 14, 2015 18:56
A silly test script for testing Apploi's angular script loader.
angular.test = 4;
@johndgiese
johndgiese / winstonConfig.js
Last active May 6, 2019 09:09
Make node's winston logger print stack traces
// Extend a winston by making it expand errors when passed in as the
// second argument (the first argument is the log level).
function expandErrors(logger) {
var oldLogFunc = logger.log;
logger.log = function() {
var args = Array.prototype.slice.call(arguments, 0);
if (args.length >= 2 && args[1] instanceof Error) {
args[1] = args[1].stack;
}
return oldLogFunc.apply(this, args);
@johndgiese
johndgiese / circular_buffer.lua
Last active May 4, 2021 05:48
Circular Buffer in Lua
-- circular buffer factory for lua
local function rotate_indice(i, n)
return ((i - 1) % n) + 1
end
local circular_buffer = {}
local function circular_buffer:filled()