Skip to content

Instantly share code, notes, and snippets.

@kanemu
kanemu / deepMapToMap.js
Created Dec 10, 2013
ドットつなぎのキーを使った連想配列を、深い階層の連想配列にする ref: http://qiita.com/kanemu@github/items/8d103877ddcefd0c0ebf
View deepMapToMap.js
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 Oct 9, 2013
[groovy]groovyでodsを読む
View read_ods.groovy
@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 Dec 23, 2015
groovyで足し算コンソールアプリ
View tasu.groovy
groovy https://gist.github.com/kanemu/6557373/raw/tasu.groovy
View gvm-glstart.sh
# 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 Sep 1, 2012
[groovy][java][jackson]マルチバイト文字と指定の文字をエスケープしたjsonを作る。
View ultraEscapeJson.groovy
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 Jul 26, 2012
[illustrator][indesign]Illustartor→InDesign間でBridgeTalk
View bridgetalktest.jsx
#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 Nov 16, 2011
[groovy][jackson]jacksonで読み込むJSONにシングルクォートの使用を許可する。
View json.groovy
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 Nov 9, 2011
[indesign]ドキュメントのxmlタグを全部解除する。
View untag.jsx
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 Nov 7, 2011
[groovy][git]ExtendScript.tmbundleをインストールする。
View gitclonetmbundle.groovy
@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 Nov 5, 2011
MapからMapを作る。
View map2map.groovy
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