Skip to content

Instantly share code, notes, and snippets.

@tomoyamkung
tomoyamkung / gist:3313797
Created August 10, 2012 12:00
[Ruby]Test::Unit を使ったテストケースの雛型
#! ruby
#-*- encoding: utf-8 -*-
require 'test/unit'
require 'hoge'
class HogeTest < Test::Unit::TestCase
def setup
@obj = Hoge.new
end
@tomoyamkung
tomoyamkung / gist:3384547
Created August 18, 2012 04:54
[MongoDB]MongoDB の起動・停止を実行するスクリプト
#!/bin/sh
if [ "start" = "$1" ] ; then
cd /cygdrive/c/mongodb/bin
./mongod.exe --dbpath=../data --auth > /dev/null &
elif [ "stop" = "$1" ] ; then
ps ax | grep '/bin/mongod' | awk '{print $1}' | xargs kill -9
else
@tomoyamkung
tomoyamkung / rename.rb
Created September 24, 2012 02:34
[Ruby]リネームスクリプト
#! ruby
#-*- encoding: utf-8 -*-
require 'getoptlong'
#search_pattern = '-DVD-BOX-'
#replace_pattern = 'DVD-BOX '
opts = GetoptLong.new(
['--confirm', '-c', GetoptLong::NO_ARGUMENT],
@tomoyamkung
tomoyamkung / gist:3839830
Created October 5, 2012 13:31
[Ruby]指定したディレクトリを再帰的に LOAD_PATH に追加する
#! ruby
#-*- encoding: utf-8 -*-
require 'test/unit'
class RequireUtilTest< Test::Unit::TestCase
def self.add(dir)
dir = dir[0, dir.size - 1] if dir.end_with?('/')
Dir::glob(dir + '/**/*').each do |file|
@tomoyamkung
tomoyamkung / gist:3865716
Created October 10, 2012 13:41
[Ruby]Mechanize を使って a タグの href を取得するスニペット
require 'mechanize'
agent = Mechanize.new
agent.get('http://hogehoge.com')
agent.page.at("a").attributes["href"].text
# at は一致した最初の要素を返す
@tomoyamkung
tomoyamkung / gist:3904014
Created October 17, 2012 06:26
[Ruby]CamelCase に変換するスニペット
def camelize string
string.split('-').map do |word|
word.capitalize
end.join
end
@tomoyamkung
tomoyamkung / gist:3904037
Created October 17, 2012 06:35
[Ruby]Test::Unit を使ったテストケースを生成するスクリプト
#! ruby #-*- encoding: utf-8 -*-
class GenerateTestCase
TEMPLATE = <<-EOS
#! ruby
#-*_ encoding: utf-8 -*-
require 'test/unit'
class _CLASS_NAME_Test < Test::Unit::TestCase
@tomoyamkung
tomoyamkung / gist:3909545
Created October 18, 2012 02:29
[Shell]カレントディレクトリを取得するスニペット
PWD=`pwd | xargs basename`
echo $PWD
@tomoyamkung
tomoyamkung / cvs-diff.sh
Created April 15, 2013 16:54
[Shell]CVS で指定した2つのタグ間(開始タグと終了タグ)で変更があったファイルを抽出する
#!/bin/sh
IFS="
"
WORK_DIR='./diff'
[ -d ${WORK_DIR} ] && rm -fr ${WORK_DIR}
mkdir ${WORK_DIR}
DIFF_TXT='diff.txt'
cvs -d USER_NAME@HOST:/path/to/repo rdiff -kk -s -u -r BEGIN_TAG -r END_TAG PROJECT_NAME > ${DIFF_TXT}
@tomoyamkung
tomoyamkung / string-delete-test.rb
Last active December 16, 2015 10:09
[Ruby]文字列削除の動作確認スニペット
# encoding: utf-8
class StringDelete
def delete(str, del)
str.delete(del)
end
end
if __FILE__ == $0
require 'test/unit'