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 / choco.bat
Created October 25, 2014 15:09
Installs Chocolatey and my preferred Windows programs
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
choco install Atom
choco install notepadplusplus.install
choco install 7zip
choco install flashplayerplugin
choco install vlc
choco install nodejs
choco install vcredist2010
choco install PowerShell
@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):
@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):
@avenet
avenet / trie.py
Created December 15, 2014 22:56
Python Trie implementation
class TrieNode(object):
def __init__(self, character, is_word=False, tag=None, children=None):
children = children or []
self.value = character
self.is_word = is_word
self.children = children
self.tag = tag
def __str__(self):
return self.value
@avenet
avenet / lcs.py
Created December 17, 2014 12:06
Longest common subsequence
def lcs(str1, str2):
return _lcs(str1, str2, 0, 0, "")
def _lcs(str1, str2, i, j, result):
if i==len(str1) or j==len(str2):
return result
str1_char = str1[i]
str2_char = str2[j]
@avenet
avenet / binary_search.py
Created December 17, 2014 15:56
Binary search implementation
def binary_search(array, value):
return _binary_search(array, value, 0, len(array)-1)
def _binary_search(array, value, i, j):
if i > j:
return -1
middle = (i+j)/2
if array[middle] == value:
@avenet
avenet / memoize.py
Created December 17, 2014 16:02
Memoize pattern implementation
def memoize(f):
cache = {}
def decorated(n):
if n in cache:
return cache[n]
else:
cache[n] = f(n)
return cache[n]
return decorated
@avenet
avenet / quicksort_in_place.py
Last active March 2, 2016 15:02
Implementing quicksort in place
def swap(array, i, j):
temp = array[i]
array[i] = array[j]
array[j] = temp
def partition(array, i, j):
pos = i
pivot = array[j]
for k in xrange(i, j):