Skip to content

Instantly share code, notes, and snippets.

View bradmontgomery's full-sized avatar

Brad Montgomery bradmontgomery

View GitHub Profile
@bradmontgomery
bradmontgomery / paper.py
Created May 9, 2011 14:19
Short python script to show that if you could fold a piece of paper in half 50 times, its thickness will be 3/4 the distance from the Earth to the Sun (71 million miles). Discovered on a very interesting Quora question.
"""
Folding paper in half 50 times is 3/4 of the distance from earth to sun
From:
http://www.quora.com/What-are-some-of-the-most-mind-blowing-facts#answer_526501
Thickness of a sheet of paper: 0.1 mm (~0.004 inches)
"""
@bradmontgomery
bradmontgomery / social-auth-wrapper.py
Created June 28, 2011 09:26
This is my temporary solution to handle Exceptions in django-social-auth.
# Define this in your root URLconf, above the entry for social_auth.urls:
url(r'^associate/complete/(?P<backend>[^/]+)/$', 'my_app.views.associate_complete_wrapper'),
# In my_app/views.py:
from social_auth.views import associate_complete
@login_required
def associate_complete_wrapper(request, backend):
try:
return associate_complete(request, backend)
@bradmontgomery
bradmontgomery / stripperparser.py
Last active April 1, 2019 18:30
Quick & dirty HTML parsers: 1) Strip all the HTML out of a document, leaving just the document's content, 2) A way to remove all element attributes, leaving just clean markup.
import re
try:
from HTMLParser import HTMLParser # python 2
except ImportError:
from html.parser import HTMLParser # python 3
class HTMLStripperParser(HTMLParser):
"""Simple, stupid parser to remove all HTML tags from
a document. The point is to just get a the data.
@bradmontgomery
bradmontgomery / tablib-headers.py
Created July 30, 2011 20:11
Extra headers in tablib?
In [111]: tablib.__version__
Out[111]: '0.9.11'
In [112]: d = tablib.Dataset()
In [113]: d.headers = ['heading1', 'heading2', 'heading3', ]
In [114]: d.append_col(['h1-val1', 'h1-val2', 'h1-val3', None], header="heading1")
In [115]: d.append_col(['h2-val1', 'h2-val2', None, None], header="heading2")
.....: d.append_col(['h3-val1', 'h3-val2', 'h3-val3', 'h3-val4', ], header="heading3")
In [116]: print d.csv
@bradmontgomery
bradmontgomery / nth-child.html
Created August 23, 2011 03:33
Trying out nth-child(3n)
<html>
<head><title>nth child</title>
<style type="text/css">
ol.items { color: red; padding: 20px; border: 1px solid red; clear: both; margin: 20px; min-height: 110px; width: 490px;}
ol.items li { display: block; padding: 5px; margin: 5px; border: 1px solid #aaa; float: left; width: 100px; }
li:nth-child(3n) { color: orange; background-color: yellow; }
</style>
</head>
<body>
@bradmontgomery
bradmontgomery / manage_fabric.py
Created October 31, 2011 02:33
A stab at running remote Django management commands via fabric.
def manage(management_command, args=None):
with cd(REMOTE_PROJECT_DIR):
cmd = "source /path/to/virtualenv/bin/activate && "
cmd += "python manage.py %s %s" % (management_command, args or '')
run(cmd)
@bradmontgomery
bradmontgomery / README.rst
Last active September 28, 2015 18:38
Generate random numbers for the various Tennessee Lottery Games. (see http://www.tnlottery.com)
root@polenta:~# chef-client
[Wed, 04 Jan 2012 19:30:43 +0000] INFO: *** Chef 0.10.8 ***
[Wed, 04 Jan 2012 19:30:46 +0000] INFO: Run List is [role[base], role[radiant_database_master], role[radiant], recipe[radiant::db_bootstrap], role[radiant_load_balancer]]
[Wed, 04 Jan 2012 19:30:46 +0000] INFO: Run List expands to [zsh, users::sysadmins, sudo, apt, git, build-essential, database::master, mysql::client, application, radiant::status, radiant::db_bootstrap, haproxy::app_lb]
[Wed, 04 Jan 2012 19:30:46 +0000] INFO: Starting Chef Run for polenta
[Wed, 04 Jan 2012 19:30:46 +0000] INFO: Running start handlers
[Wed, 04 Jan 2012 19:30:46 +0000] INFO: Start handlers complete.
[Wed, 04 Jan 2012 19:30:50 +0000] INFO: Loading cookbooks [apache2, application, apt, aws, build-essential, database, git, gunicorn, haproxy, java, jpackage, mysql, openssl, passenger_apache2, php, python, radiant, runit, sqlite, sudo, tomcat, unicorn, users, xfs, xml, zsh]
[Wed, 04 Jan 2012 19:30:50 +0000] WARN: Missing gem 'right_aws'
[Wed, 0
@bradmontgomery
bradmontgomery / rvm_apache_passenger.txt
Created January 10, 2012 04:45
RVM + Apache + passenger setup for Ubuntu
# Install rvm system-wide
bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
# Update the packages
apt-get update
apt-get upgrade
apt-get install build-essential
# get the packages required by ruby
rvm pkg install zlib
@bradmontgomery
bradmontgomery / pg_hba.conf
Created January 13, 2012 17:51
don't know why I always forget how to do the "trust all local connections" thing
# Trust all connections from localhost
local all all trust
# password auth from elsewhere
host all all 10.0.0.1/32 md5