from collections import namedtuple
import random
import string
import sys
Node = namedtuple('Node', ['grammar'])
Output = namedtuple('Output', ['text'])
# All of these are easier to compute than to specify literally in the grammar
ALPHABET_NODES = [[Output(letter)] for letter in string.letters]
View prepared.vbs
' Creates a prepared statement and populates its parameters
' Usage:
' Dim stmt as QueryDef
' Set stmt = PrepareStatement(CurrentDb, "SELECT * FROM T WHERE A = [aval] AND B = [bval]", _
' "aval", 42, _
' "bval", "Carrot Cake")
Public Function PrepareStatement(db As Database, sql As String, ParamArray params()) As QueryDef
An NDFA-based regular expression evaluator, built in the style of the Thompson NFA.
from collections import deque, namedtuple
# These are both singletons indicating:
# - A split in the NDFA. These never read any characters, so the matcher has to
# evaluate every side of the split in order to continue.
# - The end of the NDFA.
help() {
echo "`basename $0` [-h] -d <DEPLOY-DIR> -r <REPO-DIR>
Does the necessary work to use a Git repository for deployment.
This creates two directories - DEPLOY-DIR and REPO-DIR. REPO-DIR is
a bare repository that you can push to and pull from like any repository,
while DEPLOY-DIR contains the contents of the 'master' branch. Git hooks
are used to keep DEPLOY-DIR up to date with REPO-DIR."
View utils.js
* Returns a list of all the text nodes under the given node.
* The order should be depth-first, first-to-last across siblings.
function findTextNodes(node) {
if (node.nodeType == HTML_TEXT_NODE) {
return [node];
from __future__ import print_function # Py2 compat
from collections import namedtuple
import sys
# These define the structure of the history, and correspond to diff output with
# lines that start with a space, a + and a - respectively.
Keep = namedtuple('Keep', ['line'])
Insert = namedtuple('Insert', ['line'])
Remove = namedtuple('Remove', ['line'])
View default.js
// NOTE: Only expect this to work on FF, Chrome or Edge.
// There are several arrow functions sprinkled around,
// and caniuse suggests that these are the only browsers
// that can handle them natively
init: function(elevators, floors) {
// The backlog is (an approximation of) the number of people currently waiting at
// the given floor.
import static org.junit.Assert.*;
import org.junit.Test;
public class TestDiGraph {
* Refactoring the commonalities of comparing toposorts with multiple
* valid results, into its own function.
public void assertCorrectSort(DiGraphInterface graph, String... correct) {
String[] sorted = graph.topoSort();
import static org.junit.Assert.*;
import org.junit.Test;
public class BinaryHeapTest {
* If you are expecting null, then don't use this function - it is not null
* safe.
private void entryPairAssertEqual(EntryPair expect, EntryPair actual) {
if (expect.getPriority() != actual.getPriority() ||
# Computes the offsets of values in a MIPS .data segment
my $in_data = 0;
my $mem_offset;
my $current_label = "";
# Gets rid of C escapes like \n - note that this is only meant to preserve
# the length of the string, so it uses single-character placeholders rather
# than actually interpreting the escapes. For example, it would replace:
# Foo\'s bar\n