Skip to content

Instantly share code, notes, and snippets.

@kevinwright
kevinwright / autoThingy.scala
Last active August 29, 2015 14:07
AutoThingy
import shapeless._
trait Thingy[T] { def stringy(t:T): String }
implicit def autoThingy[T <: Product](implicit gen: LabelledGeneric[T]) : Thingy[T] = new Thingy[T] {
def toRecord[T <: Product, Repr](obj: T)(implicit lg: LabelledGeneric.Aux[T, Repr]): Repr = lg.to(obj)
def stringy(t: T) = {
val rec = toRecord(t)
val keys = rec.keys
keys.mkString
@kevinwright
kevinwright / LabelledGenericOddness.scala
Created October 21, 2014 10:55
LabelledGeneric Oddness
import shapeless._
case class Wibble(x: Int, y: String)
val wib = Wibble(42, "towel")
def recOf[T](obj: T)(implicit gen: LabelledGeneric[T]) = gen.to(obj)
recOf(wib) // works beautifully
class ClassyRecOf[T](implicit gen: LabelledGeneric[T]) {
def doIt(obj: T) = gen.to(obj)
@kevinwright
kevinwright / DeferredActorRef.scala
Last active August 29, 2015 14:07
Sending to an actor you don't know yet...
import akka.actor._
import scala.collection.mutable
case class DeferredActorRef(implicit factory: ActorRefFactory) {
private[this] val innerActor = factory.actorOf(Props(new TheActor))
private[this] case class SetRef(ref: ActorRef)
private[this] class TheActor extends Actor with ActorLogging {
val buffer: mutable.Queue[(Any, ActorRef)] = mutable.Queue.empty
@kevinwright
kevinwright / keybase.md
Last active February 13, 2018 14:54
keybase.md

Keybase proof

I hereby claim:

  • I am kevinwright on github.
  • I am thecoda (https://keybase.io/thecoda) on keybase.
  • I have a public key whose fingerprint is 7B0A E482 1479 D389 A452 49B7 EF27 0EC3 7CC6 9FE9

To claim this, I am signing this object:

@kevinwright
kevinwright / stacktrace.txt
Created July 1, 2014 19:03
epic fail in macros...
java.lang.NullPointerException
at scala.reflect.internal.Scopes$Scope.unlink(Scopes.scala:202)
at scala.reflect.internal.Scopes$Scope.unlink(Scopes.scala:222)
at org.scalamacros.paradise.typechecker.Namers$Namer$MaybeExpandeeCompleter$$anonfun$destroy$1.apply(Namers.scala:301)
at org.scalamacros.paradise.typechecker.Namers$Namer$MaybeExpandeeCompleter$$anonfun$destroy$1.apply(Namers.scala:299)
at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
at scala.collection.mutable.WrappedArray.foreach(WrappedArray.scala:35)
at org.scalamacros.paradise.typechecker.Namers$Namer$MaybeExpandeeCompleter.destroy(Namers.scala:299)
at org.scalamacros.paradise.typechecker.Namers$Namer$$anon$2.maybeExpand(Namers.scala:393)
at org.scalamacros.paradise.typechecker.Namers$Namer$MaybeExpandeeCompleter.completeImpl(Namers.scala:320)
@kevinwright
kevinwright / scaladays2014.md
Last active March 8, 2018 20:25
Scaladays 2014 slides

As compiled by Kevin Wright a.k.a @thecoda

(executive producer of the movie, and I didn't even know it... clever huh?)

please, please, please - If you know of any slides/code/whatever not on here, then ping me on twitter or comment this Gist!

This gist will be updated as and when I find new information. So it's probably best not to fork it, or you'll miss the updates!

Monday June 16th

#!/bin/bash
if [ $# -lt 2 ]; then
echo "format: git_cleanup <repo name> [-x/--expunge <directory 1> -l/--keeplatest <directory 2> ...]"
exit
fi
PROJ="$1"
shift
@kevinwright
kevinwright / minevaluator.sh
Created May 1, 2014 20:36
minified evaluator
#!/bin/bash
set -f
SUBBED=($(sed -e "s,multiply,*,g" -e "s,divide,/,g" -e "s,add,+,g" -e "s,subtract,-,g" -e "s,apply,,g" -e "s, *,,g" $1))
EXPR=""
for (( idx=${#SUBBED[@]}-1 ; idx>=0 ; idx-- )) ; do EXPR="($EXPR ${SUBBED[idx]})"; done
echo $(($EXPR))
#!/bin/bash
#disable globbing of the *
set -f
INPUT=$1
SUBBED=($(
sed \
-e "s,multiply,*,g" \
trait Proletariat {
type BigNumberT
def retirementAge: BigNumberT
val bippy = "hi mum"
def twiddle = 42
def twaddle = 1
}
trait BiggerTwaddle {