Skip to content

Instantly share code, notes, and snippets.

@remydagostino
remydagostino / gist:6348814
Last active December 21, 2015 18:39
Calculate the width of the browser scrollbars. Credit: http://davidwalsh.name/detect-scrollbar-width
var getScrollbarWidth = function() {
var scrollbarWidth;
return (function() {
if (scrollbarWidth) {
return scrollbarWidth;
}
// Create the measurement node
var scrollDiv = document.createElement("div");
@remydagostino
remydagostino / intercept-bindings.js
Created September 9, 2013 07:22
Find duplicate ko.applyBindings
(function() {
var boundElements = [];
ko.applyBindings = function(vm, el) {
if (boundElements.indexOf(el) > -1) {
console.log("dupe", el);
}
boundElements.push(el);
};
@remydagostino
remydagostino / include-ko-templates.php
Created September 12, 2013 00:26
Create Include all files within a directory
<?php
function IncludeKoTemplates($path) {
$files = scandir(dirname(__FILE__).$path);
foreach($files as $file_name){
if( in_array($file_name,array(".","..")) ) continue;
$template_id = basename($file_name, ".html");
$contents = file_get_contents(dirname(__FILE__). $path . $file_name);
@remydagostino
remydagostino / sql-intersect-helper.php
Created September 13, 2013 00:36
A helper class to perform various kinds of intersections across related tables.
<?php
/**
* External logic for a complex search helper - keeps main files cleaner
*/
class SqlIntersectHelper{
// Outersects are the same as intersects but data lists without any entries will always be included in the result
// Any - Any value from the criterion list must exist at least once in the data list
@remydagostino
remydagostino / wings-example.js
Created March 26, 2014 02:13
Example Wings Javascript Interface
var app = (function() {
var self = {};
self.storage = {
get: function(key) {
return localStorage.getItem(key);
},
set: function(key, value) {
if (typeof value == "undefined") {
return localStorage.removeItem(key);
@remydagostino
remydagostino / functions.js
Last active August 29, 2015 14:02
Haskell JS ideas
var haskellFunction = hs.create(
hs.when('[]', function() {
}),
hs.when('(x:xs)',
//
hs.gaurd(hs.gte(5), function(self, a, x, xs, b) {
}),
hs.gaurd(hs.lte(2), function(self, a, x, xs, b) {
@remydagostino
remydagostino / autocurry.js
Created June 8, 2014 14:55
Tiny Autocurry
// curry :: ((a, b) -> c) -> a -> b -> c
function curry(fn) {
return function() {
if (arguments.length < fn.length) {
return curry(fn.bind.apply(fn, [this].concat(Array.prototype.slice.call(arguments))));
}
else {
return fn.apply(this, arguments);
}
}
@remydagostino
remydagostino / pure-obj.js
Created June 12, 2014 04:16
Idea for pure objects in javascript
// PureObj is an object wrapper for fantasy land
// which is pure, every change is cloned into
// a new object
// - Semigroup (concat)
// - monoid (empty)
// - functor (map)
// When a pure obj is created, the original values are cloned
// deeply into a new object
var myObj = PureObj({ a: 'hello' });
/* Functional Programming makes you look like a mad man
* Exhibit A.
* I define 23 helper functions so that I can write my solution point-free style
* - Remy D'Agostino
*/
// :: a -> b -> bool
var eq = autocurry(function(a, b) { return a === b; });
// :: a -> b -> bool
@remydagostino
remydagostino / add-number-array.js
Created July 21, 2014 01:38
Iterative Implementation
/**
* 654 + 59 = 713
* addArrayNumbers([6, 5, 4], [5, 9]) // [7, 1, 3];
*
* @param {Array} first
* @param {Array} second
* @return {Array}
*/
function addArrayNumbers(first, second) {
var result = [],