Skip to content

Instantly share code, notes, and snippets.

View yuroyoro's full-sized avatar
🍣
🍣

しいたけ yuroyoro

🍣
🍣
View GitHub Profile
trait Memoized[T,R] {
import scala.collection.mutable._
private[this] val cache = new HashMap[T,R]
def cacheOrApply( t:T )( f: => R ):R = cache get(t) getOrElse{
val rv = f
cache += t -> rv
rv
}
}
trait Memorized[T,R] {
import scala.collection.mutable._
val cache = new HashMap[T,R]
def cacheOrApply( t:T )( f: => R ):R = cache get(t) getOrElse{
val rv = f
cache += t -> rv
println("do %s:%s" format(t, rv))
rv
}
object AAMaker {
import util.Random
val rnd = new Random
def asSeq[T](xs:Seq[Product]) = xs.map{_.productIterator.toSeq.asInstanceOf[Seq[T]]}
def choice[T](xs:Seq[T]):T = xs(rnd.nextInt(xs.size))
val rinkaku = asSeq[String](Seq(("(", ")"), ("(", ")"), ("|", "|"), ("|", "|")))
var otete = asSeq[String](Seq(("", "", "", "", ""), ("", "", "m", "", ""), ("", "", "ლ", "", ""), ("ლ", "", "", "ლ", ""), ("", "「", "", "", "「"), ("", " つ", "", "", "つ"), ("", " ", "", "", "o彡゚"), ("", "n", "", "", "η"), ("", "∩", "", "∩", ""), ("∩", "", "", "", "∩"), ("ヽ", "", "", "", "ノ"), ("┐", "", "", "", "┌"), ("╮", "", "", "", "╭"), ("<", "", "", "", "/"), ("╰", "", "", " ", ""), ("o", "", "", "", "o"), ("o", "", "", "", "ツ"), ("", "", "", "", "ノシ")))
val omeme = asSeq[String](Seq(("\u25d5", "\u25d5"), ("╹", "╹"), (">", "<"), ("^", "^"), ("・", "・"), ("´・", "・`"), ("`・", "・´"), ("´", "`"), ("≧", "≦"), ("゚", "゚"), ("\"", "\""), ("・ิ", "・ิ"), ("❛", "❛"), ("⊙", "⊙"), (" ̄", " ̄"), ("◕ˇ", "ˇ◕")))
var okuti = Seq("ω", "∀",
import scala.io.{Codec, Source}
import scala.util.matching.Regex
import java.io._
import java.net.URL
object HtmlScraper {
def getSource(url: String ) = {
val in = new URL(url).openStream
scala> implicit def d2s(d:Date) = {println("d2s"); d.toString}
d2s: (d: java.util.Date)java.lang.String
scala> def foo[T](d:T)(implicit f:(T =>String) ) = {println(f.toString);f(d) }
foo: [T](d: T)(implicit f: (T) => String)String
scala> foo( new Date)
<function1>
d2s
res2: String = Wed Sep 15 16:10:46 JST 2010
import scala.io.{Codec, Source}
import scala.util.matching.Regex
import java.io._
import java.net.URL
trait ScrapedHtml {
val src:Iterable[String]
def write( fileName:String ):Unit = {
import scala.util.control.Exception._
import scala.io.{Codec, Source}
import java.io._
import java.net.URL
import scala.collection.{Iterable, IterableLike}
trait ScrapedHtml extends Iterable[String] with IterableLike[String, ScrapedHtml]{
val src:Iterable[String]
import scala.collection.generic.CanBuildFrom
hogehoge
scala> import java.util.{Map => JMap, HashMap => JHashMap}
import java.util.{Map=>JMap, HashMap=>JHashMap}
scala> import java.io.Serializable
import java.io.Serializable
scala> type SerializableMap[A,B] = JMap[A,B] with Serializable
defined type alias SerializableMap
scala> def process[A,B]( key:A,value:B,m:SerializableMap[A,B]) = {
// import ModelImplicitly._
// modelOf[AbstractReadOnlyModel].as{"foo"}
object ModelImplicitly{
trait ModelBuilder[A[X] <: IModel[X]] {
def as[B](f: => B): A[B]
}
implicit object AbstractReadOnlyModelBuilder extends
ModelBuilder[AbstractReadOnlyModel]{