This file contains 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
@GrabResolver(name="maven-repo", root="https://raw.github.com/uehaj/maven-repo/gh-pages/snapshot") | |
@Grab("groovyx.ast.bytecode:groovy-bytecode-ast:0.2.0-separate-asm") | |
import groovyx.ast.bytecode.Bytecode | |
import java.lang.invoke.* | |
import java.lang.invoke.MethodHandles.Lookup | |
import static groovyjarjarasm.asm.Opcodes.H_INVOKESTATIC | |
class Brainfuck { | |
// Bootstrapメソッド |
This file contains 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 list = [].withDefault{0} | |
def nestLevel = 0 | |
def level = { it << list[0..nestLevel-1].join('_') }.asWritable() | |
def increaseLevel = { list[nestLevel++]++; level(it) }.asWritable() | |
def decreaseLevel = { level(it); nestLevel-- }.asWritable() | |
// Brainfuck命令をJVMバイトコードにコンバートする | |
def genCode = { | |
new File(args[0]).text.replaceAll(/[^\+\-\<\>\.\,\[\]]/, '').eachMatch(/[^\[\]]+|[\[\]]/) { g0 -> |
This file contains 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
shortestPath' :: Int -> Int -> Int | |
shortestPath' n maxn | |
| n==0 = 0 | |
| n==1 = 1 | |
| n > maxn = maxBound::Int | |
| even(n) = (shortestPath' (n `div` 2) (maxn-2)) + 1 | |
| otherwise = minimum [(shortestPath' (n-1) (maxn-2)) + 1, (shortestPath' (n+1) (maxn-2)) + 1] | |
shortestPath :: Int -> Int | |
shortestPath n = shortestPath' n (n*2) |
This file contains 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 org.codehaus.groovy.runtime.* | |
assert String.metaClass instanceof HandleMetaClass | |
String.metaClass.hello = {println "hello"} | |
"hoge".hello() | |
assert String.metaClass instanceof ExpandoMetaClass |
This file contains 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
@Grab('org.gperfutils:gbench:0.4.2-groovy-2.1') | |
import groovy.transform.* | |
@CompileStatic | |
class BusStatic { | |
int ceil10(int n) { (Math.ceil(n/10) * 10) as Integer } | |
int half(int n) { ceil10(n/2) } | |
List parse(String input) { |
This file contains 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 groovy.transform.* | |
class HtmlBuilder { | |
def html(@DelegatesTo(Html) Closure c) { | |
c.delegate = new Html() | |
println "<html>"; c(); println "</html>" | |
} | |
} | |
class Html { | |
def head(@DelegatesTo(Head) Closure c) { | |
c.delegate = new Head() |
This file contains 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
/* | |
* Copyright 2004-2012 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 |
This file contains 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
;; flymake for groovy | |
;; setup: | |
;;(when (require 'flymake-groovy nil t) | |
;; (add-hook 'groovy-mode-hook | |
;; (lambda () (define-key groovy-mode-map "\C-ce" 'next-flymake-error)))) | |
(require 'flymake) | |
(defvar groovyc-command | |
(expand-file-name (concat (getenv "GROOVY_HOME") "/bin/groovyc"))) |
This file contains 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
println "hello world" |
This file contains 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
#!/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()) |