Skip to content

Instantly share code, notes, and snippets.

View stephenjudkins's full-sized avatar

Stephen Judkins stephenjudkins

View GitHub Profile
@stephenjudkins
stephenjudkins / gist:1725668
Created February 2, 2012 20:47
Start and stop background tasks in SBT
val runner = AttributeKey[Runner]("runner")
val start = TaskKey[Unit]("start", "start web runner")
val stop = TaskKey[Unit]("stop", "stop web runner")
trait Startable {
def start()
def stop()
}
class Runner {
@ {
import shapeless._
import shapeless.nat._
import shapeless.ops.nat._
import shapeless.ops.hlist._
trait Fizz
trait Buzz
trait Match[N <: Nat, FB] { def s: String }
@stephenjudkins
stephenjudkins / .bazelrc
Last active November 7, 2019 17:37
bazel-managed JDK
build --javabase=//:jdk
build --host_javabase=//:jdk
build --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
build --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
trait HListContains[-H <: HList, A] { def apply(h: H):A }
implicit def headContains[A, T <: HList] = new HListContains[A :: T, A] {
def apply(h: A :: T) = h.head
}
implicit def tailContains[A, H, T <: HList](implicit tc: HListContains[T, A]) = new HListContains[H :: T, A] {
def apply(h: H :: T) = tc(h.tail)
}
<stephenjudkins> luft: SBT can do anything, it's turing-complete
<stephenjudkins> there are examples of SBT tasks that generate scala source code
<dobblego> sbt is turing-complete? what does this mean?
<mapreduce> It can use an infinite amount of tape.
<stephenjudkins> luft: see https://github.com/twitter/sbt-scrooge
<dobblego> what does it mean specifically for sbt to be turing-complete?
<stephenjudkins> dobblego: use your imagination, and don't pick fights
<dobblego> jesus christ you are sook
<dobblego> it's a fucking question
<dobblego> can you tell me what it means please?
trait Imp[T] {}
object Imp {
implicit val i = new Imp[Int] {}
}
import Imp._
trait F {
type T
object Sort extends App {
//val toCells = (_: String).trim.split(" +")
//val input = io.Source.stdin.getLines.toList.map(toCells).foreach{line => }
val input = List("car", "truck", "8", "4", "bus", "6", "1")
val (matches, mismatches) = input.partition(_.matches("""\d+"""))
}
scala> @annotation.implicitNotFound("whoa there! ${A} is not ${B}, buddy") trait Equals[A,B]
defined trait Equals
scala> implicit def equals[A,B](implicit e: A =:= B):Equals[A,B] = null
equals: [A, B](implicit e: =:=[A,B])Equals[A,B]
scala> implicitly[Equals[String, Int]]
<console>:16: error: whoa there! String is not Int, buddy
implicitly[Equals[String, Int]]
^
scala> @annotation.implicitNotFound("oh no! could not find Foo with ${A} ${B}") trait Foo[A,B]
defined trait Foo
scala> implicitly[Foo[String, Int]]
<console>:12: error: oh no! could not find Foo with String Int
implicitly[Foo[String, Int]]
import bytecask.Bytecask
import org.slf4j.{LoggerFactory, Logger}
import akka.dispatch.Future
import annotation.tailrec
import org.slf4j.helpers.{NOPLoggerFactory, SubstituteLoggerFactory}
private def tellLoggerToStfu() {
@tailrec def impl(i: Int, wait: Long) {
Thread.sleep(wait - 1)
LoggerFactory.getILoggerFactory() match {