Skip to content

Instantly share code, notes, and snippets.

@garyb
garyb / RAF.purs
Last active December 5, 2020 19:02
requestAnimationFrame looping subscription in Halogen 5
module RAF where
import Prelude
import Data.Foldable (traverse_)
import Data.Maybe (Maybe(..))
import Effect.Aff.Class (class MonadAff)
import Effect.Ref as Ref
import Halogen as H
import Halogen.HTML as HH
// Generated by purs bundle 0.12.0
var PS = {};
(function(exports) {
"use strict";
var replicate = function (count) {
return function (value) {
if (count < 1) {
return [];
}
@garyb
garyb / gistlist.md
Last active June 29, 2018 16:33
gistlist
@garyb
garyb / data.json
Created November 24, 2017 18:02
Structure edits
{ "a": 1, "b": { "ba": { "innermost": true }, "bb": ["x", false, { "foo": "bar" }], "bc": 0.5 }, "c": [] }
{ "a": 2, "b": { "ba": { "innermost": false }, "bb": ["y", true, { "foo": "baz" }], "bc": 60 }, "c": [true, false, "maybe"] }
{ "a": 3, "b": { "ba": true, "bb": ["z", { "foo": "quux" }] }, "c": null }
-- | Binary operation
class Magma a where
op ∷ a → a → a
-- | Associativity: `∀ a b. (a • b) • c = a • (b • c)`
class Magma a ⇐ Associative a
-- | Identity: `∀ a. a • identity = a && identity • a = a`
class Magma a ⇐ Identity a where
identity ∷ a
@garyb
garyb / typelevel-datetime.purs
Last active July 14, 2017 13:43
Type-level date/time formatter sketch
module Main where
import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
import Data.Symbol (class IsSymbol, SProxy(..), reflectSymbol)
-- First we define a HList with custom kinds, so that we can restrict it to
-- format stuff
@garyb
garyb / gist:3054646
Created July 5, 2012 16:25
JavaScript Bézier curve
// `a` and `d` are anchor points, `b` and `c` are control points, and `t` is a scalar that specifies the point on the curve you want
var calcBezierValue = function (a, b, c, d, t) {
if (t < 0 || t > 1) return null;
return { x: (t * t * (d.x - a.x) + 3 * (1 - t) * (t * (c.x - a.x) + (1 - t) * (b.x - a.x))) * t + a.x,
y: (t * t * (d.y - a.y) + 3 * (1 - t) * (t * (c.y - a.y) + (1 - t) * (b.y - a.y))) * t + a.y };
};
@garyb
garyb / gist:2006131
Created March 9, 2012 11:21
Very basic canvas displaylist
class Node
constructor: (@renderer) ->
@customMatrix = null
@rotation = 0
@scaleX = 1
@scaleY = 1
@x = 0
@y = 0
@children = []