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
// g100pon #47 QuickSort | |
def quickSort(lambda, list) { | |
if (!list || list.size() < 2) return list | |
def pivot = list[0] // とりあえず先頭のものを基準にする | |
def middle = list.findAll{ it == pivot } | |
def left = list.findAll{ lambda(it, pivot) } - middle | |
def right = list.findAll{ !lambda(it, pivot) } - middle | |
quickSort(lambda, left) + middle + quickSort(lambda, right) | |
} |
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
// 正規表現版で実行 | |
getKeywordList1('', 3000).with { | |
println "${it.size()}件" | |
it.each { li -> | |
println "[${li.title}](${li.entryCount}) ${li.url}" | |
} | |
} | |
// XmlSlurper版で実行 | |
getKeywordList2('', 3000).with { |
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
interface ReduceOp<E, T> { | |
void add(E e); | |
T value(); | |
} | |
class CounterOp<E> implements ReduceOp<E, Integer> { | |
private int v; | |
public void add(E e){++v;} | |
public Integer value(){return v;} | |
} |
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
(-128..127).each { | |
printf('%02x\n', it as byte) | |
} |
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 java.security.* | |
MessageDigest md = MessageDigest.getInstance('SHA-1') | |
md.update('1234'.getBytes('UTF-8')) | |
def result = md.digest().collect{ String.format('%02x', it) }.join() | |
assert result == '7110eda4d09e062aa5e4a390b0a572ac0d2c0220' |
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
# 同フォルダにhatenahaiku4j-1.1.1.jarを読み込む | |
require 'hatenahaiku4j-1.1.1.jar' | |
# キーワードリストの1ページ目を取得しタイトルを出力 | |
api = Java::hatenahaiku4j.HatenaHaikuAPILight.new | |
api.get_keyword_list.each do |k| | |
puts k.get_title | |
end |
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
java.util.UUID.randomUUID().toString() |
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
String getSHA1(String source) { | |
java.security.MessageDigest md = java.security.MessageDigest.getInstance('SHA-1') | |
md.update(source.getBytes('UTF-8')) | |
md.digest().collect{ String.format('%02x', it) }.join() | |
} | |
def list = (1..10).collect{ | |
[it, getSHA1(it.toString())] | |
} | |
println list |
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
set backupdir=~/vimfiles/tmp | |
set clipboard=unnamed |
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
String getSHA1(String source) { | |
java.security.MessageDigest md = java.security.MessageDigest.getInstance('SHA-1') | |
md.update(source.getBytes('UTF-8')) | |
md.digest().collect{ String.format('%02x', it) }.join() | |
} | |
def list = (1..10).collect{ | |
[it, getSHA1(it.toString())] | |
} | |
println list |
OlderNewer