Skip to content

Instantly share code, notes, and snippets.

View millerdev's full-sized avatar

Daniel Miller millerdev

  • Dimagi, Inc.
View GitHub Profile
@millerdev
millerdev / prattparse.py
Last active April 3, 2024 14:50
Pratt Parsers: Expression Parsing Made Easy
# Pratt Parser in Python
# https://journal.stuffwithstuff.com/2011/03/19/pratt-parsers-expression-parsing-made-easy/
#
# Works with input like `a + b`.
# The lexer does not support numbers (yet).
#
# https://gist.github.com/millerdev/03d881620dd0879d4347b0e971ff0be5
from dataclasses import dataclass
@millerdev
millerdev / steps.md
Last active September 19, 2022 19:53
Upgrade to new version of PostgreSQL in docker

Upgrade to new version of Postgres in Docker

This example upgrades PostgreSQL 9.4 to 9.6. Substitute the versions you're upgrading to/from as needed below.

Dump all databases to a file

Run the following command to make a backup of all postgres data in a local file:

docker exec -i hqservice_postgres_1 pg_dumpall -U commcarehq | gzip > pg-backup.sql.gz
@millerdev
millerdev / gtk.css
Created March 15, 2021 14:43
Gnome CSS customizations - mainly narrower titlebar
/*
Gnome 3 - based on https://blog.samalik.com/make-your-gnome-title-bars-smaller/
https://securitronlinux.com/bejiitaswrath/how-to-make-the-title-bars-in-gnome-shell-much-thinner-than-the-default/
sizes tweaked to make the close button bigger on 20.04 (not tested on earlier versions)
Copy or symlink to ~/.config/gtk-3.0/gtk.css
To change titlebar font from Bold to normal (maybe there is CSS for this too?):
$ gsettings get org.gnome.desktop.wm.preferences titlebar-font
'Ubuntu Bold 12'
@millerdev
millerdev / git-flake8
Last active September 15, 2020 05:38
Run fake8 on lines changed in current branch
#! /bin/bash
# https://gist.github.com/millerdev/e25014e4b886a5c619419d56b778a423
#
# Usage: git flake8 [refname] [flake8 options]
if [ "${1:0:1}" = "-" ]; then
BRANCH=origin/master
else
BRANCH=${1:-origin/master}
shift
fi
@millerdev
millerdev / fix-virtualenv-readline.md
Last active April 3, 2020 22:00
Fix broken readline in python and pdb interactive prompts in virtualenv with MacPorts python

Problem: borked readline in virtualenv

Python 3.7

$ mkvirtualenv test
$ python
Python 3.7.7 (default, Mar 18 2020, 09:44:23)
[Clang 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
@millerdev
millerdev / bucket_domains.py
Last active March 19, 2020 20:21
Categorize CommCare HQ domains needing couch -> sql migration of forms and cases
#!/usr/bin/env python
# coding: utf-8
"""
DEPRECATED moved to
https://github.com/dimagi/commcare-hq/blob/master/corehq/apps/couch_sql_migration/management/commands/couch_domain_report.py
Categorize CommCare HQ domains needing couch -> sql migration of forms and cases
This script requires a domains.csv file, which can be obtained by following
these steps:
#! /usr/bin/env python
"""Download events form Sentry as CSV
https://gist.github.com/millerdev/3d0a541f90b9817c3be5dd9bffed288e
"""
import sys
import csv
from argparse import ArgumentParser
import requests
@millerdev
millerdev / rm-future.py
Last active August 23, 2019 15:44
Remove __future__ imports from Python files
#! /usr/bin/env python
"""Remove __future__ imports from Python files
Acts on *.py files in the current directory and all subdirectories.
Only removes lines in which all imported names are in KNOWN_FUTURES.
Public URL of this script:
https://gist.github.com/millerdev/f71648c1a9690cfca7c8b7c049867cfc
"""
@millerdev
millerdev / delete_gmail.py
Last active July 1, 2019 17:40
Permanently bulk-delete messages from gmail
#! /usr/bin/env python3
"""Permanently delete messages from Gmail
WARNING: THIS SCRIPT CAN DO GREAT DAMAGE TO YOUR GMAIL ACCOUNT.
USE AT YOUR OWN RISK!
Setup guide:
1. Create and activate a new virtualenv with Python 3
@millerdev
millerdev / generate-locations.py
Last active July 6, 2018 14:37
Generate XLSX file containing CommCare locations
#! /usr/bin/env python
"""Generate XLSX file containing CommCare locations
Requires: pip install openpyxl==2.2.5
https://gist.github.com/millerdev/57a5c1363773a92d9ee6332e79789cd3
"""
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division