Skip to content

Instantly share code, notes, and snippets.

View avenet's full-sized avatar

Andy Venet avenet

  • Bioinnovation
  • Santiago de Chile
View GitHub Profile
@avenet
avenet / admin.py
Created January 6, 2018 13:59 — forked from hakib/admin.py
Django Admin InputFilter
# 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):
@avenet
avenet / psql-with-gzip-cheatsheet.sh
Created August 22, 2017 14:10 — forked from brock/psql-with-gzip-cheatsheet.sh
Exporting and Importing Postgres Databases using gzip
# 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
@avenet
avenet / test_attrs.py
Created February 14, 2017 20:44 — forked from buddylindsey/test_attrs.py
test_attrs
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):
import asyncio
@asyncio.coroutine
def slow_operation(n):
yield from asyncio.sleep(1)
print("Slow operation {} complete".format(n))
@asyncio.coroutine
def main():
@avenet
avenet / exception.py
Created August 27, 2015 20:17
Get exception line number
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))
@avenet
avenet / boostrap-datatables.html
Created June 2, 2015 14:26
Fancy table using jquery datatables and boostrap
<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>
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 = []
@avenet
avenet / sqlite_example.py
Created April 23, 2015 15:08
SQLite example
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):
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:]
@avenet
avenet / permutations.py
Last active March 2, 2016 15:02
Prints all of the permutations of a given string
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):