Skip to content

Instantly share code, notes, and snippets.

View tpope's full-sized avatar

Tim Pope tpope

View GitHub Profile
def ccexp?d;m=d[-2,2].to_i;m<10||m==10&&d[0,2].to_i<7;end
def morse s;26.times{|i|s.gsub!(/#{(97+i).chr}/i,"$be5 J8G#T6P'&9Sl/,!-H0cfk".split('').map{|x|(x[0]-31).to_s(3).tr('12','.-')}[i])};s;end
def ccexp?d;d[-2,2].to_i<=10&&d[0,2].to_i<7 end
def fibsum _;_<3?_:1+fibsum(_-1)+fibsum(_-2)end
def ccexp?d;d[-2,2].to_i<=10&&d[0,2].to_i<7 end
def luhn?n;s=0;n.size.times{|i|x=n[-i-1,1].to_i*(i%2+1);s+=x>9?x+1:x};s%10==0;end
def mask _;_[6..-5]='*'.*_.size-10;_;end
When /^(.*) in the "([^\"]*)" section$/ do |action, title|
within "//*[(h1|h2|h3|h4|h5|h6|legend|caption)/descendant-or-self::*[contains(text(), '#{title}')]]" do
When action
end
end
When /^(.*) in the "([^\"]*)" row$/ do |action, title|
within "//*[(th|td)/descendant-or-self::*[contains(text(), '#{title}')]]" do
When action
end
inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a
function! s:align()
let p = '^\s*|\s.*\s|\s*$'
if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
Tabularize/|/l1
normal! 0
call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
@tpope
tpope / env.rb
Created September 2, 2009 21:27
# Enable Webrat's Selenium mode if one or more scenarios is tagged @selenium
Webrat.configure do |config|
config.mode = :rails
ObjectSpace.each_object(Cucumber::Ast::Features) do |features|
config.mode = :selenium if features.tag_count('selenium').nonzero?
end
end