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
@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 |
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
# 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
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 |
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 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] |
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 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: |
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 memoize(f): | |
cache = {} | |
def decorated(n): | |
if n in cache: | |
return cache[n] | |
else: | |
cache[n] = f(n) | |
return cache[n] | |
return decorated |
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 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): |
NewerOlder