All your notes, scripts, config files and snippets deserve version control and tagging!
gist
is a simple bash script for gist management.
It is lightweight(~700LOC) and dependency-free! Helps you to boost coding workflow.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://unpkg.com/@webcomponents/custom-elements"></script> | |
<style> | |
body { | |
margin: 0; | |
} | |
/* Style the element from the outside */ | |
/* | |
fancy-tabs { | |
margin-bottom: 32px; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* 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 |