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 | |
import argparse | |
import datetime | |
import humanfriendly # pip install humanfriendly | |
import os | |
import shutil | |
import subprocess | |
import sys | |
import time |
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 | |
''' | |
This script demonstrates some basic inter-process communication. Typical usage: | |
1. Run this script with the "make" argument. On Windows, a new console window | |
will appear; that is the worker. Copy the last line of the output from this | |
window to the clipboard. | |
2. Run this script with the "query" argument and paste the last line of the | |
output from the last step as the second argument. Repeat this step as many | |
times as you want. After the worker finishes, repeating this step will cause |
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
// ==UserScript== | |
// @name NJ Transit Train Schedule Station Persister | |
// @namespace https://www.wecsam.com/ | |
// @version 0.1 | |
// @description This script fills the origin and destination fields with the last values that you entered. | |
// @author You | |
// @match https://www.njtransit.com/sf/sf_servlet.srv?hdnPageAction=TrainTo | |
// @match https://www.njtransit.com/sf/sf_servlet.srv?hdnPageAction=TrainTo# | |
// @grant none | |
// ==/UserScript== |
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 | |
import flask | |
app = flask.Flask(__name__) | |
HTML_HOME = """<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> |
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 | |
import argparse, collections, os.path, sys | |
def move_lines(fin, fout, lines_to_leave, preserve_first_line): | |
# For CSV files, preserve the first line, which is the header row. | |
if preserve_first_line: | |
first_line = next(fin) | |
else: | |
first_line = "" | |
# If the output file is new, write the first line into it. |
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 | |
# pip install z3-solver | |
import z3 | |
class OrdAt: | |
''' | |
Z3 has no way of arbitrarily getting a character at an index from a string. | |
However, this problem requires us to get ASCII character codes from a | |
string. When an object of this class is called, the return value is a | |
BitVec with a number of bits that you specify; the 8 least significant bits |
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 | |
import argparse, gettext, sys | |
class FileType(argparse.FileType): | |
''' | |
This class is just like argparse.FileType, except that it supports all | |
keyword arguments for open() and returns a function that opens a handle | |
rather than returning the handle itself. This means that the file is not | |
actually opened until that function is called. This also means that the | |
result can be used with a "with" block. |
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 | |
''' | |
Import this module to ensure that at most one instance of the main script can | |
be running at once. If another instance is detected, sys.exit() will be called. | |
The psutil package is required: pip install psutil | |
''' | |
import atexit, logging, math, os, psutil, socket, sys | |
logger = logging.getLogger("prevent_parallel") | |
PID_FILE = \ |
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
' This macro is for Microsoft Outlook. It opens a file picker dialog and then | |
' attaches the selected files to the selected items. | |
' This macro requires the object library for the installed version of Microsoft | |
' Word. In the VBA editor, go to Tools > References... and make sure that it is | |
' checked off. For Word 2016, choose the Microsoft Word 16.0 Object Library. | |
Sub AddAttachmentsToSelection() | |
Dim objMessage As Variant | |
Dim strPath As Variant | |
' Outlook does not have a file picker. Use an instance of Word instead. | |
Dim appWord As Word.Application |
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 | |
import collections, os.path, queue, sys, textwrap, threading, time | |
UNITS = { | |
"char": lambda fin: fin.read(1), | |
"line": lambda fin: fin.readline(), | |
} | |
def producer(backlog, stop, unit_getter, fin): | |
''' | |
Continually does backlog.put(unit_getter(fin)). If KeyboardInterrupt |
NewerOlder