Skip to content

Instantly share code, notes, and snippets.

View alexwlchan's full-sized avatar

Alex Chan alexwlchan

View GitHub Profile
@alexwlchan
alexwlchan / spoilerrific.js
Last active January 8, 2016 21:58
Opt-in to spoilers on SFF.SE questions with particular tags
// ==UserScript==
// @name SFF.SE Show spoilers on questions with particular tags
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Show all spoilers on SFF.SE questions with specified tags
// @author alexwlchan
// @match *://scifi.stackexchange.com/questions/*
// @match *://meta.scifi.stackexchange.com/questions/*
// @grant none
// ==/UserScript==
@alexwlchan
alexwlchan / settern_rss.py
Created February 14, 2016 08:44
Python script for creating a per-author RSS feed from iMore
#!/usr/bin/env python
"""
This script can be used to get a per-author RSS feed on iMore.com. It will try to
cache the entries, so the last 40 entries from an author will show up, even if
they're no longer in the main feed.
To invoke, just call this script at the command line:
python settern_rss.py
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
"""
download_files.py
~~~~~~~~~~~~~~~~~
This is a file downloader for Python with a few special features:
* If the user doesn't supply a filename, try to infer a filename and
file extension from the URL.
@alexwlchan
alexwlchan / myurlparse.py
Created August 30, 2016 20:33
Helper functions for dealing with query strings in URLs
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
Utility functions for dealing with URL query strings in Python,
i.e., URLs of the form
http://example.net?field1=value1&field2=value2
This module includes a pair of helper functions: one for getting the values
associated with a particular field; another for setting the query string
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
A script for quickly injecting records into DynamoDB.
Useful for testing apps that hang off a DynamoDB event stream.
"""
import itertools
import sys
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""Guess a filename from a URL.
Suppose you want to download a file from a URL, and you want to preserve
the name of the original file as closely as possible. This snippet
provides a function for doing so.
"""
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""Generate unique filenames for a file you're about to create.
The functions in this snippet are useful for ensuring you don't inadvertently
create a file that replaces an existing file. Given a name, they try to
find a similar name that doesn't already exist on the disk.
This code isn't safe from race conditions -- if a file pops into existence
between the check and the write, you could still lose data -- but it's a
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""Returns a human-friendly word count of the string passed to stdin.
Example outputs:
* 5 words
* 100 words
* 1.5k words
* 10k words
// auto_collapse_deferred_items.js
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// This script collapses any projects with the @defer tag in the frontmost
// window. Useful for tidying up the window, so I don't have to see the
// detail associated with those projects.
'use strict'
function TaskPaperCollapseDeferredItems(editor, options) {
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""I have a TaskPaper file I keep in Dropbox that contains some tasks for my
daily routine.
This script runs once a day and resets every item on that list, removing
the @done tag and replacing the file.
"""