Skip to content

Instantly share code, notes, and snippets.

Avatar

Alex Chan alexwlchan

View GitHub Profile
@alexwlchan
alexwlchan / README.md
Created Dec 10, 2015
drangReader – Python scripts for a simple RSS reader
View README.md

drangreader

This is a set of scripts for aggregating RSS feeds. It's based on a script originally written by Dr. Drang: http://leancrew.com/all-this/2015/11/simpler-syndication/

Installation

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

@alexwlchan
alexwlchan / elapsed.py
Created Dec 22, 2014
Prints human-readable, friendly strings to measure elapsed time
View elapsed.py
#!/usr/bin/python
"""elapsed.py - 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
alexwlchan / safeutil.py
Last active Dec 3, 2020
Non-destructive file copying/moving in Python
View safeutil.py
#!/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
alexwlchan / myurlparse.py
Created Aug 30, 2016
Helper functions for dealing with query strings in URLs
View myurlparse.py
#!/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
View keybase.md

Keybase proof

I hereby claim:

  • I am alexwlchan on github.
  • I am alexwlchan (https://keybase.io/alexwlchan) on keybase.
  • I have a public key whose fingerprint is 82FE A59D 07EE 6274 20D7 E85D F859 A49F A148 6C23

To claim this, I am signing this object:

@alexwlchan
alexwlchan / finduntaggedposts.py
Last active Mar 13, 2017
A Python script for finding untagged posts on Tumblr. See http://alexwlchan.net/2013/08/untagged-tumblr-posts/
View finduntaggedposts.py
#!/usr/bin/env python
import urllib2
import json
HOSTNAME = "example.tumblr.com"
API_KEY = "abcdefg"
URL = "http://api.tumblr.com/v2/blog/{host}/posts?api_key={key}".format(host=HOSTNAME, key=API_KEY)
View reset_taskpaper_list.py
#!/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.
"""
View auto_collapse_deferred_taskpaper_items.js
// 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) {
View word_count.py
#!/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