Skip to content

Instantly share code, notes, and snippets.

@netzwerg
netzwerg / App.scala
Last active July 14, 2018 12:10
Parsing heterogeneous JSON with Circe
package ch.netzwerg
import cats.data.Xor
import io.circe._
import io.circe.generic.auto._
import io.circe.parser._
import org.scalajs.dom.document
import scala.scalajs.js
@netzwerg
netzwerg / FizzBuzz.java
Created May 1, 2016 05:06
FizzBuzz in Java 8 with Javaslang
import javaslang.collection.Stream;
/**
* An implementation of https://dierk.gitbooks.io/fregegoodness/content/src/docs/asciidoc/fizzbuzz.html
* using http://www.javaslang.io
*
* @author Rahel Lüthy
*/
public class FizzBuzz {
@netzwerg
netzwerg / ZipWithIndexTest.java
Created January 24, 2016 11:23
Using RC3, imperative variant is 2x faster (800 ms vs. 1800 ms), GC going nuts with all the tuples...
import javaslang.collection.Stream;
import org.junit.Test;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static org.junit.Assert.assertEquals;
public class ZipWithIndexTest {
@netzwerg
netzwerg / ZipSpeedTest.java
Created January 22, 2016 18:22
Using RC2, zip variant is 10x slower (1500 ms vs. 150 ms)
import javaslang.collection.List;
import org.junit.Test;
import java.util.Iterator;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class ZipSpeedTest {
private static final java.util.List<String> JAVA_LIST = IntStream.range(0, 1_000_000).mapToObj(String::valueOf).collect(Collectors.toList());
@netzwerg
netzwerg / RectangleOffsets.elm
Last active January 16, 2016 12:49
Demonstrates scanl to paste into http://www.elm-lang.org/try
import Color exposing (..)
import Graphics.Collage exposing (..)
import Graphics.Element
import Debug exposing (..)
type alias Rect = { width: Float, color: Color }
toForm : (Rect, Float) -> Form
@netzwerg
netzwerg / HoverableYogi.elm
Created January 14, 2016 19:42
Mouse hover example to paste into http://www.elm-lang.org/try
import Graphics.Element exposing (..)
import Signal exposing (..)
import Graphics.Input exposing (hoverable)
main : Signal Element
main =
Signal.map view hover.signal
hover : Signal.Mailbox String
hover = Signal.mailbox "–"
@netzwerg
netzwerg / CircleAnimation.elm
Created January 7, 2016 20:18
Circle animation to paste into http://www.elm-lang.org/try
import Color exposing (..)
import Graphics.Collage exposing (..)
import Graphics.Element exposing (..)
import Time exposing (..)
import Window
import List exposing (..)
import Debug
-- CONFIG
@netzwerg
netzwerg / Print.fr
Last active August 29, 2015 14:26
Behavior of putStr regarding line termination (Haskell vs. Frege vs. Java)
module Print where
-- Identical to the Haskell version (Print.hs)
-- Frege doesn't print line 7 (even a manual stdout.flush afterwards doesn't work)
main = do
putStrLn "A line with line termination"
putStr "A line without line termination, e.g. to prompt for input: "
line <- getLine
putStrLn ("You entered: " ++ line)