Skip to content

Instantly share code, notes, and snippets.

@gakuzzzz
gakuzzzz / 1_disample.scala
Created July 29, 2013 03:26
cake と cake じゃない所と
package disample
case class DiSampleConfig(foo: Int, bar: String)
object DiSampleConfig {
implicit val configs: Configs[DiSampleConfig] = Configs { c =>
DiSampleConfig(
foo = c.get[Int]("foo"),
bar = c.get[String]("bar")
)
}
@halcat0x15a
halcat0x15a / pipe.md
Last active March 19, 2024 03:30
Pipe

Pipeモナドの紹介

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

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

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

Iterateeについて

@halcat0x15a
halcat0x15a / lisp.clj
Created July 30, 2013 07:24
Clojureに型付けする奴
(ns typelogic.lisp
(:refer-clojure :exclude [==])
(:require [clojure.core.logic :refer :all]
[clojure.core.logic.dcg :refer :all]))
(defna expr [g x t]
([[[x t] . _] x t])
([[_ . g'] x t] (expr g' x t))
([_ ['fn [a] b] [::-> p q]]
(fresh [g']
sealed trait Status
sealed trait HasID extends Status
sealed trait NoID extends Status
case class User[S <: Status](
firstName: String,
lastName: String,
age: Int,
createdAt: java.util.Date,
private val _id: Int = 0
@xeno-by
xeno-by / gist:6156001
Created August 5, 2013 13:43
Macro paradise 2.0.0-SNAPSHOT
~/210x $ scala -Xshow-phases
phase name id description
---------- -- -----------
parser 1 parse source into ASTs, perform simple desugaring
macroparadise 2 let our powers combine
namer 3 resolve names, attach symbols to named trees in paradise
packageobjects 4 load package objects in paradise
typer 5 the meat and potatoes: type the trees in paradise
...
@halcat0x15a
halcat0x15a / gist:6161744
Created August 6, 2013 03:20
2つの画像a,bがあり、画像bが画像aのどの位置に含まれるかを調べるコード
def point(a: BufferedImage, b: BufferedImage) =
for {
points <- (for {
ax <- 0.to(a.getWidth - b.getWidth).view
ay <- 0.to(a.getHeight - b.getHeight).view
} yield {
for {
bx <- 0.until(b.getWidth).view
by <- 0.until(b.getHeight).view
} yield (ax, ay) -> (bx, by)
@mumoshu
mumoshu / akka-2.2-io-codec.md
Last active December 22, 2015 12:29
Akka 2.2のバイナリデータのエンコーディング、デコーディング周りの概念 http://doc.akka.io/docs/akka/2.2.1/scala/io-codec.html

Akkaのネットワーキングでは、2者間の通信を最小単位としてプロトコルを組む。

A <-- Protocol --> B

2者間のプロトコルの実装はPipelineと呼ばれる。 PipelineはAからのメッセージをBに通じるように翻訳し、一方でBからのメッセージをAに通じるように翻訳するという働きをする。

@tototoshi
tototoshi / Build.scala
Last active December 22, 2015 12:39
Retrieve request token asynchronously
import sbt._
import sbt.Keys._
object ScalaoauthasyncBuild extends Build {
lazy val scalaoauthasync = Project(
id = "scala-oauth-async",
base = file("."),
settings = Project.defaultSettings ++ Seq(
name := "scala-oauth-async",
(defn points [^BufferedImage image ^BufferedImage screen]
(let [width (.getWidth image)
height (.getHeight image)
xrange (range width)
yrange (range height)]
(for [points
(for [sx (range (- (.getWidth screen) width))
sy (range (- (.getHeight screen) height))]
(for [tx xrange
ty yrange]
@seratch
seratch / SampleSpec.scala
Last active December 22, 2015 12:39
Sending ScalikeJDBC query logs to Fluentd
package example
import scalikejdbc._, SQLInterpolation._, config._, async._
import org.fluentd.logger.scala._
import org.scalatest._, matchers._
import scala.concurrent._, duration.DurationInt, ExecutionContext.Implicits.global
class SampleSpec extends FlatSpec with ShouldMatchers {
case class Name(id: Long, kanji: String, kana: String)