Skip to content

Instantly share code, notes, and snippets.

Avatar
🏜️
🚙🛸🌵🛰

Bret bcomnes

🏜️
🚙🛸🌵🛰
View GitHub Profile
View promise-backoff.js
var pause = (duration) => new Promise(res => setTimeout(res, duration));
var exponentialBackoff = (func, attempts = 1, delay = 50) => {
console.log('attempts', attempts)
return func().catch(err => {
console.log('error', err)
if (attempts > 1) {
console.log(`Retries left ${attempts - 1}`)
console.log(`Next delay ${delay * 2}`)
return pause(delay).then(() => exponentialBackoff(func, attempts - 1, delay * 2))
@bcomnes
bcomnes / Jenkinsfile
Created Dec 8, 2018
Git env vars you might need in jenkins
View Jenkinsfile
/*
Jenkins ENV Reference:
env.GIT_COMMIT: the commit sha of the current build
env.BRANCH_NAME: the branch name OR tag name of the current build, when it exists
env.GIT_BRANCH: same as BRANCH_NAME
env.TAG_NAME: the tag name of the current build, when it exists
*/
View .gitignore
node_modules
coverage
.nyc_output
@bcomnes
bcomnes / launch.json5
Last active Mar 11, 2018
How to set up vs code debugger with a run script
View launch.json5
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
// https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_launch-configuration-support-for-npm-and-other-tools
"version": "0.2.0",
"configurations": [
{
"name": "Launch via test NPM",
"type": "node",
View gist:12d7bb78088159dee24a642c8a96bb6f

Epistle 3

I hope this letter finds you well. I can hear your complaint already, “Gordon Freeman, we have not heard from you in ages!” Well, if you care to hear excuses, I have plenty, the greatest of them being I’ve been in other dimensions and whatnot, unable to reach you by the usual means. This was the case until eighteen months ago, when I experienced a critical change in my circumstances, and was redeposited on these shores. In the time since, I have been able to think occasionally about how best to describe the intervening years, my years of silence. I do first apologize for the wait, and that done, hasten to finally explain (albeit briefly, quickly, and in very little detail) events following those described in my previous game (referred to herewith as Episode 2).

To

@bcomnes
bcomnes / idb-dat-storage.js
Created Jan 18, 2018 — forked from creationix/idb-dat-storage.js
A simple abstract-random-access implementation using indexed DB that takes advantage of hypercore's behavior or consistent boundaries/offsets.
View idb-dat-storage.js
/* eslint-env browser */
var Buffer = require('buffer').Buffer
var name = 'dat'
function withStore (type, block, callback) {
var req = indexedDB.open(name + '-db', 1)
req.onerror = () => callback(req.error)
req.onupgradeneeded = () => req.result.createObjectStore(name)
req.onsuccess = () => {
@bcomnes
bcomnes / cloudSettings
Last active Jan 29, 2018
Visual Studio Code Settings Sync Gist
View cloudSettings
{"lastUpload":"2018-01-05T23:15:02.658Z","extensionVersion":"v2.8.7"}
View ctx-dom-event-handler.js
// https://medium.com/@WebReflection/dom-handleevent-a-cross-platform-standard-since-year-2000-5bf17287fd38
export default class DOMEventHandler {
constructor(ctx, node) {
if (!ctx) throw new Error("DOMEventHandler: A context is required.");
this.ctx = ctx;
if (node) this.addEventListeners(node);
}
get events() {
return (
View index.js
const CC = require('class-cache')
const Class = require('some-class')
function gc (instance, key, Class) {
return instance.element
}
const c = new CC({
gc // DEFAULT GC function... most of the time you do this
// Return bool to keep or toss