Skip to content

Instantly share code, notes, and snippets.

View potato2003's full-sized avatar
🏠
Working from home

potato2003

🏠
Working from home
View GitHub Profile
@potato2003
potato2003 / file0.php
Created March 21, 2013 21:24
重複した要素のみを取得する ref: http://qiita.com/items/13fbec7170da5caa46bc
<?php
$array = ['A', 'A', 'A', 'B', 'B', 'C', 'D'];
function selectDuplicates($array) {
$duplicate = array_filter(array_count_values($array), function($v) {
return $v > 1;
});
return array_keys($duplicate);
}
@potato2003
potato2003 / gist:6056162
Created July 22, 2013 18:14
かっこいいScala 1
val (text, status) = args.headOption.collect {
case "new" => newCommand _
case "help" => helpCommand _
}.map { command =>
command(args.drop(1))
}.getOrElse {
(Colors.red("Error"), -1)
}
@potato2003
potato2003 / gist:6069821
Created July 24, 2013 11:39
ちょっとかっこいいScala 2
app.configuration.getBoolean("trustxforwarded").orElse(Some(false))
@potato2003
potato2003 / gist:6268417
Created August 19, 2013 12:05
http://togetter.com/li/429782 UTF8モードだとalnumでひらがながマッチする
<?php
preg_match('/^([[:alnum:]]*)([[:^alnum:]]*)$/u', 'aaaaああああ', $matches);
if ($matches[0] === 'aaaaああああ') {
echo 'MATCH!'
}
/*
UTF8モードだとalnumでひらがながマッチする
@potato2003
potato2003 / gist:6268428
Created August 19, 2013 12:08
Pretty。
module.exports = (time) ->
elapse =
if time instanceof Date
time.getTime() - Date.now()
else if typeof time == "number"
time - Date.now()
else
console.warn "Given a invalid date type(\"#{typeof time}\") arguments. expected date type is Date or Number."
""
@potato2003
potato2003 / gist:6281430
Created August 20, 2013 13:30
Scala の ちょっとかっこいい implicit parameter
object Application extends Controller {
implicit val charset = Codec.javaSupported("iso-8859-1")
def index = Action {
Ok(<h1>hello</h1>).as(HTML)
}
}
@potato2003
potato2003 / gist:6697131
Created September 25, 2013 09:20
StackableController + Slick + PlayFramework で暗黙的にDBSession使いまわすのやつメモ
trait SlickDBSessionElement extends StackableController {
self: Controller =>
import play.api.db.slick
type Session = slick.Session
case object DBSessionKey extends RequestAttributeKey[Session]
override def proceed[A](req: RequestWithAttributes[A])(f: RequestWithAttributes[A] => Result): Result = {
val session:Session = play.api.db.slick.DB.createSession()
@potato2003
potato2003 / gist:6760691
Last active December 24, 2015 06:59
Scaladoc で OutOfMemory が出た時の対処 ref: http://qiita.com/potato2003@github/items/f7bed8ef8197fdf2f4c0
$ scaladoc -d doc/ -s src/main/scala/**/*.scala
@potato2003
potato2003 / gist:6790082
Created October 2, 2013 07:16
Play2のコードみてて気になったメモ。なにをやっているのかわからない。 def session(implicit request: RequestHeader) = request.session と何が違うのだろうか
implicit def session(implicit request: RequestHeader) = request.session
@potato2003
potato2003 / 1.scala
Last active December 24, 2015 12:39
implicit def xxx(implicit yyy) が 暗黙的パラメータと理解するために試した。 参考: http://d.hatena.ne.jp/gakuzo/20111204/1323007376
class ClassA(val label: String)
implicit val arg1:ClassA = new ClassA("ぼくは暗黙的パラメータ") // implicit def foo のための暗黙的パラメータ定義
implicit def foo(implicit a: ClassA):String = { // 引数の implicit 消すと 暗黙的パラメータ見つからないってエラーになる
println("fooだよ")
a.label
}
def bar()(implicit argStr:String):String = {