Skip to content

Instantly share code, notes, and snippets.

View MasseGuillaume's full-sized avatar

Guillaume Massé (马赛卫) MasseGuillaume

  • narrative.io
  • Montréal, Québec, Canada
  • 19:29 (UTC -04:00)
View GitHub Profile
@MasseGuillaume
MasseGuillaume / worksheet.scala
Created February 24, 2014 18:37
Worksheet using scala reflexion toolbox
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 July 24, 2014 13:36
Atom styles: padding + small scroll
// 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);
}
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 August 29, 2015 14:05
Twitter OSCON coding puzzle
import scala.util.Try
val nl = System.lineSeparator
def gliff(xs: String) = {
xs.stripMargin.split(nl).to[List]
}
val gliffs =
Map(
@MasseGuillaume
MasseGuillaume / build.sbt
Last active August 29, 2015 14:05
vars & vals
libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value
@MasseGuillaume
MasseGuillaume / ordering.scala
Created September 30, 2014 19:56
node ordering
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)
@MasseGuillaume
MasseGuillaume / MillionDollarHomepage.scala
Created October 4, 2014 23:06
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",
@MasseGuillaume
MasseGuillaume / uri.scala
Last active August 29, 2015 14:07
Uri Extractor
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)
@MasseGuillaume
MasseGuillaume / xmonad.hs
Created November 3, 2014 03:27
My xmonad config
--
-- 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
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] {