Skip to content

Instantly share code, notes, and snippets.

@rsuniev
rsuniev / gist:1120957
Created August 2, 2011 19:18 — forked from dcsobral/gist:1120811
Existential _ vs Higher-kind _
scala> def f[A[_] <: Seq[_]](f: A[Int]) = f.head
f: [A[_] <: Seq[_]](f: A[Int])A
scala> def f[A[_] <: Seq[t] forSome { type t }](f: A[Int]) = f.head
f: [A[_] <: Seq[_]](f: A[Int])A
scala> def f[A[t] <: Seq[_] forSome { type t}](f: A[Int]) = f.head
f: [A[t] <: Seq[_] forSome { type t }](f: A[Int])A
@rsuniev
rsuniev / ApplicativeMagic.scala
Created August 4, 2011 19:19 — forked from jsuereth/ApplicativeMagic.scala
reason #37 Why macros against Function1->22 would be useful..
trait ApplicativeMagic[F[_]] {
def apply[C](f: ApplicativeMagicFunctionHolder[FunctionArg => C]): F[C]
type FunctionArg
}
class ApplicativeMagicFunctionHolder[F](val f: F)
object ApplicativeMagicFunctionHolder {
implicit def fix2[A,B,C](f: (A,B) => C): ApplicativeMagicFunctionHolder[Tuple2[A,B] => C] =
new ApplicativeMagicFunctionHolder({ case (a,b) => f(a,b) })
implicit def fix3[A,B,C,D](f: (A,B,C) => D): ApplicativeMagicFunctionHolder[Tuple2[Tuple2[A,B],C] => D] =
new ApplicativeMagicFunctionHolder({ case ((a,b),c) => f(a,b,c) })
@rsuniev
rsuniev / gist:1166584
Created August 23, 2011 21:21 — forked from milessabin/gist:1164885
Boxed lazy values
// Is this even faintly novel? The closest I've seen is
//
// http://stackoverflow.com/questions/2618891/using-lazy-evaluation-functions-in-varargs
//
// which is a bit clunky by comparison. But this is so trivial someone must have
// done it this way before.
// UPDATE:
// Thanks to the Twittersphere (@etorreborre, @pchiusano and @loverdos) for a few sightings of related things,
//
@rsuniev
rsuniev / lensed.scala
Created September 25, 2011 10:55 — forked from gseitz/lensed.scala
Lensed
// see https://github.com/gseitz/Lensed
object Lensed {
import scalaz._
import Scalaz._
case class Address(street: String, number: Int)
case class Person(name: String, address: Address)
@rsuniev
rsuniev / SCC-scalaz.scala
Created October 16, 2011 08:24 — forked from mads-hartmann/SCC-scalaz.scala
Strongly Connected Components algorithm implemented in Scala using ScalaZ
/*
This is implemented following the instructions in "The Design and Analysis of
Computer Algorithms, AHO Hopcroft Ullman, 1974".
The implementation uses a DFS to find the strongly connected components (SCCs)
of a graph. During the DFS the vertices are placed on a stack in the order
they are visited. Whenever a root is found, all vertices of the corresponding
SSC are on the top of the stack and are popped.
@rsuniev
rsuniev / SCC.scala
Created October 16, 2011 08:25 — forked from mads-hartmann/SCC.scala
Strongly Connected Components algorithm implemented in Scala
/*
This is implemented following the instructions in "The Design and Analysis of
Computer Algorithms, AHO Hopcroft Ullman, 1974".
The implementation uses a DFS to find the strongly connected components (SCCs)
of a graph. During the DFS the vertices are placed on a stack in the order
they are visited. Whenever a root is found, all vertices of the corresponding
SSC are on the top of the stack and are popped.
<blueprint xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
xmlns:camel="http://camel.apache.org/schema/blueprint"
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<camel:camelContext xmlns="http://camel.apache.org/schema/blueprint" id="paginationRouteContext">
</camel:camelContext>
ActiveMQ Task-1] FailoverTransport INFO Successfully connected to tcp://MacBook-Pro.local:57022
[.local/172.28.1.21:57022@58129] FailoverTransport WARN Transport (tcp://MacBook-Pro.local/172.28.1.23:57022@58129) failed, reason: , attempting to automatically reconnect
java.io.EOFException
at java.io.DataInputStream.readInt(DataInputStream.java:392)
at org.apache.activemq.openwire.OpenWireFormat.unmarshal(OpenWireFormat.java:258)
at org.apache.activemq.transport.tcp.TcpTransport.readCommand(TcpTransport.java:221)
at org.apache.activemq.transport.tcp.TcpTransport.doRun(TcpTransport.java:213)
at org.apache.activemq.transport.tcp.TcpTransport.run(TcpTransport.java:196)
at java.lang.Thread.run(Thread.java:745)
[ main] ZooKeeper INFO Session: 0x148d131f76d002b closed
package derivation
import shapeless._
import shapeless.ops.coproduct.Length
import shapeless.ops.nat.ToInt
import scala.util.Random
sealed trait Animal
case class Cat(name: String, fish: Int) extends Animal
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext
import scala.concurrent.Future
import akka.pattern.after
import akka.actor.Scheduler
/**
* Given an operation that produces a T, returns a Future containing the result of T, unless an exception is thrown,
* in which case the operation will be retried after _delay_ time, if there are more possible retries, which is configured through
* the _retries_ parameter. If the operation does not succeed and there is no retries left, the resulting Future will contain the last failure.