This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class JsonRpcBody[P <: Product](jsonrpc: String, method: String, params: P, id: String) | |
case class SampleParams(_1: String, _2: Int) extends Product2[String, Int] | |
// JsonRpcBody[SampleParams] にデコードするためには、DecodeJson[JsonRpcBody[SampleParams]] を | |
// 定義する必要がある。しかし、SampleParams 以外にも増えるのは予想され、その度に DecodeJson[JsonRpcBody[OtherParams]] などを | |
// 書くと大変めんどう。params の解釈の仕方が違うだけなのに、jsonrpc, method, id の部分も解釈しなきゃだし。 | |
// と言うわけで以下のように書く。 | |
implicit def jsonRpcBodyDecodeJson[P <: Product](implicit paramsDecodeJson: DecodeJson[P]): DecodeJson[JsonRpcBody[P]] = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import user | |
import message | |
object Main { | |
def main(args: Array[String]) { | |
import MessageSender._ | |
val natsuki = User("Natsuki Ando") | |
val sakura = User("Sakura Domyoji") | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// IDみたいな仕組みがあって | |
trait Identifier[A] { | |
val value: A | |
} | |
case class UserId(value: UUID) extends Identifier[UUID] | |
case class GroupId(value: UUID) extends Identifier[UUID] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Main { | |
implicit class Capping[+A](value: A) { | |
def cap[B >: A](limit: B)(implicit ordering: Ordering[B]): B = { | |
if (ordering.lteq(value, limit)) value else limit | |
} | |
} | |
def main(args: Array[String]) { | |
println( 99.cap(100)) // => 99 | |
println(101.cap(100)) // => 100 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Violation(message: String) | |
class Funny[V](value: V) { | |
def validateWith(validator: Validator[V]): Validity[V] = validator(value) | |
} | |
object Funny { | |
def apply[V](value: V): Funny[V] = new Funny(value) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"strconv" | |
"strings" | |
"time" | |
) | |
func main() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(['file-chunk'], function(FileChunk) { | |
var file = pickupFile(); | |
var fileChunk = new FileChunk(file); | |
var chunks = fileChunk.chop(4096); | |
// each: 各チャンクのpromiseのdoneを設定する | |
chunks.each(function(chunk) { | |
}); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait FlipFlap[A, B] { | |
def doFlipFlap(x: A): B | |
} | |
class FlipFlapOps[A, B](v: A, f: FlipFlap[A, B]) { | |
def flipFlap = f.doFlipFlap(v) | |
} | |
object Main { | |
implicit def intFlipFlap = new FlipFlap[Int, Int] { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Submodule | |
def subset(&pred) | |
mod = self | |
Module.new do | |
include mod | |
public_instance_methods.each do |method_name| | |
method = instance_method(method_name) | |
undef_method method_name unless pred.call(method) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Paperclip | |
module Model | |
extend ActiveSupport::Concern | |
module ClassMethods | |
def has_attached_file(name) | |
{ | |
file_name: :original_filename, | |
content_type: :content_type, | |
file_size: :size |
NewerOlder