Skip to content

Instantly share code, notes, and snippets.

View BigAB's full-sized avatar
🇨🇦
JavaScript Loving Canadian

Adam L Barrett BigAB

🇨🇦
JavaScript Loving Canadian
View GitHub Profile
@BigAB
BigAB / function-utils.js
Created February 5, 2025 06:08
useful JSDoc typeguards for Promise.allSettled()
/**
* @template T
* @param {PromiseSettledResult<T>} input
* @returns {input is PromiseRejectedResult}
*/
const isRejected = (input) => input.status === 'rejected'
/**
* @template T
* @param {PromiseSettledResult<T>} input
@BigAB
BigAB / try-catch.ts
Last active September 9, 2024 05:52
A module to wrap function calls or functions so that they return a tuple return type with [error, value]
/*
* Example:
* // sync
* const [error, value] = tryCatch(() => doIt(50));
* const doItWithStandardResultType = tryCatchDef(doIt);
* // async
* const [error, value] = await tryCatch(() => doItAsync(50));
* const doItAsyncWithStandardResultType = tryCatchDef(doItAsync);
*/
@BigAB
BigAB / machine.js
Created September 15, 2020 21:01
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@BigAB
BigAB / queue.js
Created November 29, 2018 17:01
This is a simple queue structure, but it demostrates 2 things, private data in a class, and having both a construtctor and a factory function that do the exact same thing
function Queue(){
return createQueue();
}
function createQueue() {
const queue = [];
const q = Object.create(Queue.prototype, {
constructor: {
configurable: true,
enumerable: false,
value: Queue,
@BigAB
BigAB / ylem-mission.md
Last active May 31, 2018 16:22
On ylems mission

High Level Goals

  1. To generate high quality qualified sales leads.
  2. To be effective developers because we know and can fix big chunks of the stack.
  3. To give our developers a fun outlet for creativity.

Focus on "simpler and more scalable state management"

I think it's in Bitovi's best interests to start out pursuing the following mission and identity:

@BigAB
BigAB / old-school.js
Created March 3, 2018 01:04
A little snippet to use ES2018 code to old school load a bunch of UI Widgets, where the HTML configures the options of the UI widget and which element is to be enhanced with a stateful UI widget
const uiWidgets = {
draggable: class Draggable {
constructor({
element,
options: { dropZones = [], dragUI = 'standard' } = {}
}) {
Object.assign(this, {
element,
dropZones,
dragUI,
@BigAB
BigAB / ssl-on-localhost.md
Created October 31, 2017 17:06
A set of really simple commands to enable https over localhost for Mac

From paulbrowne.xyz

cd; mkdir .ssl

openssl req -newkey rsa:2048 -x509 -nodes -keyout .ssl/localhost.key -new -out .ssl/localhost.crt -subj /CN=localhost -reqexts SAN -extensions SAN -config <(cat /System/Library/OpenSSL/openssl.cnf <(printf '[SAN]\nsubjectAltName=DNS:localhost')) -sha256 -days 3650

sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain .ssl/localhost.crt
@BigAB
BigAB / async-transform.js
Last active November 23, 2016 15:48
Async Transform Function in JavaScript
/***************************************************/
function asyncTransform( transforms, val, context ) {
if (typeof val === 'undefined') {
return v => asyncTransform(transforms, v, context);
}
const v = Promise.resolve(val);
if (context) {
transforms = transforms.map( t => v => t.call(context, v));
}
@BigAB
BigAB / README.md
Last active September 29, 2016 08:20
CanReact problem: props always win

This just tries to demostrate the fact that because attr1 is supplied by props, even though the viewModels property keeps getting set, it just keeps going back to the props value because of the current implementation. To run the demo:

  • clone this repo (a gist is a repo)
  • run npm install (or npm i if you're nasty)
  • run npm start and checkout http://localhost:3000/
@BigAB
BigAB / my-stache-bindings.md
Last active September 23, 2016 04:28
Do we need more stache binding than this?

two-way binding

ParentVM to ChildVM Attr / DOM Attr¹

attribute="{ vmKey }"

one-way parent to child

attribute="{{ vmKey }}"