Skip to content

Instantly share code, notes, and snippets.

@brianstorti
brianstorti / config
Created March 9, 2012 17:48
ssh config
# This is ~/.ssh/config
# For all hosts
ServerAliveInterval 30
@brianstorti
brianstorti / observer.rb
Created March 4, 2012 20:48
Observer in ruby
module Subject
attr_reader :observers
def subscribe_observer(observer)
@observers ||= []
@observers << observer
end
def unsubscribe_observer(observer)
@observers.delete(observer)
@brianstorti
brianstorti / gist:1502497
Created December 20, 2011 17:52
Oracle tablespace size
select a.TABLESPACE_NAME,
a.BYTES bytes_used,
b.BYTES bytes_free,
b.largest,
round(((a.BYTES-b.BYTES)/a.BYTES)*100,2) percent_used
from
(
select TABLESPACE_NAME,
sum(BYTES) BYTES
from dba_data_files
@brianstorti
brianstorti / gol_spec.rb
Created December 14, 2011 02:47
game of life
require "rspec"
class Cell
attr_accessor :world, :x, :y
def initialize(world, x=0, y=0)
@world, @x, @y = world, x, y
world.cells << self
end
class Thing
def do_something
puts "a"
end
end
thing = Thing.new
def thing.do_something
puts "b"
end
@brianstorti
brianstorti / eval.rb
Created November 20, 2011 16:16
attr_create (attr_accessor like)
class Module
def attr_create(*symbols)
symbols.each do |symbol|
class_eval("def #{symbol}; @#{symbol}; end;")
class_eval("def #{symbol}=(value); @#{symbol} = value; end;")
end
end
end
class A
@brianstorti
brianstorti / module.rb
Created November 15, 2011 02:00
this_var
class Class
def method_missing(name, *args)
name = name.to_s
if name =~ /this/
name["this_"] = ""
eval("@#{name}")
end
end
end
@brianstorti
brianstorti / open.rb
Created November 15, 2011 01:06
MyOpenScruct
class MyOpenStruct
def initialize
@attributes = {}
end
def method_missing(name, *args)
attribute = name.to_s
if attribute =~ /=$/
@attributes[attribute.chop] = args[0]
else
@brianstorti
brianstorti / 1.rb
Created November 12, 2011 16:27
Open classes
var = "foo"
@brianstorti
brianstorti / module.rb
Created November 9, 2011 01:23
extend and include
module Test
def class_method
"class method"
end
end
class A
extend Test
end