Skip to content

Instantly share code, notes, and snippets.

@battermann
battermann / SameGame.scala
Last active April 17, 2023 13:47
SameGame
object SameGame {
final case class Position(col: Int, row: Int)
sealed trait Color
case object Green extends Color
case object Blue extends Color
case object Red extends Color
case object Brown extends Color
case object Gray extends Color
@battermann
battermann / free.fsx
Last active February 17, 2022 23:26
Free Monad like pattern in F#
#load @"paket-files/fsprojects/Chessie/src/Chessie/ErrorHandling.fs"
type Continuation<'output, 'next> = 'output -> 'next
module TerminalDsl =
open Chessie.ErrorHandling
type Terminal<'next> =
| WriteLine of string * Continuation<unit, 'next>
| ReadLine of unit * Continuation<string, 'next>
@battermann
battermann / io.fsx
Last active July 6, 2020 15:21
IO Monad in F#
[<AutoOpen>]
module IO =
type IO<'a> =
private
| Return of (unit -> 'a)
| Suspend of (unit -> IO<'a>)
let rec run x =
match x with
| Return v -> v()
module Main exposing (main)
import Bootstrap.CDN as CDN
import Bootstrap.Card as Card
import Bootstrap.Card.Block as Block
import Bootstrap.Form as Form
import Bootstrap.Form.Input as Input
import Bootstrap.Grid as Grid
import Bootstrap.Utilities.Spacing as Spacing
import Browser
@battermann
battermann / index.js
Created July 21, 2019 14:29
Web Midi with WebMidi.js
import WebMidi from 'webmidi'
var btn1 = document.createElement('BUTTON')
btn1.innerHTML = 'send to all channels'
btn1.onclick = function () { play(song, 'all') }
document.body.appendChild(btn1)
var btn2 = document.createElement('BUTTON')
btn2.innerHTML = 'only one channel'
btn2.onclick = function () { play(song, 1) }
public class Optimalstrategie : IStrategie
{
private List<Schnitt> _ausgangsgroessen;
private Schnittverteilung _best;
private ILaufzeitMonitor _monitor;
public Optimalstrategie(ILaufzeitMonitor monitor)
{
_monitor = monitor;
_best = null;
@battermann
battermann / fpmaxpureapp.scala
Created August 8, 2018 18:37
reimplementation of the program from "FP to the Max" by John De Goes (https://www.youtube.com/watch?v=sxudIMiOo68) with PureApp (https://github.com/battermann/pureapp)
import $ivy.`com.github.battermann::pureapp:0.6.0`
import com.github.battermann.pureapp._
import com.github.battermann.pureapp.interpreters.Terminal._
import cats.effect.IO
import cats.implicits._
import scala.util.Try
object Main extends StandardPureApp[IO] {
// The NUnit and Chessie Nuget packages are required for this
// To install NUnit and Chessie run the following commands from the Package Manager Console
// PM> Install-Package NUnit -Version 2.6.4
// PM> Install-Package Chessie
using System;
using System.Text.RegularExpressions;
using Chessie.ErrorHandling;
using Chessie.ErrorHandling.CSharp;
using Microsoft.FSharp.Core;
@battermann
battermann / App.xaml.cs
Last active December 8, 2018 00:11
Typesafe conversion of viewmodel property to observable stream
using System.Windows;
namespace PropertyToobsevable
{
public partial class App : Application
{
private void Application_Startup(object sender, StartupEventArgs e)
{
var vm = new MainWindowViewModel();
var mainWindow = new MainWindow { DataContext = vm };