Skip to content

Instantly share code, notes, and snippets.

<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.0//EN' 'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>
<svg width='1000' height='1000'
xmlns='http://www.w3.org/2000/svg'
xmlns:xlink='http://www.w3.org/1999/xlink'
onload='init(evt)' >
<style>
@nbenns
nbenns / flame.html
Last active October 15, 2020 13:41
<html>
<body>
<canvas id="canvas1" width="500", height="500">
Random Canvas
</canvas>
<script type="text/javascript">
element = document.getElementById("canvas1");
c = element.getContext("2d");
import Data.List
quicksort :: Ord a => [a] -> [a]
quicksort [] = []
quicksort xs = quicksort lessThanPivot ++ equalToPivot ++ quicksort greaterThanPivot
where
(lessThanPivot, equalToPivot, greaterThanPivot) = epart (head xs) xs
epart :: Ord a => a -> [a] -> ([a], [a], [a])
epart n xs = inner ([], [], []) xs
where
{-# LANGUAGE GADTs, DataKinds, TypeFamilies, FlexibleInstances #-}
-- from my stackoverflow question: https://stackoverflow.com/questions/40939508/translate-a-scala-type-example-to-haskell
data Status = Open | Closed deriving(Show)
data Door (status :: Status) = Door
--OpenDoor :: Door Open
--ClosedDoor :: Door Closed
// From http://milessabin.com/blog/2011/06/09/scala-union-types-curry-howard/
type ∧[A, B] = A with B
type ¬[A] = A => Nothing
type ¬¬[A] = ¬[¬[A]]
type ∨[A, B] = ¬[¬[A] ∧ ¬[B]] // De Morgan equivalence
type <|[X, T] = ¬¬[X] <:< T // lift and check subtype
def size[T: ? <| (Int ∨ String)](t: T): Int =
t match {
sealed trait Json
case class JsonString(value: String) extends Json
sealed trait Yaml
case class YamlString(value: String) extends Yaml
object Symbols {
type |>[From, To] = Converter[From, To]
type <|[To, From] = Converter[From, To]
}
import scala.language.higherKinds
import cats.Functor
import cats.implicits._
/*
* A Free Functor is a Functor definition that doesn't care what F[_] is.
* We are Free from having to know about F[_] until we run() it.
* It uses the second Functor Law: fmap (g . f) = fmap g . fmap f
* FreeF is just a container that composes functions
* When you run it, you give it an actual container and the intial value
import com.amazonaws.auth.{AWSStaticCredentialsProvider, BasicAWSCredentials}
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder
import com.amazonaws.services.dynamodbv2.model._
import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType._
import scala.collection.convert.decorateAsJava._
val credentials = new BasicAWSCredentials("dev", "dev")
val credProvider = new AWSStaticCredentialsProvider(credentials)
val endpointConfiguration = new EndpointConfiguration("http://localhost:8000", "local")
@nbenns
nbenns / betterenum.scala
Created June 19, 2017 15:03
better scala enum with play reads/writes
import play.api.libs.json._
sealed trait Color
object Color {
type Red = Red.type
type Green = Green.type
type Blue = Blue.type
case object Red extends Color
case object Green extends Color
'use strict';
const R = require('ramda');
/*
* Mathematically, Monoids are a SemiGroup with an identity element.
*
* Monoids are defined under a certain operation, they require 3 things:
* the operation must be associative, so op(op(A,B),C) == op(A,op(B,C))
* an identity (sometimes called the Zero) such that type op(A, I) = A and op(I, A) = A,