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
<?php | |
abstract class IterableUtils | |
{ | |
public static function reduce(Iterable $collection, Callable $accumulator, $result = null) | |
{ | |
foreach ($collection as $item) { | |
$result = $accumulator($result, $item); | |
} |
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
import React from 'react' | |
import { render } from 'react-dom' | |
import Foo from './components/foo' | |
const components = { | |
foo: Foo | |
} | |
Object.keys(components) | |
.map(name => { |
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 promiseOnce () { | |
let promise = null | |
return function (createPromise) { | |
if (promise) { | |
return promise | |
} | |
promise = createPromise() |
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
.u-ratio | |
--ratioX 1 | |
--ratioY 1 | |
position relative | |
&:before | |
display block | |
padding-top calc(var(--ratioY) / var(--ratioX) * 100%) | |
content '' |
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
const log = (...message) => | |
console.log.apply(console, [ '[PREFIX]', ...message ]) | |
log('foo', 'bar', 'bat', 1, 2, 3) | |
// [PREFIX] foo bar bat 1 2 3 |
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
<?php | |
function l ($name) { | |
return function ($line) use ($name) { | |
file_put_contents($name, $line . PHP_EOL, FILE_APPEND); | |
}; | |
} |
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
<?php | |
function b () { | |
$start = microtime(true); | |
return function () use ($start) { | |
$end = microtime(true); | |
return $end - $start; | |
}; | |
} |
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
'use strict'; | |
const timeoutPromise = ms => promise => new Promise((resolve, reject) => { | |
const timeout = setTimeout(() => { | |
reject(new PromiseTimeout()); | |
}, ms); | |
promise.then( | |
res => { | |
clearTimeout(timeout); | |
resolve(res); |
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
const delay = delayPromise(1000) | |
delay(() => fetch('/')) | |
.then(console.log) |
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
/* | |
* !!! IMPORTANT !!! | |
* This has been modified to accept "onRemove" and "onAppend" callbacks. | |
* See comments 1, 2, and 3. | |
*/ | |
/*! appendAround markup pattern. [c]2012, @scottjehl, Filament Group, Inc. MIT/GPL | |
how-to: | |
1. Insert potential element containers throughout the DOM | |
2. give each container a data-set attribute with a value that matches all other containers' values | |
3. Place your appendAround content in one of the potential containers |