Skip to content

Instantly share code, notes, and snippets.


Josiah Carlson josiahcarlson

View GitHub Profile
josiahcarlson /
Last active Aug 8, 2019
Example from a livecoding stream, updated with fixes
This this was retyped from for notes and
then updated by the author of rom, me, Josiah Carlson
* For created_at, or any default, if it is "callable", it will be called at
entity creation/instantiation. In the demo in the video, we see:
created_at = rom.DateTime(
View reply_to_blog.txt
This is my reply to Alex Mills:
Yes, with threads, processes, or an async reactor. That said...
$ redis-benchmark -n 2000000 -c 20 -q
SET: 115141.05 requests per second
GET: 134048.27 requests per second
INCR: 180505.41 requests per second
LPUSH: 176056.33 requests per second
josiahcarlson / search_output.txt
Last active Feb 14, 2016
A new ordering on an array that offers faster searching than binary search, yet is just as simple. Allows for O(log(n)) modifications and searches. Paper and details forthcoming.
View search_output.txt
$ gcc -O4 -o shuffle_search.out shuffle_search.c
$ ./shuffle_search.out
Generate 10000000 random input values...
Select 1000000 random items from the input and duplicating 10x times...
Random reorder selected items
Sorting input... qsort O(nlogn)
Shuffle transforming input... O(n)
Binary searching
View redis-zadd-sum.lua
-- keys: key dest
-- argv: score member [score member ...]
-- e.g. keys: "data:test:1:2" "data-sum:test:1:2"
-- argv: 10 a 15 b
local key = KEYS[1]
local dest = KEYS[2]
local sum = tonumber('get', dest)) or 0
for i=1, #ARGV, 2 do
josiahcarlson /
Created Nov 19, 2014
Some useful crc utility functions for Redis cluster
Released into the public domain.
This code will append 2 bytes to the end of a key to force the key to a specific Redis slot.
from collections import defaultdict
from itertools import imap
import struct
josiahcarlson /
Last active Apr 17, 2022
Regular and sliding window rate limiting to accompany two blog posts.
Copyright 2014, Josiah Carlson -
Released under the MIT license
This module intends to show how to perform standard and sliding-window rate
limits as a companion to the two articles posted on Binpress entitled
"Introduction to rate limiting with Redis", parts 1 and 2:
josiahcarlson /
Created Oct 12, 2014
Reliably multiplex receiving results via Redis lists
Copyright 2014 Josiah Carlson
Released as LGPL 2 or 3, your choice.
You have a task processor that writes the results of tasks to a specified key
josiahcarlson /
Last active Feb 25, 2022
Rate limiting with Redis primarily using Lua scripting
Written May 7-8, 2014 by Josiah Carlson
Released under the MIT license.
Offers a simple interface for offering rate limiting on a per second, minute,
hour, and day basis. Useful for offering varying rate limits depending on user
behavior. Sliding window based limits offer per minute, hour, and day limits
josiahcarlson /
Created Apr 13, 2014
Python function to offer "tail -F"-like functionality in Python
Written April 13, 2014 by Josiah Carlson
Released under the MIT license.
This could likely be made more efficient with the use of the pyinotify library,
and some of the module-level constants could be tuned for better performance,
depending on your platform.
josiahcarlson /
Last active Aug 29, 2015
Zunion Range Score, an interesting scripting solution.
Written on March 28, 2014 by Josiah Carlson
Released into the public domain
Zunion Range Score performs a Redis ZUNIONSTORE operation, selecting *only
those items in the provided ranges. The scores are added. Proof of concept.
Warning: untested, use at your own risk.