Skip to content

Instantly share code, notes, and snippets.

@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
#!/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 / 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 / pandoc_identifier.py
Last active February 20, 2020 23:09
Convert string to pandoc auto_identifiers default algorithm. Intended as a CopyQ clipboard function.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# (c) Copyright 2019 by Joseph Reagle
# Licensed under the GPLv3, see <http://www.gnu.org/licenses/gpl-3.0.html>
#
""" Convert string to pandoc auto_identifiers default algorithm.
Intended as a CopyQ clipboard function.
"""
@reagle
reagle / pel2pan.py
Created December 9, 2020 15:29
Given a FOLDER, replicate all markdown files with pelican metadata converted to pandoc YAML metadata in `new-FOLDER`
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# DESCRIPTION
# (c) Copyright 2020 by Joseph Reagle
# Licensed under the GPLv3, see <http://www.gnu.org/licenses/gpl-3.0.html>
#
import argparse # http://docs.python.org/dev/library/argparse.html
import codecs
import logging
@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/
@reagle
reagle / sublime_semantic_wrap.py
Created May 13, 2021 18:32
A Sublime Text 3 (python 2.7) plugin for wrapping text, including semantic wraps.
# A Sublime Text 3 (python 2.7) plugin for wrapping text, including
# semantic wraps.
import re
import sublime # https://www.sublimetext.com/docs/3/api_reference.html
import sublime_plugin
SEMANTIC_BREAK_RE = re.compile(
r"""
( # end of sentence includes...
[a-z]{2,}| # end of word
@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 / tz.py
Created October 12, 2022 12:58
Print world clock in terminal
#!/usr/bin/env python3
# Print world clock in terminal
# (c) Copyright 2022 by Joseph Reagle
# Licensed under the GPLv3, see <http://www.gnu.org/licenses/gpl-3.0.html>
#
# replacing: https://superuser.com/questions/164339/timezone-conversion-by-command-line
import argparse # http://docs.python.org/dev/library/argparse.html
import sys