Skip to content

Instantly share code, notes, and snippets.

@tlync
tlync / split-json.js
Created September 1, 2012 06:08
Split large json file
if(process.argv.length < 3){
console.log('target file path is required.')
process.exit(1)
}
var target = process.argv[2]
console.log('file: ' + target)
var fs = require('fs')
fs.readFile(target, function (err, data) {
@tlync
tlync / gist:1868304
Created February 20, 2012 07:48
Wrapper for android Log class
package me.tlync.android.util;
import android.util.Log;
/**
* Android Log wrapper class that can use {@link String#format(String, Object...)} in logging message
*/
public class Logger {
private static final String TAG = Logger.class.getSimpleName();
@tlync
tlync / UserApiSpec.scala
Last active December 15, 2021 23:07
ScalaTest 2.0 RC1 with Play 2.2
import org.scalatest._
import org.scalatest.GivenWhenThen
import play.api.libs.json._
import play.api.test._
import play.api.test.Helpers._
class UserApiSpec extends FunSpec with GivenWhenThen with Matchers {
describe("Users API") {
describe("GET /users") {
@tlync
tlync / transparent-context.scala
Last active February 8, 2018 06:36
Scala Advent Calendar 2013 12/11 の記事で利用した Transparent IO Context パターンのコード
// Transparent IO Context pattern using implicit parameter
// ---
// domain
// ---
// base (サンプルなのでほぼただの Marker Trait)
trait Entity
// 永続化に利用するセッションを保持するただのコンテナ
@tlync
tlync / private.xml
Created June 20, 2013 08:31
Disable keyremap4macbook's emacs keybindings in InteliJ IDEA and enable a portion of bindings.
<?xml version="1.0"?>
<root>
<appdef>
<appname>INTELIJ</appname>
<equal>com.jetbrains.intellij</equal>
</appdef>
<replacementdef>
<replacementname>EMACS_MODE_IGNORE_APPS</replacementname>
<replacementvalue>
// base (サンプルなのでただの marker trait)
trait Entity
trait Repository
// domain layer
case class User(id: Int, name: String) extends Entity
trait Users extends Repository {
def find(id: Int): Option[User]
}
@tlync
tlync / gist:7576585
Last active December 28, 2015 23:09
ドメイン層を特有のトランザクション管理の概念から独立させる為の Transparent context pattern (適当)
// domain layer
trait Entity
trait Repo
case class Context[T](session: T)
trait TransparentContext[T] {
implicit def c2s(implicit ctx: Context[T]) = ctx.session
implicit def s2c(implicit session: T) = Context(session)
}
@tlync
tlync / gist:7560473
Last active December 28, 2015 20:49
Isolate domain models from transaction management. version 2
// dummy session classes for sample codes
final class AnormSession {
def anormMethod = {
println("anorm")
}
def start = {}
def commit = {}
}
@tlync
tlync / nyankoro.scala
Created November 20, 2013 05:32
Isolate domain models from transaction management
// dummy session classes for sample codes
final class AnormSession {
def anormMethod = {
println("anorm")
}
def start = {}
def commit = {}
}
@tlync
tlync / gist:6841791
Created October 5, 2013 14:45
Single field json serialization using Play's JSON
import play.api.libs.json._
import play.api.libs.functional.syntax._
object Main {
implicit val jsonFormat =
(__ \ "v").write[String].contramap((fb: FizzBuzz) => fb.v)
def main(args: Array[String]) {
print(Json.toJson(FizzBuzz.Fizz))
print(Json.toJson(FizzBuzz.Buzz))