Skip to content

Instantly share code, notes, and snippets.

@sramam
sramam / njb-tryouts-2018-gscript.gs
Last active September 29, 2018 22:26
Script to setup tryout spreadsheet from registration data. setting-sheet.tsv contains all the externalities that can be changed and must be put on a sheet called "Settings" (note capitalization). Also the registration information exported as a .csv file, is assumed to be present in a sheet called "CSV" (again, note capitalization).
function createForm() {
// global constants, that drive the script
var G = {
Settings: 'Settings',
CSV: 'CSV',
Grade: {}
};
var SS = SpreadsheetApp.getActive();
@sramam
sramam / pmap-test.js
Created August 21, 2018 12:43
p-map - testing concurrency when errors happen
const pmap = require('p-map');
const delay = (n) => new Promise(res => setTimeout(res, n));
const promises = [
new Promise(async (res) => {
await delay(20);
res('a')
}),
new Promise(async (res) => {
@sramam
sramam / fizzbizz.js
Last active May 14, 2018 10:42
fizzbizz
/**
A fizzbizz implementation in modern JavaScript
*/
const fizzbizz = (n) => {
const fz = (n) => {
switch(true) {
case (n%15 === 0): return 'fizzbizz';
case (n%5 === 0): return 'bizz';
case (n%3 === 0): return 'fizz';
@sramam
sramam / cli-spinners.js
Last active May 16, 2018 11:44
cross platform spinners - cli-spinners
/**
List of spinners that work on Windows (and mac)
*/
'line,pipe,star2,flip,balloon2,noise,boxBounce2,bouncingBar,shark,dqpb,layer'.split(',')
@sramam
sramam / updateOrRecreate.ts
Created March 26, 2018 20:15
Maps oldData, newData and associated json-schema, to determine if update/recreate/no-op - not perfect, but a start
import * as traverse from 'json-schema-traverse';
import * as jsonFilter from 'json-schema-filter';
import * as concordance from 'concordance';
import * as _ from 'lodash';
import * as jsonPtr from 'json-ptr';
export enum Modification {
Update = 'Update',
Recreate = 'Recreate',
Noop = 'Noop'

Keybase proof

I hereby claim:

  • I am sramam on github.
  • I am sramam (https://keybase.io/sramam) on keybase.
  • I have a public key ASCI8gYhUTm48z9FzuBDI_JvHuzIHiZ7PfN8FcLgwhlEsQo

To claim this, I am signing this object:

@sramam
sramam / bank-account.js
Created March 17, 2018 20:56
A simple bank-account FSM, implemented in javascript-state-machine
const StateMachine = require('javascript-state-machine');
const Account = StateMachine.factory({
init: 'open',
transitions: [
// open state
{name: 'deposit', from: 'open', to: 'open'},
{name: 'withdraw', from: 'open', to: 'open'},
{name: 'available', from: 'open', to: 'open'},
@sramam
sramam / gist:ccd2f221a12b55a38e4fe47a40ccc7fc
Created March 17, 2018 00:48
Map & Reduce promises with concurrency throttling - an example
const pReduce = require('p-reduce');
const pMap = require('p-map');
const delay = require('delay');
// const batches = [['a'], ['b', 'c'], ['d', 'e', 'f', 'g'], ['h'], ['i'], ['j', 'k']];
const batches = [['a', 'b', 'c', 'd', 'e', 'f', 'g'], ['h'], ['i'], ['j', 'k']];
const step = 2000;
const max = 5000;
/**
script adapted from https://www.youtube.com/watch?v=pXUsW6VRQak
*/
function myFunction() {
var sheetName = 'Sheet1';
var formId = '1LnmQRJX0l586EvNeXYNLujO2vqhqB-Grtfe1J5zfFWI';
var title = 'Form Title here';
var description =
'Form description here.' +
'This should really be moved to a cell in the sheet.' +
@sramam
sramam / async_generators.ts
Created February 21, 2018 02:52
understanding async generators
import * as delay from 'delay';
(<any>Symbol).asyncIterator = Symbol.asyncIterator || Symbol.for("Symbol.asyncIterator");
async function* g() {
yield 1;
await delay(100);
yield* [2, 3];
yield* (async function *() {