Skip to content

Instantly share code, notes, and snippets.

View scottwrobinson's full-sized avatar

Scott Robinson scottwrobinson

View GitHub Profile
@scottwrobinson
scottwrobinson / retry.js
Created November 16, 2023 22:33
Retry logic for any async function. Specify error validation, number of retries, delay, etc.
const delay = ms => {
return new Promise(fulfill => {
setTimeout(fulfill, ms);
});
};
const callWithRetry = async (fn, {validate, retries=3, delay: delayMs=2000, logger}={}) => {
let res = null;
let err = null;
for (let i = 0; i < retries; i++) {
@scottwrobinson
scottwrobinson / .babelrc
Last active February 15, 2016 22:53
Working example for use with babel-preset-camo (see Camo issue #17)
{
"presets": ["camo", "stage-0"]
}
@scottwrobinson
scottwrobinson / brain-mnist.js
Created December 7, 2015 15:22
Brain.js example for training and testing on MNIST data
var brain = require('brain');
var fs = require('fs');
var getMnistData = function(content) {
var lines = content.toString().split('\n');
var data = [];
for (var i = 0; i < lines.length; i++) {
var input = lines[i].split(',').map(Number);
@scottwrobinson
scottwrobinson / sublimelinter-jshint-issue-70.js
Last active August 29, 2015 14:23
Follow directions described by comments on lines 482 and 489 to recreate SublimeLinter-jshint issue #70
"use strict";
var Document = require('camo').Document;
class Source extends Document {
constructor() {
super();
// BUG: Type 'this.a' below to recreate: https://github.com/SublimeLinter/SublimeLinter-jshint/issues/70
// Setup: jshint v2.5.11, sublimelinter-jshint v1.2.1, io.js 2.2.1