Skip to content

Instantly share code, notes, and snippets.

View ericyd's full-sized avatar

Eric Yancey Dauenhauer ericyd

View GitHub Profile
@ericyd
ericyd / get_combinations.rs
Last active April 30, 2018 19:40
Rust script to get all possible combinations of sets of vectors
// some experiments with combinations and deduping
// I think clippy has some good recommendations - I wrote this while learning Rust so it's rough
fn main() {
let arr = vec![vec![1, 1, 1], vec![2, 2, 2], vec![3, 3, 3], vec![4, 4, 4]];
let mut indices = arr.iter().map(|ref _x| 0).collect();
let mut paths: Vec<Vec<usize>> = vec![];
let paths = find_combinations(&arr, &mut indices, 0, &mut paths);
let paths_dedupe1 = dedupe(&paths, &mut vec![]);
/**
* Takes a date object and returns a string in the form YYYY-MM-DD
* e.g. formatDate(newDate()) should return 2017-02-17 for February 17, 2017.
*
* @param {date} d the date object to be formatted
*/
function formatDate (d = new Date()) {
// explain:
// | YYYY format | add leading 0 to Jan-Sep | month is 0-indexed | add leading 0 to days 1-9 | day of month
return `${d.getFullYear() }-${ d.getMonth() < 9 ? '0' : '' }${ d.getMonth() + 1 }-${ d.getDate() < 10 ? '0' : '' }${ d.getDate()}`;
@ericyd
ericyd / fuse_web_worker.js
Created September 14, 2018 17:19
Fuse JS Web Worker implementation
/************************
search.js
************************/
// an example of how to implement fuse.js with a web worker
var searchWorker; // initialized in document ready function
if(typeof(Worker) !== "undefined") {
if(typeof(searchWorker) == "undefined") {
searchWorker = new Worker('/scripts/searchWorker.js');
}
@ericyd
ericyd / compose.rb
Created November 16, 2018 06:05
Ruby Compose
add = Proc.new{|a| a + 2}
times = Proc.new{|a| a * 2}
def compose2(f, g)
Proc.new {|*x| f.call(g.call(*x))}
end
def compose(*x)
x.reduce { |all, a| compose2(all, a) }
end
@ericyd
ericyd / ostructify.rb
Created October 11, 2019 17:06
Ostructify: Recursively create OpenStructs of your hash or array or hashes
require 'ostruct'
# Recursively return OpenStructs from a hash or nested hash
# Handles array of hashes too
# Returns primitives when they are neither Hash nor Array
def ostructify(thing, camelize: false, snakify: false)
if thing.class == Hash
thing.reduce(OpenStruct.new) do |ostruct, (key, value)|
key = camelize ? camelize(key) : key
key = snakify ? snakify(key) : key
@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 {
@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 / 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 / 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 / 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;