Skip to content

Instantly share code, notes, and snippets.

View gist:457325e8901b866bebc0
import java.io.PrintWriter
import scala.io.Source
implicit class Using[T <: AutoCloseable](resource: T) {
def foreach[R](op: T => R): R = {
try op(resource)
catch { case e: Exception => throw e }
finally resource.close()
}
View gist:515c241100d1e68e2522
import java.io.PrintWriter
import scala.io.Source
import scala.util.continuations._
trait ContextType[B]
def contextType[B]: ContextType[B] = null
def using[A <: AutoCloseable, B: ContextType](resource: A)(op: A => B) = {
View gist:62589714b12315aaf1c1
val n = reset {
println("A")
val num = shift { (cont: Int => Int) =>
println("B")
cont(cont(1))
}
println("num", num)
num * 2
}
println("n", n)
View gist:39f6fc6b7203e26adf7a
val plus012 = Array((_: Int) + 0,
(_: Int) + 1,
(_: Int) + 2)
/* plus012.apply(1) で (_: Int) + 1 を取り出して、2 を渡す */
plus012(1)(2) // 3
/* SeqがPartialFunction[Int, A]を継承しているので orElseを呼べる
* plus: PartialFunction[Int, (Int) => Int] */
val plus = plus012.orElse[Int, Int => Int] { case i => (_: Int) + i }
View gist:33e7444b390be6142ede90632f648708
implicit class ArgmaxColl[A, CC[X] <: Seq[X]](val coll: CC[A]) extends AnyVal {
def argmax(implicit o:Ordering[A]): Int = coll.indices.maxBy(coll)
}
val as = scala.util.Random.shuffle(1 to 10)
as.argmax
@Yuichiroh
Yuichiroh / mouse_point.lua
Last active Jul 30, 2020
そこそこ便利そうなマウス強調表示できた
View mouse_point.lua
-- mouse highlighting
_c = require("hs.canvas")
function createCanvas(screen)
local cp = hs.mouse.getAbsolutePosition()
local f = screen:frame()
canvas = _c.new(f):show()
canvas[1] = {
action = "build",
type = "circle",
You can’t perform that action at this time.