This file contains hidden or 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 findInDomAncestry = predicate => node => | |
typeof node.nodeType === 'undefined' || node.nodeType === Node.DOCUMENT_NODE | |
? undefined | |
: predicate(node) | |
? node | |
: findInDomAncestry(predicate)(node.parentNode); | |
/* | |
Example usage: | |
This file contains hidden or 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 reverse = ([head, ...rest]) => | |
!head ? [] : reverse([...rest]).concat([head]); |
This file contains hidden or 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 isEven = n => n === 0 ? | |
true : | |
!isEven(n - 1); |
This file contains hidden or 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 toObj = (keys, values, index = keys.length - 1) => | |
typeof keys[index] === "undefined" | |
? {} | |
: Object.assign( | |
toObj(keys, values, index - 1), | |
{ | |
[keys[index]]: values[index] | |
} | |
); |
This file contains hidden or 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 sum = (collection, runningTotal = 0) => | |
!collection.length ? | |
runningTotal : | |
sum(collection.slice(1), collection[0] + runningTotal); |
This file contains hidden or 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 range = (max, n = 0) => | |
n >= max ? | |
[] : | |
[n].concat(range(max, n+1)); |
This file contains hidden or 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
/** | |
* Sexy functional bits | |
* ---------------------------------------------------- | |
*/ | |
const range = max => Array.apply(null, Array(max)).map((_, i) => i); | |
const slice = (xs, index, size) => xs.slice(index, index + size); | |
const segmentSize = (len, iteration, segments) => | |
Math.ceil((len - iteration) / segments); |
This file contains hidden or 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 | |
/** | |
* Extract a substring from $input centered around $search with a maximum of $maxLength chars. | |
* | |
* | |
* @param string $input | |
* @param string $search The substring to search for. | |
* @param int $maxLength Maxlength of the excerpt, including delimiters. | |
* @param string $delimiter Character used to denote a break at the front or end of the excerpt. | |
* @return string |
This file contains hidden or 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
/** | |
* Usage: | |
* $('.my-nodes').each(parameterizeJqCallback(myFunction)); | |
* | |
*/ | |
const parameterizeJqCallback = (fn) => function(...args) { | |
return fn($(this), ...args); | |
}; |
This file contains hidden or 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
<p>This is the homepage.</p> | |
<a href="<% url('home') %>">A link to myself</a> | |
<!-- | |
This will throw an error: "No route found with the name:home" | |
--> |