Skip to content

Instantly share code, notes, and snippets.

View AaronTorgerson's full-sized avatar

Aaron Torgerson AaronTorgerson

View GitHub Profile
@AaronTorgerson
AaronTorgerson / ecssh
Last active April 24, 2019 11:33
SSH into a running Docker container on ECS (depends on awless)
#!/bin/bash
set -e
cluster=$1
service=$2
container=$3
debug=$4 # pass word "debug" as 4th arg to see debug output
check_val () {
if [[ -z "${1}" ]]; then
@AaronTorgerson
AaronTorgerson / kmscrypt.py
Created February 17, 2018 01:46
KMS util using aws_encryption_sdk
"""
Use KMS to encrypt or decrypt a file.
Ex,
python kmscrypt.py encrypt myfile.txt myfile.txt.ct
python kmscrypt.py decrypt myfile.txt.ct myfile-copy.txt
"""
@AaronTorgerson
AaronTorgerson / mixins.py
Created November 15, 2016 18:36
Prevent un-mocked requests calls mixin (for use on a class that inherits from django.test.TestCase)
import requests
def _fake_requests_send(self, request, **kwargs):
raise Exception("Un-mocked request! request: {0}".format(request.__dict__))
_real_requests_send = requests.sessions.Session.send
@AaronTorgerson
AaronTorgerson / iterate_models_safely.py
Created December 4, 2015 19:25
Iterate Django models handing deserialization exceptions without killing iterator.
import sys
t = MyThing.objects.iterator()
while True:
try:
record = it.next()
sys.stdout.write('.')
except StopIteration:
break
except Exception as ex:
@AaronTorgerson
AaronTorgerson / fix_django_model_data.py
Last active December 1, 2015 17:40
Clean out bad data from bad django model records that won't load. (DANGER: DESTROYS DATA)
def fix_data(model_manager, fields_to_update_with_defaults_dict, commit=False):
bad_ids = []
all_ids = model_manager.values_list('id', flat=True)
print "There are {} total IDs.".format(len(all_ids))
for b_id in all_ids:
try:
b = model_manager.get(id=b_id)
except:
bad_ids.append(b_id)
@AaronTorgerson
AaronTorgerson / close_old_branches.rb
Created August 15, 2012 13:57
Ruby script to close old branches in a given repo
#!/usr/bin/env ruby
Dir.chdir(ARGV[0])
raw_changeset_hashes = `hg log -r "head() and not(closed()) and not(date(-30)) and not outgoing()" --template "{node}\n"`
changeset_hashes = raw_changeset_hashes.split(/\n/)
if (changeset_hashes.length > 0)
changeset_hashes.each do | h |
if (system("hg up #{h}"))
system('hg ci --close-branch -m "Closed automatically. Last changeset aged past 30 days"')
system('hg nudge')