Skip to content

Instantly share code, notes, and snippets.

💭
existing

Doruk Kutlu d0ruk

💭
existing
  • İstanbul
View GitHub Profile
View dual-mode.js
/*
Proof of concept: Writing dual-mode (sync and async) code via generators
Recommendation: start by reading the example (at the end).
API:
The API object is called `def`.
Dual-mode `await`: const unwrapped = yield wrapped;
Dual-mode `yield`: yield def.$one(singleValue)
Dual-mode `yield*`: yield def.$all(iterable)
@getify
getify / 1.js
Last active Mar 28, 2020
illustrating the hook/stale-closure problem
View 1.js
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
@developit
developit / *constant-locals-loader.md
Last active May 9, 2020
Inline Webpack CSS Modules classNames, reducing bundle size. https://npm.im/constant-locals-loader
View *constant-locals-loader.md

constant-locals-loader for Webpack

This loader optimizes the output of mini-css-extract-plugin and/or css-loader, entirely removing the potentially large CSS classname mappings normally inlined into your bundle when using CSS Modules.

Run npm install constant-locals-loader, then make these changes in your Webpack config:

module.exports = {
  module: {
View little-vdom-decompiled.js
/* 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,
@markmichon
markmichon / CircuitBreaker.js
Last active May 21, 2020
Basic CircuitBreaker Node
View CircuitBreaker.js
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 Jul 5, 2020
[bash-gist] A bash script for gist management #bash #gist
View README.md
View church-numerals.js
// 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
View number_proxy_range.js
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;
};
View providerCompose.js
function ProviderComposer({ contexts, children }) {
return contexts.reduceRight(
(kids, parent) =>
React.cloneElement(parent, {
children: kids,
}),
children
);
}
@rgrove
rgrove / body-parser-prototype-poisoning-fix.js
Last active Feb 8, 2019
How to protect against prototype poisoning when using the Express body-parser library
View body-parser-prototype-poisoning-fix.js
/*
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
You can’t perform that action at this time.