Skip to content

Instantly share code, notes, and snippets.

View lihaoyi's full-sized avatar

Li Haoyi lihaoyi

View GitHub Profile
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)
package main.scala
trait Enum[T]{ self =>
type E = this.type => T
implicit class k(e: E) extends Function0[T]{
def apply() = e(self)
}
}
def outer(x):
def inner():
print x
inner()
print x
outer(10) # 10 10
def outer(x):
var x
println("reset{} " +
reset{
shift{ cont: (Int => Int) =>
println("cont(1): " + cont(1))
println("cont(2): " + cont(2))
5
}
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?
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
@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
--- 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)
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
def thing = {
val sp = span.value
lazy val box: HTMLTextAreaElement = textarea(
onChange := () => span.innerHTML = box.value
).value
div(box, sp)
}