Skip to content

Instantly share code, notes, and snippets.

set nocompatible
filetype off
silent! call pathogen#runtime_append_all_bundles()
filetype plugin indent on
runtime macros/matchit.vim
set hidden
set autoread
set nobackup
set noswapfile
@tcrayford
tcrayford / Structs-and-nils.rb
Created March 18, 2011 10:50
Ruby's structs can lead to weird nils
irb(main):001:0> Month = Struct.new(:year, :month)
=> Month
irb(main):002:0> Month.new(1)
=> #<struct Month year=1, month=nil>
run-command-on-git-revisions 353ca58a031a9138b7fb58dc7d3598e2c1711e3e master 'find application/controllers -name "*.php" -print | xargs wc -l | sort -n | tail -2'
=> git rev-list --reverse 353ca58a031a9138b7fb58dc7d3598e2c1711e3e..master
Checking out: 41b3ab4 Set up template
=> git checkout --quiet 41b3ab4f711c59a3d99b222702f6769b87c31245
=> find application/controllers -name "*.php" -print | xargs wc -l | sort -n | tail -2
find: |: unknown option
set nocompatible
filetype off
silent! call pathogen#runtime_append_all_bundles()
filetype plugin indent on
runtime macros/matchit.vim
set hidden
set autoread
set nobackup
set noswapfile
class MyObject
def self.my_attr_reader(*args)
args.each do |method_name|
class_eval do
define_method(method_name) do
self.instance_variable_get("@#{method_name}")
end
end
end
end
step1specs = describe "removing implication" [
it "removes a simple implication"
(Disj (Not (Atom "A")) (Atom "B") `eql` (eliminateImplications $ Imp (Atom "A") (Atom "B")))
]
@tcrayford
tcrayford / vim_calculator_golf.rb
Created June 15, 2011 15:21
Vim golf challenge
# Turn the first block of code into the second one
# Starting on the 'r' of return
def add(string)
if /,/.match string
return string.split(',').map(&:to_i).inject(0, &:+)
end
if string.empty?
0
else
string.to_i
valid = some_method_to_set_valid()
status = error_message_from_valid_flag(valid)
def error_message_from_valid_flag(valid)
if valid == 1:
return "VALIDATED"
elif valid == 0:
return "INVALID"
elif valid == -1:
return "UNINITIALIZED_ERROR"
DestroysAllSoftware.byTypingFast becomes
DestroyAllSoftware.byTypingFast
SubscribesUsers.to(screencasts) becomes
SubscribeUsers.to(screencasts)
etc
>> foo = 1
>> x = lambda { if foo == 0; return foo; else; foo = foo - 1; x.call; end }
=> #<Proc:0x0000000106b9bd40@(irb):16>
>> x.call
=> 0