Skip to content

Instantly share code, notes, and snippets.

View stephenjudkins's full-sized avatar

Stephen Judkins stephenjudkins

View GitHub Profile
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 {
@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 {
@stephenjudkins
stephenjudkins / gist:1628612
Created January 17, 2012 20:11
lift-json bug
{
import net.liftweb.json._
val json = """
{"a": "Value"}
"""
case class ExtractTo(a: String, b: Option[Boolean])
implicit val formats = DefaultFormats
println(parse(json).extract[ExtractTo])
}
@stephenjudkins
stephenjudkins / gist:1335736
Created November 3, 2011 03:57
Unfiltered matchers and responders working w/ Finagle
import com.twitter.finagle.builder.ServerBuilder
import com.twitter.finagle.http.Http
import com.twitter.finagle.{ClientConnection, Service}
import com.twitter.util.{Promise, Future}
import java.io.{ByteArrayOutputStream, BufferedReader, InputStreamReader}
import java.net.{URLDecoder, InetSocketAddress}
import java.nio.charset.{Charset => JNIOCharset}
import org.jboss.netty.buffer.{ChannelBuffers, ChannelBufferInputStream}
import org.jboss.netty.handler.codec.http.{HttpResponseStatus, DefaultHttpResponse, HttpVersion, CookieDecoder, HttpHeaders, HttpResponse => NHttpResponse, HttpRequest => NHttpRequest}
import unfiltered.Cookie
import annotation.tailrec
object SplitList {
def split[A](all: List[A], f: (A, A) => Boolean): List[List[A]] = {
@tailrec def _split(list: List[A], acc: List[List[A]], current: List[A]): List[List[A]] = list match {
case Nil => current match {
case Nil => Nil
case _ => acc ::: current :: Nil
}
require 'java'
module Java::scala::collection::Seq
def each(&block)
foreach &block
end
include Enumerable
end
2010-12-23 15:11:50.204:INFO::Logging to STDERR via org.mortbay.log.StdErrLog
2010-12-23 15:11:50.297:INFO::jetty-6.1.26
-> builtin/core_ext/symbol
<- builtin/core_ext/symbol - 449ms
-> enumerator
<- enumerator - 39ms
-> java
-> java
<- java - 0ms
-> builtin/javasupport/java
Around do |scenario, block|
RSpec::Mocks.setup(self)
RSpec::Mocks.teardown
block.call
RSpec::Mocks.verify
end
ruby-1.9.2-p0 > t = Time.now
=> 2010-10-27 17:41:00 -0700
ruby-1.9.2-p0 > t.utc?
=> false
ruby-1.9.2-p0 > t2 = t.utc
=> 2010-10-28 00:41:00 UTC
ruby-1.9.2-p0 > t
=> 2010-10-28 00:41:00 UTC
ruby-1.9.2-p0 > t.object_id
=> 2154182900