Skip to content

Instantly share code, notes, and snippets.

View ysawa's full-sized avatar

Ysawa ysawa

View GitHub Profile
@ysawa
ysawa / .vimrc
Created October 12, 2011 14:31
converting ruby old hash syntax to new one
function! RubyNewHashSyntax()
:%s/:\(\w\+\) =>/\1:/ge
endfunction
command! RubyNewHashSyntax :call RubyNewHashSyntax()
@ysawa
ysawa / magic.rb
Created October 13, 2011 00:40
insert magic comment to **/*.rb
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
Dir['**/*.rb'].each do |f|
File.open(f, 'r+') do |io|
buf = io.readlines
unless /coding:/ =~ buf[0]
io.rewind
buf.unshift "# -*- coding: utf-8 -*-\n\n"
io.write buf.join
@ysawa
ysawa / truncatesvn
Created October 13, 2011 00:42
remove all .svn directories
#!/bin/sh
find . -name ".svn" -type d -exec rm -rf {} ";"
@ysawa
ysawa / .vimrc
Created October 13, 2011 02:57
push ESC twice and clear high light of text
nmap <ESC><ESC> :nohlsearch<CR><ESC>
@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 04:59
add magic comment
function! MagicComment()
return "# -*- coding: utf-8 -*-\<CR>"
endfunction
inoreabbrev <buffer> ## <C-R>=MagicComment()<CR>
@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 / 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 / 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 / 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