Skip to content

Instantly share code, notes, and snippets.

@squamous
squamous / parallel-ansible-execution.yml
Created April 17, 2017 23:53
Parallel ansible execution
# http://toroid.org/ansible-parallel-dispatch
- name: Set up EC2 instances
ec2:
...
wait: yes
with_items: instances
register: ec2_instances
async: 7200
poll: 0
@squamous
squamous / remote-user-info.yml
Last active April 17, 2017 18:36
Trick for getting remote user info in Ansible
---
# Ansible doesn't expose the shell environment of the remotely logged in user
# so we need to use a few tricks to get some of these values.
#
# This playbook demonstrates how to get a couple of useful environment variables.
#
# NOTE: these values are different to ansible_env.ansible_user_dir and
# ansible_env.ansible_user_shell which represent the user running ansible.
@squamous
squamous / gist:92458310cb50adc5b9dec5ab13386c92
Created March 7, 2017 04:47
List of icons in Wagtail CMS
https://github.com/wagtail/wagtail/blob/master/wagtail/contrib/wagtailstyleguide/templates/wagtailstyleguide/base.html#L610
@squamous
squamous / install-flake8-pre-commit-hook.sh
Last active January 24, 2017 04:26
Pre-commit git hook to lint all python files
#!/bin/sh
# works as of flake8 3.2.1
echo -n "Enter the project directory and press [Enter]: "
read project
if [ ! -d $project ]; then
echo "FAILURE: Could not find directory '$project'"
fi
@squamous
squamous / savings-earnings-calculator.py
Last active August 3, 2016 06:46
Calculate savings goals with inflation adjustment
#!/usr/bin/env python
#
# Calculate savings goals with inflation adjustment.
#
import locale
locale.setlocale(locale.LC_ALL, '')
SAVING_PERIOD = 5 # years
@squamous
squamous / image_resize.py
Last active August 9, 2016 14:40
Resize a set of images by a given percentage
#!/usr/bin/env python
#
# Resize a set of images by a given percentage.
import sys, os
from PIL import Image
if __name__ == '__main__':
if len(sys.argv) > 2:
@squamous
squamous / secret_key_gen.py
Last active July 25, 2016 07:43
generate secure Django SECRE_KEY
"""
Two things are wrong with Django's default `SECRET_KEY` system:
1. It is not random but pseudo-random
2. It saves and displays the SECRET_KEY in `settings.py`
This snippet
1. uses `SystemRandom()` instead to generate a random key
2. saves a local `secret.txt`