Skip to content

Instantly share code, notes, and snippets.

View adamghill's full-sized avatar

Adam Hill adamghill

View GitHub Profile
@adamghill
adamghill / urls.py
Created October 2, 2019 20:04
Stream large files through a Django view
from django.conf import settings
from django.conf.urls.static import static
from django.conf.urls import url
from .views media
urlpatterns = (
# normal url includes
)
@adamghill
adamghill / restore_database.sh
Created July 26, 2019 00:55
Copies one Postgres database into another
#!/bin/bash
read -p "This will wipe your destination database with a copy from the source database. Are you really sure you wanna do that? " -n 1 -r
echo
SOURCE_DATABASE_NAME=database1
SOURCE_HOST=localhost
SOURCE_PORT=5432
DESTINATION_DATABASE_NAME=database2
DESTINATION_HOST=localhost
@adamghill
adamghill / .editorconfig
Last active August 2, 2019 18:00
Opinionated guide to Python development in Sublime Text
root = true
[*]
end_of_line = lf // Helps keep Windows, Mac, Linux on the same page since they handle end of line differently
charset = utf-8
trim_trailing_whitespace = true // Auto-trims trailing whitespace
insert_final_newline = true // Auto-adds a blank newline to the end of a file
[*.scss]
indent_size = 2 // More common to see 2 spaces in SCSS, HTML, and JS
@adamghill
adamghill / clean_osx.md
Last active August 25, 2024 13:06
Things to setup on a clean OSX install

An opinionated list of things that I tend to do on a clean install of OSX.

OSX applications

  • Rectange: Resize and move around windows with the keyboard
  • Postgres.app: Easiest way to run a local Postgres server
  • VS Code: For when an IDE might actually be useful
  • 1Password7: Better than a Post-It note stuck to your monitor
  • iTerm2: Terminal replacement
  • GitUp: A clean git UI
  • DevUtils: Offline toolbox for developers
@adamghill
adamghill / threads_with_tqdm.py
Created May 29, 2019 23:00
Use tqdm with a thread pool
from multiprocessing.dummy import Pool as ThreadPool
import time
import tqdm
def _square(number):
time.sleep(.5)
return number * number
@adamghill
adamghill / validate.py
Created February 16, 2019 05:04
Validate Heroku webhooks in Python
"""
Heroku documentation has sample code in Ruby for validating that the
webhook request came from them (based on the secret that was used when creating the webhook):
https://devcenter.heroku.com/articles/app-webhooks#using-the-shared-secret
Here is sample Python 3 code from a Django app that accomplishes the same goal.
"""
import base64
import hashlib
@adamghill
adamghill / aspnetcrypto.py
Created October 8, 2018 17:16
Decrypting ASP.NET identity cookies
# -*- coding: utf-8 -*-
# From https://lowleveldesign.org/2014/11/11/decrypting-asp-net-identity-cookies/
import base64
import logging
import argparse
import struct
import gzip
from StringIO import StringIO
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
@adamghill
adamghill / .buildpacks
Created July 31, 2018 02:13
Scalable Django + Python setup for Heroku
https://github.com/beanieboi/nginx-buildpack.git
https://github.com/cyberdelia/heroku-geo-buildpack.git#1.3
https://github.com/heroku/heroku-buildpack-pgbouncer
https://github.com/heroku/heroku-buildpack-python#v69
@adamghill
adamghill / up.sh
Last active July 29, 2018 11:43
Shell script to start a Django webserver
#!/bin/sh
set -e
PIPENV_VENV_IN_PROJECT=1 pipenv install --dev
if [ $? -eq 0 ]; then
PIPENV_VENV_IN_PROJECT=1 pipenv run python manage.py migrate --noinput &&
PIPENV_VENV_IN_PROJECT=1 PYTHONDONTWRITEBYTECODE=1 pipenv run python manage.py runserver_plus --settings=project.settings 0:8001
else
echo "ERROR: pipenv instll failed."
@adamghill
adamghill / migrateFirebaseData.sh
Created July 26, 2018 01:24
Shell script to move data from one Firebase realtime database to another (helpful for live->test migrations)
#! /bin/bash
live_database="LIVE_DATABASE_NAME"
test_database="TEST_DATABASE_NAME"
read -p "This is a destructive operation on the test Firebase database ($test_database). Are you sure you want to continue? (y/N) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then