Skip to content

Instantly share code, notes, and snippets.

@sidmitra
sidmitra / benchmark_serializers.py
Created October 10, 2021 01:30
Benchmark json/pickle/orjson/msgpack/ormsgpack serialization performance.
"""
Trying to see if there's a reasonably fast/safe replacement to the default pickle serializer
used by django-redis.
See https://github.com/jazzband/django-redis#pluggable-serializer
# Adapted from https://raw.githubusercontent.com/Arvind2222/pickle-vs-json/master/pickle_vs_json.py
"""
import pickle
import json
### Keybase proof
I hereby claim:
* I am sidmitra on github.
* I am sidmitra (https://keybase.io/sidmitra) on keybase.
* I have a public key ASBJ806NJY-5Co4lI3C6EBU8L4wb7WTlTykAKw8mwAczCgo
To claim this, I am signing this object:
@sidmitra
sidmitra / alacritty.yml
Created May 26, 2017 13:18
Alacritty - Config with Dracula theme
env:
TERM: xterm-256color
dimensions:
columns: 500
lines: 100
dpi:
x: 96.0
y: 96.0
@sidmitra
sidmitra / flatten_nested_lists.py
Created December 26, 2016 21:11
Flatten arbitrary nested lists in Python
def flatten(lst):
for item in lst:
# if item is a sublist
if isinstance(item, (list,tuple)):
# flatten sublist
for j in flatten(item):
yield j
else:
yield item
@sidmitra
sidmitra / gist:34ab870459f051d37d6d
Created August 9, 2015 05:49
Webtask.io - Twitter Daily Activity Chart
module.exports =
function (context, req, res) {
var Twit = require('twit');
var ejs = require('ejs');
var T = new Twit({
consumer_key: context.data.consumer_key,
consumer_secret: context.data.consumer_secret,
access_token: context.data.access_token,
access_token_secret: context.data.access_token_secret
@sidmitra
sidmitra / gist:3082521
Created July 10, 2012 10:27 — forked from chalmerj/gist:1492154
Init Script for Graphite/Gunicorn
#! /bin/sh
### BEGIN INIT INFO
# Provides: gunicorn-graphite
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Should-Start: $nginx
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: gunicorn + nginx ubuntu init script
# Description: gunicorn + nginx ubuntu init script
@sidmitra
sidmitra / add_user_info_to_request_middleware.py
Created October 26, 2010 05:16
Middleware to add user info to the current django request
class ExceptionUserInfoMiddleware(object):
"""
Adds user details to request context on receiving an exception, so that they show up in the error emails.
Add to settings.MIDDLEWARE_CLASSES and keep it outermost(i.e. on top if possible). This allows
it to catch exceptions in other middlewares as well.
"""
def process_exception(self, request, exception):
"""