Skip to content

Instantly share code, notes, and snippets.

@ms8r
ms8r / dtren.py
Last active August 15, 2018 09:41
#!/usr/bin/env python
"""
Script to rename filesnames that include a year and month (e.g. reports,
account statements) such that the respective month appears as YYYY-MM and can
therefore be sorted correctly.
Original filenames can contain month names spelled out, abbreviated, or as
zero-padded decimals (the first two also from different locales). By default
the new filename will simply show the corresponding YYYY-MM as prefix,
@ms8r
ms8r / .gitignore
Last active August 2, 2018 02:40
Script to extract sales data from Audible monthly report XLS files
archive
*.xls
*.ods
*.tsv
*~
*.pyc
*.ipynb
.ipynb_checkpoints
@ms8r
ms8r / .gitignore
Last active August 26, 2018 09:04
Simple script to synthesize text to speech from text file using Google Cloud TTS
*.pyc
*~
*.log
*.mp3
archive
non-git
.ipynb_checkpoints
ipython_log.py
gce_cred.json
*.md
@ms8r
ms8r / pudz.py
Created January 22, 2017 20:49
Build continuous PuD code ranges based on ZIP:distance mapping. Writes to stdout.
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from bisect import bisect_left
import begin
@begin.start(auto_convert=True, short_args=False)
def main(airport: """3 letter airport code""",
infile: """input file with whitespace separted (code, dist) pairs""",
breaks: """whitespace separated string containing sorted list with
@ms8r
ms8r / apdm.py
Last active February 4, 2017 22:21
Uses Google Distance Matric API to get distances (in meters) between an airport and a list of lat/lon values. Writes to stdout.
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import fileinput
from itertools import groupby
import json
from tablib import Dataset
import googlemaps
import begin
@ms8r
ms8r / geoc.py
Last active December 28, 2016 15:35
Uses Google Maps API to add lat/lon info to address data provided in a CSV file
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import re
import time
from collections import namedtuple
from functools import partial
import json
import logging
from tablib import Dataset
@ms8r
ms8r / sudo-relaunch.py
Created June 19, 2016 11:39
Python: Use sudo to re-launch a script as root
# This is how I ensure a Python script is launched as root, and automatically
# call 'sudo' to re-launch it as root if not.
# I found it useful to check the parameters are valid *before* re-launching as
# root, so I don’t have to enter the sudo password if there is a problem with
# the parameters, or I just want the help message.
import os
import sys
@ms8r
ms8r / yaml_ordered_dict.py
Created April 10, 2016 10:24 — forked from enaeseth/yaml_ordered_dict.py
Load YAML mappings as ordered dictionaries
import yaml
import yaml.constructor
try:
# included in standard lib from Python 2.7
from collections import OrderedDict
except ImportError:
# try importing the backported drop-in replacement
# it's available on PyPI
from ordereddict import OrderedDict