Skip to content

Instantly share code, notes, and snippets.

@pinzolo
pinzolo / .travis.yml
Last active July 24, 2019 08:18
Redmine のプラグインを Travis-ci でテストするための各種スクリプト
language: ruby
rvm:
- 1.9.3
- 2.0.0
before_install: sh travis/before_install.sh
script: sh travis/exec_test.sh
@pinzolo
pinzolo / install_ruby_by_rbenv_on_mavericks.sh
Last active December 29, 2015 05:59
よく忘れるので、最新をインストールした際にメモ
# Install ruby 2.1.2
CONFIGURE_OPTS="--enable-shared --with-readline-dir=`brew --prefix readline` --with-openssl-dir=`brew --prefix openssl`" rbenv install 2.1.2
# Install ruby 2.0.0-p247
CONFIGURE_OPTS="--enable-shared --with-readline-dir=`brew --prefix readline` --with-openssl-dir=`brew --prefix openssl`" rbenv install 2.0.0-p247
# Install ruby 1.9.3-p448
CONFIGURE_OPTS="--enable-shared --with-readline-dir=`brew --prefix readline` --with-openssl-dir=`brew --prefix openssl`" rbenv install 1.9.3-p448
@pinzolo
pinzolo / remove_color_sequences.rb
Last active December 29, 2015 12:19
コンソール出力用の文字列からカラーシーケンスを除去する
def remove_color_sequences(text)
text.gsub(/\e\[(\d+;)*\d+m/, "")
end
@pinzolo
pinzolo / coveralls_filter_1.rb
Created November 29, 2013 00:58
Coveralls でカバレッジ集計対象のファイルを制限する方法 https://coveralls.io/docs/ruby を参照
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
SimpleCov.start do
# スペックファイルを除外
add_filter "/spec/"
end
@pinzolo
pinzolo / find_lost_words.rb
Last active December 30, 2015 11:09
各辞書ファイルに未登録の可能性があるキーを列挙する
# coding: utf-8
require "yaml"
def to_flat(key, value)
{}.tap do |dic|
if value.is_a?(Hash)
value.each do |k, v|
dic.merge!(to_flat("#{key}.#{k}", v))
end
else
@pinzolo
pinzolo / i18n_load_path_adjustment.rb
Last active December 30, 2015 16:19
Redmine プラグインの言語ファイルが優先されるように I18n.load_path を調整する
# coding: utf-8
module RedmineApp
class Application < Rails::Application
config.after_initialize do
plugin_root_path = File.expand_path(File.join(File.dirname(__FILE__), '../'))
Dir.glob(File.join(plugin_root_path, 'config', 'locales', '*.yml')) do |path|
if I18n.load_path.include?(path)
I18n.load_path.delete(path)
I18n.load_path << path
end
@pinzolo
pinzolo / test_console_output_by_rspec.rb
Created December 13, 2013 07:12
コンソールに文字を出力する処理を検証する
require "stringio"
def capture(stream)
begin
stream = stream.to_s
eval "$#{stream} = StringIO.new"
yield
result = eval("$#{stream}").string
ensure
eval "$#{stream} = #{stream.upcase}"
@pinzolo
pinzolo / object_cordinated_with_child_window.js
Created December 13, 2013 13:04
子ウィンドウを開き、特定のオブジェクトを disabled にし、子ウィンドウが閉じられたら、自動的にオブジェクトを enable にする。
var obj = document.getElementById("obj");
obj.setAttribute("disabled", "disabled");
var child = window.open("child.html", "child window");
child.focus();
var timer;
timer = setInterval(function() {
if (child.closed) {
obj.removeAttribute("disabled");
clearInterval(timer);
@pinzolo
pinzolo / clip_file_element.vim
Last active May 28, 2020 01:41
現在開いているファイルのパスなどをレジスタやクリップボードへ登録する
" 指定のデータをレジスタに登録する
function! s:Clip(data)
let @*=a:data
echo "clipped: " . a:data
endfunction
" 現在開いているファイルのパスをレジスタへ
command! -nargs=0 ClipPath call s:Clip(expand('%:p'))
" 現在開いているファイルのファイル名をレジスタへ
command! -nargs=0 ClipFile call s:Clip(expand('%:t'))
@pinzolo
pinzolo / array_is_uniq.rb
Created January 6, 2014 02:52
Array クラスに uniq? メソッドを追加する
class Array
# Is self a unique array?
def uniq?
self.uniq.size == self.size
end
end