This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class DdlBuilder { | |
| def writer | |
| DdlBuilder(writer) { this.writer = writer } | |
| def scheme(Closure cls) { | |
| new NodeBuilder().scheme(cls).each { table -> | |
| writer.println "CREATE TABLE ${table.name()} (" | |
| writer.println table.collect { col -> | |
| " ${col.name()} ${type(col.attribute('type'))}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.security.MessageDigest | |
| println "-"*40 | |
| println "MessageDigest:" | |
| File.metaClass.getMd5 = { | |
| MessageDigest.getInstance("md5"). | |
| digest(delegate.readBytes()). | |
| collect{ String.format("%02x", it) }. | |
| join() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def map = [a:'A', b:'B'] | |
| def sw = new StringWriter() | |
| def builder = new groovy.xml.MarkupBuilder(sw) | |
| builder.hoge { | |
| map.each { key, value -> | |
| "$key"(value) | |
| } | |
| } | |
| println sw.toString() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| String map2xml(Map input) { | |
| def sw = new StringWriter() | |
| def builder = new groovy.xml.MarkupBuilder(sw) | |
| builder.doubleQuotes = true | |
| builder.metaClass.recursive = { Map map -> | |
| map.each { key, value -> | |
| "${key}"(value in Map ? { recursive(value) } : value) | |
| } | |
| } | |
| builder.langs(type: "current") { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class XmlConvertCategory { | |
| static String toXml(Map input) { | |
| def sw = new StringWriter() | |
| def builder = new groovy.xml.MarkupBuilder(sw) | |
| builder.doubleQuotes = true | |
| builder.metaClass.recursive = { Map map -> | |
| map.each { key, value -> | |
| "${key}"(value in Map ? { recursive(value) } : value) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| nnoremap <Space>gn :<C-u>w<CR>:Git now<CR> | |
| nnoremap <Space>gN :<C-u>w<CR>:Git now --all<CR> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.IOException; | |
| public class MultiCatch { | |
| public static void main(String... args) { | |
| try { | |
| if (args.length == 1) { | |
| throw new IOException("!!"); | |
| } | |
| if (args.length == 2) { | |
| throw new ClassNotFoundException("??"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.IOException; | |
| public class MultiCatch { | |
| static class X extends Exception { | |
| public void x() { System.out.println("XXX!"); } | |
| }; | |
| static class A extends X { | |
| public void a() { System.out.println("AAA!"); } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // java.lang.Listにメソッドを追加する | |
| List.metaClass.carcdr = { | |
| [delegate.head(), delegate.tail()] | |
| } | |
| assert [1, 2, 3].carcdr() == [1, [2, 3]] | |
| {-> | |
| def (car, cdr) = [1, 2, 3].carcdr() | |
| assert car == 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Hoge { | |
| static String hoge(String delegate) { | |
| return "HOGE: $delegate" | |
| } | |
| static String foo(String delegate, String param) { | |
| return "FOO: $delegate ($param)" | |
| } | |
| static String bar(Class<String> string) { | |
| return "BAR" | |
| } |