This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def tapRender[B: ToRefTree](value: B) = { render(value); value } | |
def zipperControl[A](zipper: Zipper[A])(implicit toRefTree: ToRefTree[Zipper[A]]): Unit = { | |
Iterator | |
.continually(Console.in.read()) | |
.takeWhile(_ != 'q') | |
.filter(Set('w', 'a', 's', 'd')) | |
.foldLeft(tapRender(zipper)) { | |
case (z, 'w') ⇒ tapRender(z.tryMoveUp.orStay) | |
case (z, 'a') ⇒ tapRender(z.tryMoveLeft.orStay) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Definitions | |
# Functor map | |
def fmap(f): | |
if type == "object" then | |
map_values(f) | |
else | |
if type == "array" then | |
map(f) | |
else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# MIT License | |
# | |
# Copyright (c) 2017 Nick Stanchenko | |
# | |
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check whether the input array intersects the specified array of items | |
def intersects(items): | |
reduce .[] as $item (false; . or (items | index($item))); | |
# Find all references to other resources | |
def references(ref): | |
[.. | objects | ref | values]; | |
# Remove entries whose keys do not match the predicate | |
def filter_keys(pred): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class MapImplicit[A](f: A => A)(implicit current: A) { | |
def in[B](code: A => B) = code(f(current)) | |
} | |
// start with an implicit value | |
implicit val foo: Int = 3 | |
// prints “3” | |
println(implicitly[Int]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// git clone https://github.com/stanch/reftree && cd reftree | |
// sbt demo | |
def add(n: Int)(q: Queue[Int]) = Utils.iterate(q, n + 1)(q => q :+ (q.max + 1)).tail | |
def remove(n: Int)(q: Queue[Int]) = Utils.iterate(q, n + 1)(q => q.tail).tail | |
def addRemove(n: Int)(q: Queue[Int]) = Utils.flatIterate(q)(add(n), rm(n)) | |
val queues = Utils.flatIterate(Queue(1, 2, 3), 3)(addRemove(2)) | |
diagram.renderAnimation( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import de.sciss.fingertree.{FingerTree, Measure} | |
import reftree.{Diagram, Utils} | |
import reftree.contrib.FingerTreeInstances._ | |
implicit val measure = Measure.Indexed | |
val trees = Utils.iterate(FingerTree(1), 22)(t ⇒ t :+ (t.measure + 1)) | |
Diagram().renderAnimation("finger", tweakOptions = _.copy( | |
delay = 200, loop = false, onionSkin = 0, diffAccent = true, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import reftree.{Diagram, Utils} | |
import scala.collection.immutable.TreeSet | |
val adding = Utils.iterate(TreeSet(1), 15)(s ⇒ s + (s.size + 1)) | |
val removing = Utils.iterate(adding.last, 15)(s ⇒ s - s.size) | |
Diagram().renderAnimation("treeset", tweakOptions = _.copy( | |
delay = 200, onionSkin = 0, diffAccent = true, | |
verticalSpacing = 1.1, highlightColor = "coral1", density = 75 | |
))(adding ++ removing) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load.ivy("com.nimbusds" % "nimbus-jose-jwt" % "4.21") | |
load.ivy("org.bouncycastle" % "bcprov-jdk15on" % "1.51") | |
@ | |
import com.nimbusds.jose.jwk._ | |
import org.bouncycastle.util.io.pem._ | |
import java.io._ | |
def main(input: String) = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Street(name: String, house: Int) | |
case class Address(street: Street, city: String) | |
case class Person(address: Address, age: Int) | |
val person1 = Person(Address(Street("Functional Rd.", 1), "London"), 35) | |
val person2 = person.modify(_.address.street.house).using(_ + 3) | |
/* | |
┌───────────┐ ┌───────────┐ | |
│Person (35)│ │Person (35)│ |
NewerOlder