Skip to content

Instantly share code, notes, and snippets.

View Softsapiens's full-sized avatar

Daniel Pous Montardit Softsapiens

View GitHub Profile
@ceedubs
ceedubs / gist:d705dc450596ae75e45c
Last active August 29, 2015 14:07
Turning List[Int => Int] into Int => List[Int] with cosequence
import scalaz.std.function._
import scalaz.syntax.functor._
import scalaz.Functor
/* https://gist.github.com/ceedubs/f8273ede78f86df7df7f shows we can do this with sequenceU.
* Stephen Compall (S11001001) pointed out that cosequence can do this without requiring a
* Traverse instance of the outer type by using the Distributive instance of the inner type.
* (It still requires a Functor instance of the outer type, but many types such as Task, Future,
* etc have Functor but not Traverse.)
*/
@nraychaudhuri
nraychaudhuri / TypedAkkaActorRef.scala
Last active August 29, 2015 14:05
Typed Akka actor ref
//PLEASE NOTE: Typing actor refs are really hard problem(take a look at the discussions in Akka mailing list regarding this subject). This is no way a complete solution. This will only work if you know all the possible
//messages an actor can handle (that means no become/unbecome business).
package experiment
import akka.actor.{Props, ActorSystem, Actor, ActorRef}
case class TypedActorRef[A](actorRef: ActorRef) extends AnyVal {
def ![B](msg: B)(implicit ev: A <:< B, sender: ActorRef = Actor.noSender) = actorRef ! msg
}
package org.paulbetts.shroom.core;
import android.os.AsyncTask;
import com.squareup.okhttp.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
package com.rr.experiment
import org.specs2.ScalaCheck
import org.specs2.mutable._
import org.scalacheck._
import scalaz._
import scodec._
@pchiusano
pchiusano / Json.scala
Last active November 7, 2023 12:53
Simple JSON parser combinator library that does not use zippers
// WARNING! totally untested, I have only compiled the code! :)
package json
import collection.immutable.Map
import scalaz.{\/, MonadPlus}
import scalaz.\/._
import scalaz.std.vector._
import scalaz.std.map._
import scalaz.std.list._
package com.codecommit.scatter
import scodec._
import scalaz._
import scalaz.stream._
trait Server[Key, Value] {
type Transformer <: Server.Transformer[Value]

Reading SBT Credentials from OS X Keychain

In the following, replace the REPO_NAME value with the natural-language name of your repository, replace REPOSITORY with the domain name (e.g. repo1.maven.org) and replace USERNAME with your repository user.

credentials += {
  val Password = """.*password: "([^"]+)".*""".r
  var lines: String = ""
  val logger = new ProcessLogger {
 def info(s: =&gt; String) = {}
import scala.language.experimental.macros
import scala.reflect.macros.whitebox.Context
class Foo {
override def toString: String = macro Foo.toStringImpl
}
object Foo {
def toStringImpl(c: Context): c.Expr[String] = {
import c.universe._
@milessabin
milessabin / gist:71ea435a2f2ec8a381c1
Created July 14, 2014 14:01
fixpoint combinator in Scala using shapeless's Lazy (it could be done similarly with Scalaz's Need).
scala> import shapeless._
import shapeless._
scala> def fix[A](f: Lazy[A] => Lazy[A]): Lazy[A] = f(Lazy(fix(f).value))
fix: [A](f: shapeless.Lazy[A] => shapeless.Lazy[A])shapeless.Lazy[A]
scala> val step = (rec: Lazy[Int => Int]) => Lazy((n: Int) => if(n == 0) 1 else n*rec.value(n-1))
step: shapeless.Lazy[Int => Int] => shapeless.Lazy[Int => Int] = <function1>
scala> val fact = fix(step).value
@luciferous
luciferous / Op.scala
Last active January 20, 2019 15:32
Church-encoded free and operational monad
sealed trait ~>[F[_], G[_]] {
def apply[A](f: F[A]): G[A]
}
trait Monad[M[_]] {
def pure[A](a: A): M[A]
def flatMap[A, B](a: M[A])(f: A => M[B]): M[B]
}
object Monad {