Skip to content

Instantly share code, notes, and snippets.

View hammeiam's full-sized avatar

David Hamme hammeiam

  • San Francisco, CA
View GitHub Profile
@hammeiam
hammeiam / elf-marbles.py
Last active December 9, 2018 09:46
Advent of Code 2018: Day 9
"""
The Elves play this game by taking turns arranging the marbles in a circle
according to very particular rules. The marbles are numbered starting with 0
and increasing by 1 until every marble has a number.
First, the marble numbered 0 is placed in the circle. At this point,
while it contains only a single marble, it is still a circle:
the marble is both clockwise from itself and counter-clockwise from itself.
This marble is designated the current marble.
# A command for a mapping project I'm working on.
# Converts one big shapefile of countries into individual files.
# Data file from www.naturalearthdata.com
errors=()
for country in "${countries[@]}"
do
echo "$country"
# skip if we've already processed this country
test -d "$country" && continue
@hammeiam
hammeiam / closest-word.js
Last active March 9, 2021 19:50
Simple Find Closest Word
// You can modify these
const wordsToCheck = ["Apple", "red delisous", "orangg", "rgapefruit"];
const dictionary = ["apple", "banana", "orange", "grapefruit", "red delicious"];
// Don't modify below here
const ALPHABET = "qwertyuiopasdfghjklzxcvbnm1234567890_ ".split("").sort();
const BASE_ALPHABET_HASH = ALPHABET.reduce((acc, x) => ({[x]: 0, ...acc}), {});
const DICTIONARY_HASHES = dictionary.map((w) => buildFreqHash(cleanStr(w)));
@hammeiam
hammeiam / jq-scripts.md
Created August 14, 2022 03:05
Running list of helpful JQ scripts

Merkle tree to address: amount map

Select the key containing merkle proofs and amounts. to_entries[] returns objects on new lines instead of in an array, so wrap the statement in [()] to make it an array again. For each entry, map the amount to the address key. Merge back in to one big object with add.

jq '.recipients | [(to_entries[] | {(.key): .value.amount})] | add' results.json