This file contains hidden or 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
# common/admin.py | |
class InputFilter(admin.SimpleListFilter): | |
template = 'admin/input_filter.html' | |
def lookups(self, request, model_admin): | |
# Dummy, required to show the filter. | |
return ((),) | |
def choices(self, changelist): |
This file contains hidden or 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
# This is just a cheat sheet: | |
# On production | |
sudo -u postgres pg_dump database | gzip -9 > database.sql.gz | |
# On local | |
scp -C production:~/database.sql.gz | |
dropdb database && createdb database | |
gunzip < database.sql.gz | psql database |
This file contains hidden or 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
class CompanyViewSet(ListModelMixin, GenericViewSet): | |
authentication_classes = (TokenAuthentication,) | |
serializer_class = CompanySerializer | |
filter_backends = (filters.DjangoFilterBackend, filters.OrderingFilter) | |
ordering_fields = ('name',) | |
filter_class = CompanyFilterSet | |
class CompanyViewSetTests(TestCase): | |
def test_attrs(self): |
This file contains hidden or 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 asyncio | |
@asyncio.coroutine | |
def slow_operation(n): | |
yield from asyncio.sleep(1) | |
print("Slow operation {} complete".format(n)) | |
@asyncio.coroutine | |
def main(): |
This file contains hidden or 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 | |
import traceback | |
try: | |
exec(open('error.py').read()) | |
except Exception as e: | |
exc_type, ex, tb = sys.exc_info() | |
imported_tb_info = traceback.extract_tb(tb)[-1] | |
line_number = imported_tb_info[1] | |
print('{}: Exception in line: {}, message: {}'.format(exc_type.__name__, line_number, ex)) |
This file contains hidden or 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
<html> | |
<head> | |
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"> | |
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/plug-ins/1.10.7/integration/bootstrap/3/dataTables.bootstrap.css"> | |
<style type="text/css" class="init"> | |
body { font-size: 140%; } | |
</style> | |
<script language="javascript" src="https://code.jquery.com/jquery-1.11.1.min.js"></script> | |
<script language="javascript" src="https://cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js"></script> |
This file contains hidden or 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
require "pg" | |
require "redis" | |
words = File.read("/usr/share/dict/words").split "\n" | |
pgconn = PGconn.open :dbname => "test_hstore", :port => 5433, :user => "test_user", :password => "changeme" | |
redis = Redis.new | |
reps = [1,10,100,1000,10000] | |
pg_inserts = [] | |
pg_selects = [] | |
redis_sets = [] |
This file contains hidden or 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 sqlite3 | |
created_db = sqlite3.connect('test.db') | |
cursor = created_db.cursor() | |
def create_table(): | |
cursor.execute("""CREATE TABLE IF NOT EXISTS Scores | |
(id INTEGER PRIMARY KEY, Name TEXT, Class TEXT, Score INTERGER)""") | |
def add_pupil(name, klass, score): |
This file contains hidden or 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 httplib | |
import urlparse | |
from django.http import HttpResponse | |
from django.views.decorators.csrf import csrf_exempt | |
def format_header(header_name): | |
if header_name.startswith("HTTP_"): | |
header_name = header_name[5:] |
This file contains hidden or 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 permutations(str_value): | |
chars = list(str_value) | |
used_chars = [False] * len(str_value) | |
return _permute(chars, used_chars, "") | |
def _permute(chars, used_chars, current): | |
if len(current) == len(used_chars): | |
yield current | |
else: | |
for i, used_char in enumerate(used_chars): |
NewerOlder