Skip to content

Instantly share code, notes, and snippets.

Avatar

Guillaume Massé MasseGuillaume

View GitHub Profile
@MasseGuillaume
MasseGuillaume / worksheet.scala
Created Feb 24, 2014
Worksheet using scala reflexion toolbox
View worksheet.scala
val code = """def html[X, Y](xs: List[(X, Y)]) = xs.toString
val a = List((1,1))
a
val b = List((1,1))
b"""
val tree = tb.parse(code)
val identifiers = tree.children.collect{ case i @ Ident(_) => i }
val instrumentation = identifiers.map{ i =>
Apply(Select(Ident("scala"), TermName("Tuple2")),
@MasseGuillaume
MasseGuillaume / styles.less
Created Jul 24, 2014
Atom styles: padding + small scroll
View styles.less
// props: https://github.com/soloman1124/atom-solo-dark-ui
::-webkit-scrollbar {
width: 8px;
height: 8px;
}
::-webkit-scrollbar-track,
::-webkit-scrollbar-corner {
background: rgba(42, 42, 42, 0.5);
}
View gist:9c0c79a2468af211724b
object TC {
trait Ser[In, Out] {
def ser(in: In): Out
}
implicit object StringString extends Ser[String, String] {
def ser(a: String) = a
}
}
@MasseGuillaume
MasseGuillaume / sol.scala
Last active Aug 29, 2015
Twitter OSCON coding puzzle
View sol.scala
import scala.util.Try
val nl = System.lineSeparator
def gliff(xs: String) = {
xs.stripMargin.split(nl).to[List]
}
val gliffs =
Map(
View build.sbt
libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value
View ordering.scala
sealed trait Node[T]
case class Leaf[T](v: T) extends Node[T]
case class Branch[T](l: Node[T], r: Node[T]) extends Node[T]
implicit def nodeOrdering[W, C](implicit num: Numeric[W]): Ordering[Node[(W, C)]] = {
def weight(a: Node[(W, C)]): Tuple2[W, C] = a match {
case Leaf((w, c)) => (w, c)
case Branch(l, r) => {
val (wl, cl) = weight(l)
val (wr, _) = weight(r)
View MillionDollarHomepage.scala
/***
scalaVersion := "2.11.2"
resolvers ++= Seq(
"Sonatype" at "https://oss.sonatype.org/content/repositories/releases",
"spray repo" at "http://repo.spray.io"
)
libraryDependencies ++= Seq(
"io.spray" %% "spray-client" % "1.3.2-20140909",
View uri.scala
case class Uri(
scheme: String, user: Option[String], host: String, port: Option[Int],
path: List[String], query: List[String])
object Uri {
def unapply(uri: String): Option[Uri] = {
scala.util.Try(new java.net.URI(uri)).map{ v =>
Some(new Uri(v.getScheme, Option(v.getUserInfo), v.getHost, Option(v.getPort),
v.getRawPath.split("/").to[List], v.getRawQuery.split("&").to[List]))
}.getOrElse(None)
View xmonad.hs
--
-- xmonad example config file for xmonad-0.9
--
-- A template showing all available configuration hooks,
-- and how to override the defaults in your own xmonad.hs conf file.
--
-- Normally, you'd only override those defaults you care about.
--
-- NOTE: Those updating from earlier xmonad versions, who use
-- EwmhDesktops, safeSpawn, WindowGo, or the simple-status-bar
View TTFI.scala
object TTFI {
import scala.language.higherKinds
object Initial {
// {{{ OOP
object OOP {
// extending language is easy, adding more functions is hard since it
// involves having to modify each case class
trait Exp[A] {