This file contains hidden or 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 on March 28, 2014 by Josiah Carlson | |
Released into the public domain | |
ZUNIONRANGESCORE: | |
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. |
This file contains hidden or 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 hidden or 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
''' | |
The Josiah Carlson recommended way of replacing the session object. This code | |
should be run prior to any subsequent imports/uses of the session object. | |
Released into the public domain. | |
''' | |
from rom import util |
This file contains hidden or 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
import time | |
import redis | |
def _script_load(script): | |
''' | |
Borrowed from my book, Redis in Action: | |
https://github.com/josiahcarlson/redis-in-action/blob/master/python/ch11_listing_source.py | |
''' |
This file contains hidden or 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
''' | |
sort_zset_cols.py | |
Copyright 2013 Josiah Carlson | |
Released into the public domain. | |
''' | |
''' | |
Let's imagine that there are 3 restaurants with price, score, distance info | |
being: |
This file contains hidden or 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
import rom | |
class ModelA(rom.Model): | |
m2m_test = rom.OneToMany('HiddenModel') | |
@property | |
def b_models(self): | |
return [x.model_b for x in self.m2m_test] |
This file contains hidden or 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 a module that defines some helper classes and functions for | |
expiring groups of related keys at the same time. | |
Written July 1-2, 2013 by Josiah Carlson | |
Released into the public domain | |
''' | |
import time |
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
''' | |
Steganogrphy in Python | |
Copyright 2013 Josiah Carlson | |
Released under the GNU LGPL v2.1 license | |
What, how, why, etc, are discussed: | |
http://www.dr-josiah.com/2013/05/steganography-in-python.html |
This file contains hidden or 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
''' | |
prefix_code.py | |
Copyright 2012-2013 Josiah Carlson | |
Released under the GNU LGPL v 2.1 license | |
This module offers the ability to encode/decode a sequence of integers into | |
strings that can then be used to compare sequences of integers (or paths on | |
trees) quickly. This module was originally intended to be used in a case- | |
preserving index in a relational database (where 'Z' comes before 'a', as is |
This file contains hidden or 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
''' | |
Answer to this thread: | |
http://www.manning-sandbox.com/thread.jspa?messageID=140363 | |
''' | |
def refresh_lock(conn, lockname, identifier, timeout=10): | |
pipe = conn.pipeline(True) | |
lockname = 'lock:' + lockname |