Skip to content

Instantly share code, notes, and snippets.

selwin /
Created June 28, 2014 11:59
Scheduler test
from redis import Redis
from rq import Queue
def func():
queue = Queue('default', connection=Redis())
<img src="" alt="" style="width: 300px; float: left; margin-top: 10px; margin-right: 15px; margin-bottom: 10px; ">
<h3>Fahrenheit 451</h3>
<span style="color: #a5a5a5;"><em>by Ray Bradbury</em></span>
He took hold of a straight-backed chair and moved it slowly and steadily into the hall near the front door and climbed up on it and stood for a moment like a statue on a pedestal, his wife standing under him, waiting. Then he reached up and pulled back the grill of the air-conditioning system and reached far back inside to the right and moved still another sliding sheet of metal and took out a book. Without looking at it he dropped it to the floor. He put his hand back up and took out two books and moved his hand down and dropped the two books to the floor. He kept moving his hand and dropping books, small ones, fairly large ones, yellow, red, green ones. When he was done he looked down upon some twenty books lying at his wife’s feet.
selwin /
Created September 2, 2013 06:06
Find most common email domains
from collections import defaultdict
from collections import Counter
emails = User.objects.values_list('email', flat=True)
domains = defaultdict(int)
for email in emails:
domain = email.split('@')[1]
domains[domain] += 1
"token": "abc",
"user_email": "",
"store": 32,
"invoice_number": "abc123456",
"total_value": 50000,
"subtotal": 40000,
"discount": 0,
"service_charge": 5000,
"tax": 5000,
selwin / gist:5696156
Last active December 18, 2015 00:19
Stamps API example
curl -X POST -H "Content-Type: application/json" -i -d '{ "token": "830a2413ccccd3f82ec39f10f8cf5852ea518815", "user_email": "", "store": 104, "invoice_number": "2", "total_value": 50000 }'
# On Windows, double quotes need to be escaped:
curl -k -X POST -H "Content-Type: application/json" -i -d "{ \"token\": \"6ef480e7ac6d374f5e29fdd9abff8cbfbbb9a7ea\", \"user_email\": \"\", \"store\": 11, \"invoice_number\": \"invoice_2\", \"total_value\": 50000}"
curl -k -X POST -H "Content-Type: application/json" -i -d "{ \"token\": \"6ef480e7ac6d374f5e29fdd9abff8cbfbbb9a7ea\", \"user_email\": \"\", \"store\": 11, \"invoice_number\": \"invoice_3\", \"total_value\": 50000, \"items\": [{\"product_name\": \"Cappucino\", \"quantity\": 2, \"price\": 10000}, {\"product_name\": \"Iced Tea\", \"quantity\": 4, \"price\": 5000}]}"
selwin / gist:5583395
Created May 15, 2013 11:42
How to run Django's tests
./ --settings=test_sqlite get_earliest_or_latest
<img src="" alt="Autumn" style="float: left; margin-top;
6px; margin-right: 20px; margin-bottom: 10px;">
<h3>The Sky Is Everywhere</h3>
<p><span style="color: #a5a5a5;"><i>Jandy Nelson</i></span></p>
<p>She opens her case, starts putting together her instrument. "Joe studied at
a conservatory in <i>Fronce</i>. Did he tell you?" Of course she doesn't say
<i>France</i> so it rhymes with dance like a normal English-speaking human
being. I can feel Sarah bristling beside me. She has zero tolerance for
Rachel ever since she got first chair over me, but Sarah doesn‘t know what
from gevent import monkey
import gevent.pool
import os
import signal
import random
import time
import datetime
from multiprocessing import Semaphore, Array
selwin /
Created December 12, 2012 02:00
Django's management command base that logs errors
from __future__ import with_statement
import sys
import django
from import BaseCommand
from django.utils.log import getLogger
class LoggingBaseCommand(BaseCommand):
# A subclass of BaseCommand that logs errors to django.commands