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
# -*- coding: utf-8 -*- | |
# Google 翻訳 | |
require 'rubygems' | |
require 'json' | |
require 'open-uri' | |
URL = "http://ajax.googleapis.com/ajax/services/language/translate" | |
query = ARGV[0] |
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
# Translation | |
function gtranslation() { | |
RESULT=`ruby "gtranslation.rb のパス" "${RBUFFER}"` | |
zle push-line | |
echo "${RESULT}" | |
zle send-break | |
} | |
zle -N gtranslation | |
bindkey "^t" gtranslation |
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
#!/usr/bin/ruby | |
# 拡張子が .gz であれば、zlib でオープンする。 | |
require 'zlib' | |
module FOpener | |
def self.open( f_name ) | |
f = Filename.extname(f_name) == ".gz" ? Zlib::GzipReader.open( f_name ) : File.open( f_name ) | |
yield( f ) | |
f.close | |
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
require 'tokyocabinet' | |
include TokyoCabinet | |
N = 5 | |
class NgramCounter | |
def initialize(f_name) | |
@tcdb = TokyoCabinet::ADB::new | |
@tcdb.open("*") # オンメモリ | |
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
#! /bin/sh | |
# 親プロセスが死んだら、孤児プロセスを kill する | |
echo $PPID >&2 | |
while [ ! "`ps --no-headers -p $PPID`" = "" ] | |
do | |
sleep 5 | |
done |
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
function cd_last_opt() { | |
eval $BUFFER | |
cd `echo -c "${BUFFER}" | awk '{print $NF}'` | |
zle send-break | |
} | |
zle -N cd_last_opt | |
bindkey "^g" cd_last_opt |
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
# -*- coding: utf-8 -*- | |
class Array | |
def comb | |
n = self.length - 1 | |
0.upto(n) do |head_n| | |
head_n.upto(n) {|tail_n| yield self[head_n..tail_n] } | |
end | |
end | |
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
# coding:utf-8 | |
# du -h の結果をソート | |
# usage: du -h | ruby du_sort.rb | |
results = [] | |
while l=STDIN.gets | |
size_h = l.split("\t")[0] | |
m = 1 | |
case size_h[-1].chr | |
when "K"; m=1000 |
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
class Array | |
def set_index( index_name, i ) | |
eval(" | |
class << self | |
define_method( '#{index_name}' ) { return self[#{i}] } | |
end | |
") | |
end | |
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
# coding:utf-8 | |
# Word Error Rate (空白が区切り文字前提) | |
module Eval | |
# cost[挿入, 削除, 置換] | |
def self.wer( str1, str2, c=[1,1,1] ) | |
s1 = str1.split(' ') | |
s2 = str2.split(' ') | |
d = Array.new(s1.size+1) { Array.new(s2.size+1){ 0 } } |
OlderNewer