Skip to content

Instantly share code, notes, and snippets.

View ericyd's full-sized avatar

Eric Yancey Dauenhauer ericyd

View GitHub Profile
@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 / 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 <[email protected]>"]
//
// [dependencies]
// nannou = "0.13"
//
@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 / 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 / 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.