Skip to content

Instantly share code, notes, and snippets.

Avatar

Li Haoyi lihaoyi

View GitHub Profile
View gist:4081484
import tools.nsc.plugins.{Plugin, PluginComponent}
import tools.nsc.Global
import tools.nsc.transform.{TypingTransformers, InfoTransform, Transform}
import tools.nsc.symtab.Flags
class MyPlugin(val global: Global) extends Plugin {
val name = "annotations-inject-implicit"
val description = "generates code which adds an implicit parameter of type BindingModule when an AutoInjectable trait is mixed in"
val components = List[PluginComponent](AnnotationsInjectComponent)
View gist:4583011
package main.scala
trait Enum[T]{ self =>
type E = this.type => T
implicit class k(e: E) extends Function0[T]{
def apply() = e(self)
}
}
View gist:5384596
def outer(x):
def inner():
print x
inner()
print x
outer(10) # 10 10
def outer(x):
View gist:5430318
var x
println("reset{} " +
reset{
shift{ cont: (Int => Int) =>
println("cont(1): " + cont(1))
println("cont(2): " + cont(2))
5
}
View gist:5577609
case class Thing(s: String){
def :=(t: Thing) = s + ": " + t.s
}
val float = Thing("float")
val left = Thing("left")
val backgroundImage = Thing("background-image")
def radialGradient(s: String) = Thing(s"radialGradient($s)")
val red = Thing("red")
val blue = Thing("red")
@lihaoyi
lihaoyi / gist:6386815
Last active March 19, 2022 12:22
Scala without braces/parens?
View gist:6386815
package metascala
import collection.mutable
import annotation.tailrec
import metascala.imm.Type
import metascala.rt.{Obj, FrameDump, Thread}
import metascala.natives.Bindings
import metascala.imm.Type.Prim
import org.objectweb.asm.ClassReader
import org.objectweb.asm.tree.ClassNode
View BasicOperations.scala
@JSExport
object ScalaJSExample{
@JSExport
def main(args: Array[String]): Unit = {
val xs = Seq(1, 2, 3)
println(xs)
val ys = Seq(4, 5, 6)
println(ys)
val zs = for{
x <- xs
View gist:dc63796497638d56fc2e
--- a/spray-util/src/main/scala/spray/util/pimps/PimpedRegex.scala
+++ b/spray-util/src/main/scala/spray/util/pimps/PimpedRegex.scala
@@ -20,12 +20,9 @@ import java.util.regex.Pattern
import scala.util.matching.Regex
class PimpedRegex(regex: Regex) {
def groupCount = {
try {
- val field = classOf[Pattern].getDeclaredField("capturingGroupCount")
- field.setAccessible(true)
View BasicOperations.scala
object ScalaJSExample extends js.JSApp{
def main() = {
val xs = Seq(1, 2, 3)
println(xs.toString)
val ys = Seq(4, 5, 6)
println(ys.toString)
val zs = for{
x <- xs
y <- ys
} yield x * y
View gist:18bc16c0d22c89ce49d6
def thing = {
val sp = span.value
lazy val box: HTMLTextAreaElement = textarea(
onChange := () => span.innerHTML = box.value
).value
div(box, sp)
}