Skip to content

Instantly share code, notes, and snippets.

View ybiquitous's full-sized avatar
💬

Masafumi Koba ybiquitous

💬
View GitHub Profile
@ybiquitous
ybiquitous / bench.scala
Created May 24, 2012 02:00
Scala 末尾再帰とループとfoldのベンチマーク
import scala.testing.Benchmark
import scala.annotation.tailrec
trait Times {
def times(elems: Seq[BigInt]): BigInt
}
abstract class Bench extends Times with Benchmark {
val fixture = BigInt(1) to BigInt(2000)
def run() { times(fixture) }
@ybiquitous
ybiquitous / build.sbt
Created May 24, 2012 02:38
JPA2.0+Spring3.1+Scala2.9 Example
libraryDependencies ++= Seq(
"org.springframework" % "spring-orm" % "3.1.1.RELEASE",
"cglib" % "cglib-nodep" % "2.2.2" % "runtime",
"javax.inject" % "javax.inject" % "1",
"org.hibernate" % "hibernate-entitymanager" % "4.1.3.Final",
"log4j" % "log4j" % "1.2.16" % "runtime",
"com.h2database" % "h2" % "1.3.166" % "runtime"
)
scalaVersion := "2.9.2"
@ybiquitous
ybiquitous / mkstr.scala
Created June 3, 2012 10:25
Scala `mkString` tail-recursion version
import scala.annotation.tailrec
import scala.collection.mutable.StringBuilder
def mkStr(elems: Seq[_], sep: String = ""): String = {
/* invoke java.lang.StackOverflowError
elems match {
case Seq() => ""
case Seq(head) => head.toString
case _ => elems.head + sep + mkStr(elems.tail, sep)
}
@ybiquitous
ybiquitous / VelocityServlet.java
Created June 11, 2012 07:03
Simple Velocity Servlet (without Velocity Tools)
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
@ybiquitous
ybiquitous / test.coffee
Created July 23, 2012 09:27
CoffeeScript+Underscore.js+jQuery
jQuery ($) ->
nums = [20..0]
doms = _.map nums, (e, i, l) -> "<li>[#{i}]=#{e}</li>"
$("<ul>#{doms.join("")}</ul>").appendTo("body")
hoge =
name: "Hoge"
age: 10
@ybiquitous
ybiquitous / app.js.coffee
Created July 24, 2012 09:06
Sinatra+Sprockets+DataMapper+CoffeeScript
//= require foo
document.write "<p>#{foo.f(10)}</p>"
@ybiquitous
ybiquitous / md5sum.scala
Last active December 26, 2015 20:29
compiled by scala 2.10.3
object md5sum {
def main(args: Array[String]) {
if (args.isEmpty) {
println("Usage: scala md5sum FILE1, FILE2, ...")
return
}
args.foreach{ file =>
// calculate hash
@ybiquitous
ybiquitous / EchoEndPoint.java
Last active June 16, 2021 06:49
JSR 356 (Java API for WebSocket) Example
package jsr356.example;
import java.io.IOException;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.logging.Logger;
import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
@ybiquitous
ybiquitous / index.js
Created July 2, 2014 07:57
Express 4.x file upload sample
/* jshint node: true, multistr: true */
var express = require('express');
var multer = require('multer');
var serveIndex = require('serve-index');
var serveStatic = require('serve-static');
var app = express();
var pubdir = 'public';
@ybiquitous
ybiquitous / index.html
Last active August 29, 2015 14:05
Unicode - 結合文字と補助文字 (Java 1.6+)
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8" />
<title>Unicode - 結合文字と補助文字</title>
</head>
<body>
<form action="test.jsp" method="POST">
<input type="text" name="p" value="がが丈𠀋" />
<input type="submit" />