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 / 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):
@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 / 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 / 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 / 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
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:
@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 / forms.py
Last active August 29, 2015 14:07 — forked from maraujop/forms.py
# -*- 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()
@avenet
avenet / App.config.xml
Last active August 29, 2015 14:05
Use local machine proxy configuration by default
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true">
<proxy usesystemdefault="true" bypassonlocal="true" />
</defaultProxy>
</system.net>
</configuration>
@avenet
avenet / outlook_periodic_items.py
Created August 26, 2014 22:24
Generating Outlook periodic items via Python Dateutil
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))