Skip to content

Instantly share code, notes, and snippets.

View adamghill's full-sized avatar

Adam Hill adamghill

View GitHub Profile
@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
@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 / 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 / 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
abaci.io
aback.io
abaft.io
abase.io
abash.io
abate.io
abbe.io
abbess.io
abbey.io
abbot.io
@adamghill
adamghill / parse_available_io_domains.py
Last active December 31, 2015 00:09
Validate that an .io TLD is available to purchase. Uses https://gist.github.com/isaacbw/6831088#file-available-txt as the initial seed of domains to check. Props to http://whomsy.com/ for not blocking me.
import requests
gist_url = 'https://gist.github.com/isaacbw/6831088/raw/33b0072c6160f0fe304e998fa04715117456414d/available.txt'
gist_response = requests.get(gist_url)
if gist_response.ok:
with open('available.txt', 'w') as file:
lines = gist_response.content.split('\n')
available_count = 0
@adamghill
adamghill / python_sql_server.md
Last active January 2, 2016 03:49
Access Sql Server from Python on OSX
  1. brew install freetds
  2. pip install pymssql==2.0.1
  3. vim ~/.odbc.ini
[dsn]
Driver = FreeTDS
Server = SERVER
Database = DATABASE
Port = 1604
@adamghill
adamghill / handle_stupid_python_on_snow_leopard.txt
Created January 4, 2014 16:13
How to handle invalid mach-o architecture error for Python on Snow Leopard OS X. From http://api.mongodb.org/python/current/installation.html#osx.env.
env ARCHFLAGS='-arch i386 -arch x86_64' pip install {PACKAGE_NAME}
e.g. env ARCHFLAGS='-arch i386 -arch x86_64' pip install psycopg2
import urllib2
from multiprocessing.dummy import Pool as ThreadPool
urls = [
'http://www.python.org',
'http://www.python.org/about/',
]
pool = ThreadPool()