Skip to content

Instantly share code, notes, and snippets.

View Pauan's full-sized avatar

Pauan

View GitHub Profile
@Pauan
Pauan / ADTs.js
Last active July 31, 2017 07:12
Microbenchmark for ADTs in JavaScript
var $benchmark = require("./benchmark");
var group = $benchmark.group;
var benchmark = $benchmark.benchmark;
var runBenchmarks = $benchmark.runBenchmarks;
function random(i) {
return Math.floor(Math.random() * i);
}
@Pauan
Pauan / Main.purs
Last active February 23, 2021 00:42
Canvas rendering in PureScript
module Main where
import Prelude
import Data.Maybe (Maybe(..))
import Control.Monad.Eff (Eff)
import Math (pi, cos, sin)
import Graphics.Canvas (CANVAS, Context2D, getCanvasElementById, getContext2D, setFillStyle, fillRect, moveTo, lineTo, withContext, setStrokeStyle, beginPath, closePath, stroke, CanvasElement, getCanvasWidth, getCanvasHeight, clearRect)
import DOM (DOM)
import DOM.HTML (window)
import DOM.HTML.Types (Window)
@Pauan
Pauan / LICENSE
Last active April 18, 2017 06:34
Fable Elmish Counter Sample (in vanilla JavaScript)
Copyright (c) 2017 Paul Chapman
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
module Main where
import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Class
import Control.Monad.Aff (launchAff, Aff, makeAff, attempt)
import Control.Monad.Aff.Console (CONSOLE, log)
import Control.Monad.Eff.Exception (Error, try)
import Network.HTTP.Affjax as Ajax
import Data.Either (Either(..), either)
@Pauan
Pauan / psc-bundle.js
Last active December 27, 2016 21:25
PureScript Tree Shaking Comparison
// Generated by psc-bundle 0.10.3
var PS = {};
(function(exports) {
// Generated by psc version 0.10.3
"use strict";
var Control_Category = PS["Control.Category"];
var $$const = function (a) {
return function (v) {
return a;
};
@Pauan
Pauan / Bar.fs
Created November 4, 2016 08:28
F# does not execute do statements in Foo.fs
module Bar
open Foo
do
System.Console.WriteLine(foo)
System.Console.WriteLine("Bar")
@Pauan
Pauan / commonjs-to-es6-modules.js
Created September 30, 2016 02:33 — forked from wegry/commonjs-to-es6-modules.js
purescript psc 0.9 output webpack loader that allows tree shaking
"use strict"
/*
* Webpack 2 loader that can take CommonJS output by psc 0.9.1 and convert
* it into tree shakable ES6 modules. No transpiling required.
*/
const fs = require('fs')
const commonJsRequire = /var ([_$a-zA-Z0-9]+) = require\([\'\"]([^\'\"]+)[\'\"]\)/g
const moduleExports = /module\.exports = \{(\n( ([\"\'_$a-zA-Z0-9]+): ([_$a-zA-Z0-9\.]+)(, )?\n)*)?\};/m
@Pauan
Pauan / Immutable-js.js
Created December 21, 2014 02:39
Benchmarks for Facebook's Immutable-js
var benchmark = require("./benchmark");
var immutable = require("immutable");
function generateKeys(counter) {
var keys = [];
while (counter--) {
keys.splice(Math.floor(Math.random() * keys.length), 0, "foo" + counter);
}