Skip to content

Instantly share code, notes, and snippets.

@marioaquino
marioaquino / gist:844088
Created February 25, 2011 16:59
gvimrc.local & vimrc.local
#.gvimrc.local
" Cancel the current search hightlight
nnoremap <esc> :noh<return><esc>
set guifont=Mensch:h12
---
#.vimrc.local
map <Leader>nf :NERDTreeFind<CR>
@marioaquino
marioaquino / queue.rb
Created February 26, 2011 15:21
Comparison of linked list vs array shift performance for FIFO queue
require 'rubygems'
require 'rspec'
require 'benchmark'
class FifoQueue
  def push(item)
    if (@head.nil? && @tail.nil?)
      @head = @tail = Wrapper.new(item)
    else
@marioaquino
marioaquino / gist:1007445
Created June 4, 2011 01:32
Git push failure
mario:(git)strangeloop[master]/$ git push origin master
Counting objects: 9, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 445 bytes, done.
Total 5 (delta 4), reused 0 (delta 0)
remote: Push worked, but post-receive failed: Connection reset by peer
remote: /data/github/current/vendor/gems/ruby/1.8/gems/redis-2.2.0/lib/redis/client.rb:234:in `ensure_connected'
remote: /data/github/current/vendor/gems/ruby/1.8/gems/redis-2.2.0/lib/redis/client.rb:114:in `process'
remote: /data/github/current/vendor/gems/ruby/1.8/gems/redis-2.2.0/lib/redis/client.rb:183:in `logging'
@marioaquino
marioaquino / gist:1273667
Created October 9, 2011 13:13
Binary chop (recursive solution)
require 'test/unit'
def chop(num, arr)
return -1 if arr.empty?
return -1 unless num <= arr.last
return -1 unless num >= arr.first
seek = lambda do |lower, upper|
next_index = (upper - lower) / 2
val = arr[next_index]
return next_index if val == num
@marioaquino
marioaquino / gist:1273956
Created October 9, 2011 17:55
Simple List Kata
require 'test/unit'
class List
def add(item)
new_item = Item.new(item, @tail)
@tail = new_item
end
def delete(item)
if item == @tail
@marioaquino
marioaquino / gist:1274004
Created October 9, 2011 18:44
Data Munging Kata
require 'test/unit'
TempRecord = Struct.new(:index, :high, :low)
class TempRecord
def <=>(record)
(high - low).<=>(record.high - record.low)
end
end
@marioaquino
marioaquino / group_of_thingies.rb
Created December 1, 2011 03:22 — forked from coffeencoke/group_of_thingies.rb
Test a block in Ruby
class GroupOfThingies
attr_accessor :thingies
# Use like this:
#
# group_of_thingies = GroupOfThingies.new
# group_of_thingies.each do |thing|
# puts "Check out this awesome thing: #{thing}!"
# end
#
@marioaquino
marioaquino / explanation.txt
Created January 13, 2012 14:14
RSpec tagging syntax with numbers fail
In the example, I can run:
$> rspec . --tag "2"
or
$> rspec . --tag 2
and it will find the test I want. The others are unreachable via tag.
@marioaquino
marioaquino / immutable_ruby1.rb
Created March 18, 2013 02:08
Partially immutability in object construction in Ruby.
class Profile
def initialize(email)
self.class.send :define_method, :email, -> { email }
end
end
p = Profile.new '[email protected]'
p.email #=> '[email protected]'
p.email = '[email protected]' #=> <boom>
p.instance_variable_set :@email, '[email protected]'
@marioaquino
marioaquino / ruby_immutability_2.rb
Created March 18, 2013 02:16
Polite Ruby immutability
class Profile
def initialize(email)
email_val = email.dup.freeze
self.class.send :define_method, :email, -> { email_val }
end
end