Skip to content

Instantly share code, notes, and snippets.

@tomvon
tomvon / resize-image-keep-aspect-ratio.py
Created June 8, 2014 22:59
Python script to resize an image while keeping the original aspect ratio.
#Resizes an image and keeps aspect ratio. Set mywidth to the desired with in pixels.
import PIL
from PIL import Image
mywidth = 300
img = Image.open('someimage.jpg')
wpercent = (mywidth/float(img.size[0]))
hsize = int((float(img.size[1])*float(wpercent)))
@tomvon
tomvon / generate-year-select-menu.py
Created June 8, 2014 22:51
Python script to generate year select menu.
#Python script to generate year select menu.
print '<select name="year">'
for i in range(2013,2051):
print '<option value="'+str(i)+'">'+str(i)+'</option>'
print '</select>'
@tomvon
tomvon / generate-google-fonts-stylesheet-links.py
Last active August 29, 2015 14:02
Python script to get google fonts json feed, parse it and print the info. Can be useful for automatically generating stylesheet links for Google Fonts.
@tomvon
tomvon / python-create-jekyll-post.py
Last active February 21, 2021 03:15
Create a default post for a Jekyll instance using Python, save it and open it in BBEdit.
import os
from datetime import datetime
import time
import slugify
#Generate timestamps for post id and date.
ts = time.time()
timeid = datetime.fromtimestamp(ts).strftime('%Y-%m-%d')
timestamp = datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
@tomvon
tomvon / python-generate-states-select-menu.py
Last active August 29, 2015 14:02
Generate state options for an HTML select menu using python.
states = ["Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Carolina","North Dakota","Ohio","Oklahoma","Oregon","Pennsylvania","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington","West Virginia","Wisconsin","Wyoming"]
for s in states:
print '<option value="'+s+'">'+s+'</option>'