Skip to content

Instantly share code, notes, and snippets.

View brookinc's full-sized avatar

Brook McEachern brookinc

View GitHub Profile
@brookinc
brookinc / wordle-solutions.txt
Created May 1, 2023 10:21
The original "solutions.txt" Wordle / WordleBot data file as hosted on nytimes.com
# https://static.nytimes.com/newsgraphics/2022/01/25/wordle-solver/assets/solutions.txt
# current contents:
# Hello! WordleBot previously had a data file called solutions.txt that it once used for certain calculations. It was no longer used, and no longer accurate. We decided to empty this outdated file so it's not confused with any kind of an official solutions list.
# If you're looking for an alternative, you can use a search engine to find many third-party tools and lists that can help you identify words to guess in Wordle, using a variety of techniques and criteria.
# original data:
aback
abase
abate
@brookinc
brookinc / ffmpeg-concat.zsh
Last active April 18, 2022 17:23
Script to concatenate a directory of mp4 files into one
#!/bin/zsh
# requires ffmpeg: https://ffmpeg.org/download.html
# clear the file list
echo "" > ./output.txt
# recursively find all mp4 files in the current directory and subdirectories
# (will preserve alphabetical order by full path)
for entry in ./**/*.mp4
@brookinc
brookinc / PushBackEmplaceBack.cpp
Created July 31, 2019 17:15
Comparison of various push_back() / emplace_back() approaches.
// https://www.onlinegdb.com/online_c++_compiler
// https://stackoverflow.com/questions/35404932/stdvectoremplace-back-and-stdmove
// https://stackoverflow.com/questions/11572669/move-with-vectorpush-back
#include <iostream>
#include <utility>
#include <vector>
int main()
{
@brookinc
brookinc / FormatCode.gs
Created June 27, 2019 01:14
Google Apps Script that adds a "Format Code" menu option for documents.
// Source: https://webapps.stackexchange.com/a/117682
// Docs: https://developers.google.com/apps-script/reference/document/
// Add new menu item
function onOpen() {
DocumentApp.getUi()
.createMenu('Styles')
.addItem('Format Code', 'formatCode')
.addToUi();
}
@brookinc
brookinc / ExifTag.swift
Created December 30, 2018 07:26
Apply macOS file system tags based on EXIF metadata.
#!/usr/bin/swift
// ExifTag.swift
// Scans files in the given directory and any subdirectories for EXIF metadata and applies
// macOS tags based on the results.
//
// Usage:
// swift ExifTag.swift [options] path
// or...
// chmod +x ExifTag.swift
@brookinc
brookinc / ArchiveInboxThreads.gs
Last active November 17, 2021 16:04
Google Apps Script that archives Gmail threads with a given label.
// ArchiveInboxThreads
//
// This Google Apps Script moves all threads containing any label in the labelsToArchive list out of the
// user's inbox, except for threads that also have a label from the labelsToPreserve list.
//
// If numInboxThreadsToProcess is set to a value greater than 0, the script will only examine that number
// of the most recent inbox threads when it runs; otherwise, it will examine every thread in the inbox.
//
// To use this script, visit https://script.google.com/home and click "New script",
// then paste this code into the text editor area and edit the "labelsToArchive" and "labelsToPreserve"
@brookinc
brookinc / .gitconfig
Last active February 22, 2023 16:16
Git config settings that I like to reuse.
[alias]
add-branch = "!f(){ git fetch origin $1 && git branch $1 FETCH_HEAD && git checkout $1; }; f"
alias = "!f(){ git config --global alias.$1 \"$2\"; }; f"
aliases = config --get-regexp ^alias\\.
aliasverbose = "!sh -c '[ $# = 2 ] && git config --global alias.\"$1\" \"$2\" && exit 0 || echo \"usage: git alias <new alias> <original command>\" >&2 && exit 1' -"
br = branch --contains
cherry-pick-external = "!f(){ git --git-dir=$1/.git format-patch -k -1 --stdout $2 | git am -3 -k; }; f"
cleanup = gc
cleanup-slow = gc --aggressive
curr-branch = symbolic-ref --short HEAD
@brookinc
brookinc / -shell.swift
Last active December 29, 2018 05:43
A simple script to demonstrate some basics of Swift scripting.
#!/usr/bin/swift
// shell.swift
// A simple script to demonstrate some basics of Swift scripting.
import Foundation
// Docs: https://developer.apple.com/documentation/foundation
// ...and: https://github.com/apple/swift-corelibs-foundation/blob/master/Docs/Status.md
extension CommandLine {
@brookinc
brookinc / -ECS.swift
Last active December 29, 2018 05:42
A simple Entity-Component System experiment in Swift.
import Foundation
#if swift(>=4.2)
// no shim necessary
#else
// add shims for swift-4.2-style random(in:) methods
// NOTE: unlike Swift 4.2's implementations, these versions are prone to modulo bias,
// are not cryptographically secure, and don't support the full range of Int64 values
#if os(Linux)
srandom(UInt32(time(nil)))
@brookinc
brookinc / gifsicle.bat
Last active June 14, 2018 18:41
An interactive batch file that simplifies resizing and compressing GIFs with gifsicle.
@echo off
set /p filename="Enter GIF filename (without .gif extension) to resize: "
set /p scale="Enter scale to resize by (eg. 0.5): "
set /p colors="Enter color palette size to use (between 2 and 256): "
@echo on
gifsicle-1.89-win64\gifsicle.exe --scale %scale% --colors %colors% -O3 --no-extensions %filename%.gif > %filename%-%scale%-%colors%.gif
@echo off