Skip to content

Instantly share code, notes, and snippets.

View tylerneylon's full-sized avatar

Tyler Neylon tylerneylon

View GitHub Profile
tylerneylon /
Created March 3, 2024 20:36
A script to help with the Split Decisions word puzzles in the New York Times
#!/usr/bin/env python3
# coding: utf-8
./splits .in,cr..
This will print out all known words that match both patterns with fixed
letters per dot. In the above example, one answer pair would be:
tylerneylon / depth_first_traverse.js
Created August 24, 2023 18:56
A general depth-first traversal utility function in JavaScript
// This is a depth-first traversal function with a few nice features.
// * Call this function as depthFirstTraverse(root, tree, fn)
// `tree` is an object whose properties are nodes in a tree; the
// values are arrays of that node's child nodes.
// `root` is the starting point for the traversal; a property in `tree`.
// `fn` is called as in fn(node, depth, childNum) for each node.
// childNum is the index of node as a child of its parent;
// as a special case, the childNum of `root` is undefined.
// `depth` is 0 for the root, and in general indicates how
tylerneylon / printTree.js
Last active July 22, 2023 21:04
A cute and simple way to print trees via console.log().
/* printTree.js
* A little function to print out a tree via console.log().
* The tree is expected to be an object whose keys (aka properties) are
* treated as nodes; each node mapping to an array of its children.
* Leaf nodes don't need to be present as keys.
* Here is an example tree with root element 'a':
* t = {a: ['b', 'c'], b: ['d'], c: ['e'], d: ['f', 'g'], g: ['h']}
tylerneylon / table.js
Created June 24, 2023 22:59
a JavaScript function to print out a table with right-justified columns
// Print out a simple table with right-justified columns of strings.
// This can handle some columns having fewer entries than others.
// (For mid-table missing entries, provide empty strings.)
// The `cols` value is an array of arrays of strings, the columns of the table.
// The optional `topSep` is a string the indicates the separator to use in the
// top row only. If you don't provide topSep, a single space is used.
function showTableWithColumns(cols, topSep) {
if (topSep === undefined) topSep = ' ';
tylerneylon / sort_w_partial_info.js
Last active May 22, 2023 22:45
Sort an array based on a comparison function that can say "order is flexible" for some pairs.
// This will sort the values in `inputArr` according to the comparison data
// provided by calls to `inputCmp()`, which is expected to return the values '='
// (a string), '<', '>', or null; where a null indicates that the comparison
// value is undetermined, and that those two elements may go in any order.
// This function attempts to reduce the number of calls to inputCmp() in several
// ways:
// * It memorizes given return values.
// * It assumes that if a < b then also b > a (otherwise what is happening?).
// * It builds a tree to infer transitive comparisons, and tries to maximize
// the use of that tree.
tylerneylon / partial_order.js
Created April 29, 2023 21:15
Sort an array using a partial order, ie, using a cmp() function which may return "not sure" as an answer.
// The inputArr is an array of any kind of values.
// The inputCmp() function accepts two values, x and y; with the return
// value indicating the relationship as such:
// If: then cmp(x, y) returns:
// x < y '<'
// x > y '>'
// x = y '='
// x ? y null
tylerneylon / toggle
Created March 20, 2023 20:19
A short sweet Python script to simplify starting/stopping a particular ec2 instance
#!/usr/bin/env python3
""" toggle
toggle start
toggle getip
toggle stop
tylerneylon /
Created January 28, 2023 00:16
A little bash script to make your images 16x9 via adding white border stripes.
if [ -z "$1" ]; then
echo Usage: ./ '<img_file>'
echo This will create a new image file with the word 'fixed' appended before
echo the filename extension. Eg, myimg.jpg will become myimg.fixed.jpg.
tylerneylon /
Created January 12, 2023 19:10
This is an example implementation of an efficient reservoir sampling algorithm.
This is an example implementation of an efficient
reservoir sampling algorithm -- this algorithm is useful
when you have a data stream, possibly of unknown length,
and you'd like to maintain an incrementally updated
random subset of fixed size k. This algorithm works by
occasionally adding a new data point from the stream
into the 'reservoir,' which is simply a length-k list
of data points.
tylerneylon /
Created December 17, 2022 22:40
A simple prototype Python script that uses GPT-3.5 to add docstrings to functions in any given Python file.
#!/usr/bin/env python3
Usage: <>
NOTE: This requires Python 3.9+ (this is openai's library requirement).
This app is a work in progress.