Skip to content

Instantly share code, notes, and snippets.

@huydx
huydx / foo.rb
Created March 18, 2015 12:10
foo.rb
#read_onlyコラムを追加
class Follow < ActiveRecord::Base
before_update :validate_read_only
before_create :set_read_only
def set_read_only
self.read_only = true
end
@huydx
huydx / sample.sbt
Created March 26, 2015 00:37
spray-client-example
name := "akka-train"
version := "1.0"
scalaVersion := "2.10.5"
libraryDependencies ++= {
val sprayVersion = "1.3.1"
val akkaVersion = "2.3.9"
Seq(

ActionFunction の紹介

この記事は Play framework Advent Calendar 2014 の7日目です。

昨日は @dorako321 さんの Play framework Advent Calendar 2014 6日目 位置情報を使ってみよう でした。

明日は @nazoking さんの play2.3 の sbt-web を使わず node で代替システムを作るための資料 です。

さて、そんなこんなで公式ドキュメントではまだ語られていない ActionFunction とそのサブトレイトについて紹介したいと思います。 (公式ドキュメントにも記載ありました https://www.playframework.com/documentation/2.3.x/ScalaActionsComposition#Different-request-types )

@huydx
huydx / 3nightclubs.scala
Last active August 29, 2015 14:27 — forked from oxbowlakes/3nightclubs.scala
A Tale of 3 Nightclubs
/**
* Part Zero : 10:15 Saturday Night
*
* (In which we will see how to let the type system help you handle failure)...
*
* First let's define a domain. (All the following requires scala 2.9.x and scalaz 6.0)
*/
import scalaz._
import Scalaz._
@huydx
huydx / lifx.scala
Last active November 10, 2015 10:57
lifx.scala
import java.net.{NetworkInterface, InetAddress, DatagramPacket, DatagramSocket}
object Command {
case class Header(frame: Frame, frameAdress: FrameAddress, protocolHeader: ProtocolHeader, payload: Array[Byte])
case class Frame(size: Short, protocol: Short, addressable: Byte, tagged: Byte, origin: Byte, source: Int) {
val length = 64 //64 bit
}
case class FrameAddress(target: Byte, reserved: Byte, resRequired: Byte, ackRequired: Byte, blank: Byte, sequence: Byte) {
val length = 128 //128 bit
@huydx
huydx / gist:cf1b647db7bdab07404c
Created December 14, 2015 02:38
OffHeap Experiment
////////////////OnHeapGC
Java HotSpot(TM) 64-Bit Server VM (25.45-b02) for bsd-amd64 JRE (1.8.0_45-b14), built on Apr 10 2015 10:46:38 by "java_re" with gcc 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
Memory: 4k page, physical 16777216k(1141424k free)
/proc/meminfo:
CommandLine flags: -XX:InitialHeapSize=734003200 -XX:MaxHeapSize=734003200 -XX:MaxNewSize=734003200 -XX:NewSize=734003200 -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseParallelGC
0.991: [GC (Allocation Failure) [PSYoungGen: 538112K->9320K(627200K)] 538112K->9328K(627712K), 0.0064314 secs] [Times: user=0.01 sys=0.01, real=0.01 secs]
1.481: [GC (Allocation Failure) [PSYoungGen: 547432K->13644K(627200K)] 547440K->13660K(627712K), 0.0068257 secs] [Times: user=0.01 sys=0.03, real=0.01 secs]
module TacosMachineLearning
class TrainDat
attr_accessor :features, :label
def initialize(features, label)
@features = features
@label = label
end
end
@huydx
huydx / simple_regex.go
Last active August 30, 2016 01:18
simple_regex.go
package main
import (
"fmt"
)
func match(regex string, text string) bool {
if string(regex[0]) == "^" {
return matchhere(regex[1:], text)
}
@huydx
huydx / descent_parser.go
Created September 3, 2016 13:22
descent_parser.go
package main
import "fmt"
// <regex> ::= <term> '|' <regex> | <term>
// <term> ::= { <factor> }
// <factor> ::= <base> { '*' }
// <base> ::= <char>
// | '\' <char>
// | '(' <regex> ')'