Skip to content

Instantly share code, notes, and snippets.

View adamghill's full-sized avatar

Adam Hill adamghill

View GitHub Profile
@adamghill
adamghill / scorched_earth.sh
Last active September 25, 2023 18:08
Start from scratch for database migrations in Django
#!/bin/sh
set -e
die () {
echo >&2 "$@"
exit 1
}
[ "$#" -eq 1 ] || die "Database name argument is required"
@adamghill
adamghill / Procfile
Last active November 13, 2022 16:31
Settings, files, and a checklist to deploy a Django app to Heroku with nginx + gunicorn + postgres + redis and using `poetry` for dependencies.
web: python manage.py collectstatic --noinput && bin/start-pgbouncer bin/start-nginx gunicorn -c gunicorn.conf.py project.wsgi
@adamghill
adamghill / pyproject.toml
Last active December 18, 2022 21:43
Default pyproject.toml for Django projects
[tool.poetry]
name = ""
version = "0.1.0"
description = ""
authors = [""]
[tool.poetry.dependencies]
python = "^3.9"
Django = ">3"
django-fbv = "<1"
@adamghill
adamghill / settings.json
Last active March 3, 2024 15:59
VS Code settings
{
"editor.minimap.enabled": false,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[html]": {
"editor.insertSpaces": true,
"editor.tabSize": 2,
"editor.defaultFormatter": "HookyQR.beautify"
},
@adamghill
adamghill / heart.html
Created August 21, 2020 15:38
Beating heart animation
<!--
From https://ackee.electerious.com/
-->
<style>
.heart {
width: 16px;
height: 16px;
fill: #73fac8;
margin: 0 4px -1px;
@adamghill
adamghill / yeti.css
Created March 4, 2020 15:57
Yeti styles for goatcounter.com (https://jenil.github.io/bulmaswatch/yeti/)
@-moz-document domain("goatcounter.com"), domain("stats.arp242.net") {
html, body {
background-color: white;
}
.page {
padding-top: 4em;
box-shadow: none;
}
@adamghill
adamghill / create_setup.py
Created February 7, 2020 23:27
Convert pyproject.toml to setup.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# @Author: José Sánchez-Gallego ([email protected])
# @Date: 2019-12-18
# @Filename: create_setup.py
# @License: BSD 3-clause (http://www.opensource.org/licenses/BSD-3-Clause)
# https://github.com/sdss/flicamera/blob/master/create_setup.py
# This is a temporary solution for the fact that pip install . fails with
@adamghill
adamghill / apps.py
Last active May 5, 2022 09:03
Watch .env file for changes in a Django app
from django.apps import AppConfig
from django.conf import settings
from django.utils.autoreload import autoreload_started
class Config(AppConfig):
name = "random_app_name"
def ready(self):
autoreload_started.connect(watch_env)
@adamghill
adamghill / middleware.py
Created November 17, 2019 22:43
Middleware to add method properties to Django's request object instead of string comparisons
class RequestMethodMiddleware:
"""
Add request method as properties to the request object.
Example: `request.is_post` instead of `request.method == "POST"`
"""
def __init__(self, get_response):
self.get_response = get_response
@adamghill
adamghill / parse_querystrings.py
Created November 13, 2019 02:40
Parse url for querystrings
"""
`furl` is really nice, but if it's only used for easily grabbing querstrings, you can use the `urlib.parse` module instead.
"""
url = "http://www.test.com?some_qs_here=asdf"
# Instead of this...
from furl import furl
parsed_url = furl(url)