Skip to content

Instantly share code, notes, and snippets.

View bradmontgomery's full-sized avatar

Brad Montgomery bradmontgomery

View GitHub Profile
@bradmontgomery
bradmontgomery / dummy-web-server.py
Last active April 15, 2024 14:27
a minimal http server in python. Responds to GET, HEAD, POST requests, but will fail on anything else.
#!/usr/bin/env python
"""
Very simple HTTP server in python (Updated for Python 3.7)
Usage:
./dummy-web-server.py -h
./dummy-web-server.py -l localhost -p 8000
Send a GET request:
@bradmontgomery
bradmontgomery / install-comodo-ssl-cert-for-nginx.rst
Last active April 1, 2024 11:21
Steps to install a Comodo PositiveSSL certificate with Nginx.

Setting up a SSL Cert from Comodo

I use Namecheap.com as a registrar, and they resale SSL Certs from a number of other companies, including Comodo.

These are the steps I went through to set up an SSL cert.

Purchase the cert

@bradmontgomery
bradmontgomery / list_gists.py
Last active March 6, 2024 20:23
Quick & dirty hack to list a user's gists, sorted by stars
#!/usr/bin/env python
"""
A quick & dirty hack to list all of your Gists sorted by stars.
This script lists your gists, the number of stars, the number of comments,
a truncated description, and the url for the gist.
NOTE: This only returns public gists. If you want to see (your own) private gists,
you can provide a personal access token.
@bradmontgomery
bradmontgomery / line-highlighter.js
Created February 10, 2012 05:47
bookmarklet to highlight one line of text based on the position of your mouse
javascript:(function (){h=document.createElement("div");h.setAttribute("id","_bradshiliteline");h.setAttribute("style","width:100%;height:20px;background-color:yellow;font-size:inherit;line-height:inherit;position:absolute;left:0px;top:0px;z-index:999;opacity:0.4;");document.getElementsByTagName("body")[0].appendChild(h);window.onmousemove=function(e){var h=document.getElementById("_bradshiliteline");h.style.top=(e.pageY+15)+"px";h.setAttribute("class",e.pageY);}})();
@bradmontgomery
bradmontgomery / packages.txt
Created December 31, 2023 18:26
Packages I've installed during my journey using Linux Mint
1password
ack
apt-transport-https
battery-stats
bcmwl-kernel-source
build-essential
chromium-browser
cmdtest
conky-all
direnv
@bradmontgomery
bradmontgomery / LICENSE.txt
Last active December 1, 2023 21:01
A python decorator that logs execution time.
Copyright 2020 Brad Montgomery
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.
@bradmontgomery
bradmontgomery / example.py
Created August 16, 2016 16:57
Example of setting a choices value for django ArrayField
# Here's your list of choices that would be displayed in a drop-down
# element on the web. It needs to be a tuple, and we define this
# as a variable just for readability/convenience.
#
# This example has 3 choices, each of which consists of two parts:
# 1. the thing that get strored in your database
# 2. the thing that you see in a dropdown list
LABEL_CHOICES = (
('this gets stored in your database', 'This item is what you see in the drop-down'),
('django', 'Django'),
@bradmontgomery
bradmontgomery / import this
Created January 14, 2012 03:34
The Zen of Python. (in a python shell, type "import this")
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
@bradmontgomery
bradmontgomery / index.html
Last active June 14, 2023 02:28
Forms & DOM nodes
<h1>Grocery List</h1>
<form action="" method="get" id="groceries">
<label for="item">Grocery Item</label>
<input type="text" id="item" name="item">
<input type="submit" value="Add Item">
</form>
<ul id="grocery-items">
</ul>
@bradmontgomery
bradmontgomery / using-jQuery-to-add-forms-to-a-Django-formset.js
Last active May 14, 2023 01:24
Use jQuery to add forms to a django formset
/*
Given the following HTML (a form generated by a django formset), I want to be able to
clone the form elements inside the div#book-form-container, omitting any values
<form action="/books/add/" method="post">
<div id="book-form-wrapper"> <input type="hidden" name="form-TOTAL_FORMS" value="1" id="id_form-TOTAL_FORMS" /> <input type="hidden" name="form-INITIAL_FORMS" value="0" id="id_form-INITIAL_FORMS" />
<div class="book-form-container">
<input type="hidden" name="form-0-id" id="id_form-0-id" />