Skip to content

Instantly share code, notes, and snippets.

View adamghill's full-sized avatar

Adam Hill adamghill

View GitHub Profile
@adamghill
adamghill / pipenv.md
Last active January 16, 2019 23:01
Opinionated pipenv installation on OSX and zshell

Install pipenv

brew install pipenv
echo "alias py=\"pipenv\"" >> ~/.zshrc
echo "PYTHONDONTWRITEBYTECODE=1" >> ~/.zshrc  # don't create .pyc files for Python source files
echo "PIPENV_VENV_IN_PROJECT=1" >> ~/.zshrc  # create .venv in the source project

To create a Python 3 virtualenv

@adamghill
adamghill / threads.py
Created December 14, 2017 19:49
Python multi-threading example code
# From http://chriskiehl.com/article/parallelism-in-one-line/
import urllib2
from multiprocessing.dummy import Pool as ThreadPool
urls = [
'http://www.python.org',
'http://www.python.org/about/',
'http://www.onlamp.com/pub/a/python/2003/04/17/metaclasses.html',
'http://www.python.org/doc/',
@adamghill
adamghill / .gitconfig
Last active June 9, 2020 13:08
Git aliases
[alias]
c = commit -m
a = add
aa = !git add -u && git add . && git status
co = checkout
cob = checkout -b
up = !git fetch origin && git rebase origin/master
ir = !git rebase -i origin/master
undo = reset HEAD~1 --mixed
st = status --short
@adamghill
adamghill / jquery-lite.js
Last active November 20, 2017 20:43
jquery-lite
window.$w8 = window.$w8 || function (fn) {
if (document.readyState === 'complete' || document.readyState !== 'loading') {
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
};
window.$gme = window.$gme || document.querySelector.bind(document);
window.$$gme = window.$$gme || document.querySelectorAll.bind(document);
@adamghill
adamghill / keybase.md
Created October 12, 2017 20:37
Keybase

Keybase proof

I hereby claim:

  • I am adamghill on github.
  • I am adamghill (https://keybase.io/adamghill) on keybase.
  • I have a public key ASBhzhNPixFGbWfcVktn6fz2RPB5T5C5sd1DR6fcVFcIpwo

To claim this, I am signing this object:

@adamghill
adamghill / bobp-python.md
Created November 8, 2015 18:32 — forked from sloria/bobp-python.md
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
@adamghill
adamghill / scope.js
Last active August 29, 2015 14:01
JavaScript examples
// http://jsfiddle.net/D8VQs/
function print(str, obj) {
console.log(str, obj);
// Use jQuery if it's available
if (typeof($) != 'undefined') {
var $output = $('#output');
if ($output) {
@adamghill
adamghill / static_urls.py
Created February 2, 2014 01:27
Serve static files from Django. This is bad for performance and you shouldn't do it and blah, blah, blah.
from os import path
from django.conf import settings
DOCUMENT_ROOT = path.dirname(path.realpath(__file__))
urlpatterns += patterns('',
url(r'^robots\.txt$', 'django.views.static.serve', {
'path': settings.STATIC_URL + 'robots.txt',
'document_root': DOCUMENT_ROOT,
@adamghill
adamghill / content_views.py
Created January 29, 2014 14:02
Load arbitrary content from templates without creating a ton of unnecessary view methods.
from django.http import Http404
from django.shortcuts import render_to_response
from django.template import RequestContext, TemplateDoesNotExist
def content(request, template_name):
try:
return render_to_response('content/' + template_name + '.html', {}, RequestContext(request))
except TemplateDoesNotExist:
raise Http404
import urllib2
from multiprocessing.dummy import Pool as ThreadPool
urls = [
'http://www.python.org',
'http://www.python.org/about/',
]
pool = ThreadPool()