Skip to content

Instantly share code, notes, and snippets.

View countdown-timer.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Countdown Timer</title>
<style>
body, html {
display: flex;
align-items: center;
justify-content: center;
View Main.hs
{-# 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
View 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
View textnode-innerhtml.js
/**
* 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 =
View arrayEq.coffee
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
View bind.coffee
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