Skip to content

Instantly share code, notes, and snippets.

@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
@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' });
@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 / 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 / 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);