Skip to content

Instantly share code, notes, and snippets.

View ysawa's full-sized avatar

Ysawa ysawa

View GitHub Profile
@ysawa
ysawa / spec_helper.rb
Created October 16, 2012 08:51
use Mongoid 3 and delete all collections before :each spec
# Mongoid 3 uses Moped as MongoDB driver, not mongo-ruby-driver.
# Thus we should replace some codes.
# Change your spec/spec_helper.rb like this code below:
RSpec.configure do |config|
config.before(:each) do
Mongoid.session(:default).collections.each do |collection|
# Each Moped::Collection instance is picked up,
# and drop the collection.
collection.drop
@ysawa
ysawa / Gemfile
Created September 27, 2012 09:50
Partial codes of Gemfile to notify on Mac OS X, Linux, and Windows
# Notifiers
case RUBY_PLATFORM
when /linux/i
gem 'libnotify'
when /darwin/i
gem 'growl'
when /mswin(?!ce)|mingw|cygwin|bccwin/i
gem 'rb-notifu'
end
@ysawa
ysawa / .vimrc
Created July 2, 2012 00:32
my .vimrc 2012/07/02
syntax on
set number
set nocompatible
set nosmartcase
set expandtab
set ts=2 st=2 sts=2
set shiftwidth=2
set cursorline
@ysawa
ysawa / birth.rb
Created November 30, 2011 11:00
calculate age from birthday
birth = Time.parse('1986/06/08')
(Time.now.strftime("%Y%m%d").to_i - birth.strftime("%Y%m%d").to_i) / 10000
@ysawa
ysawa / cakephp.vim
Created November 18, 2011 06:24
modify codes to use CakePHP Helpers
function! CakePHPHelpers()
:%s/\$this->Form/\$form/ge
:%s/\$this->Html/\$html/ge
endfunction
command! CakePHPHelpers :call CakePHPHelpers()
@ysawa
ysawa / phpabbreviation.vim
Created November 4, 2011 02:44
PHPAbbreviation: abbreviate php syntax
function! PHPAbbreviation()
:%s/<?\(\s\+\|php\s\+\)echo\s\+\(.*\)\s*;\s*?>/<?= \2; ?>/ge
endfunction
command! PHPAbbreviation :call PHPAbbreviation()
@ysawa
ysawa / search.sh
Created October 13, 2011 07:25
search text in the directory recursively
#!/bin/sh
find . -type f | grep -v "\/\." | xargs grep $1
@ysawa
ysawa / .vimrc
Created October 13, 2011 04:59
add magic comment
function! MagicComment()
return "# -*- coding: utf-8 -*-\<CR>"
endfunction
inoreabbrev <buffer> ## <C-R>=MagicComment()<CR>
@ysawa
ysawa / .vimrc
Created October 13, 2011 02:58
move on the line
nnoremap j gj
nnoremap k gk
nnoremap <Down> gj
nnoremap <Up> gk
@ysawa
ysawa / .vimrc
Created October 13, 2011 02:57
push ESC twice and clear high light of text
nmap <ESC><ESC> :nohlsearch<CR><ESC>