Skip to content

Instantly share code, notes, and snippets.

View nobeans's full-sized avatar

Yasuharu Nakano nobeans

  • Yokohama, Japan
View GitHub Profile
@nobeans
nobeans / i18n-key-naming.md
Last active July 22, 2016 01:59
Grailsのi18nキーの命名規約ルール案

Grailsのi18nキーの命名規約ルール案

`default.xxxx`
:   defaultはあくまでGrails標準で提供されるキーのプレフィックスとする

`xxx.label`
:   ドメイン名、プロパティ名

`xxx[.yyy].label`
@nobeans
nobeans / gist:92b6ff4242a258c17136
Last active September 2, 2015 16:04
各種コレクション型と四則演算
import static groovy.test.GroovyAssert.shouldFail
Iterable i1 = new Iterable() {
@Delegate
Iterable l = [1, 2]
}
Iterable i2 = new Iterable() {
@Delegate
Iterable l = [2, 3]
@nobeans
nobeans / gist:fbe4d3684ed44e0aab0e
Last active August 29, 2015 14:20
Grails3で双方向1対1のドメインクラスの保存がrun-appしたときだけNPEになる事象
{org.grails.orm.hibernate.GrailsHibernateTemplate$7@17518}
OK
2
org.grails.orm.hibernate.AbstractHibernateGormInstanceApi$_performSave_closure3@27ba4c03
3
org.grails.orm.hibernate.validation.UniqueConstraint$2@40259e2
OK
#!/bin/bash
set -e
#
# NWの制約がある場合に大きいリポジトリをチマチマとpushするスクリプト
#
# 実行時の注意事項:
# 巨大サイズのブランチ操作をするとファイルバッファの出し入れが大きすぎるため、
# git statusするだけで1分ぐらい待たされる場合がある。
def average = { double v, int count ->
double sum = 0;
for (int i = 0; i < count; i++) {
sum += v;
}
return sum / count;
}
println average(0.1d, 10)
@nobeans
nobeans / grails-switcher.sh
Last active August 29, 2015 14:18
GVM version switcher for Grails 2.x and 3.x
if [ `basename $SHELL` = "zsh" ]; then
if which gvm >/dev/null 2>&1; then
__gvm_switch_grails_griffon() {
# for 2.x
if [ -s "application.properties" ]; then
local array candidate target current
array=($(cat application.properties | grep --color=never 'app.\(grails\|griffon\).version' | sed -E "s|app.(.*).version=(.*)|\1 \2|g" | tr -d "\r\n"))
candidate=${array[1]}
target=${array[2]}
current=$((gvm offline enable >/dev/null && gvm current ${candidate} && gvm offline disable > /dev/null) | awk '{ print $4 }')
@nobeans
nobeans / Application.groovy
Last active August 29, 2015 14:17
Banner in Grails 3.0
class Application extends GrailsAutoConfiguration {
static void main(String[] args) {
def app = new GrailsApp(Application)
// インラインでロゴ文字列を指定できる
// クラスパスにbanner.txtがある場合はそちらが優先して使われる(grails-app/conf/banner.txt)。
app.setBanner { org.springframework.core.env.Environment environment, Class<?> sourceClass, PrintStream out ->
out.println ">" * 100
out.println "My Banner!"
out.println "Env: ${environment.dump()}"
@nobeans
nobeans / pipeline.groovy
Created March 6, 2015 02:21
Catn with pipeline style by Groovy
def fileContents = { fileName, encoding -> new File(fileName).getText(encoding) }
def toLines = { text -> text.split(/\r?\n/).toList() }
def sizePair = { lines -> [lines.size(), lines] }
def format = { max, lines ->
def size = "$max".size() + 1
def zipped = [(1 .. max), lines].transpose()
zipped.collect { index, line -> String.format("%${size}d: %s", index, line) }
}
def toUnlines = { lines -> lines.join(System.getProperty('line.separator'))}
@nobeans
nobeans / gist:ffdd70d4629e5afe02a9
Created March 6, 2015 02:18
Composition of functions by Groovy
def by8 = { it * 8 }
def plus3 = { it + 3 }
def devide2 = { it / 2 }
// two closures
assert (by8 << plus3).call(3) == 48
assert (plus3 >> by8).call(3) == 48
assert (plus3 >> by8)(3) == 48
// three closures
@nobeans
nobeans / closureParameterSize.groovy
Created January 29, 2015 08:24
クロージャの引数の数はどうなってるのか
def cd = { println("cd") }
def c0 = { -> println("c0") }
def c1 = { a -> println("c1:$a") }
def c2 = { a, b -> println("c2:$a:$b") }
assert cd.parameterTypes.size() == 1
assert c0.parameterTypes.size() == 0
assert c1.parameterTypes.size() == 1
assert c2.parameterTypes.size() == 2