Skip to content

Instantly share code, notes, and snippets.

View ybiquitous's full-sized avatar
💬

Masafumi Koba ybiquitous

💬
View GitHub Profile
@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" />
@ybiquitous
ybiquitous / math.js
Last active August 29, 2015 14:06
JavaScript テストライブラリ使用例
module.exports = {
add: function(a, b) {
if (typeof a === 'undefined' || a === null) a = 0;
if (typeof b === 'undefined' || b === null) b = 0;
return Number(a) + Number(b);
}
};
@ybiquitous
ybiquitous / PaginatedResultSetExtractor.java
Last active August 29, 2015 14:07
PaginatedResultSetExtractor (Spring JDBC)
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.jdbc.core.RowMapper;
public final class PaginatedResultSetExtractor<T> implements ResultSetExtractor<List<T>> {
@ybiquitous
ybiquitous / jndi.jsp
Last active August 29, 2015 14:10
JNDI listing JSP
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="javax.naming.*"%>
<!DOCTYPE html>
<html>
<head><title>JNDI list</title></head>
<body>
<h1>JNDI list</h1>
<%
String root = request.getParameter("root");
if (root == null) {
root = "";
@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