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
#!/bin/sh | |
# | |
# Usage: ./redis-movekeys.sh [-h host] [-p port] [-n src] [-m dest] pattern | |
# | |
# Move keys matching pattern from the src Redis database to the | |
# dest Redis database. | |
set -e | |
HOST="localhost" |
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
#!/bin/sh | |
# | |
# Usage: ./redis-delkeys.sh [-h host] [-p port] [-n db] pattern | |
# | |
# Matches keys with the KEYS command matching pattern | |
# and deletes them from the specified Redis DB. | |
set -e | |
HOST="localhost" |
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
package main | |
import ( | |
// "encoding/binary" | |
"crypto/rand" | |
"fmt" | |
"hash" | |
"hash/fnv" | |
"io" | |
"io/ioutil" |
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
import re | |
from werkzeug.exceptions import NotFound, MethodNotAllowed | |
from werkzeug.wrappers import Request, Response | |
class RouteNode(object): | |
@property | |
def converter(self): | |
return None |
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
import random | |
class CountMinSketch(object): | |
def __init__(self, w, d, p): | |
self.w = w | |
self.d = d | |
self.p = p | |
self.C = [[0] * self.w for _ in range(self.d)] | |
self.a = [random.randint(1, self.p) for _ in range(self.d)] |
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
import math | |
import struct | |
def rank(num): | |
if num == 0: | |
return 32 | |
p = 0 | |
while (num >> p) & 1 == 0: | |
p += 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
import sys | |
from calendar import timegm | |
from collections import Counter, defaultdict | |
from datetime import datetime, timedelta | |
import redis | |
class DictBackend(object): | |
def __init__(self, maximum=None): |
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
""" | |
SimpleDB Query DSL | |
>>> stmt = select(Star(), 'mydomain') | |
>>> stmt.where(Field('city') == 'Seattle').to_sql() | |
'select * from mydomain where city = "Seattle"' | |
>>> city = Field('city') | |
>>> stmt.where((city == 'Seattle') | (city == 'Portland')).to_sql() | |
'select * from mydomain where (city = "Seattle") or (city = "Portland")' |
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
def floor(size=10): | |
"""Return a list of rooms represented by dictionaries. | |
The list is procedurally generated. Each room is represented by a ``dict`` | |
with ``'x'``, ``'y'``, and ``'exits'`` keys. | |
>>> floor(5)[0] | |
{'x': 0, 'y': 0, 'exits': {'up': {...}, 'right': {...}}} | |
""" |
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
from functools import partial | |
from itertools import imap, izip, product | |
from redis import Redis | |
class SearchIndex(object): | |
"""Autocomplete search index. | |
>>> index = SearchIndex(Redis()) |