Skip to content

Instantly share code, notes, and snippets.

View lihaoyi's full-sized avatar

Li Haoyi lihaoyi

View GitHub Profile
@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)
def thing = {
val sp = span.value
lazy val box: HTMLTextAreaElement = textarea(
onChange := () => span.innerHTML = box.value
).value
div(box, sp)
}
import utest._
object Tests extends TestSuite
val tests = TestSuite do
'simple do
'class-assert((new scalite.simple.Class)() == "Hello World!12")
'assignments-assert((new scalite.simple.Assignments)() == 9)
'modassignments-assert((new scalite.simple.ModAssignments)() == 9)
'ifelsewhile-assert((new scalite.simple.IfElseWhile)() == 40)
'ifelsewhilelite-assert((new scalite.simple.IfElseWhileLite)() == 36)
package com.example
import akka.actor.Actor
import spray.routing._
import spray.http._
import MediaTypes._
// we don't implement our route structure directly in the service actor because
// we want to be able to test it independently, without having to spin up an actor
package com.example
import akka.actor.Actor
import spray.routing._
import spray.http._
import MediaTypes._
// we don't implement our route structure directly in the service actor because
// we want to be able to test it independently, without having to spin up an actor
def words(s: String): Set[String]
def makeWordMap(sentences: List[String]) = {
val forwardMap = sentences.map(s => (s, words(s))).toMap
sentences.flatMap(words)
.distinct
.map(w => sentences.filter(forwardMap(s)))
}
def makeWordMap2(sentences: List[String]) = {
package ammonite.sh2
import acyclic.file
import scala.collection.{immutable => imm}
object PConfig{
implicit val pc = new PConfig()
}
case class PConfig(maxDepth: Int = 100, depth: Int = 0)
object PPrint extends LowPriPPrint{
@lihaoyi
lihaoyi / gist:c069926724b1739a1b69
Last active August 29, 2015 14:15
Ammonite REPL Demo
[info] Running ammonite.repl.Repl
@ Range(0, 5).ma
max map maxBy
@ while(true) ()
Interrupted!
@ val x = 1
x: Int = 1
@ val y = 2
y: Int = 2
// Input Scala sources
def lightIsVisible(l: Vec, p: Vec) = {
val ray = Ray(p, l - p)
val length = (l - p).magnitude
var visible = true
for (i <- 0 until objects.length){
val (o, s) = objects(i)
val t = o.intersectionTime(ray)
if (t > Epsilon && t < length - Epsilon){
visible = false