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 / 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
@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 / 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.
import itertools
"""
The following math problem illustrates the essence of hacking:
Use each of the numbers 1, 3, 4, and 6 exactly once with any of the four basic math operations (addition, subtraction, multiplication, and division) to total 24. Each number must be used once and only once, and you may define the order of operations; for example, 3 * (4 + 6) + 1 = 31 is valid, however incorrect, since it doesn’t total 24.
The rules for this problem are well defined and simple, yet the answer eludes many. Like the solution to this problem (shown on the last page of this book), hacked solutions follow the rules of the system, but they use those rules in counterintuitive ways.
"""
nums = ['1','3','4','6']
@hammeiam
hammeiam / gist:8596a75029a5887eedc830cbe2b1803e
Created July 16, 2017 01:15
recursively find movie files and sort by size
find . -iname '*.mkv' -o -iname '*.avi' -o -iname '*.mp4' -o -iname '*.mov' | xargs -d '\n' du -sh | sort -hr
class SudokuValidator {
constructor(board) {
if (board.length !== board[0].length) {
throw new Error('Board must be square');
}
if (Math.sqrt(board.length) !== Math.floor(Math.sqrt(board.length))) {
throw new Error('Board size must be a square number')
}
# All Imports
import pickle
import csv
import numpy as np
import matplotlib.pyplot as plt
import cv2
from math import floor, ceil
from sklearn.model_selection import ShuffleSplit
from sklearn.utils import shuffle
import tensorflow as tf
from tensorflow.contrib.layers import flatten
# TODO: pull outs weights from individual functions, make them globally accessible
CLASSES_LEN = 43
DEBUG = False
def get_depth(input_tensor):
if(input_tensor.get_shape):
# Git Push Upstream
# A quick command for people that create a lot of feature branches
#
# Whereas `git push` will return an error if you haven't set the upstream branch
# `gpu` will automatically push to the correct upstream branch
# so you don't have to type `git push --set-upstream origin my_branch` for each new branch
function gpu() {
local RESPONSE=$( git push 2>&1 )
local UPSTREAM=$( echo "$RESPONSE" | grep -o "git push --set-upstream origin.*" )
# 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