Skip to content

Instantly share code, notes, and snippets.

View ericyd's full-sized avatar

Eric Yancey Dauenhauer ericyd

View GitHub Profile
@ericyd
ericyd / async-validation-with-generators.js
Created November 3, 2023 15:07
Async Validation with Generators
/**
* Running multiple validations asynchronously can present some interesting challenges,
* especially if the calling function should return a "result" type (or some other non-throwing value).
* There is even more complexity if you want to run the validations in sequence,
* and stop on the first failure.
*
* It is fairly easy to construct a meta function that executes the validators imperatively,
* but what if you want a more generic approach?
* This gist suggests a generic solution using generators, and slowly builds up the intuition
* until the final example shows a more realistic use case.
@ericyd
ericyd / git-stats.js
Last active January 19, 2023 18:22
Git repo stats
/**
* Hosted at: https://gist.github.com/ericyd/c36ff66a40c3b7ede7ac9dd95ae260af
* Usage:
* cd my-local-git-repo
* curl https://gist.githubusercontent.com/ericyd/c36ff66a40c3b7ede7ac9dd95ae260af/raw/git-stats.js > git-stats.js
* node git-stats.js
*/
const { exec } = require('child_process')
const { promisify } = require('util')
@ericyd
ericyd / SketchSystems.spec
Created January 6, 2021 21:24
User Registration
User Registration
User enters phone number -> Send authentication SMS
Send authentication SMS
User taps authentication link -> Prove checks mobile identity
Prove checks mobile identity
User is valid -> Registration complete
User is invalid -> Error message
@ericyd
ericyd / main.rs
Created March 24, 2020 04:20
Flow field in rust
// Cargo.toml
// ===============
// [package]
// name = "flow-field-1"
// version = "0.1.0"
// authors = ["ericyd <eric@ericyd.com>"]
//
// [dependencies]
// nannou = "0.13"
//
@ericyd
ericyd / baduuid.js
Created March 6, 2020 18:02
Poor man's UUID
/**
* This is NOT a cryptographically strong UUID algorithm
* It is purely for quick-n-easy drag-n-drop scripting applications where
* data quality does not matter.
*
* For a proper UUID implementation, see
* https://github.com/uuidjs/uuid/blob/master/src/v4.js
*/
const max = Math.pow(2, 8) - 1
// this slick trick thanks to https://github.com/uuidjs/uuid/blob/e8cb0a03a5408415d1f93a1499d8cda47246adc7/src/bytesToUuid.js#L7
@ericyd
ericyd / rainbow_phaser.ino
Created February 4, 2020 06:08
Arduino LEDs
/*
Basically, an experiment right now
*/
bool const DEBUG_NEXT_VALUE = false;
bool const DEBUG_CALCULATE_NEXT_VALUES = false;
struct RGB
{
double r;
@ericyd
ericyd / SketchSystems.spec
Last active January 24, 2020 01:27
Smart Deposits
Smart Deposits
First paycheck for employer -> Intro Carousel step 1
Subsequent paychecks for employer -> Receipt View
First Time experience
Intro Carousel step 1
Swipe to step 2 -> Intro Carousel step 2
Continue -> Edit View
@ericyd
ericyd / help.sh
Last active November 3, 2020 22:40
Helpful shell functions. Should work with Bash or Zsh
#!/bin/zsh --login
LOG_FILE="$(pwd)/qa-setup-$(date +%Y-%m-%d_%H.%M.%S%Z).log"
#############################
#
# Utilities and setup
#
#############################
warnings="\n\nResources / References\n======================\n\n"
@ericyd
ericyd / rgb.js
Last active December 31, 2019 03:51
Convert a number from an arbitrary scale to a color value
/////////////////////////
//
// Examples
//
// Live examples:
// https://observablehq.com/@ericyd/rgb-factory
//
/////////////////////////
console.log(rgbFactory()(0)); // { r: 212, g: 90.00000000000004, b: 90 }
@ericyd
ericyd / twoDimensionalArray.js
Last active October 25, 2019 04:52
Two dimensional array in JS
/*
It is common to address two-dimensional array problems with nested arrays.
It works, but then you have all these nasty references like array[0][3].
This class abstracts the element selection to a method which takes the x and y indices
as arguments.
If you wanted to go purely functional obviously you can, but this class demonstrates the idea.
*/
class TwoDimensionalArray {