Skip to content

Instantly share code, notes, and snippets.

View yitsushi's full-sized avatar
🏳️‍⚧️

Victoria (Balazs) Nadasdi yitsushi

🏳️‍⚧️
View GitHub Profile
class Array
def randomize
self.sort {rand(self.length / 2)-1}
end
def randomize!
self.sort! {rand(self.length / 2)-1}
end
end
# File: person_module.rb
module Person
def age
Time.now - self.birthday
end
end
# File: main.rb
require 'person_module'
class Queue
@@list = []
def self.add(entry)
@@list << entry
end
def self.list
@@list
end
end
class String
def camelize(first_letter_in_uppercase = :upper)
s = gsub(/\/(.?)/){|x| "::#{x[-1..-1].upcase unless x == '/'}"}.gsub(/(^|_)(.)/){|x| x[-1..-1].upcase}
s[0...1] = s[0...1].downcase unless first_letter_in_uppercase == :upper
s
end
def constantize
raise(NameError, "#{inspect} is not a valid constant name!") unless m = /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/.match(self)
Object.module_eval("::#{m[1]}", __FILE__, __LINE__)
class AppleTree
def initialize
puts "OMG! /root"
end
end
module NS
class AppleTree
def initialize
puts "ROFL /root/NS"
diff --git a/pivotal_tracker.rb b/pivotal_tracker.rb
index 8ed3884..03da167 100644
--- a/pivotal_tracker.rb
+++ b/pivotal_tracker.rb
@@ -170,7 +170,7 @@ private
:estimate => doc.at('estimate').innerHTML,
:current_state => doc.at('current_state').innerHTML,
:description => doc.at('description').innerHTML,
- :url => doc.at('url').innerHTML
+ :url => doc.at('url').innerHTML,
def gen_log_base(base)
return Proc.new { |num| Math.log(num, base) }
end
log2 = gen_log_base(2)
log10 = gen_log_base(10)
puts log2.call(4)
puts log10.call(100)
@yitsushi
yitsushi / poem.rb
Created October 14, 2010 14:22
Program of the true Love
# Title
feelings = {:happy => 1, :suicide => 0}
supernaturals = { }
begin
# begining
me = i = Person.new
you = Angel.new
i.love you if you.love? me
@yitsushi
yitsushi / mongomapper_integer_size_limit.rb
Created October 22, 2010 23:48
[demo] Vaidator for size of an integer
class TestCucc
include MongoMapper::Document
key :cucc, Integer
validates_true_for :cucc,
:logic => lambda { | x | x.cucc >= 1 && x.cucc <= 5 },
:message => "must be in the following range: 1 to 5"
end
=begin
ruby-1.9.2-p0 > load "t.rb"
class A
def test
puts "A::test"
end
end
class B
def test
puts "B::test"
C.a.test