Skip to content

Instantly share code, notes, and snippets.

@osima
osima / MyStaticResourceServlet.groovy
Created November 12, 2010 07:30
自前のDefaultServlet(StaticResourceServlet)
//
// デフォルトサーブレット
//
import java.util.regex.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MyStaticResourceServlet extends HttpServlet {
@osima
osima / MyBuilder.groovy
Created November 12, 2010 06:36
ミニDSL
class MyBuilder extends BuilderSupport{
def rootNode
def createNode(name){
def currentNode = new javax.swing.tree.DefaultMutableTreeNode(name)
if( name=='mystyle' )
this.rootNode = currentNode
@osima
osima / build.xml
Created November 12, 2010 05:42
groovy と java を混ぜた状態でビルドする build.xml の記述方法(Ant)
<?xml version="1.0" encoding="UTF-8"?>
<project default="jar">
<property environment="env" />
<path id="groovy.classpath"> <fileset dir="${env.GROOVY_HOME}/embeddable/" /> </path>
<taskdef
name = "groovyc"
classname = "org.codehaus.groovy.ant.Groovyc"
classpathref = "groovy.classpath" />
@osima
osima / copy_eps.groovy
Created November 2, 2010 05:40
カレントディレクトリにある 文書名_hoge.eps をhoge.eps にコピーする.
//
// カレントディレクトリにある 文書名_hoge.eps をhoge.eps にコピーする.
//
@Grab(group='commons-io', module='commons-io', version='1.4')
import org.apache.commons.io.*
new File('.').listFiles( { it.name.endsWith('.eps') } as FileFilter ).each{
@osima
osima / myMergeTableCells.jsx
Created October 30, 2010 19:13
表のセルをマージ (InDesign CS3 JavaScript)
// my merge table cells
init();
function init(){
//
var myDoc=app.documents.add();
var myPage=myDoc.pages.item(0);
var myTextFrame=myPage.textFrames.add();
@osima
osima / ind.groovy
Created October 30, 2010 19:03
GroovyからInDesignを実行する
import org.codehaus.groovy.scriptom.*
//
// 引数として渡されたJSファイルのチェック
//
boolean ng=false
if( args.size()<1 ){ ng=true }
else if( new File(args[0]).exists()==false ){ ng=true }
if(ng){
@osima
osima / Test.java
Created October 30, 2010 18:54
u2029 (= PARAGRAPH SEPARATOR)の取り扱い
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
public class Test {
public static void main(String[] args) {
File f=new File("sample.xml");
try{
@osima
osima / chkimg.groovy
Created October 13, 2010 08:31
htmlファイル中に含まれる画像をピックアップ
//
// groovy chkimg htmlfile
//
@Grab(group='nekohtml', module='nekohtml', version='1.9.6')
import org.cyberneko.html.parsers.SAXParser
def imagelist = {
def rlist = []
@osima
osima / title_fetcher.groovy
Created October 11, 2010 23:43
ウェブページのタイトルを取得
@Grab(group='nekohtml', module='nekohtml', version='1.9.6')
import org.cyberneko.html.parsers.SAXParser
def title = {
def t = null
new XmlSlurper(new SAXParser()).parse(it).'**'.findAll{
if( it.name() == 'TITLE' ){ t = it.toString() }
}
t.trim()
}
@osima
osima / tw_oauth.groovy
Created October 11, 2010 01:36
Twitter: OAuthの認証サンプル
//
// g100pon #12 Twitter: OAuthの認証サンプル
//
// このコードは以下のサンプル(java)の groovy への移植です.
// http://github.com/kaeppler/signpost-examples/tree/master/OAuthTwitterExample/
//
// 使い方 :
//
// 0. tw_oauth.groovy(このファイル)の consumerKey と consumerSecret に必要な値(*1)を設定
// 1. groovy tw_oauth にて実行します.