Skip to content

Instantly share code, notes, and snippets.

View josiahcarlson's full-sized avatar

Josiah Carlson josiahcarlson

View GitHub Profile
josiahcarlson /
Created October 3, 2023 03:22
Find all 1-bit differences among provided integers.
Written September / October 2023 by Josiah Carlson -
Released into the public domain. Please include this authorship note / reference
to this GIST if you use / derive this software. Thank you.
Been thinking about this algorithm for about 17 years, haven't seen it around.
I might not know the proper literature search to find relevant references, or if
this was already done.
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 1 column, instead of 4. in line 1.
$ time docker-compose run redis-server numactl -N 1 -l /usr/src/redis/src/redis-benchmark --crc 512000000 --csv --combine
josiahcarlson /
Last active August 8, 2019 04:47
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(
josiahcarlson / reply_to_blog.txt
Created February 19, 2016 04:29
Reply to a comment
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 February 14, 2016 07:37
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.
$ 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
-- 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 November 19, 2014 22:31
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 April 17, 2022 09:22
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 October 12, 2014 21:20
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 February 25, 2022 14:33
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