Skip to content

Instantly share code, notes, and snippets.

AUTH
----
TODO
USERS
-----
Note: /user and /users are defined seperatley.
'user' refers to yourself, the authenticated user
@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
if not app.debug: # pragma: no cover
import logging
from logging.handlers import SMTPHandler
mail_handler = SMTPHandler(
('smtp.mailgun.org', 25),
'noreply@example.com',
['joe@example.com'],
'Application Error',
(USERNAME, PASSWORD)
)
@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)
@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 / 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 / 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 / pjuu.service
Last active December 15, 2015 08:59
Pjuu systemd script
[Unit]
Description=Pjuu
After=network.target
[Service]
PIDFile=/run/pjuu/pid
User=pjuu
Group=pjuu
WorkingDirectory=/pjuu/app
ExecStart=/pjuu/venv/bin/gunicorn --pid /run/pjuu/pid wsgi:application
@docapotamus
docapotamus / swappiness.md
Last active March 6, 2024 08:58
Setting swappiness on Debian

Swappiness controls the tendancy the kernel wishes to swap.

Even with free memory the kernel may swap.

100 means aggressively swap 0 means wait until the last minute to swap

To check current swappiness cat /proc/sys/vm/swappiness

PJUU_SETTINGS=/pjuu/conf/settings.py WEB_CONCURRENCY=`nproc` gunicorn -b 127.0.0.1:8000 -D -k gevent pjuu.wsgi