Skip to content

Instantly share code, notes, and snippets.

arrayEq = (a, b) ->
if a is b
# 0 isnt -0
a isnt 0 or 1/a is 1/b
else if a instanceof Array and b instanceof Array
return no unless a.length is b.length
return no for el, idx in a when not arrayEq el, b[idx]
yes
else
# NaN is NaN
unless Function::bind?
Function::bind = (scope, args...) ->
target = this
if typeof target isnt "function" then throw new TypeError
bound = ->
unless this intanceof bound
return target.apply scope, [args..., arguments...]
F = ->
F.prototype = target.prototype
self = new F
@michaelficarra
michaelficarra / countdown-timer.html
Last active August 29, 2015 14:24 — forked from anonymous/index.html
countdown timer
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Countdown Timer</title>
<style>
body, html {
display: flex;
align-items: center;
justify-content: center;
{-# LANGUAGE PolyKinds, KindSignatures, MultiParamTypeClasses #-}
module Main where
class Category (arr :: k -> k -> *) where
id :: arr t t
(.) :: arr b c -> arr a b -> arr a c
instance Category (->) where
id x = x
@michaelficarra
michaelficarra / monads.js
Last active August 29, 2015 14:07 — forked from pselle/monads.js
function Container(val) {
this.val = val
}
// Functor's `fmap` in Haskell
Container.prototype.map = function(f) {
return new Container(f(this.val));
};
// Monad's `>>=` (pronounced bind) in Haskell
/**
* Proof of concept ESLint rule for warning about potential
* XSS vulnerabilities caused by mixing innerHTML/text node
* property access.
*
* More here: http://benv.ca/2012/10/2/you-are-probably-misusing-DOM-text-methods/
*/
'use strict';
var WARNING_MSG =