Skip to content

Instantly share code, notes, and snippets.

@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: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 / unittest-template.xml
Last active October 13, 2015 15:12
[Eclipse,JUnit]JUnit のテストメソッド作成テンプレート
<?xml version="1.0" encoding="UTF-8" standalone="no"?><templates><template autoinsert="true" context="java-members" deleted="false" description="" enabled="true" name="test_abnormal">@${testType:newType(org.junit.Test)}
public void 異常系_${testName}() throws Exception {
${staticImport:importStatic('org.junit.Assert.*')}${cursor}// setup
// exercise
// verify
}</template><template autoinsert="true" context="java-members" deleted="false" description="" enabled="true" name="test_normal">@${testType:newType(org.junit.Test)}
public void 正常系_${testName}() throws Exception {
${staticImport:importStatic('org.junit.Assert.*')}${cursor}// setup
// exercise
// verify
@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'
@tomoyamkung
tomoyamkung / paapi-sample.rb
Last active December 16, 2015 13:09
[Ruby]amazon-ecs を使った商品情報取得サンプル。ResponseGoup は ItemAttributes, SalesRank, OfferSummary を指定。
# encoding: utf-8
require 'amazon/ecs'
require 'yaml'
require 'nokogiri'
class PaapiSample
def initialize
@config = YAML.load_file('./paapi-sample.yaml')