Skip to content

Instantly share code, notes, and snippets.

@philangist
philangist / cocktail_shaker_sort.py
Created August 4, 2013 00:17
I saw the cocktail shaker sort in the [15 Sorting Algorithms in 6 Minutes](https://www.youtube.com/watch?v=kPRA0W1kECg) video and wanted to implement it.
import random
def cocktail_shaker_sort(array):
smallest_array=[]
largest_array = []
while len(array) > 0:
smallest_element = min(array)
smallest_element_index = array.index(smallest_element)
smallest_array.append(smallest_element)
array.pop(smallest_element_index)
@philangist
philangist / reset_db.sh
Created August 4, 2013 00:21
Reset db to fix any migration inconsistencies in Django
#delete all migrations and reset models.py to initial state
rm -r app/migrations/
chmod +x manage.py
./manage.py flush
./manage.py schemamigration app --initial
./manage.py migrate app --fake
#after changing models.py
./manage.py schemamigration app --auto
./manage.py migrate app
@philangist
philangist / logger_factory.py
Created August 4, 2013 00:22
Factory Method for creating logging instances that follow a standard format.
import logging
def logger_factory(name, filename='default'):
logger = logging.getLogger(name)
logger.setLevel(logging.DEBUG)
if filename == 'default':
filename = name + '.log'
file_handler = logging.FileHandler(filename)
format = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s: %(message)s')
file_handler.setFormatter(format)

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@philangist
philangist / github_api_fix.py
Last active November 17, 2016 18:58
codespeed github retrieve revision updated api fix
def retrieve_revision(commit_id, username, project, revision=None):
commit_url = 'https://api.github.com/repos/%s/%s/git/commits/%s' % (
username, project, commit_id)
commit_json = None
if commit_json is None:
try:
commit_json = json.load(urllib.urlopen(commit_url))
except IOError, e:
import time
import md5
from functools import wraps
from bottle import (
get,
abort,
request,
run
)
import md5
import requests
from requests.auth import HTTPBasicAuth
class DigestClient(object):
def __init__(self, url, username, password):
self.url = url
self.username = username
{% extends "base.html" %}
{% block content %}
<h2>Dry Cleaning Orders</h2>
{% url 'dry_cleaning_add' as add_dry_cleaning_url %}
<div class="btn-toolbar">
<a href="{{ add_dry_cleaning_url }}">
<button class="btn btn-primary">New Order</button>
</a>
</div>
@philangist
philangist / Emacs_Commands.md
Created September 9, 2013 21:18
Emacs commands

Emacs Commands

File

ctrl+x, ctrl+f Open file
ctrl+x, ctrl+s Save
ctrl+x, ctrl+w Save As
ctrl+x, s Save All

@philangist
philangist / binary_decimal_hexadecimal.py
Last active August 29, 2015 14:02
Base 2 to Base 10 and Base 10 to Base 16 interger conversion
BASE_16 = 16
HEXADECIMAL_CHARACTERS = [
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
'A', 'B', 'C', 'D', 'E', 'F',
]
DECIMAL_TO_HEXADECIMAL_MAPPING = {
x: HEXADECIMAL_CHARACTERS[x]
for x in range(len(HEXADECIMAL_CHARACTERS))
}