Skip to content

Instantly share code, notes, and snippets.

file = File.open("filename","r")
2.times { file.gets.chomp }
data = ""
while data = file.gets
puts data
end
@atton
atton / ref_install.sh
Created August 12, 2012 08:07
ref.vim install script
#!/bin/sh
# iedevのVim勉強会(http://atnd.org/events/30822)用のスクリプト。
# vunldeとref.vimをインストール + webdict周りの設定をします。
# git と w3m は用意しておいてください
# git のチェック
which git > /dev/null
if [ $? -ne 0 ]; then
echo git not found. please install git.
exit
@atton
atton / gist:3337950
Created August 13, 2012 07:46
install vim
hg clone http://vim.googlecode.com/hg vim
cd vim
./configure --enable-multibyte
make
make test
sudo make install
cd ..
rm -rf vim
@atton
atton / gist:3360562
Created August 15, 2012 14:23
ruby settings
.vimrcにこの行を追加
autocmd BufNewFile *.rb 0r ~/.vim/templates/ruby.rb "ruby
~/.vim/templates/ruby.rb に下の行だけのファイルを作る
# -*- coding: utf-8 -*-
@atton
atton / puts_hash.rb
Created August 25, 2012 13:50
メソッドへの {} 渡し
# -*- coding: utf-8 -*-
# method { ... } だと
# ブロックを渡してるのかハッシュを渡してるのか、ってなるので
# ハッシュを渡したい時は {} を省略して良いらしい
def puts_hash_hoge hash
puts hash[:hoge]
end
puts_hash_hoge :hoge => "hogehoge" , :fuga => "fugafuga"
@atton
atton / hash_and_array.rb
Created August 26, 2012 11:33
hash and array
# -*- coding: utf-8 -*-
# ハッシュの中に配列
array_in_hash = {:hoge => [1,2] , :fuga => [3,4]}
# keyを渡すと配列が返ってくる
p array_in_hash[:hoge] # => [1, 2]
# その配列の0番目
p array_in_hash[:hoge][0] # => 1
@atton
atton / next.rb
Created August 28, 2012 08:47
next test
# 0 から 5 まで出力
(0..5).each do |num|
if num == 3
next # 3だけ飛ばす
end
puts num
end
@atton
atton / make.txt
Created September 26, 2012 13:25
watchdogsrun
:compiler ruby
:make -c %
した時のquickfix
hoge.rb|1 error| syntax error, unexpected '{', expecting '\n' or ';'
hoge.rb|2 error| unterminated string meets end of file
\ "watchdogs_checker/ruby" : {
\ "command" : "ruby",
\ "exec" : "%c %o -c %s:p",
\ "quickfix/errorformat" : "%E%f:%l:\ %m",
\ },
{
'args': '',
'cmdopt': '',
'command': 'ruby',
'exec': '%c %o -c %s:p',
'hook/hier_update/enable_exit': 1,
'hook/output_config/enable_module_loaded': '1',
'hook/output_config/log': '1',
'hook/quickfix_replate_tempname_to_bufnr/enable_exit': 1,
'hook/quickfix_replate_tempname_to_bufnr/priority_exit': -10,