Skip to content

Instantly share code, notes, and snippets.

View aya-eiya's full-sized avatar

ayabe hidetoshi aya-eiya

View GitHub Profile
@aya-eiya
aya-eiya / staticMemberFail.groovy
Created October 12, 2012 01:33
staticメンバー変数のスコープにまつわる地雷を踏み抜いた話 ref: http://qiita.com/items/8d8a04f4e99ec43c5169
// 久々に触ったJavaでこういうことをやってしまったと言う話
public final class MyClassOne{
private static final ArrayList<String> myList = new ArrayList<String>()
//-------^これがミス
public MyClassOne add(String str){
myList.add(str)
return this
}
public int size(){
myList.size()
@aya-eiya
aya-eiya / ArrayListToArrayCheck.groovy
Created October 15, 2012 05:11
気になったらすぐテストしよう ref: http://qiita.com/items/7ddb52be1ad0cd67e36f
// はたと困ったのでテスト
// T[] arr=ArrayList<T>.toArray(T[])
// で得られた配列arrをいじくるとどうなるんだったっけ?
// 予想では引数として与えた配列へ値がコピーされ、
// 返却値は配列への参照となっているハズ。
ArrayList<String> alist = new ArrayList<String>()
alist.add(0,'文字列1')
alist.add(0,'文字列2')
alist.add(0,'文字列3')
assert(alist.get(0)=='文字列3')
@aya-eiya
aya-eiya / meter_sample.html
Created January 21, 2013 12:21
Canvasを使用したメーター表示のサンプル ref: http://qiita.com/items/add9d658add7f6307b1c
<html>
<head>
<title>サンプル</title>
<script src="./meter.js"></script>
</head>
<body>
<p>180pxくらいの大きさで80%のメーターを表示する。</p>
<div id="meter"></div>
<script>
var _id = 'meter';
@aya-eiya
aya-eiya / build.gradle
Created January 23, 2013 18:22
前から気になっていたLiftを使って見る話 ref: http://qiita.com/items/9c6981a1ec7d47bf97d0
// Minimal build.gradle for Lift project
apply {
plugin 'scala'
plugin 'war'
plugin 'jetty'
plugin 'eclipse'
}
scalaVersion = '2.9.2'
liftVersion = '2.5-M4'
@aya-eiya
aya-eiya / file0.txt
Created May 16, 2013 08:11
GitHubのパスフレーズを省略するコードをconfig置いても大丈夫にした ref: http://qiita.com/items/67b0fdf80aa7b568d28e
#! /bin/bash
SSH_CONFIG="$HOME/.ssh/config"
SSH_ENV="$HOME/.ssh/environment"
# start the ssh-agent
function start_agent {
echo "Initializing new SSH agent..."
# spawn ssh-agent
ssh-agent | sed 's/^echo/#echo/' > "$SSH_ENV"
@aya-eiya
aya-eiya / file0.txt
Created May 17, 2013 11:35
.gitattributesを作る際の参考情報を出力するコマンド ref: http://qiita.com/items/52cefef8231f11945a33
find . -type f | grep -v ".git/" | xargs -Ixx file -i -N xx | sed -e 's/.\+\([\/\.][^\/^\.]\+\+\):/\1/g' |sort -u > .gitattributes
@aya-eiya
aya-eiya / file0.bat
Created June 7, 2013 13:22
Windowsのパスの長さ制限に引っかかったので短くしてみた ref: http://qiita.com/items/d2677c85017a010f2772
C:\>echo %path% | perl -nle "s/;/;\n/g;print $_"
C:\Program Files (x86)\Haskell\bin;
C:\Program Files (x86)\Haskell Platform\2013.2.0.0\lib\extralibs\bin;
C:\Program Files (x86)\Haskell Platform\2013.2.0.0\bin;
C:\Program Files (x86)\Intel\iCLS Client\;
C:\Program Files\Intel\iCLS Client\;
%SystemRoot%\system32;
%SystemRoot%;
%SystemRoot%\System32\Wbem;
%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;
@aya-eiya
aya-eiya / quateToString()
Created June 27, 2013 07:18
ちょっとしたことがGroovy 「リストの文字列表現で要素に任意の引用符つけたい」 ref: http://qiita.com/aya_eiya/items/c9b8e0b3d417dae2a7a3
List.metaClass.toString = { squate,equate=null ->
if(equate==null) equate = squate
delegate.collect {"${squate}${it}${equate}"}
}
def l = ["a","b","c"];
println l.toString()
println l.toString("'")
@aya-eiya
aya-eiya / getSteps.groovy
Created June 27, 2013 09:19
ちょっとしたことがGroovy「ある値まで一定間隔のRangeのリストを作りたい」 ref: http://qiita.com/aya_eiya/items/d48541f1ca2e57c16ef2
def getSteps = {start=1,max,step=1000 ->
if(max <= start + step) return [[start..max]]
def rs = (start..max).step(step).inject([]) {a,c -> (c>start) && a << [ ((a!=[])?a.last().to[0]+1:start)..c-1];a}
(rs.last().to[0] != max) && rs << [rs.last().to[0]+1..max];rs
}
println"""
getSteps(max=10020) = ${getSteps(max=10020)}
"""
println"""
@aya-eiya
aya-eiya / regexp_faster.groovy
Created July 1, 2013 13:29
ちょっとしたことがGroovy「正規表現の部分で遅くなってたのを検証」 ref: http://qiita.com/aya_eiya/items/cd49e5a8a70149947a74
import java.util.regex.Matcher
import java.util.regex.Pattern
def stopWatch = {c->
s = System.nanoTime()
c()
"${(System.nanoTime() - s) / 1000} [microsec]"
}
Pattern slowp = Pattern.compile(/[^。「」]{30,}/)