Skip to content

Instantly share code, notes, and snippets.

// g100pon #62 Groovy Truthのカスタマイズ
class Complex {
double re
double im
boolean asBoolean() {
im != 0 && re != 0
}
}
assert !new Complex(im:0, re:0)
// g100pon #78 HTTPファイルアップロード
// (はてなfotolifeに画像をアップロード、要はてなアカウント)
@Grab('net.sourceforge.htmlunit:htmlunit:2.8')
import java.net.URL;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
if (args.size() == 0) {
println "Usage: groovy fotoupload.groovy file"
@uehaj
uehaj / flymake-groovy.el
Created October 17, 2010 16:27
flymake-groovy.el(GroovyServ version)
;;;; flymake for groovy
(require 'flymake)
(setq exec-path
(cons "/tool/groovyserv-0.4/bin" exec-path))
;; Invoke groovyclient for compile with syntax checking
(defun flymake-groovy-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
def kvmap = [
key1: "value1",
key2: "value2",
key3: [
"key3-1" : "value3-1",
"key3-2" : "value3-2",
],
]
LinkedHashMap.metaClass.toXml = { builder ->
@uehaj
uehaj / map2xml.groovy
Created March 18, 2011 04:48
convert map to xml
def kvmap = [
key1: "value1",
key2: "value2",
key3: [
"key3-1" : "value3-1",
"key3-2" : "value3-2",
],
]
sw = new StringWriter()
@uehaj
uehaj / gvm.groovy
Created July 6, 2011 14:39
GVM: JVM written in Groovy
/*
* gvm.groovy: Java VM written in Groovy
*/
import org.objectweb.asm.*
import org.objectweb.asm.util.*
import org.objectweb.asm.tree.*
import static GVM.*
class GVMClass {
def methods = [:]
@uehaj
uehaj / intro.groovy
Created November 5, 2011 05:26
クソゲーによる自己紹介(by uehaj)
/*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@uehaj
uehaj / search_files_sqlite.groovy
Created November 5, 2011 08:36
指定したディレクトリ配下の全ファイルをトラバースしてファイル情報をSqliteDBに突っこんで、クエリをかけて抽出(by uehaj)
// 指定したディレクトリ配下の全ファイルをトラバースしてファイル情報をSqliteDBに突っこんで、クエリをかけて抽出
@Grab('org.xerial:sqlite-jdbc:3.7.2')
@GrabConfig(systemClassLoader=true)
import groovy.sql.Sql
//Class.forName("org.sqlite.JDBC");
Class.forName("org.sqlite.SQLite")
if (args.length == 0) {
println "Usage: ${this.class} <dir>"
@uehaj
uehaj / codenarc.groovy
Created November 6, 2011 00:59
CodeNarcでGroovyコードをチェック(カレントディレクトリの**/*.groovyを検証し、結果をCodeNarcReport.htmlに出力)
// CodeNarcでGroovyコードをチェックする。
// カレントディレクトリの**/*.groovyを検証し、結果をCodeNarcReport.htmlに出力する。
@Grab(group='org.codenarc', module='CodeNarc', version='0.15')
import org.codenarc.CodeNarc
CodeNarc.main(args)
@uehaj
uehaj / groovy--with-stc.groovy
Created March 28, 2012 10:12
groovy script invoker with statically type check without annotation.
#!/usr/bin/env groovy # -*-groovy-*-
import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer
import org.codehaus.groovy.control.CompilerConfiguration
import groovy.transform.TypeChecked
def configuration = new CompilerConfiguration()
configuration.addCompilationCustomizers(new ASTTransformationCustomizer(TypeChecked))
def binding = new Binding()
binding.setVariable("args", args.tail())