Skip to content

Instantly share code, notes, and snippets.

View msiegenthaler's full-sized avatar

Mario Siegenthaler msiegenthaler

View GitHub Profile
@msiegenthaler
msiegenthaler / Union.scala
Created June 22, 2011 21:11
Union Type in Scala with some experimental functions on top of it (like toEither)
import annotation.implicitNotFound
package object union {
private type ¬[A] = A => Nothing
private type ¬¬[A] = ¬[¬[A]]
private type ∧[A, B] = A with B
private type ∨[A, B] = ¬[∧[¬[A], ¬[B]]] // since (A ∨ B) ⇔ ¬(¬A ∧ ¬B)
sealed trait UnionInstance[A, B, T, -From, +To] {
@msiegenthaler
msiegenthaler / gist:2361997
Created April 11, 2012 19:58
HList and TypeEq
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, ScopedTypeVariables, UndecidableInstances, OverlappingInstances #-}
module OptTest () where
data HTrue
data HFalse
class HBool b where hBool :: b -> Bool
instance HBool HTrue where hBool _ = True
instance HBool HFalse where hBool _ = False
@msiegenthaler
msiegenthaler / import_bitbucket.rb
Created April 10, 2013 18:50
Import a whole directory structure of GIT repositories into bitbucket.
require 'find'
base = '/your/repostructure/root'
repo = 'you' # Bitbucket user
user = 'you'
pass = 'pass'
Find.find('../gits') do |path|
if File.basename(path) == '.git'
gitpath = File.dirname(path)
import scala.annotation.implicitNotFound
import scala.reflect._
object Protocol extends App {
def witness = null
sealed trait Action
sealed trait End extends Action
sealed trait Receive[Value, Next <: Action] extends Action
sealed trait Send[V, Next <: Action] extends Action {
@msiegenthaler
msiegenthaler / keybase.md
Created October 25, 2014 14:38
keybase.md

Keybase proof

I hereby claim:

  • I am msiegenthaler on github.
  • I am msiegenthaler (https://keybase.io/msiegenthaler) on keybase.
  • I have a public key whose fingerprint is D3EF DE59 51C0 6ED8 498A E137 5347 F80F 1FA9 C267

To claim this, I am signing this object:

import scalaz._
import scalaz.syntax.monad._
object Console {
import ConsoleOp._
def println(text: String): Console[Unit] = Free.liftFC(Println(text))
def readln: Console[String] = Free.liftFC(Readln())
//cannot use FreeC, because type inference for implicits will diverge
@msiegenthaler
msiegenthaler / random-color.coffee
Created October 21, 2015 16:15
Random color with Coffeescript
# Generates random color such as #f0d3a2
getRandomColor = () ->
letters = '0123456789ABCDEF'.split('')
color = '#'
for i in [0..5]
color += letters[Math.floor(Math.random() * 16)]
color
package example2
import cats.std.list._
import cats.std.function._
import cats.syntax.foldable._
import cats.state.State
import cats._
import cats.free._
object Console {
@msiegenthaler
msiegenthaler / FreeMacro.scala
Created November 5, 2015 16:24
Macro that auto-creates lifted functions for Free monads.
package free
import scala.annotation.{StaticAnnotation, compileTimeOnly}
import scala.language.experimental.macros
import scala.language.higherKinds
import scala.reflect.macros.whitebox
/**
* Usage:
[info] Running org.ensime.server.Server 
[error] Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
[error] Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release
[info] 14:27:38.992 INFO None a.e.s.Slf4jLogger - Slf4jLogger started
[info] 14:27:39.000 DEBUG EventStream(akka://ENSIME) a.e.EventStream - logger log1-Slf4jLogger started
[info] 14:27:39.003 DEBUG EventStream(akka://ENSIME) a.e.EventStream - Default Loggers started
[info] 14:27:39.043 INFO None o.a.c.v.i.StandardFileSystemManager - Using "/var/folders/zn/_wm6vwn95b73_2___c1j5l0w0000gn/T/vfs_cache" as temporary files store.
[info] 14:27:39.083 DEBUG akka://ENSIME/system/IO-TCP/selectors/$a/0 a.i.TcpListener - Successfully bound to /127.0.0.1:63571
[info]