Skip to content

Instantly share code, notes, and snippets.

View clinuxrulz's full-sized avatar

Clinton Selke clinuxrulz

View GitHub Profile
@clinuxrulz
clinuxrulz / Main.purs
Last active June 12, 2020 16:42
JavaScript monad in PureScript
module Main where
import Prelude
import Data.Array.ST as STArray
import Control.Monad.Eff.Console (log) as Console
import Control.Monad.Eff (runPure, Eff)
import Control.Monad.Rec.Class (tailRecM)
import Control.Monad.ST (newSTRef, runST, readSTRef, writeSTRef, ST, STRef)
import Data.Array.ST (pushSTArray, emptySTArray, STArray)
import Data.Either (either, Either(Left, Right))
public interface Draw {
void drawLine(double x1, double y1, double x2, double y2);
}
public class DrawUtil {
public static void drawBox(Draw draw, double x1, double y1, double width, double height) {
draw.drawLine(x1, y1, x1 + width, y1);
draw.drawLine(x1 + width, y1, x1 + width, y1 + height);
@clinuxrulz
clinuxrulz / index.html
Created April 23, 2017 07:01
Load XML embedded in Zip in JavaScript (uses JSZip)
<html>
<head>
<script src="lib/jszip.min.js"></script>
</head>
<body>
<input type="file" id="file" name="file" />
<output id="list"></output>
<script>
function handleFileSelect(evt) {
var f = evt.target.files[0];
(Weak Ref)
+-------------+ +-----------------+
| | | | (Returned)
V | | V
loop_s :: forall a b. (Stream a -> (Stream a, b)) -> (Stream a, b)
| ^
| | (Returned)
+------------------------------+
@clinuxrulz
clinuxrulz / node.rs
Created September 27, 2017 03:52
FRP node idea
struct Node {
id: u32,
rank: u32,
update: Box<FnMut()>,
children: Vec<Weak<Node>>
}
struct Context {
next_id: u32,
transaction_depth: u32,
@clinuxrulz
clinuxrulz / UpdateGraphMut.java
Created October 30, 2017 20:54
FRP without finalizers
package test;
import fj.F;
import fj.F2;
import fj.data.Option;
import java.lang.ref.WeakReference;
import java.util.Comparator;
import java.util.Optional;
import java.util.Vector;
@clinuxrulz
clinuxrulz / DependsOnAnyOf.ts
Created November 1, 2017 01:13
Dependency Fusion
interface DependsOnAnyOf {
fn dependsOnAnyOf(v: Vertex[]): boolean;
fn toFixedDependsOnAnyOf(): FixedDependsOnAnyOf? {
return null;
}
fn toDeferredDependsOnAnyOf(): DeferredDepensOnAnyOf? {
return null;
}
@clinuxrulz
clinuxrulz / cooroutine.txt
Last active November 28, 2017 01:38
Cooroutine for Mode notes
data AwaitF a
= SelectRoof (RoofBlock -> a)
| AskDistIn (Double -> a)
| AskOverhang (Double -> a)
data YeildF a
= InsertRoof roofBlock a
data Mode = FreeT AwaitF YieldF ()
@clinuxrulz
clinuxrulz / Mode.hs
Created December 12, 2017 07:15
Generalized Mode
data Mode f m = Mode (f (m, Mode f m))
-- f is a f-algebra representing the input the mode is wait on, it has a functor instance
-- m is a monoid representing the effects that get pushed out once the input gets recieved
-- f is like await
-- m is like yield
@clinuxrulz
clinuxrulz / AltUtil.java
Created December 15, 2017 00:16
Alt experiment many() some() fix()
package org.highj.typeclass1.alternative;
import org.derive4j.hkt.__;
import org.highj.data.List;
import org.highj.data.tuple.T1;
import org.highj.data.tuple.T2;
import org.highj.function.F1;
import org.highj.typeclass1.LazifyH;
import org.highj.typeclass1.monad.Applicative;