Skip to content

Instantly share code, notes, and snippets.

View mather's full-sized avatar
🐻
friendly bear

Eisuke Kuwahata mather

🐻
friendly bear
View GitHub Profile
import akka.actor.{ExtendedActorSystem, Extension, ExtensionId}
class SampleExtentionImpl(system: ExtendedActorSystem) extends Extension {
val hoge = "HOGE"
}
object SampleExtension extends ExtensionId[SampleExtensionImpl] {
def createExtension(system: ExtendedActorSystem) = new SampleExtensionImpl(system)
}
@mather
mather / Dockerfile
Last active August 29, 2015 14:04
Scala REPL by Docker
FROM debian:latest
MAINTAINER mather <mather314@gmail.com>
RUN apt-get update
RUN apt-get autoremove -y
RUN apt-get install -y wget openjdk-7-jre
RUN wget http://downloads.typesafe.com/scala/2.11.1/scala-2.11.1.deb
RUN dpkg -i scala-2.11.1.deb
@mather
mather / file0.scala
Created July 29, 2014 02:46
IgnoreCaseなパーサコンビネータ ref: http://qiita.com/mather314/items/0535f237f007c13942dc
trait SampleParsers extends RegexParsers {
/** 文字列に".i"を付けると大文字小文字を区別せずマッチさせるようにする拡張 */
implicit class IgnoreCaseString(s: String) {
def i: Parser[String] = ("""(?i)\Q""" + s + """\E""").r
}
def keyword: Parser[String] = "keyword:".i
def value: Parser[String] = "[a-zA-Z0-9]+".r
def parameter: Parser[(String,String)] = keyword ~ value ^^ { case k~v => (k,v) }
}
@mather
mather / mandelbrot.scala
Last active August 29, 2015 14:04
http://justindomke.wordpress.com/2008/11/29/mandelbrot-in-scala/ のマンデルブロ集合を描画するプログラムのリファクタ
import java.io._
import java.lang.Math
import scala.annotation.tailrec
/**
* ref: http://justindomke.wordpress.com/2008/11/29/mandelbrot-in-scala/
*/
object mandelbrot {
// tiny complex number class including syntactic sugar for basic operations
class A
class B extends A
class C extends A
def isType[T <: A](a: A) = a.isInstanceOf[T]
// <console>:9: warning: abstract type T is unchecked since it is eliminated by erasure
// def isType[T <: A](a: A) = a.isInstanceOf[T]
// ^
// isType: [T <: A](a: A)Boolean
@mather
mather / Calculator.scala
Created February 23, 2015 02:32
Calculator Sample
// "sealed" : Declare that no other subclass except this file. This helps compiler to verify loss of pattern.
sealed trait Expression {
def a: Int
def b: Int
}
case class Addition(a: Int, b: Int) extends Expression
case class Subtraction(a: Int, b: Int) extends Expression
case class Multiply(a: Int, b: Int) extends Expression
case class Division(a: Int, b: Int) extends Expression
import Data.List
main = do
l <- fmap toInt $ getLine -- 標準入力からLを読み込む
n <- fmap toInt $ getLine -- 標準入力からNを読み込む(使わない
bars <- fmap (fmap toInt . lines) $ getContents -- 残りのリストを取得
print (sum $ fmap (findTripleSum l) $ tails bars) -- tails で部分リストを順番に調べる
-- Int化
toInt :: [Char] -> Int
@mather
mather / TraitLazyExam.scala
Last active August 29, 2015 14:25
Scalaのトレイトで抽象メンバとそれを参照する`lazy val`のあるときに、`lazy val`を参照する側にも常に`lazy`であることを要求してしまう例
trait Hoge {
protected val hoge: String
lazy val l = hoge.length
}
trait Piyo {
this: Hoge =>
val p = l
}
@mather
mather / ParserSample.scala
Created November 30, 2012 16:40
Parser Test
import scala.util.parsing.combinator.JavaTokenParsers
object ParserSample extends JavaTokenParsers {
/*
* RegexParserで定義されたメソッド。
* default(=true) だと行末の改行などが無視される。
*/
override def skipWhitespace = false
/*
@mather
mather / stat_test.c
Last active December 12, 2015 10:48
stat関数でできることをチェック。コマンドライン引数でファイルとかシンボリックリンクとか指定するとstatまたはlstatを呼び出してチェックできる。
CC = gcc
OPT = -O2 -Wall
BIN = stat_test
default: bin
bin: $(BIN)
stat_test: stat_test.o
$(CC) $(OPT) -o $@ $<