Skip to content

Instantly share code, notes, and snippets.

View alexwlchan's full-sized avatar

Alex Chan alexwlchan

View GitHub Profile
@alexwlchan
alexwlchan / curlparser.py
Created November 2, 2014 16:19
Unpack sets and ranges expressed in a string, using cURL syntax for multiple URLs
"""The cURL command line tool allows you to specify multiple URLs in a
single string. For example:
http://site.{one,two,three}.com
ftp://ftp.numericals.com/file[1-100].txt
ftp://ftp.numericals.com/file[001-100].txt (with leading zeros)
ftp://ftp.letters.com/file[a-z].txt
This module can take a string in this format, and return the list of strings
that it specifies. The exact syntax can be seen in the examples on the cURL man
@alexwlchan
alexwlchan / organize-photos.py
Last active January 2, 2016 08:59 — forked from cliss/organize-photos.py
My fork of @cliss’s photo management script. Tweaked to: * Get date from `os.path.getmtime(f)` (lifted from @jdmonaco’s fork) * Sort any format with a three-character extension (currently .JPG, .TIF, .PNG and .MOV). Edit the list in line 40 for more formats. It also normalises extensions to lowercase. * Tweaked some bits of the code * Moves file…
#!/usr/bin/python
import sys
import os, shutil
import subprocess
import os.path
from datetime import datetime
######################## Functions #########################
@alexwlchan
alexwlchan / open-irssi-iterm
Last active December 16, 2015 20:49
AppleScript to find a running instance of irssi in my iTerm windows, and launch one if not. For use with an application launcher such as Alfred.
tell application "iTerm"
activate
-- Change this if you want to find a different process
set myprocess to "irssi"
set procrunning to false
-- Count the number of terminal windows open
set mytermcount to count of terminal
@alexwlchan
alexwlchan / image-width-rescaler
Created May 1, 2013 11:33
This is a quick AppleScript written to shrink wide images to at most 1200px. To use it, open it in Script Editor, then save it as an Application, and drag files on to its icon in Finder. Target width is set in line 17. We can similarly use it to shrink tall images if we want to.
on open some_images
repeat with my_image in some_images
try
rescale_and_copy(my_image)
end try
end repeat
end open
to rescale_and_copy(my_item)
tell application "Image Events"