Skip to content

Instantly share code, notes, and snippets.

View dinks's full-sized avatar

Dinesh Vasudevan dinks

View GitHub Profile
@dinks
dinks / m.rb
Created May 17, 2015 19:43
Mutable Objects as Hash Keys
a = [1, 2] # [1, 2]
a.object_id # 70364895085700
a << 3 # [1, 2, 3]
a.object_id # 70364895085700
h = {} # {}
h[a] = true # true
h # {[1, 2, 3]=>true}
h[a] # true
@dinks
dinks / load.rb
Created May 17, 2015 19:20
Autoload pitfalls
# qux.rb
Qux = "I'm at the root!"
# foo.rb
module Foo
end
# foo/qux.rb
module Foo
Qux = "I'm in Foo!"
@dinks
dinks / memoize.rb
Created April 22, 2015 13:17
Memoize in Ruby
# Memoize with extend
module Memoize
def memoize(method)
unmemoized_name = :"__unmemoized_#{method}"
alias_method unmemoized_name, method
define_method method do
@__memoized_results ||= {}
@dinks
dinks / prepend_vs_include.rb
Created April 22, 2015 13:04
Prepend versus Include
module AA
def hi
end
end
class A
include AA
end
class B
@dinks
dinks / keybase.md
Created March 20, 2015 08:08
keybase

Keybase proof

I hereby claim:

  • I am dinks on github.
  • I am dinks (https://keybase.io/dinks) on keybase.
  • I have a public key whose fingerprint is D872 3799 C467 BC06 6591 DAE0 75E9 3E8C 90F0 C705

To claim this, I am signing this object:

@dinks
dinks / test.sh
Created March 11, 2015 10:04
Gems of a project
bundle show | wc -l
@dinks
dinks / hearts_formatter.rb
Last active February 6, 2023 13:18
Hearts Formatter
require 'rspec/core/formatters/base_text_formatter'
# Custom Rspec formatter
# bundle exec rspec --require ./hearts_formatter.rb --format HeartsFormatter
#
class HeartsFormatter < RSpec::Core::Formatters::BaseTextFormatter
DOT_SUCCESS = "💚"
DOT_PENDING = "💛"
DOT_FAILURE = "💔"
@dinks
dinks / app.conf
Created January 24, 2015 17:03
Conf for Passenger
<VirtualHost *:80>
ServerName app
ServerAlias app.dev app.local
DocumentRoot /opt/app/public
PassengerRuby /home/user/ruby-wrapper.sh
PassengerMinInstances 1
PassengerMaxPoolSize 3
PassengerUser user
RailsBaseURI /
@dinks
dinks / .gitconfig
Last active August 29, 2015 14:14
My Gitconfig
[color]
ui = true
[difftool "sourcetree"]
cmd = opendiff \"$LOCAL\" \"$REMOTE\"
path =
[mergetool "sourcetree"]
cmd = /opt/homebrew-cask/Caskroom/sourcetree/2.0.4/SourceTree.app/Contents/Resources/opendiff-w.sh \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\"
trustExitCode = true
[alias]
co = checkout
@dinks
dinks / infinite_collection.rb
Created January 19, 2015 19:05
Ruby infinites collections
# Always use lazy!
(0..3).lazy.cycle.map {|x| x * 10}.take(5).to_a
# Without lazy, the program wont stop!