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): |
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 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 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
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
class LoggingMixin(object): | |
def dispatch(self, request_type, request, **kwargs): | |
logger.debug( | |
'%s %s %s' % | |
(request.method, request.get_full_path(), request.raw_post_data)) | |
try: | |
response = super(LoggingMixin, self).dispatch( | |
request_type, request, **kwargs) | |
except (BadRequest, fields.ApiFieldError), e: |
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
# -*- coding: utf-8 -*- | |
from django import forms | |
from crispy_forms.helper import FormHelper | |
from crispy_forms.layout import Layout, Div, Submit, HTML, Button, Row, Field | |
from crispy_forms.bootstrap import AppendedText, PrependedText, FormActions | |
class MessageForm(forms.Form): | |
text_input = forms.CharField() |
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
<?xml version="1.0" encoding="utf-8" ?> | |
<configuration> | |
<system.net> | |
<defaultProxy enabled="true" useDefaultCredentials="true"> | |
<proxy usesystemdefault="true" bypassonlocal="true" /> | |
</defaultProxy> | |
</system.net> | |
</configuration> |
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
from datetime import datetime | |
from itertools import islice | |
from dateutil.rrule import rrule, DAILY, WEEKLY, MONTHLY, YEARLY, SU, MO, TU, WE, TH, FR, SA | |
#Every two days from now on | |
rule_day = rrule(DAILY, dtstart=datetime.today(), interval=2) | |
#Every two weeks (Monday, Tuesday and Wednesday) starting from now | |
rule_week = rrule(WEEKLY, dtstart=datetime.today(), interval=2, byweekday=(MO, TU, WE)) |