Skip to content

Instantly share code, notes, and snippets.

View jwineinger's full-sized avatar

Jay Wineinger jwineinger

  • SPS Commerce
  • Minneapolis, MN
View GitHub Profile
@jwineinger
jwineinger / storage.py
Created December 16, 2011 16:46
Django staticfiles JS-minifying storage backend
from django.core.files.storage import FileSystemStorage
from slimit import minify
class StaticFileStorageAndJSMinifier(FileSystemStorage):
"""
A storage backend to be used by the staticfiles app -- STATICFILES_STORAGE
setting. This backend operates just as a normal filesystem storage backend
except when it detects a javascript file.
After a javascript file is saved, we reopen the file, minify the contents
@jwineinger
jwineinger / django_multivalue_datetime_timezone.py
Created August 1, 2013 17:55
A Django MultiValue form field that handles a text datetime input and a pytz timezone input from a select list. Also, widget classes and data-format attribute are intended for use with bootstrap-datetimepicker from https://github.com/tarruda/bootstrap-datetimepicker
from django import forms
from django.forms.fields import MultiValueField
import pytz
# provided by django-timezone-field==0.4
from timezone_field import TimeZoneFormField
class DatetimeTZWidget(forms.MultiWidget):
@jwineinger
jwineinger / media_mover.py
Created September 1, 2013 05:49
Just a script to move media files from one directory (recursively by default) into a different directory with date-based hierarchy. For JPG images, the EXIF data is read to determine the proper directory. If it cannot find the date via EXIF, then it falls back to the file's last modification time. It also uses the file's mtime for all other medi…
import os, argparse, hashlib
from datetime import datetime
from PIL import Image, ExifTags
from shutil import move
def modification_date(filename):
t = os.path.getmtime(filename)
return datetime.fromtimestamp(t)
def md5_for_file(f, block_size=2**20):
include:
- requirements
nodejs:
pkg.installed
statsd:
git.latest:
- name: https://github.com/etsy/statsd.git
- rev: v0.7.0
@jwineinger
jwineinger / .bashrc
Last active August 29, 2015 14:06
bash config to speed up SSHing to EC2 nodes by name through a jumpbox. Also supports opening a set of similarly named servers in new tabs in OSX terminal.
# bashrc
. ~/.newtab.sh
tssh() { ssh `aws_name_to_ip $1` | sed -n "${2:-1}p"; }
aws_name_to_ip() {
if [ -z "$VIRTUAL_ENV" ]; then
workon aws;
fi
aws ec2 describe-instances --filters "Name=tag-value,Values=$1" --output text --query 'Reservations[*].Instances[*].PrivateIpAddress' | sort;
}
@jwineinger
jwineinger / picasa-web-2-facebook.py
Created October 2, 2014 06:33
Copy a picasa web album to a facebook album
import json
import requests
import gdata.photos.service
GOOGLE_ALBUM_ID = 0
GOOGLE_EMAIL = "you@gmail.com"
GOOGLE_PASSWORD = "hunter42"
FB_ACCESS_TOKEN = ""
@jwineinger
jwineinger / graph_gist_template.adoc
Created February 18, 2016 17:44 — forked from cheerfulstoic/graph_gist_template.adoc
CHANGEME: GraphGist Template. Fork to make your own, view source to see instruction comments

TITLE OF YOUR GRAPHGIST

@jwineinger
jwineinger / gist:1c0406e690c7c9e7aa9912d25fadedee
Created February 6, 2017 21:09
Sort pictures based on EXIF datetime
exiftool '-Directory<DateTimeOriginal' -d %Y-%m-%d dir
@jwineinger
jwineinger / gist:68021d73189b70fca63a17c6d88c5669
Created November 17, 2017 05:10
syslog-ng sidecar to send log messages to AWS CloudWatch Logs
# syslog-ng.conf
@version: 3.12
options { chain_hostnames(off); flush_lines(0); use_dns(no); use_fqdn(no);
owner("root"); group("adm"); perm(0640); stats_freq(0);
bad_hostname("^gconfd$");
};
source s_src {
network(
@jwineinger
jwineinger / conftest.py
Created March 23, 2018 18:21
reorder pytest tests based on dependencies
def pytest_collection_modifyitems(session, config, items):
"""Reorder the execution of tests based on the dependency marks on tests.
To setup a test dependency, decorate the test function with the "depends"
mark and give a list of dependencies via the "on" keyword arg to the
decorator. Dependencies can be specified by name only when in the same
file as the test being decorated, or by pytest node path for tests in
other files/classes.
@pytest.mark.depends(on=["test_in_same_file",