This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import re | |
import urllib | |
import urllib2 | |
class Spreadsheet(object): | |
def __init__(self, key): | |
super(Spreadsheet, self).__init__() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sendmail(subject, to, sender, body, mailserver, body_type="html", attachments=None, cc=None): | |
"""Send an email message using the specified mail server using Python's | |
standard `smtplib` library and some extras (e.g. attachments). | |
NOTE: This function has no authentication. It was written for a mail server | |
that already does sender/recipient validation. | |
WARNING: This is a non-streaming message system. You should not send large | |
files with this function! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2.7 | |
""" | |
This script is used to convert a WordPress XML dump to Hugo-formatted posts. | |
NOTE: The WP post data is kept as-is (probably HTML). It is not converted to | |
Markdown. This is to reduce the amount of "fixing" one has to do after the | |
data is converted (e.g. line endings, links, etc). This is generally not an | |
issue since Markdown allows HTML. | |
The post Metadata is converted to TOML. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
''' | |
This script shows an example of using `requests` and the USPS Address | |
Information API. | |
In order to use this, you must first register so you can get your USERID. Your | |
ID must be in the environment variable `USPS_USERID`. | |
For information on the API see here: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
r''' | |
This script converts a vCard file to a Dymo ABX address book. | |
Usage: | |
vcf2abx <input VCF file> <output ABX file> | |
Example: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2.7 | |
# coding: utf-8 | |
''' | |
This script shows an example of rotating log files in a directory. | |
''' | |
# Imports ##################################################################### | |
import os | |
import sys | |
import tarfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
""" | |
This sample script is an example use of the threading pool to process a | |
sequence of items. | |
This is both python2 and python3 compatible. | |
""" | |
from __future__ import print_function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def format_timespan(seconds: float) -> str: | |
"""Formats the number of seconds in h:m:s""" | |
hours, seconds = divmod(seconds, 3600) | |
minutes, seconds = divmod(seconds, 60) | |
return f"{hours:d}h:{minutes:02d}m:{seconds}s" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# You can check to see if someone ran your script with `echo -n test | myscript.py`. | |
# In that case, there's no tty attached. If there _is_ an attached tty, then you | |
# can just prompt the user like normal. | |
import sys | |
def read_secret_key(): | |
if sys.stdin.isatty(): | |
return getpass("Enter the secret key: ") | |
else: | |
return sys.stdin.readline() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function array_join() { | |
# Join an array with a a separator character. | |
# WARNING: This only works in bash. You should also pass the array by | |
# reference. Example: | |
# my_array=( "one" "two" "three") | |
# joined=$( array_join my_array "|") | |
local -n arr=$1 | |
local sep=${2:-" "} | |
printf -v result "%s${sep}" "${arr[@]}" |
OlderNewer