Skip to content

Instantly share code, notes, and snippets.

@webbower
webbower / _font-size.scss
Created February 28, 2014 04:51
SCSS font-size mixin for using rems with fallback
// strip-unit function courtest of Karl Merkli http://css-tricks.com/snippets/css/less-mixin-for-rem-font-sizing/
@function strip-unit($num) {
@return $num / ($num * 0 + 1);
}
// $size arg is the desired font size in pixels (e.g. @include font-size(16px);)
// Requires a $base-font-size variable be set and used like so:
//
// $base-font-size: 16px;
//
@webbower
webbower / p2rl.php
Created June 6, 2014 18:26
Takes an export file from Pocket (export format as of 2014-06-06) and imports the Unread items into Safari's Reading LIst
#!/usr/bin/env php
<?php
// OSA Script command line template
$osascriptTpl = 'osascript -e "tell application \"Safari\" to add reading list item \"%s\""';
// Read in export file from Pocket app
$pocketList = file_get_contents("{$_ENV['HOME']}/Downloads/ril_export.html");
// Get the ul that contains my unread list
@webbower
webbower / lib.lambdafy.54.php
Created June 24, 2014 22:20
Functional utility function to wrap a declared function in a passable variable for chaining (PHP 5.4+ version)
function lambdafy(callable $funcname) {
return function() use ($funcname) {
return call_user_func_array($funcname, func_get_args());
};
}
@webbower
webbower / lib.lambdafy.53.php
Created June 24, 2014 22:30
Functional utility function to wrap a declared function in a passable variable for chaining (PHP 5.3- version)
function lambdafy($funcname) {
if (function_exists($funcname)) {
return function() use ($funcname) {
return call_user_func_array($funcname, func_get_args());
};
}
throw new ErrorException('Catchable fatal error: Argument 1 passed to lambdafy() must be callable, string given', E_RECOVERABLE_ERROR);
}
@webbower
webbower / maybe.js
Last active August 29, 2015 14:05
Maybe monad in JS
// Requires testers.js for existy() and isRealNaN()
/**
* Maybe Monad (chainable, failure tolerant)
*
* Maybe(value, failOn).bind(function(value) { return value * value; }).value()
*/
var Maybe = function Maybe(val) {
if (!(this instanceof Maybe)) {
return new Maybe(val);
@webbower
webbower / testers.js
Created August 19, 2014 23:24
Value testing functions
function existy(val) {
return val !== undefined && val !== null && !isRealNaN(val);
}
function toClass(obj) {
return Object.prototype.toString.call(obj);
}
function isMaker(type) {
return function(val) {
@webbower
webbower / utils.misc.js
Last active August 29, 2015 14:05
Misc functional utilities
// Requires tester.js for isFunction()
function not(val) {
return !(value);
}
function unbind(fn) {
return function() {
return fn.apply(arguments[0], Array.prototype.slice.call(arguments, 1));
};
@webbower
webbower / utils.list.js
Created August 19, 2014 23:29
Functional list utilities
// Requires utils.misc.js for unbind() and testers.js for existy()
var slice = unbind(Array.prototype.slice);
function toList(arr) {
return existy(arr) ? slice(arr) : [];
}
function nth(index, list) {
return list[index];
@webbower
webbower / mfr.js
Created August 19, 2014 23:31
Recursive implementations of map, filter, reduce
// Requires utils.list.js for first() and rest()
function map(callback, list) {
if (!list.length) return [];
else return [callback(first(list))].concat(map(callback, rest(list)));
}
function filter(predicate, list) {
if (!list.length) return [];
else return (predicate(first(list)) ? [first(list)] : []).concat(filter(predicate, rest(list)));
@webbower
webbower / composition.js
Created August 19, 2014 23:34
Functional combinators and composition helpers
// 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());