Skip to content

Instantly share code, notes, and snippets.

View maxcountryman's full-sized avatar
🦀

Max Countryman maxcountryman

🦀
View GitHub Profile
(defmacro loop-vars
"Like loop, but will automatically populate recur points where the special
var recur-> is found.
Mostly useful in mutable contexts, where some external factor causes the
recur bindings to change.
"
[bindings & body]
{:pre [(and (vector? bindings)
(even? (count bindings)))]}
(defn half
[s]
(bit-shift-right (count s) 1)) ;; faster division by 2
(defn left-right
[v]
(let [v (if-not (vector? v) (vec v) v)
h (half v)]
[(subvec v 0 h) (subvec v h)]))
(def ^{:const true :private true}
base-62-alphabet
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
(defn encode
"Encodes v in a new base of ks."
[ks v]
(let [base (count ks)]
(apply str
(reduce

Flask-Login Demo

Setup

$ pip install flask
$ pip install flask-login

Run

backend primary {
.host = "127.0.0.1";
.port = "8080";
}
acl purge {
"127.0.0.1";
}
sub vcl_recv {
@maxcountryman
maxcountryman / queue.py
Created November 20, 2010 22:57
Custom Queue, all credit goes to Pedro! (just posting here for archiving purposes, this is *not* my script)
#!/usr/bin/env python2
import sys
import pickle
class QueueError(Exception):
pass
class Queue:
def __init__(self, *args):
⨀_⨀
⨂_⨂
(/◔ ◡ ◔)/
°ﺑ°
(¬_¬)
(´・ω・`)
(ʘ_ʘ)
(ʘ‿ʘ)
(๏̯͡๏ )
(◕_◕)
@maxcountryman
maxcountryman / brainfuck_converter.py
Created December 16, 2010 00:32
Converts a string to Brainfuck
def string_process(s):
cs = map(ord, '{0}'.format(s))
clist = ''.join(['>' + c for c in
['+' * n for n in
[(i-i%10)/10 for i in cs]]])
cell_zero = ''.join(['<' * n for n in [len(cs)]]) + '-'
@maxcountryman
maxcountryman / tabula.py
Created December 17, 2010 21:22
Simple tabula recta generator, using Python's random module.
import string, random
print ' '+' '.join(string.ascii_uppercase) + '\n'+' +'+''.join(['-' for x in range(52)])+'\n'+''.join([chr(x)+' | '+' '.join([chr(random.randrange(33,127)) for x in range(26)])+'\n' for x in xrange(65,91)])
@maxcountryman
maxcountryman / weasel.py
Created January 5, 2011 22:01
A weasel program
import random, string, time
TEST = False
def timeit(func, *args):
'''Simple timeit wrapper for functions.'''
start = time.time()
func(*args)
elapsed = time.time() - start