Skip to content

Instantly share code, notes, and snippets.

@xuwei-k
xuwei-k / Main.scala
Created September 8, 2013 09:20
Json4s Scalaz7 example
/**
* https://github.com/json4s/json4s/issues/39
*
* Validation Monad instance removed from Scalaz7.
* https://github.com/scalaz/scalaz/blob/v6.0.4/core/src/main/scala/scalaz/Validation.scala#L133-L147
*
* need explicitly convert to `scalaz.\/` (aka disjunction) if you want use the `Kleisli` composition
*/
object Main extends App {
@shibukawa
shibukawa / JSX_proposal.rst
Last active December 22, 2015 13:59
JSXに今後必要になると思われる、import文の拡張のプロポーザル

JSXのimport文の拡張のプロポーザル

ゴールデン・ゲート・ブリッジを渡りながら考えたことのまとめ。

JSXが非常に沢山の人に使われるようになった未来

JSXがたくさんの人に使われるようになりました。とてもすばらしいですね。

@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)
(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]
@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",
@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に通じるように翻訳するという働きをする。

@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)
@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
...
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
@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']