Skip to content

Instantly share code, notes, and snippets.

View tototoshi's full-sized avatar

Toshiyuki Takahashi tototoshi

View GitHub Profile
@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 / 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}
@tototoshi
tototoshi / future.scala
Created March 26, 2015 03:54
Future.successful と Future.apply
import scala.concurrent.Future
// def successful[T](result: T): Future[T] を使った場合
// result を評価する時点でブロックされるので
// a b c の順に表示される
println("a")
val f1 = Future.successful { Thread.sleep(1000); println("b") }
println("c")
// def apply[T](body: ⇒ T)(implicit execctx: ExecutionContext): Future[T]
@tototoshi
tototoshi / Test.scala
Last active August 29, 2015 14:16
scalacache bug?
case class User(id: Int, name: String)
object Test {
import scalacache._
import memoization._
import redis._
implicit val scalaCache = ScalaCache(RedisCache("localhost", 6379))
@tototoshi
tototoshi / a.sql
Created July 19, 2014 14:14
timestamp with time zone
example=# CREATE TABLE tstest (ts1 timestamp, ts2 timestamp with time zone);
CREATE TABLE
example=# \d tstest;
Table "public.tstest"
Column | Type | Modifiers
--------+-----------------------------+-----------
ts1 | timestamp without time zone |
ts2 | timestamp with time zone |
example=# INSERT INTO tstest VALUES (current_timestamp, current_timestamp);