Skip to content

Instantly share code, notes, and snippets.

View windymelt's full-sized avatar
😄
Working from Home

Windymelt windymelt

😄
Working from Home
View GitHub Profile
@windymelt
windymelt / play2.1.0 SJISify
Created October 30, 2013 09:41
play 2.1.0のエンコーディングをShift-JISに変更するdiff
--- play-2.1.0.orig/play-2.1.0/framework/src/play/src/main/scala/play/api/mvc/ContentTypes.scala 2013-02-05 09:51:23.000000000 +0900
+++ play-2.1.0/framework/src/play/src/main/scala/play/api/mvc/ContentTypes.scala 2013-08-31 12:58:01.000000000 +0900
@@ -277,7 +277,7 @@
*/
def tolerantText(maxLength: Int): BodyParser[String] = BodyParser("text, maxLength=" + maxLength) { request =>
Traversable.takeUpTo[Array[Byte]](maxLength)
- .transform(Iteratee.consume[Array[Byte]]().map(c => new String(c, request.charset.getOrElse("utf-8"))))
+ .transform(Iteratee.consume[Array[Byte]]().map(c => new String(c, request.charset.getOrElse("Shift_JIS/*utf-8*/"))))
.flatMap(Iteratee.eofOrElse(Results.EntityTooLarge))
}
@windymelt
windymelt / sjis_patch.diff
Created December 10, 2013 16:45
Play-2.2.1をSJISに対応させるパッチ(仮)
diff -ru play-2.2.1 2/framework/project/plugins.sbt play-2.2.1/framework/project/plugins.sbt
--- play-2.2.1 2/framework/project/plugins.sbt 2013-10-30 16:44:48.000000000 +0900
+++ play-2.2.1/framework/project/plugins.sbt 2013-11-08 02:13:56.000000000 +0900
@@ -6,6 +6,8 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "0.6.0")
+addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.1.0")
+
libraryDependencies <+= sbtVersion { sv =>
def check = {
val cond1 = (_: String) => if (1==2) Left("cond1") else Right("not matched")
val cond2 = (_: String) => if (2==2) Left("cond2") else Right("not matched")
val cond3 = (_: String) => if (3==2) Left("cond3") else Right("not matched")
val condList = List(cond1, cond2, cond3)
condList.reduce(_.flatMap)
}
object StreamT extends StreamTInstances {
// 略
def unfoldM[M[_],A,B](start: B)(f: B => M[Option[(A,B)]])(implicit M: Functor[M]): StreamT[M,A] =
StreamT[M,A](M.map(f(start)) {
case Some((a, b)) => Yield(a, unfoldM(b)(f))
case None => Done
})
@windymelt
windymelt / failable.scala
Last active August 29, 2015 13:56
unfold_example1
val failable: Int => Option[Int] = {
(n: Int) =>
n match {
case n if 0 until 100 contains n => Some(n + 1)
case otherwise => None
}
}
@windymelt
windymelt / gist:8886521
Created February 8, 2014 16:48
unfold_example1
import scalaz.std.stream._
import scalaz.syntax.id._
unfold(0)(failable(_).map(_.squared)).force // => Stream(1, 2, 3, 4, 5, ..., 99, 100)
unfold(0)(failable(_).map(n => (s"n=${n}", n))).force // => Stream("n=1", "n=2", ... "n=100")
@windymelt
windymelt / isFirstArgNumber.c
Created October 29, 2014 05:03
数値判定
#include <stdio.h>
/* 定数定義 */
#define CHAR_ZERO 0x30
#define CHAR_ONE 0x31
#define CHAR_NINE 0x39
#define CHAR_NULL 0x00
/* cが0から9までのcharのとき真 */
int isZeroToNine(char c) {
@windymelt
windymelt / .xmodmap
Last active August 29, 2015 14:13 — forked from anonymous/.xmodmap
Shellscript to use SandS and to assign Shift_R to "@"
pointer = default
! shift_r -> @
clear Shift
add Shift = Shift_L
!remove Shift = Shift_R
keycode 62 = at
@windymelt
windymelt / Application.scala
Last active August 29, 2015 14:17
Play 2.3.x でShift_JISのパーセントエンコーディングされたデータを受け取る
package controllers
import play.api._
import play.api.mvc._
import play.api.data._
object Application extends Controller {
def hoge = Action(parse.tolerantText) { request ⇒ // 生の文字列で受け取る。
// 修正したリクエストでimplicit宣言する。
// あたかも最初からパースされたフォームデータが渡されたような状態にする。
@windymelt
windymelt / Pub.scala
Created June 6, 2015 10:10
Akka ZeroMQ Extension Example
package momijikawa.exercisezmq
import scala.concurrent.ExecutionContext
object Main extends App {
import akka.actor._
import akka.zeromq._
import akka.util.ByteString
import concurrent.duration._
import collection.immutable.Seq