This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
one_bit_difference.py | |
Written September / October 2023 by Josiah Carlson - [email protected] | |
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ time docker-compose run redis-server numactl -N 1 -l /usr/src/redis/src/redis-benchmark --crc 512000000 --csv --combine | |
algorithm,buffer,performance,crc64_matches | |
crc_1byte,512000000,400,1 | |
crcspeed,512000000,1354,1 | |
crcdual,512000000,2129,1 | |
crctri,512000000,2243,1 | |
crc_1byte,312000000,401,1 | |
crcspeed,312000000,1352,1 | |
crcdual,312000000,2090,1 | |
crctri,312000000,2213,1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
This this was retyped from https://www.twitch.tv/videos/459202303 for notes and | |
then updated by the author of rom, me, Josiah Carlson | |
Notes: | |
* 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(default=datetime.datetime.now()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is my reply to Alex Mills: http://www.binpress.com/tutorial/introduction-to-rate-limiting-with-redis/155 | |
Yes, with threads, processes, or an async reactor. That said... | |
$ redis-benchmark -n 2000000 -c 20 -q | |
[snip] | |
SET: 115141.05 requests per second | |
GET: 134048.27 requests per second | |
INCR: 180505.41 requests per second | |
LPUSH: 176056.33 requests per second |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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(redis.call('get', dest)) or 0 | |
for i=1, #ARGV, 2 do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
rate_limit2.py | |
Copyright 2014, Josiah Carlson - [email protected] | |
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
result_multiplex.py | |
Copyright 2014 Josiah Carlson | |
Released as LGPL 2 or 3, your choice. | |
Problem: | |
You have a task processor that writes the results of tasks to a specified key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
rate_limit.py | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
follow_file.py | |
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. |
NewerOlder