Skip to content

Instantly share code, notes, and snippets.

View machuz's full-sized avatar
💙
foo!

machu machuz

💙
foo!
View GitHub Profile
// 1992年: https://ir.nctu.edu.tw/bitstream/11536/3533/1/A1992HE70800003.pdf
// 1997年: http://msn.iecs.fcu.edu.tw/~ccc/profile/publish/ij_paper2/IJ-135.pdf
// 2000年: https://ir.nctu.edu.tw/bitstream/11536/30118/1/000166289900002.pdf
import scala.math.BigInt
sealed class PermissionCompound(protected val value: BigInt) { self =>
def +(that: PermissionCompound): PermissionCompound = PermissionCompound(
self.value * that.value
@startuml
title: 1マイクロサービスにおける依存関係図
scale 0.6
package "xxxApiExternalAdapter" as extA {
frame "PlayFramework" {
[Controller]
[Presenter]
[InputJson]
@machuz
machuz / redisclientSpec
Last active August 1, 2018 12:12
redis Hash実装のテスト
class RedisClientImplSpec extends AbstractSpecification {
import Matchers._
import Mockito._
import monix.execution.Scheduler.Implicits.global
import RedisClientImplSpec._
println("---------------------------------------------")
@machuz
machuz / redisclient
Created August 1, 2018 12:11
redis実装パターン(hash利用。これに決めた)
class RedisClientImpl @Inject()(
system: ActorSystem
)(
host: String,
port: Int,
password: Option[String],
dbNum: Option[Int]
) extends RedisClient {
@machuz
machuz / CacheIO.scala
Created July 31, 2018 05:35
CacheIOのADT
sealed abstract class CacheIO[+A] {}
object CacheIO extends CacheIOCreation {
case class Put[T](
key: CacheKey,
value: T,
expireSecond: Option[Long],
fmt: ByteStringFormatter[T]
@machuz
machuz / CacheIOInterpreter.scala
Created July 31, 2018 05:35
CacheのEffInterpreter実装
trait CacheIOInterpreter {
// Effects of type R, returning a value of type A
def run[R, U, A](effects: Eff[R, A])(
implicit m: Member.Aux[CacheIO, R, U],
m1: _readerRedisClient[U],
m2: _writerLogMsg[U],
m3: _errorEither[U],
m4: _task[U]
): Eff[U, A] = {
@machuz
machuz / redisclient
Created July 31, 2018 05:33
redis実装パターン2(transactionを利用して動的にDB番号を切り替える)
// ↓のようにもかけるがテストしづらいのでやめた
//val t = c.multi( redis => {
// redis.select(Tag.unwrap(dbNum))
// redis.get(Tag.unwrap(key)
//})
// 動的DB変更案はトランザクションにロールバックがないredisで、
// 複数コマンド叩かないと整合性が取れない状態を生みやすいので厳しいかも
@machuz
machuz / redisclient
Last active July 31, 2018 05:29
redis実装パターン1
sealed abstract class RedisClient {
def put[A: ByteStringFormatter](
key: CacheKey,
value: A,
expireSeconds: Option[Long] = None
): Task[\/[EsError, A]]
def putList[A: ByteStringFormatter](
key: CacheKey,
@machuz
machuz / monadLaws.scala
Last active May 25, 2018 05:25
scalacheckのmonad.lawsで自作Maybeのテスト
import scalaz.Functor
// Functor(F)と、計算値(A)を型パラメータでとる
// mapとflatMapを持ち、Pureなら関数適用、InpureならFunctorを使ってFの計算値(A)にfを適用する
sealed abstract class Free[F[_], A] {
import Free._
def map[B](f: A => B)(implicit F: Functor[F]): Free[F, B] =
// コンテナ型Fに対してmapを持つ
trait Functor[F[_]] {
def map[A, B](fa: F[A])(f: A => B): F[B]
}
implicit def functorOps[F[_]: Functor, A](self: F[A]) = new {
def map[B](f: A => B): F[B] = implicitly[Functor[F]].map(self)(f)
}