Skip to content

Instantly share code, notes, and snippets.

@kanemu
kanemu / deepMapToMap.js
Created December 10, 2013 16:46
ドットつなぎのキーを使った連想配列を、深い階層の連想配列にする ref: http://qiita.com/kanemu@github/items/8d103877ddcefd0c0ebf
function deepMapToMap(map,tmpMap,suffixkey){
if(suffixkey==null) suffixkey = '';
if(tmpMap==null) tmpMap = {};
for(var key in map){
if(map[key].constructor.name==='Object'){
deepMapToMap(map[key],tmpMap,suffixkey+key+'.');
}else{
tmpMap[suffixkey+key] = map[key];
}
}
@kanemu
kanemu / read_ods.groovy
Created October 9, 2013 05:13
[groovy]groovyでodsを読む
@Grab('org.jopendocument:jOpenDocument:latest.release')
import org.jopendocument.dom.spreadsheet.*
def odsPath = '/Users/kanemu/Desktop/画像整理.ods'
def odsFile = new File(odsPath)
def odsDoc = SpreadSheet.createFromFile(odsFile)
def odsSheetLastIndex = odsDoc.getSheetCount()-1
MutableCell cell = null
@kanemu
kanemu / tasu.groovy
Last active December 23, 2015 00:59
groovyで足し算コンソールアプリ
groovy https://gist.github.com/kanemu/6557373/raw/tasu.groovy
# usage:
# This script must be placed in the ~/.gvm/ext folder
function gvm_glstart {
ARGS=$@
EXECUTABLE="grails"
if [ -f application.properties ]; then
G_VERSION=$( cat application.properties | grep "app.grails.version=" | sed -e "s/^.*=//" | tr -d '\r\n ' )
@kanemu
kanemu / ultraEscapeJson.groovy
Created September 1, 2012 04:30
[groovy][java][jackson]マルチバイト文字と指定の文字をエスケープしたjsonを作る。
import org.codehaus.jackson.map.ObjectMapper
import org.codehaus.jackson.io.CharacterEscapes
import org.codehaus.jackson.SerializableString
import org.codehaus.jackson.JsonGenerator.Feature
@Grab(group='org.codehaus.jackson', module='jackson-mapper-lgpl', version='1.9.9')
public class CustomCharacterEscapes extends CharacterEscapes {
private final int[] _asciiEscapes;
@kanemu
kanemu / bridgetalktest.jsx
Created July 26, 2012 01:44
[illustrator][indesign]Illustartor→InDesign間でBridgeTalk
#target " Illustrator"
//InD風Boundsに変換するfunction
forIndBounds=function(bounds){
var h=app.activeDocument.height;
var ary=[
h-bounds[1],
bounds[0],
h-bounds[3],
bounds[2]
@kanemu
kanemu / json.groovy
Created November 16, 2011 12:06
[groovy][jackson]jacksonで読み込むJSONにシングルクォートの使用を許可する。
import org.codehaus.jackson.map.ObjectMapper
import org.codehaus.jackson.JsonParser.Feature
@Grab(group='org.codehaus.jackson', module='jackson-mapper-lgpl', version='1.6.0')
def mapper = new ObjectMapper()
//読み込み
String jsonText = """{
"名前" : { "first" : "一朗", "last" : "鈴木" },
"打率" : ".315",
@kanemu
kanemu / untag.jsx
Created November 9, 2011 00:50
[indesign]ドキュメントのxmlタグを全部解除する。
var doc=app.activeDocument;
var items = doc.allPageItems;
for(var i=items.length-1;i>=0;i--){
var item = items[i];
if(item.associatedXMLElement){
items[i].associatedXMLElement.untag();
}
}
@kanemu
kanemu / gitclonetmbundle.groovy
Created November 7, 2011 10:13
[groovy][git]ExtendScript.tmbundleをインストールする。
@Grab('com.madgag:org.eclipse.jgit:1.0.99.0.7-UNOFFICIAL-ROBERTO-RELEASE')
import org.eclipse.jgit.api.Git
String userHome = System.getProperty("user.home")
Git.cloneRepository().setURI("git://github.com/kanemu/extendscript.tmbundle.git")
.setDirectory(new File("${userHome}/Library/Application Support/TextMate/Bundles/extendscript.tmbundle"))
.setBare(false)
.setCloneAllBranches(false)
.call()
@kanemu
kanemu / map2map.groovy
Created November 5, 2011 08:30
MapからMapを作る。
def map2Map(defaultMap,map){
def resultMap = [:]
defaultMap.each{k,v ->
if(v instanceof Map){
resultMap[k] = map2Map(v,map)
}else if(v instanceof Closure){
resultMap[k] = map.with(v)
}
}
return resultMap