code

Although most, if not all, of the code snippets here are in use today and work without issue we provide warranties or guarantees. :) Some of this code may be out of date but probably still useful as a starting point. Contact us if you have any questions or comments.

Convert Text Files (UNIX / OS X)

Convert Word docs to text files, concatenate text files and convert to html. Woohoo! Use the code below in Terminal to convert all files in the current directory to txt files. I used this to de-M$ a bunch of Word docs. Very handy. Check out the man page for textutil at Apple's Developer site.

textutil -convert txt *.*

Resize an Image with PIL and Keep Aspect Ratio (Python)

This script will resize an image using PIL (Python Imaging Library) to a width of 300 pixels and a height proportional to the new width. It does this by determining what percentage 300 pixels is of the original width (img.size[0]) and then multiplying the original height (img.size[1]) by that percentage. Change "300" to any other number to change the default width of your images.

import PIL
from PIL import Image

img = Image.open('somepic.jpg')
wpercent = (300/float(img.size[0]))
hsize = int((float(img.size[1])*float(wpercent)))
img = img.resize((300,hsize), PIL.Image.ANTIALIAS)
img.save('sompic.jpg')