Skip to content

Instantly share code, notes, and snippets.

@akihiro4chawon
akihiro4chawon / ilovefoldleft.scala
Created May 15, 2011 09:12
My `foldLeft` solution to Tony's scala excersize for beginners
// My `foldLeft` solution to http://blog.tmorris.net/scala-exercises-for-beginners/
object FoldExercises {
// Exercise 2
def sum(x: List[Int]): Int =
x.foldLeft(0){_ + _}
// Exercise 3
def length[A](x: List[A]): Int =
@gakuzzzz
gakuzzzz / 1.scala
Created September 11, 2012 07:33
Case クラス固有のメソッドをトレイトで使いたい
case class User(id: String, name: String, options: Seq[String]) {
def options(os: String*): User = copy(options = options ++ os)
}
case class Group(id: String, name: String, subgroups: Seq[Group], options: Seq[String]) {
def options(os: String*): Group = copy(options = options ++ os)
}

!SLIDE PartialFunction ってなあに?

部分関数のことだよ

!SLIDE 部分関数ってなあに?

そもそも関数ってなあに?

@rxin
rxin / ByteBufferPerf.scala
Last active May 14, 2018 21:27
Comparison of performance over various approaches to read Java ByteBuffer. The best way is to use Unsafe, which also enables reading multiple primitive data types from the same buffer.
/**
* To compile:
* scalac -optimize ByteBufferPerf.scala
*
* JAVA_OPTS="-Xmx2g" scala IntArrayPerf 10
* 49 62 48 45 48 45 48 50 47 45
*
* JAVA_OPTS="-Xmx2g" scala ByteBufferPerf 10
* 479 491 484 480 484 481 477 477 472 473
@halcat0x15a
halcat0x15a / pipe.md
Last active March 19, 2024 03:30
Pipe

Pipeモナドの紹介

Scalaの記事です。Haskellはあまり書けません。

Iterateeの複雑さから開放されたいのでPipe系ライブラリ使いましょうという記事です。

Iterateeとの比較や簡単な使い方についてつらつらと書いていきます。

Iterateeについて

@kitak
kitak / doc.md
Last active October 18, 2023 09:57
コマンドによる「負荷」の原因切り分け

コマンドによる「負荷」の原因切り分け

この文章では、Linuxコマンド、sar, top, psを使って、一般的に負荷といわれるものの原因を切り分けることを目的とする。

そもそも負荷とは

「複数のタスクによるサーバリソースの奪い合いの結果に生じる待ち時間」を一言で表した言葉。OSのチューニングとは負荷の原因を知り、それを取り除くことにほかならない。

ボトルネックの見極め作業の大まかな流れ

  • ロードアベレージ(処理を実行したくても、実行できなくて待たされているプロセス(CPUの実行権限が与えられるのを待っている、またはディスクI/Oが完了するのを待っている)の数)を見る

!SLIDE

Interruptible Program with Actor and Trampoline

@halcat0x15a

!SLIDE

デモ

@gakuzzzz
gakuzzzz / enum.scala
Last active April 26, 2023 12:26
Enum
trait EnumLike {
type Value
def value: Value
}
trait StringEnumLike extends EnumLike {
type Value = String
}
@JamesMGreene
JamesMGreene / gitflow-breakdown.md
Last active July 19, 2024 01:24
`git flow` vs. `git`: A comparison of using `git flow` commands versus raw `git` commands.

Initialize

gitflow git
git flow init git init
  git commit --allow-empty -m "Initial commit"
  git checkout -b develop master

Connect to the remote repository

@runarorama
runarorama / gist:a8fab38e473fafa0921d
Last active April 13, 2021 22:28
Compositional application architecture with reasonably priced monads
sealed trait Interact[A]
case class Ask(prompt: String)
extends Interact[String]
case class Tell(msg: String)
extends Interact[Unit]
trait Monad[M[_]] {
def pure[A](a: A): M[A]