Skip to content

Instantly share code, notes, and snippets.

def modify_cache(cache, key, timeout, callback):
"""
A abstraction from the common, cache.get, if None, cache.set pattern.
Test an uncached value:
>>> cache = __mock_cache(None)
>>> modify_cache(cache, 'foo', 1000, lambda: 1)
1
>>> cache.get.assert_called_with('foo')
>>> cache.set.assert_called_with('foo', 1, 1000)
function arraySum(i) {
return i.reduce(function(sum, x) {
if(x.reduce) {
return sum + arraySum(x);
} else if (typeof x === "number") {
return sum + x;
} else {
return sum;
}
}, 0);
@ericmoritz
ericmoritz / .gitignore
Last active December 23, 2015 18:19
A simple protobuf based web service
*.pyc
*~
.env/
static/
data/
*_pb2.py
{-# LANGUAGE TemplateHaskell #-}
module MMURL (encodeURL, decodeURL, setActions, actions) where
import Text.Parsec.Prim
import Text.Parsec.Error
import Text.ParserCombinators.Parsec.Char
import Text.ParserCombinators.Parsec.Combinator
import Data.HMAC
import Data.Char (ord)
import Codec.Utils (Octet)
function maybe(x) {
return {
bind: function(f) {
if(x == null) {
return null;
} else {
return f(x);
}
},
getDefault: function(y) {
@ericmoritz
ericmoritz / .gitignore
Last active December 21, 2015 13:19
A simple Haskell program to bump a semantic version number by 1
*.hi
*.o
bin/
*~
from functools import partial
class Monad(object):
@classmethod
def liftM(cls, f):
def arrow(x):
return cls.ret(f(x))
def lifted(m):
return cls.bind(m, arrow)
*.pyc
simpleParse :: ParseState -> (a, ParseState)
simpleParse = undefined
betterParse :: ParseState -> Either String (a, ParseState)
betterParse = undefined
newtype Parse a = Parse {
runParse :: ParseState -> Either String (a, ParseState)
}
module Config (Config, config, dir, enqueue) where
import Data.Sequence (Seq, empty, (|>))
import qualified Data.Foldable as F
data Config = Config {
dir :: String
, seq :: Seq String
} deriving (Show)