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
(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) |
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
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Main</title> | |
<style> | |
html, head, body { padding:0; margin:0; } | |
</style> | |
</head> | |
<body> |
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
if (Math.random() > 0.5) { | |
return $.Deferred().reject({ id: sound.id }, '', {status: 400 }); | |
} |
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
/* | |
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) |
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
/** | |
* 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 = [], |
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
/* 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 |
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
// 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' }); |
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
// 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); | |
} | |
} |
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
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) { |
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
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); |