Skip to content

Instantly share code, notes, and snippets.

@reagle
reagle / semantic_wrap.py
Last active July 13, 2021 12:00
Wrap text, including semantically by add breaks at terminal punctuation.
#!/usr/bin/env python2.7
"""Wrap text, including semantically by add breaks at
terminal punctuation."""
# Using python 2.7 so portions can be used in Sublime Text 3 plugin
import argparse # http://docs.python.org/dev/library/argparse.html
import logging
import re
import sys
@reagle
reagle / unmangle_safelinks.py
Last active February 21, 2019 22:45
Sublime Text plugin for editing emails in Thunderbird/exteditor; it unmangles MS Outlook safelinks and wraps quotes
@reagle
reagle / md-pp.py
Last active May 13, 2021 18:28
Pretty print markdown file (useful with text editors without printing)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# (c) Copyright 2016 by Joseph Reagle
# Licensed under the GPLv3, see <http://www.gnu.org/licenses/gpl-3.0.html>
#
"""Pretty print a markdown file as line-numbered source.
Perhaps one day replace with a [panflute] filter for pandoc.
[panflute]: http://scorreia.com/software/panflute/
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# detox filenames so as to across most file systems
# (c) Copyright 2016 by Joseph Reagle
# Licensed under the GPLv3, see <http://www.gnu.org/licenses/gpl-3.0.html>
#
import codecs
import glob
import locale
@reagle
reagle / semester.py
Last active January 3, 2024 20:17
Generate a class calendar using duration of semester, the days of the week a class meets, and holidays. It can modify a markdown syllabus if they share the same number of sessions and classes are designed with the pattern "### Sep 30 Fri"
#!/usr/bin/env python3
"""Generate a class calendar using duration of semester, the days of the week a
class meets, and holidays. It can modify a markdown syllabus if they share the
same number of sessions and classes are designed with the pattern "### Sep 30 Fri"
"""
# https://gist.github.com/reagle/19806122fdb22515ea0b
__author__ = "Joseph Reagle"
@reagle
reagle / book-index.py
Last active August 29, 2015 14:10
Read page indices to build book index
#!/usr/bin/python2
# -*- coding: utf-8 -*-
""" Read page indices to build book index.
Input consists of lines of a topic, page_no, and subtopic
affixed with prepositions, or a "see also". Page numbers
may have a range ('-') but no commas (',').
topic 000
topic 000-002
topic 000 subtopic
topic 000 {in, and} subtopic
@reagle
reagle / gist:5591363
Created May 16, 2013 12:25
The program I used to analyze the balance of gender coverage in Wikipedia and Britannica. The gender guessing heuristics might be useful to others.
#!/usr/bin/python2.6
# -*- coding: utf-8 -*-
# (c) Copyright 2011-2013 by Joseph Reagle
# Licensed under the GPLv3, see <http://www.gnu.org/licenses/gpl-3.0.html>
import codecs
from difflib import SequenceMatcher
from cfiledict import FileDict # compressed FileDict
#from filedict import FileDict # http://erezsh.wordpress.com/2009/05/24/filedict-a-persistent-dictionary-in-python/
import logging