Skip to content

Instantly share code, notes, and snippets.

View BigglesZX's full-sized avatar

James Tiplady BigglesZX

View GitHub Profile
@BigglesZX
BigglesZX / design.gotchas.txt
Last active December 18, 2015 23:09
WIP list of f/e dev quirks that designers sometimes don't know
Font availability
Text kerning
Fonts sized in sensible units (not pt)
Including extra fonts/variants for very small amounts of content
Shadows that need to be programmatic being added to non-square things
Underlines being thicker than one pixel (on things that for whatever reason can't be given borders)
Spacing of underlines (as above)
Impossible z-orders
Gradient masks on things that can't be faked with image overlays
Matching heights of dynamically sized elements
@BigglesZX
BigglesZX / gifextract.py
Created November 5, 2012 10:31
Extract frames from an animated GIF, correctly handling palettes and frame update modes
import os
from PIL import Image
'''
I searched high and low for solutions to the "extract animated GIF frames in Python"
problem, and after much trial and error came up with the following solution based
on several partial examples around the web (mostly Stack Overflow).
There are two pitfalls that aren't often mentioned when dealing with animated GIFs -
@BigglesZX
BigglesZX / views.py
Created April 19, 2012 20:36
Easily output an email address as a PNG image in Django
import Image
import ImageFont, ImageDraw
from django.conf import settings
from django.http import HttpResponse
from os.path import join
def emailshield(request):
address = 'info@example.com'
# change the path below to a TTF file you want to use
font = ImageFont.truetype(join(settings.PROJECT_ROOT, 'static', 'Vera.ttf'), 14)
@BigglesZX
BigglesZX / django.s3.media.settings.py
Created March 5, 2012 13:58
Django settings for S3-based media files
'''
We use S3 as our media backend on Heroku, so set that up
'''
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
AWS_ACCESS_KEY_ID = "YOUR_AWS_KEY"
AWS_SECRET_ACCESS_KEY = "YOUR_AWS_SECRET"
AWS_STORAGE_BUCKET_NAME = "YOUR_S3_BUCKET_NAME"
'''
Adjust media URL to point directly to S3
@BigglesZX
BigglesZX / Wordpress.nginx.permalinks.textile
Created January 16, 2012 11:44
Wordpress + nginx permalinks
@BigglesZX
BigglesZX / Dreamhost.Python.installation.textile
Created January 14, 2012 10:49
Installing a custom version of Python on Dreamhost

Dreamhost supplies a fairly old version of Python in their shared hosting environments. It recently became necessary for me to use a newer version, and since this involved a bit of juggling, and since I’m also likely to forget how I did it, I thought I’d detail the steps here. These instructions should work with any Dreamhost shared hosting user, but follow them at your own risk.

The end result of this process is being able to run a current version of Python from your shared hosting user’s shell. It requires compiling, installing and running Python from your home directory rather than the system bin directories.

1. Create a helpful working directory
I chose to install all Python-related stuff in a python/ directory under my user’s home directory.

$ mkdir ~/python
$ cd ~/python
@BigglesZX
BigglesZX / jQuery.Adjacent.Wrapping.htm
Created December 19, 2010 17:17
Wrap two adjacent elements in a containing div using jQuery
This is a useful trick if you want to wrap two sibling elements in a containing element, for example to fix stupid float bugs in IE7. I had a bit of a time figuring out how to select the right elements (wrapping is easy enough with one element, or one element's children), so I thought I'd share for the Greater Good.
From markup like this:
<div class='form-container'>
...
<div class='form-label'>Name (required)</div>
<div class='form-field'><input type="text" name="you-name" value="" class="textbox" size="30" maxlength="200" /></div>
<div class='form-label'>Email (required)</div>
@BigglesZX
BigglesZX / Useful.Regexes.php
Created June 20, 2010 10:43
Some handy regular expressions (and attendant PHP code) that I've come across in my travels.
<?php
//
// some useful regular expressions and sample usage
//
// convert Twitter usernames into profile links
// cred. Simon Granade (http://bit.ly/FihuS)
$text = preg_replace('/(^|\s)@(\w+)/',
'\1@<a href="http://twitter.com/\2">\2</a>', $text;