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
# https://stackoverflow.com/a/6022431/2684520 | |
function line() { | |
sed "${1}q;d" "$2" | |
} |
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
$is-included : () !default; | |
@mixin once( $name ) { | |
@if include-once( $name ) { | |
@content; | |
} | |
} | |
@function include-once( $name ) { | |
@if index( $is-included, $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
// https://css-tricks.com/snippets/javascript/javascript-keycodes/ | |
/*Key Code | |
backspace 8 | |
tab 9 | |
enter 13 | |
shift 16 | |
ctrl 17 | |
alt 18 | |
pause/break 19 | |
caps lock 20 |
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
// Functions | |
// https://css-tricks.com/snippets/sass/px-to-em-functions/ | |
@function emy($pixels, $context: $base-font-size) { | |
@if (unitless($pixels)) { | |
$pixels: $pixels * 1px; | |
} | |
@if (unitless($context)) { | |
$context: $context * 1px; |
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 beginsWith(baseStr, targetStr) { | |
return baseStr.indexOf(targetStr) === 0; | |
} | |
function endsWith(baseStr, targetStr) { | |
return baseStr.substr(-targetStr.length) === targetStr; | |
} |
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 pipe(...$fns) { | |
return function($x) use ($fns) { | |
return array_reduce( | |
$fns, | |
function($acc, $fn) { return $fn($acc); }, | |
$x | |
); | |
}; |
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
// A Unit test template for Tape | |
// See 5 Questions every unit test must answer: | |
// https://medium.com/javascript-scene/what-every-unit-test-needs-f6cd34d9836d | |
import test from 'tape'; | |
test('What are you testing?', assert => { | |
const msg = 'what should it do?' | |
const actual = 'what was the output?'; |
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
// trace() is a utility to let you easily inspect | |
// the contents. | |
const trace = x => { | |
console.log(x); | |
return x; | |
}; | |
const tap = (fn, tapper) => (...args) => { | |
const result = fn(...args); | |
tapper(result); |
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
// http://en.wikipedia.org/wiki/Fisher-Yates_shuffle#The_modern_algorithm | |
// https://stackoverflow.com/a/12646864/2684520 | |
// Pre-ES6 | |
/** | |
* Randomize array element order in-place. | |
* Using Durstenfeld shuffle algorithm. | |
*/ | |
function shuffleArray(array) { | |
for (var i = array.length - 1; i > 0; 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
// https://stackoverflow.com/a/2450976/2684520 | |
// https://bost.ocks.org/mike/shuffle/ | |
function shuffle(array) { | |
var m = array.length, t, i; | |
// While there remain elements to shuffle… | |
while (m) { | |
// Pick a remaining element… | |
i = Math.floor(Math.random() * m--); |