Skip to content

Instantly share code, notes, and snippets.

@ussy
ussy / JSON.scala
Created September 27, 2012 11:43
Jerkson is available on play2 development mode from http://takezoe.blogspot.com/2012/08/jerkson-in-play2-development-mode.html
import play.api.Play._
import play.api.Play.current
import com.codahale.jerkson._
object JSON {
def stringify(o: Any): String = if (isDev) { new Json{}.generate(o) } else { Json.generate(o) }
def parse[T](json: String)(implicit m: Manifest[T]): T = try {
if (isDev) { new Json{}.parse[T](json) } else { Json.parse[T](json)}
@ussy
ussy / shutdown.sh
Created May 25, 2012 18:11
daemon for play 2.0
#!/bin/sh
PLAY_HOME=/var/play
pid=`cat $PLAY_HOME/RUNNING_PID 2> /dev/null`
if [ "$pid" == "" ]; then echo "play application is not running"; exit 1; fi
kill $pid
echo "shutdown play application."
@ussy
ussy / Resources.java
Created March 30, 2012 17:53
Localizer
package com.example;
import java.util.Locale;
import org.jvnet.localizer.LocaleProvider;
public class Resources {
public static void main(String[] args) throws Exception {
final WebRequestLocaleProvider localeProvider = new WebRequestLocaleProvider();
@ussy
ussy / AbstractNonValidatingSAXTemplateParser.patch
Created March 2, 2012 06:59
include the line number in the error message for Thymeleaf
--- AbstractNonValidatingSAXTemplateParser.java 2012-03-02 15:43:16.000000000 +0900
+++ AbstractNonValidatingSAXTemplateParser.java 2012-03-02 15:42:53.000000000 +0900
@@ -123,6 +123,9 @@
throw new TemplateInputException("Exception parsing document", e);
} catch (final TemplateProcessingException e) {
throw e;
+ } catch(final SAXParseException e) {
+ final String message = String.format("Exception parsing document: template=%s, near line=%d, column=%d", documentName, e.getLineNumber(), e.getColumnNumber());
+ throw new TemplateInputException(message, e);
} catch (final SAXException e) {
--- /Users/ussy/tmp/a.txt 2012-01-08 15:21:38.000000000 +0900
+++ /Users/ussy/tmp/b.txt 2012-01-08 15:21:51.000000000 +0900
@@ -1,3 +1,2 @@
-<bean id="connectionProvider" class="jp.sf.amateras.mirage.dialect.HyperSQLDialect">
- <property name="dialect" ref="dialect" />
-</bean>
+<bean id="dialect" class="jp.sf.amateras.mirage.dialect.HyperSQLDialect" />
+
@ussy
ussy / my.el
Created August 26, 2011 11:06
Quick Scala Specs
(defun my-quick-specs()
(interactive)
(if buffer-file-name
(cond
((string-match "^\\(.*?/src/\\)test\\(/scala/.+?/\\)\\(.+?\\)Spec\\.scala$" buffer-file-name)
(let* ((base-dir (match-string 1 buffer-file-name))
(target-dir (match-string 2 buffer-file-name))
(target-name (match-string 3 buffer-file-name))
(target-path (concat base-dir "main" target-dir target-name ".scala")))
(find-file target-path)))
@ussy
ussy / sbm-counter.ks.js
Created August 20, 2011 19:03
SBMCounter for KeySnail
var PLUGIN_INFO =
<KeySnailPlugin>
<name>SBMCounter</name>
<name lang="ja">SBMCounter</name>
<description>Social Bookmark Counter</description>
<description lang="ja">ソーシャルブックマークカウンタ</description>
<version>0.1.0</version>
<!--<iconURL></iconURL>-->
<!--<updateURL></updateURL>-->
<author mail="ussy00@gmail.com" homepage="http://www.pshared.net/">ussy</author>
@ussy
ussy / AbstractBatchOperation.java
Created June 25, 2011 15:41
DbUnit + YAML for Java
/*
*
* The DbUnit Database Testing Framework
* Copyright (C)2002-2004, DbUnit.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
package com.example;
import java.lang.reflect.Method;
public class Client {
public static void main(String[] args) throws Exception {
A a = new A();
B b = new B();
Method m = A.class.getMethod("hello");
<?xml version="1.0" encoding="UTF-8"?>
<project name="library" default="package">
<property name="jarname" location="./bin/${ant.project.name}.jar" />
<property name="src" location="./src" />
<property name="bin" location="./bin" />
<target name="clean">
<delete dir="${bin}" />
</target>