Skip to content

Instantly share code, notes, and snippets.

View ihincks's full-sized avatar

Ian Hincks ihincks

View GitHub Profile
@ihincks
ihincks / query.py
Last active October 24, 2018 19:44
Some functions to query users at the command prompt.
def general_query(question, validator, default=None):
"""
Asks the given question, returning the (possibly modified) result if validator
allows it, and keeps asking until a valid answer is given.
:param str question: The question to ask.
:param validator: A function that acts on user response strings, and returns
`(success, modified_response, message)`. The loop ends if `success` is `True`,
in which case `modified_response` is returned. `message` is printed in
any case.
@ihincks
ihincks / savediff.sh
Created December 11, 2018 13:56
Saves a diff of the current working changes to a git repo into Dropbox (so that you can continue working on something somewhere else)
#!/bin/bash
timestamp() {
date +"%Y-%m-%d_%H:%M:%S"
}
pushd "$PWD" > /dev/null
SHA="$(git rev-parse --short HEAD)"
FILENAME="$HOME/Dropbox/diff/${PWD##*/}_$(timestamp)_$SHA.diff"
git diff > $FILENAME