Skip to content

Instantly share code, notes, and snippets.

@ravelll
ravelll / seats_shuffle.php
Created May 23, 2013 15:07
Seats shuffle program.
<?php
$graduates = array("okkun","kitak","takeo","gussan");
shuffle($graduates);
print_r($graduates);
?>
@ravelll
ravelll / 4_6_1.rb
Created May 24, 2013 03:02
ruby on rails tutorial Chapter4 exercise1
def string_shuffle(s)
s.split('').shuffle.join
end
puts string_shuffle("asdffdsa")
@ravelll
ravelll / 4_6_2.rb
Last active December 17, 2015 16:49
ruby on rails tutorial Chapter4 exercise2
class String
def shuffle
self.split('').shuffle.join
end
end
puts "asdffdsa".shuffle
@ravelll
ravelll / 4_6_3.rb
Created May 24, 2013 03:05
ruby on rails tutorial Chapter4 exercise3
person1 = {first:"coca",last:"cola"}
person2 = {first:"ginger",last:"ale"}
person3 = {first:"dr.",last:"pepper"}
params = {}
params[:father] = person1
params[:mother] = person2
params[:child] = person3
puts params[:father][:first]
@ravelll
ravelll / 4_6_4.rb
Created May 24, 2013 03:32
ruby on rails tutorial Chapter4 exercise4
hsh1 = {first:"Satoshi",last:"Tanaka",age:"25"}
hsh2 = {last:"Suzuki",age:"30"}
#show the newest values
puts hsh1.merge(hsh2)
#show old value when the key duplicated
puts hsh1.merge(hsh2){|key,oldv,newv|oldv}
@ravelll
ravelll / 20130701 - puppet
Created July 1, 2013 10:18
mysqlユーザ作成やrbenv導入で足りない要素があったので追加。 などなど。
[mysqlのユーザ作成まわり]
exec { 'create_user_mysql':
require => Service['mysqld'],
path => ['/usr/bin','/bin'],
command => 'mysql -u root -e "grant select,alter,index,create,insert,update,delete on *.* to \'gussan\'@\'localhost\' identified by \'gussan\';"',
# unless => 'mysql -u root -e "select User, Host from mysql.user where User=\'gussan\' and Host=\'localhost\'" | grep gussan'
}
・トラブル
@ravelll
ravelll / peco-select-rake-task.zsh
Created July 2, 2014 04:42
Zsh script to show and select rake tasks using peco.
function peco_select_rake_task_all() {
local tasks="bundle exec rake -AT"
task=$(eval $tasks | peco --query "$LBUFFER" )
task_split=("${(s/ /)task}")
BUFFER=$task_split[1,2]
CURSOR=$#BUFFER
zle -R -c
}
zle -N peco_select_rake_task_all
@ravelll
ravelll / gist:20f43687f12df09a0a79
Last active August 29, 2015 14:05
Perfect Ruby p.113 ( trap SIGINT )
# interrupt_handler.rb
trap :INT do
puts '\nInterrupted!'
exit
end
loop do
sleep 1
end
@ravelll
ravelll / gist:eeee5dc0ebdb83a80c38
Created September 29, 2014 10:48
ヒント 10-5-2
describe "pagination" do
before(:each) do
sign_in user
visit users_path
end
context 'When user has 30 microposts' do
let!(:Micropost) { 30.times { FactoryGirl.create(:micropost, user: user) } }
# micropost にあたるタグが30個ある
@ravelll
ravelll / scouter.vim
Created November 9, 2014 07:22
Vim Scouter
function! Scouter(file, ...)
let pat = '^\s*$\|^\s*"'
let lines = readfile(a:file)
if !a:0 || !a:1
let lines = split(substitute(join(lines, "\n"), '\n\s*\\', '', 'g'), "\n")
endif
return len(filter(lines,'v:val !~ pat'))
endfunction
command! -bar -bang -nargs=? -complete=file Scouter
\ echo Scouter(empty(<q-args>) ? $MYVIMRC : expand(<q-args>), <bang>0)