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
''' | |
Written October 26, 2012 by Josiah Carlson | |
Released into the public domain. | |
I'm sure this has been done before, but I've not seen any code for it. | |
This code will take an integer with absolute value of up to 2**63-2**53 | |
and pack it losslessly into an IEEE 753 FP double, preserving sort order | |
by reusing the exponent field for high order bits. | |
Note that if you keep your values under 2**62, we only use standard fp |
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
$ 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 | |
3.932018 |
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
# Josiah Carlson - Programming Challange from Erann Gat: | |
# http://www.flownet.com/ron/papers/lisp-java/ | |
# Given a list of words and a list of phone numbers, find all the ways that | |
# each phone number can be expressed as a list of words. | |
from collections import defaultdict | |
import sys | |
MAPPING = {'e':0, 'j':1, 'n':1, 'q':1, 'r':2, 'w':2, 'x':2, 'd':3, 's':3, | |
'y':3, 'f':4, 't':4, 'a':5, 'm':5, 'c':6, 'i':6, 'v':6, 'b':7, 'k':7, |
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
''' | |
Implementation of Poly1305-AES as described by Daniel J. Bernstein in | |
documents linked from: http://cr.yp.to/mac.html | |
Implemented by Josiah Carlson <josiah.carlson@gmail.com> on 2011-01-23, | |
released into the public domain. | |
Note: this implementation of Poly1305-AES uses Python's built-in long integer | |
implementation, so is not terribly performant, and likely suffers from a | |
side-channel attack related to the timing of bigint modulo. It also uses |
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
''' | |
redis_simple_chat.py | |
Written June 24, 2011 by Josiah Carlson | |
Released under the GNU GPL v2 | |
available: http://www.gnu.org/licenses/gpl-2.0.html | |
Other licenses may be available upon request. |
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
''' | |
Copyright 2010 Josiah Carlson | |
Released into the public domain | |
copy_redis.py | |
A convenient utility function for copying data from one redis server to | |
another. | |
Requires http://github.com/andymccurdy/redis-py . |
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
'''async_http_client.py | |
Originally written December 25, 2011 by Josiah Carlson | |
Released into the public domain. | |
This simple asynchat.async_chat subclass offers the ability to connect to http | |
servers to download files. The example download_file() function shows how to | |
use the class to download files from a remote webserver, automatically | |
handling redirects and errors. |
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. |