Skip to content

Instantly share code, notes, and snippets.

@markmichon
markmichon / CircuitBreaker.js
Last active July 23, 2021 21:13
Basic CircuitBreaker Node
class CircuitBreaker {
constructor(request) {
this.request = request
this.state = "CLOSED"
this.failureThreshold = 3
this.failureCount = 0
this.successThreshold = 2
this.successCount = 0
this.timeout = 6000
this.nextAttempt = Date.now()
@typebrook
typebrook / README.md
Last active April 4, 2024 14:00
A bash script for gist management #bash #gist
// Y Combinator
const Y = a => (b => b (b)) (b => a (c => b (b) (c)))
// isomorphic Church encoding/decoding
const Church = {
to: n => f => x => Array.from (Array (n)).reduce (f, x),
from: f => f (x => x + 1) (0)
}
const True = a => b => a
Number.prototype.to = function*(n) {
let finish = n.valueOf();
let start = this.valueOf();
let finishLessThan = start >= finish;
for (
let i = start;
finishLessThan ? i >= finish: i <= finish;
i += finishLessThan ? -1 : +1
) yield i;
};
@rgrove
rgrove / body-parser-prototype-poisoning-fix.js
Last active February 8, 2019 18:33
How to protect against prototype poisoning when using the Express body-parser library
/*
The Express body-parser library, which you may be using to parse incoming JSON
request bodies, doesn't currently protect against prototype poisoning via the
`__proto__` key.
The dangers of prototype poisoning are described in detail here:
https://hueniverse.com/a-tale-of-prototype-poisoning-2610fa170061
Until body-parser provides its own fix, you can protect yourself by adding a
reviver function that throws an error if it sees any key named "__proto__". This
@RabaDabaDoba
RabaDabaDoba / ANSI-color-codes.h
Last active April 19, 2024 06:01 — forked from iamnewton/bash-colors.md
The entire table of ANSI color codes working in C!
/*
* This is free and unencumbered software released into the public domain.
*
* For more information, please refer to <https://unlicense.org>
*/
//Regular text
#define BLK "\e[0;30m"
#define RED "\e[0;31m"
#define GRN "\e[0;32m"
@john-doherty
john-doherty / javascript-promise-timeout.js
Last active December 17, 2021 02:06
Adds a timeout to a JavaScript promise, rejects if not resolved within timeout period (uses requestAnimationFrame for better accuracy)
(function () {
'use strict';
/**
* wraps a promise in a timeout, allowing the promise to reject if not resolve with a specific period of time
* @param {integer} ms - milliseconds to wait before rejecting promise if not resolved
* @param {Promise} promise to monitor
* @example
* promiseTimeout(1000, fetch('https://courseof.life/johndoherty.json'))
@ebidel
ebidel / fancy-tabs-demo.html
Last active March 8, 2024 23:08
Fancy tabs web component - shadow dom v1, custom elements v1, full a11y
<script src="https://unpkg.com/@webcomponents/custom-elements"></script>
<style>
body {
margin: 0;
}
/* Style the element from the outside */
/*
fancy-tabs {
margin-bottom: 32px;
@olih
olih / jq-cheetsheet.md
Last active April 20, 2024 06:34
jq Cheet Sheet

Processing JSON using jq

jq is useful to slice, filter, map and transform structured json data.

Installing jq

On Mac OS

brew install jq

@paullewis
paullewis / requestIdleCallback.js
Last active February 21, 2024 16:56
Shims rIC in case a browser doesn't support it.
/*!
* Copyright 2015 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software