Skip to content

Instantly share code, notes, and snippets.

View cakesmith's full-sized avatar

Nick LaRosa cakesmith

  • Diameter Health
  • New Jersey
View GitHub Profile
@cakesmith
cakesmith / coroutines-and-generators.js
Created January 24, 2021 02:44 — forked from adambene/coroutines-and-generators.js
Coroutines and generators in JavaScript
function* delays() {
let a = yield delay(800, "Hello, I'm an");
console.log(a);
let b = yield delay(400, "async coroutine!");
console.log(b);
}
const coroutine = nextValue => iterator => {
const { done, value } = iterator.next(nextValue);
@cakesmith
cakesmith / options-objects.js
Created July 26, 2016 20:24 — forked from rwaldron/options-objects.js
ES6 Object.assign( target, source ) as a native options object merging pattern.
let defaults = { file: null };
function foo(options) {
// Merging defaults and options objects in ES6
options = [ defaults, options ].reduce(Object.assign, {});
}
foo({ file: "happy.md" });
@cakesmith
cakesmith / balancedPatternMatcher.cs
Created November 19, 2015 20:14 — forked from anonymous/balancedPatternMatcher.cs
Balanced pattern matcher regular expression generator
// Match everything inside balancing groups ['<' and '>'] (Variables) and ['{' and '}'] (Macros)
// ex: <This is A Variable> and {This is a macro}
// http://goo.gl/Rjo6Ih
public static string PatternBuilder(char open, char close)
{
return $"(((?<open>{open})[^{open}]*)+([^{open}]*(?<close-open>{close}))+).*?(?(open)(?!))";
}
public static string caretPattern => PatternBuilder('<', '>');