Skip to content

Instantly share code, notes, and snippets.

View annarailton's full-sized avatar

Anna Railton annarailton

  • GitHub Staff
  • Oxford
View GitHub Profile
@annarailton
annarailton / check-commit-messages.yml
Last active December 28, 2020 22:22
GitHub Action that checks PRs for commits with messages containing `fixup!` and `squash!`
name: PR commit checker
on: pull_request
jobs:
get-commits:
runs-on: ubuntu-latest
steps:
- name: Get PR commits
run: |
curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -o out.json ${{ github.event.pull_request.commits_url }}
# In yapf >0.27.0, behaviour of default behaviour around SPLIT_BEFORE_FIRST_ARGUMENT
# changed. This overrides this. Put in top level of your directory with
# .pre-commit-config.yml file.
[style]
based_on_style = pep8
split_before_first_argument = True
@annarailton
annarailton / .inputrc
Last active July 12, 2019 21:06
Config that allows history search
# May need to do
# $ bind -f ~/.inputrc
# to get these to work
"\e[A": history-search-backward
"\e[B": history-search-forward
"\e[C": forward-char
"\e[D": backward-char
@annarailton
annarailton / headphones.sh
Created July 9, 2019 07:37
A2DP sink on bluetooth headphones + Ubuntu
# Hack job script to get correct audio profile on my bluetooth headphones
# Replace DEVICE_ID with your device's ID
# From https://askubuntu.com/a/773391
DEVICE_ID="04:5D:4B:DE:CF:8E"
pacmd set-card-profile `pacmd list-cards | grep bluez_card -B1 | grep index | awk '{print $2}'` off; sleep 2 ; echo -e "disconnect $DEVICE_ID\n quit"|bluetoothctl;sleep 5; echo -e "connect $DEVICE_ID\n quit"|bluetoothctl; sleep 5; pacmd set-card-profile `pacmd list-cards | grep bluez_card -B1 | grep index | awk '{print $2}'` a2dp_sink
default_language_version:
python: python3.7
default_stages: [commit, push]
fail_fast: false
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.2.3
hooks:
@annarailton
annarailton / pre-commit-filesize.py
Last active January 29, 2019 12:21
Warns users if staged files are larger than some limit
#!/usr/bin/python3
"""
Checks file size of committed files. If there are stage files bigger than a
given size (`WARN_SIZE_MB`) then
* the commit is aborted
* you are told about the offending files
* you are told the command for forcing through the commit anyway
Save this file as "pre-commit" in your .git/hooks folder and do
@annarailton
annarailton / dump_object_example.py
Created January 4, 2019 11:00
Object that periodically dumps new contents to disk
#!/usr/bin/python3
"""
Toy example using DumpObject, a way of periodically dumping out large objects to
file as it grows. This example watches a file directory and creates a dictionary
with
* key: file name
* value: first line of file
Includes use of `watchdog` to watch for real time effects (here: new files
being created in the directory) and `atexit` to gracefully deal with the program
@annarailton
annarailton / .bashrc
Last active August 23, 2019 15:49
Useful .bashrc aliases etc.
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=5000
HISTFILESIZE=10000
# Setup default editor
export EDITOR=subl
# Start ssh agent so can ssh to Git
eval "$(ssh-agent -s)"
@annarailton
annarailton / update_sublime.sh
Last active December 14, 2018 14:47
Script to keep sublime up to date
# To be run in sudo's crontab. Access via sudo crontab -e
# You need to pick a channel first:
# $ echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list
# OR
# $ echo "deb https://download.sublimetext.com/ apt/dev/" | sudo tee /etc/apt/sources.list.d/sublime-text.list
echo $(date)
apt-get update && apt-get install sublime-text
apt autoremove -y
@annarailton
annarailton / pre-commit-autoflake.py
Last active September 20, 2020 19:10
Run autoflake against staged .py files on commit
#!/usr/bin/python3
"""Runs autoflake on commit. Blocks commit and requests adding changed files
if autoflake fires.
Installation
------------
1. You will need to install autoflake: https://pypi.org/project/autoflake/
$ pip install --upgrade autoflake
or