Skip to content

Instantly share code, notes, and snippets.

View GrayedFox's full-sized avatar
👣
Maken tracks, one step at a time.

Che Fisher GrayedFox

👣
Maken tracks, one step at a time.
View GitHub Profile

Keybase proof

I hereby claim:

  • I am grayedfox on github.
  • I am grayedfox (https://keybase.io/grayedfox) on keybase.
  • I have a public key whose fingerprint is 6847 1215 2CB4 7637 0582 3FBD CC33 73F2 7F9A 9688

To claim this, I am signing this object:

@GrayedFox
GrayedFox / RemoveHeaders.java
Last active June 2, 2018 15:58
removeCopyrightHeaders
/*
* Remove all instances of a commented copyright notice from all files inside of a project.
* Needs to be compiled first (javac).
* Will not overwrite hidden files, symbolic links, or attempt to write to directories that are not writable.
* Will only overwrite files where the copyright text is found (will not overwrite with no changes).
*/
import java.io.IOException;
import java.io.*;
import java.nio.file.Files;
@GrayedFox
GrayedFox / git-clone-latest
Last active August 13, 2018 16:52
Bash function to clone the latest tagged version of a repo
#!/usr/bin/env bash
LATEST_TAG="$(curl --silent https://api.github.com/repos/$1/$2/tags | grep -Po '"name": "\K.*?(?=")' | head -1)"
echo "Cloning $LATEST_TAG"
if [ "$3" = "-https" ]; then
git clone https://github.com/$1/$2.git --branch $LATEST_TAG
else
git clone git@github.com:$1/$2.git --branch $LATEST_TAG
@GrayedFox
GrayedFox / filter-by-named-ranges-gas.js
Last active August 21, 2018 07:27
Filter a google spreadsheet by named ranges, but don't hide frozen rows or columns.
function onOpen() {
var menu = SpreadsheetApp.getUi().createMenu('Custom Filter');
menu
.addItem('Show All', 'showAll')
.addToUi();
}
function onEdit(e) {
var cellRef = e.range.getA1Notation();
@GrayedFox
GrayedFox / dd-obs-test.sh
Created November 22, 2018 14:54
Output ideal output block size for use with dd
#!/bin/bash
# Since we're dealing with dd, abort if any errors occur
set -e
TEST_FILE=${1:-dd_obs_testfile}
[ -e "$TEST_FILE" ]; TEST_FILE_EXISTS=$?
TEST_FILE_SIZE=134217728
# Header
@GrayedFox
GrayedFox / dd-ibs-test.sh
Created November 22, 2018 14:56
Output ideal input block size for use with dd
#!/bin/bash
# Since we're dealing with dd, abort if any errors occur
set -e
TEST_FILE=${1:-dd_ibs_testfile}
if [ -e "$TEST_FILE" ]; then TEST_FILE_EXISTS=$?; fi
TEST_FILE_SIZE=134217728
# Exit if file exists
@GrayedFox
GrayedFox / okr-alignment-models.js
Created March 27, 2019 13:27
OKR Alignment Models
// Architectural Assumptions
// * Objectives don't align to other Objectives, they should be aspirational/motivational and unique
// * The total progress of an Objective averages this.keyResultsProgress + linked.keyResultsProgress
// * Mapping key results to parent KRs is strictly optional (although that is sort of the point!)
// * KRs may inherit multiple alignments but can only ever align themselves to a single parent
// For a good answer as to why we want one-to-many see the answer of "Can I align to multiple
// objectives?" taken from here: https://www.perdoo.com/blog/okr-and-alignment/
// Note: linking cells in sheets is trivial, so that gets around typical inheritance type problems.
@GrayedFox
GrayedFox / getSlackIds.js
Created April 23, 2019 08:58
Get all Slack Member IDs of a Channel
// Open up the desired channel in the Slack web interface and run the following to generate display name/id pairs
const channelMembers = members = document.querySelectorAll('#channel_page_all_members div a')
const idNamePairs = {}
members.forEach( (div) => {
const name = div.children[2].firstElementChild.innerHTML
idNamePairs[name] = div.getAttribute('data-member-id')
})
@GrayedFox
GrayedFox / reviewBot.js
Last active July 2, 2019 12:33
Send personal review request messages via Slackbot channel (sample Gist for Zap integration)
// Zap Settings
// 1 use GitHub webhooks to send review request notifications to Zapier
// 2 apply text filter: action must exactly match "review_requested"
// 3 run some JavaScript (i.e. this script)
// 4 send a message to a channel (not a direct message), as a bot
// 5 use a custom value for the channel ID which takes the output channelId of this script
const reviewerName = inputData.reviewer.toLowerCase()
const requesterName = inputData.requester.toLowerCase()
@GrayedFox
GrayedFox / formulas.js
Last active May 16, 2021 12:50
Handy Formulas and Algorithms
// Calculate Triangle Possibility From Edges
// given a set of edges from 0 to N calculate if we can make at least one triangle from them
function triangleFromLengths(a) {
// the trick here is to sort the edges into ascending order
// given a = [10, 2, 5, 1, 8, 20], when sorted, we get [1, 2, 5, 8, 10, 20]
// ascending order guarantees that every value that suceedes another is either the same size or greater (A[0] <= A[1])
// this means that if the sum of any two edges preceeding a third is greater than that third (i.e. if 5 + 8 > 10)
// the triangle inequality theorem will hold true: https://www.wikihow.com/Determine-if-Three-Side-Lengths-Are-a-Triangle
// since: 5 + 8 > 10 && 8 + 10 > 5 && 5 + 10 > 8