Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / food.md
Last active December 8, 2015 18:18
Vegan Berlin

These are my favorite vegan places in Berlin.

I've mostly avoided raw food because I don't usually like it, but if you're interested you'll probably find plenty in Berlin.

There's a big bias toward places that are near where I live, but there are many, many more places. You should use this map to find them.

Vegan berlin map

The list

@remydagostino
remydagostino / flip-files.el
Last active August 29, 2015 14:23
Flip between js, tmpl and css files in emacs
(defun open-if-exists (filename)
(when (file-exists-p filename) (set-buffer (find-file filename)) filename))
(defun get-flipped-ext (extension)
(cond ((string= extension "js") "tmpl")
((string= extension "tmpl") "css")
((string= extension "css") "js")
(t nil)))
(defun try-file-flip (base extension tries)
@remydagostino
remydagostino / custom.html
Created February 2, 2015 22:24
Custom Elm Reactor Template
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Main</title>
<style>
html, head, body { padding:0; margin:0; }
</style>
</head>
<body>
@remydagostino
remydagostino / jquery-fail-50.js
Created November 4, 2014 17:19
Fails 50% percent of requests
if (Math.random() > 0.5) {
return $.Deferred().reject({ id: sound.id }, '', {status: 400 });
}
@remydagostino
remydagostino / lambda.js
Last active August 29, 2015 14:05
Curried Functions With Guards
/*
Do you think this might be a useful way to do functional programming
in Javascript?
Gaurded, curried functions are created like:
Lambda(2).case(predicate, expression).case(predicate2, expression2);
The `2` specifies that the function accepts two arguments, it will
be partially applied if it is called with fewer (just like autocurry)
@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 = [],
/* 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