Skip to content

Instantly share code, notes, and snippets.


Alex Chan alexwlchan

View GitHub Profile
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.
View image-width-rescaler
on open some_images
repeat with my_image in some_images
end try
end repeat
end open
to rescale_and_copy(my_item)
tell application "Image Events"
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.
View open-irssi-iterm
tell application "iTerm"
-- 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 /
Last active January 2, 2016 08:59 — forked from cliss/
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…
import sys
import os, shutil
import subprocess
import os.path
from datetime import datetime
######################## Functions #########################
alexwlchan /
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[1-100].txt[001-100].txt (with leading zeros)[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 /
Last active August 29, 2015 14:11
A command-line tool for managing acronyms
"""A script for managing a dictionary of acronyms. For context, see the
associated blog post:
Invoke with the -h or --help flag for a usage message:
$ ./ -h
Invoke with the -a or --add flag to add an acronym:
alexwlchan /
Created December 22, 2014 20:36
Prints human-readable, friendly strings to measure elapsed time
""" - a script for providing a human-readable string of how much time
has elapsed since a given date, implemented only using the standard library.
Modelled on the style of dates used on Stack Overflow posts.
from datetime import datetime, timedelta
def print_date(date, incl_year=True, short_months=True):
"""Prints a datetime object as a full date, stripping off any leading
alexwlchan /
Created May 26, 2015 19:37
A script for making the XML exports from the iOS Health app more human-friendly
#!/usr/bin/env python
A quick script for tidying up data from the HealthKit export file.
To get an export file:
1) Open the Health app on iOS
2) Under "Health Data", select "All"
3) Use the share button to get a copy of your data in XML format
This script allows you to get data for one particular value, and turn it into
alexwlchan /
Last active December 3, 2020 16:17
Non-destructive file copying/moving in Python
#!/usr/bin/env python
This is a script designed to be "safe" drop-in replacements for the
shutil move() and copyfile() functions.
These functions are safe because they should never overwrite an
existing file. In particular, if you try to move/copy to dst and
there's already a file at dst, these functions will attempt to copy to
a slightly different (but free) filename, to avoid accidental data loss.
alexwlchan /
Last active July 5, 2022 01:18
A Python script for finding untagged posts on Tumblr. See
#!/usr/bin/env python
import urllib2
import json
API_KEY = "abcdefg"
URL = "{host}/posts?api_key={key}".format(host=HOSTNAME, key=API_KEY)
alexwlchan /
Created December 10, 2015 08:33
drangReader – Python scripts for a simple RSS reader


This is a set of scripts for aggregating RSS feeds. It's based on a script originally written by Dr. Drang:


Download all the files from this Gist. Put them all in a directory, create a virtualenv and install requirements: