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 / 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):
@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 / 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