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
// Requires utils.list.js for toList(), first(), and rest() | |
function tap(callback, val) { | |
callback(val); | |
return val; | |
} | |
function flip(fn) { | |
return function() { | |
return fn.apply(this, toList(arguments).reverse()); |
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://frontendbabel.info/articles/css-tricks-by-wargaming/ */ | |
.abs-center { | |
position: absolute; | |
top: 0; | |
bottom: 0; | |
left: 0; | |
right: 0; | |
margin: auto; | |
} |
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://frontendbabel.info/articles/css-tricks-by-wargaming/ */ | |
.text-overflow { | |
white-space: nowrap; /* No line breaks */ | |
overflow: hidden; /* Hide text which does not fit the block */ | |
text-overflow: ellipsis; /* Cut off with ellipsis */ | |
display: block; /* Works only for block elements */ | |
} |
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
Array.apply(null, Array(n)); | |
Array.from({length: 10}, (_, i) => i + 1) |
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
var n = 10; | |
// Simple squaring function | |
function square(n) { | |
return n * n; | |
} | |
// Flip the first and second args of a function signature | |
function flip(fn) { | |
return function(a, b) { |
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 safeLoop(max) { | |
max = (+max) || 100; | |
// Track how many times the function has been called | |
var ctr = 1; | |
return function(cmp) { | |
// Loop count test and increment counter. If we’re under the max and the live comparison is truthy, return the live comparison | |
if ((ctr++) > max) return false; | |
// Otherwise, return the comparison |
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 existy(value) { | |
return value !== undefined && value !== null; | |
} | |
function falsey(value) { | |
return !existy(value) || value === false; | |
} | |
function truthy(value) { | |
return !falsey(value); |
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 getProp($data, $key) { | |
if (is_object($data)) { | |
return $data->$key; | |
} else if (is_array($data)) { | |
return $data[$key]; | |
} | |
return $data; |
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 | |
/** | |
* Immutable (uses ->copy() to modify instances), properties are implicitly defined by constructor signature, getting an undefined property | |
* throws an exception, type check instance properties, iterate over properties?... | |
*/ | |
class ScalaCaseClass { | |
public function __construct() | |
{ | |
// Somehow make it very easy to have all the arguments in the signature map to publicly accessible (faux-)instance properties |
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
someElement.addEventListener('click', function(ev) { | |
var url = someElement.get('data-url'); | |
if(e.metaKey || e.ctrlKey) window.open(url); | |
else window.location = url; | |
}, false); |