Skip to content

Instantly share code, notes, and snippets.

View mpwoodward's full-sized avatar

Matt Woodward mpwoodward

View GitHub Profile
@mpwoodward
mpwoodward / docker-compose.yml
Created February 22, 2020 20:11
Docker Compose for WordPress, MySQL, and phpMyAdmin
version: "3.1"
services:
db:
image: mysql:5.7
command: --default-authentication-plugin=mysql_native_password
restart: always
volumes:
- db_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: ROOT_PASSWORD
@mpwoodward
mpwoodward / convert_cpbitmap.py
Created July 7, 2016 22:29
Python script to convert an iPhone wallpaper file (.cpbitmap format) to a usable image format
from PIL import Image
import struct
import sys
def r8(f):
return ord(f.read(1))
if len(sys.argv) < 3:
@mpwoodward
mpwoodward / passenger_wsgi.py
Created June 17, 2016 04:53
Example passenger_wsgi.py file for running a Django application on Dreamhost with Passenger
import sys, os
cwd = os.getcwd()
sys.path.append(cwd)
sys.path.append(cwd + '/my_django_project')
INTERP = os.path.expanduser("~/.virtualenvs/my_django_project/bin/python3")
if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv)
@mpwoodward
mpwoodward / updateElementIndices.js
Created February 26, 2015 01:17
Updating the indices of Django formset forms
function updateFormElementIndices(formClass) {
var forms = $('.' + formClass);
forms.each(function(i, el) {
var curIndex = $(el).attr('id').match(/\d+/)[0];
$(el).attr('id', $(el).attr('id').replace(curIndex, i));
var inputs = $(el).find('.' + formClass + 'Input');
@mpwoodward
mpwoodward / delete_leave_row.js
Created February 26, 2015 01:12
Delete leave row function
function deleteLeaveRow(deleteLink) {
var totalFormsField = $('#id_form-TOTAL_FORMS');
var totalForms = parseInt(totalFormsField.val()) - 1;
totalFormsField.val(totalForms);
$(deleteLink).closest('.leaveForm').remove();
// for formset functionality to work properly, need to update all existing form ids so they're sequential
updateFormElementIndices('leaveForm');
@mpwoodward
mpwoodward / delete_row.html
Created February 26, 2015 01:09
Example of delete row link
<a href="javascript:void(0);" onclick="deleteLeaveRow(this);" class="remove muted pull-right">
<div class="fa fa-times fa-lg" title="Delete day off" alt="Delete day off"></div><span class="visible-xs">Remove Day</span>
</a>
@mpwoodward
mpwoodward / form.html
Created February 26, 2015 00:42
Snippet of Django form used in formset that is called via Ajax
<div id="leaveForm{{ form_num }}" class="row row-tall row-bottom-border leaveForm">
<div class="form-group col-sm-4">
<div class="row">
<div class="col-xs-8">
<label for="id_form-{{ form_num }}-date_start" class="sr-only">From</label>
<div class="input-group{% if leave_form.date_start.errors %} has-error{% endif %}">
<span class="input-group-addon addon-small hidden-sm"><i class="fa fa-calendar"></i></span>
<input id="id_form-{{ form_num }}-date_start" name="form-{{ form_num }}-date_start" class="datepicker form-control input-sm leaveFormInput" placeholder="mm/dd/yyyy" type="text" value="{{ leave_form.date_start.value|default_if_none:'' }}" />
{% if leave_form.date_start.errors %}
<span class="input-group-addon addon-small">
@mpwoodward
mpwoodward / new_form_function.js
Created February 26, 2015 00:32
Grabbing a new Django form for a formset via Ajax
function addLeaveRow() {
var totalFormsField = $('#id_form-TOTAL_FORMS');
var nextFormNum = parseInt(totalFormsField.val());
$('#add_leave_row').addClass('disabled');
$('#loading').show();
$.ajax({
url: '/leave/leave-form/' + nextFormNum + '/',
type: 'GET'
@mpwoodward
mpwoodward / views.py
Last active December 19, 2015 17:28
Example of writing CSV data to the Django HTTP Response object
import csv
from django.http import HttpResponse
# other imports here ...
@login_required
def registrant_email_dump(request):
response = HttpResponse(content_type='text/csv')
@mpwoodward
mpwoodward / models.py
Created July 1, 2013 23:47
SponsorManager model for Old Dog Haven charity walk registration site. Example of extending the default Django model manager as well as running a SQL query directly.
class SponsorManager(models.Manager):
def with_sponsorship_totals(self):
from django.db import connection
cursor = connection.cursor()
cursor.execute("""
SELECT s.id,
s.registrant_sponsoring_id,
SUM(s.sponsorship_amount) AS total_sponsorship_amount,
r.first_name,