Skip to content

Instantly share code, notes, and snippets.

@docapotamus
docapotamus / gist:da0e6ac4ca9c1bf7941e
Created December 8, 2015 09:04
Clear Python cache data
# Remove < 3.2 cache
find . -type f -name \*.pyc -delete
# Remove > 3.2 cache
find . -type d -name "__pycache__" -delete
@docapotamus
docapotamus / redis-bench.md
Last active January 6, 2016 11:00
Redis speed comparison Digitalocean (Debian 8.2 vs. FreeBSD 10.2)

Redis Benchmark

Digitalocean $5

Debian 8.2 (Redis 3.0.5 Jessie-Backports)

PING_INLINE: 68259.38 requests per second
PING_BULK: 80840.74 requests per second
SET: 61236.99 requests per second
GET: 81766.15 requests per second
@docapotamus
docapotamus / suggestions.py
Last active November 25, 2015 13:04
Finding suggestions example
import random
from collections import Counter
def get_follow_suggestions(user_id, count=5):
# Get all users a user is following
following = r.zrange(k.USER_FOLLOWING.format(user_id), 0, -1)
# Ensure the user is getting suggestions based on at least 5 people
#
@docapotamus
docapotamus / gist:0f7893ab7bece2860353
Created July 20, 2015 18:39
Remove expired alerts
from redis import StrictRedis
hostname = ''
r = StrictRedis(hostname)
for key in r.keys('{alerts:*}'):
ttl = r.ttl(key)
if ttl == -1:
r.delete(key)
if not app.debug: # pragma: no cover
import logging
from logging.handlers import SMTPHandler
mail_handler = SMTPHandler(
('smtp.mailgun.org', 25),
'[email protected]',
['[email protected]'],
'Application Error',
(USERNAME, PASSWORD)
)
@docapotamus
docapotamus / gist:ec5bf4806456712d56c6
Created December 23, 2014 16:25
Redis benchmark UKFast Open Stack m1.small
debian@control:~$ redis-benchmark -q
PING_INLINE: 126582.27 requests per second
PING_BULK: 125000.00 requests per second
SET: 128205.12 requests per second
GET: 126582.27 requests per second
INCR: 116279.06 requests per second
LPUSH: 99009.90 requests per second
LPOP: 97087.38 requests per second
SADD: 99009.90 requests per second
SPOP: 97087.38 requests per second
AUTH
----
TODO
USERS
-----
Note: /user and /users are defined seperatley.
'user' refers to yourself, the authenticated user