Skip to content

Instantly share code, notes, and snippets.

View tototoshi's full-sized avatar

Toshiyuki Takahashi tototoshi

View GitHub Profile
@tototoshi
tototoshi / echo.scala
Created January 5, 2012 13:31
Scalaでスクリプトとか書くときのコマンドライン引数の解析
#!/bin/sh
exec scala "$0" "$@"
!#
val helpMessage = """
Usage:
-n do not output the trailing newline
-x repeat x times
@tototoshi
tototoshi / rownum.sql
Created December 26, 2012 01:14
Grouped LIMIT in PostgreSQL: show the first N rows for each group
-- http://stackoverflow.com/questions/1124603/grouped-limit-in-postgresql-show-the-first-n-rows-for-each-group
-- http://www.postgresql.jp/document/9.2/html/tutorial-window.html
CREATE TABLE empsalary (
depname varchar(10) not null
, empno integer not null
, salary integer not null
);
INSERT INTO empsalary (depname, empno, salary) VALUES ('develop', 11, 5200);
@tototoshi
tototoshi / Main.scala
Created February 10, 2022 11:58
Loggerの名前の違い
package com.example
import org.slf4j.LoggerFactory
trait BaseLogger {
private val classNameLogger = LoggerFactory.getLogger(classOf[BaseLogger])
private val thisLogger = LoggerFactory.getLogger(this.getClass)
@tototoshi
tototoshi / SplitTestPlugin.scala
Last active November 8, 2019 09:00
テストを並列実行するsbtプラグイン
import sbt._
import Keys._
/**
* テストをいい感じに分割して実行します。
* 分割にはテストクラス名のCRC32チェックサムを使っています。
* 例えば3分割したい時は
*
* > sbt 'splitTest 3 1'
* > sbt 'splitTest 3 2'
@tototoshi
tototoshi / a.scala
Created March 30, 2018 02:17
shapless example (Show)
package com.example
import shapeless._
import shapeless.labelled.FieldType
trait Show[A] {
def show(a: A): String
}
object Show {
@tototoshi
tototoshi / a.scala
Last active August 13, 2017 13:44
SortedSet#map
scala> import scala.collection.immutable.SortedSet
import scala.collection.immutable.SortedSet
scala> case class Hoge(i: Int)
defined class Hoge
scala> SortedSet(1, 2, 3, 4, 5)
res0: scala.collection.immutable.SortedSet[Int] = TreeSet(1, 2, 3, 4, 5)
scala> SortedSet(1, 2, 3, 4, 5).map(Hoge.apply)
@tototoshi
tototoshi / 00_Main.scala
Last active March 5, 2017 14:48
@tostring and @logger macro annotation
package com.example
import java.time.LocalDateTime
@ToString
case class UserName(
firs: String,
last: String
)
@tototoshi
tototoshi / KanjiNumberParser.scala
Created December 18, 2011 05:50
漢数字パーサだよ
import scalaz._
import Scalaz._
import scala.util.parsing.combinator._
object KanjiNumberParser extends RegexParsers {
def one = "一" ^^ { _ => 1L }
def two = "二" ^^ { _ => 2L }
def three = "三" ^^ { _ => 3L }
def four = "四" ^^ { _ => 4L }
def five = "五" ^^ { _ => 5L }
@tototoshi
tototoshi / scalariform.sh
Created July 1, 2016 15:03
scalariform.sh
#!/bin/bash
dir=${1:?directory is not specified}
subproject=$2
cd $dir
tmpfile=$(mktemp "project/$$.sbt")
clean() {
rm -f $tmpfile
@tototoshi
tototoshi / ConnectionPool.scala
Created April 8, 2016 09:03
scalikejdbc+play2.5
package models
import javax.inject.{Inject, Provider, Singleton}
import play.api.inject.{ApplicationLifecycle, Binding, Module}
import play.api.{Configuration, Environment, Logger}
import scalikejdbc.config.TypesafeConfigReader
import scalikejdbc.{Commons2ConnectionPoolFactory, ConnectionPool}
import scala.concurrent.{ExecutionContext, Future}