Skip to content

Instantly share code, notes, and snippets.

@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;
@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'))
@RabaDabaDoba
RabaDabaDoba / ANSI-color-codes.h
Last active May 14, 2024 18:33 — 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"
@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
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;
};
// 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
@typebrook
typebrook / README.md
Last active May 10, 2024 18:57
A bash script for gist management #bash #gist
@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()
@marvinhagemeister
marvinhagemeister / little-vdom-decompiled.js
Created March 8, 2020 14:13
Jason little-vdom decompiled
/* eslint-disable no-unused-vars */
/* eslint-disable no-else-return */
// JSX constructor, similar to createElement()
export const h = (type, props, ...children) => {
return {
type,
// Props will be an object for components and DOM nodes, but a string for
// text nodes
props,
@getify
getify / 1.js
Last active March 28, 2020 14:59
illustrating the hook/stale-closure problem
function SomeCounter() {
const [ counter, updateCounter ] = useState(0);
useEffect(function listening(){
const btn = document.getElementById("increment-counter-btn");
btn.addEventListener("click",onClick);
},[]);
useEffect(function logger(){
// this logger() is updated each time `counter` changes, so