Skip to content

Instantly share code, notes, and snippets.

View j5ik2o's full-sized avatar

Junichi Kato j5ik2o

View GitHub Profile
package domain

import java.time.temporal.ChronoUnit
import java.time.{DayOfWeek, LocalDate, LocalDateTime}

import enumeratum._

sealed trait Age extends Ordered[Age] {
  def breachEncapsulationOfValue(today: LocalDate): Int

入力されたリストの要素を2倍し合計する関数

def loop(in: List[Int], acc: Int): Int =
  in match {
    case Nil => acc // 終了条件
    case head :: tail =>
      val result = head * 2 // headのタスク
      loop(tail, acc + result) // 残りのリストと計算途中を渡して処理を継続
 }
public static boolean isNameHashUpperCase(String name) {
  boolean result = false;
  for (int i = 0; i < name.length; i++) {
    if (Character.isUpperCase(name.charAt(i)) {
      result = true;
      break;
    }
  }
 return result;
@j5ik2o
j5ik2o / gist:1786626
Created February 10, 2012 04:34
git:masterからsvn:trunkに同期する方法(その2)
# 前提:git-svnでクローンしたリポジトリで外部のリモートリポジトリを指定して同期する方法
# gitコマンドだけでsvnへ同期可能。
# git-svnでsvnリポジトリをクローンする
$ git svn clone -s http://svn-server/app/ app
# 最初の1回だけ設定する
app$ git remote add central ssh://git-server/app/central.git
# SVNリポジトリの最新情報を取得する
object PersistentWalletAggregate {
def behaviorProxy(
id: WalletId,
chargesLimit: Int = Int.MaxValue
): Behavior[CommandRequest] =
Behaviors
.supervise(Behaviors.setup[CommandRequest] { ctx =>
val childRef: ActorRef[CommandRequest] =
ctx.spawn(WalletAggregate.behavior(id, chargesLimit), WalletAggregate.name(id))
object TestMain extends App {
import akka.stream.scaladsl._
import akka.actor._
import akka.stream.ActorMaterializer
import scala.concurrent._
import scala.concurrent.duration._
implicit val system = ActorSystem()
implicit val ec = system.dispatcher
implicit val mat = ActorMaterializer()
case class Money(amount: BigDecimal,
currency: Currency) {
def plus(other: Money): Money = {
require(currency == other.currency)
new Money(amount = amount.add(other.amount), currency)
}
}
@j5ik2o
j5ik2o / try.md
Last active February 21, 2019 00:57
Tryの使い方

名前を与えると長さを返すメソッドがある。ただし、空文字列とaから始まる接頭辞を持たない場合は例外となる。

成功した時はSuccessにラップして返し、例外時はFailureでラップして返す。いずれもscala.util.Tryのサブ型である。

scala> import scala.util._
import scala.util._

scala> case class ZeroLengthException(name:String) extends Exception(s"$name is zeo length")
defined class ZeroLengthException

scala> case class PrefixInvalidException(name: String) extends Exception(s"$name's prefix is invalid")
curl -v -X GET https://oss.sonatype.org/content/repositories/releases/com/github/j5ik2o/reactive-redis-core_2.12/1.0.20/reactive-redis-core_2.12-1.0.20.pom                        INT(-2) ↵  3243  22:31:44
Note: Unnecessary use of -X or --request, GET is already inferred.
*   Trying 23.22.160.79...
* TCP_NODELAY set
* Connected to oss.sonatype.org (23.22.160.79) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations: