Skip to content

Instantly share code, notes, and snippets.

View rvbsanjose's full-sized avatar

Richard Van Breemen rvbsanjose

View GitHub Profile
@rvbsanjose
rvbsanjose / deaf_grandma.rb
Created October 7, 2012 10:03
Deaf Grandma
def deaf_grandma
returns = 0
until returns == 2
print "Say something to grandma: "
response = gets.chomp
if response.empty?
returns += 1
elsif response.match(/[A-Z]/)
puts "NO, NOT SINCE 1938!"
else
@rvbsanjose
rvbsanjose / read_the_error.rb
Created October 7, 2012 10:09
Read the Error
def print_and_sort(array)
output_string = ""
array = array.map! {|str| str.to_s }
array.each do |element|
output_string = output_string + " " + element
end
puts output_string
array.sort
end
@rvbsanjose
rvbsanjose / read_the_error_2.rb
Created October 7, 2012 10:10
Deaf Grandma 2
def print_and_sort(array)
output_string = ""
array.map!(&:to_s).each do |element|
output_string = output_string + " " + element
end
puts output_string
array.sort
end
@rvbsanjose
rvbsanjose / birthday_timestamp.rb
Created October 7, 2012 10:15
Birthday timestamp
def birthday_timestamp(date)
date = date.split('/')
month, day, year = date.pop(3)
birthday = Time.mktime(year, month, day)
time_now = Time.now
years = time_now.year - birthday.year
months = time_now.month - birthday.month
days = time_now.day - birthday.day
puts "#{years} years #{-months} months #{-days} day old" if days < 2
puts "#{years} years #{months} months #{days} days old" if days > 2
@rvbsanjose
rvbsanjose / hashed_table.rb
Created October 7, 2012 10:23
Hashed table
def hashed_table
hashed_data_table = Array.new(4)
hashed_data_table[0] = ["Number", "Name", "Position", "Points per Game"]
hashed_data_table[1] = ["12", "Joe Schmo", "Center", "[14, 32, 7, 0, 23]"]
hashed_data_table[2] = ["9", "Ms. Buckets", "Point Guard", "[19, 0, 11, 22, 0]"]
hashed_data_table[3] = ["31", "Harvey Kay", "Shooting Guard", "[0, 30, 16, 0, 25]"]
hashed_data_table[4] = ["18", "Sally Talls", "Power Forward", "[18, 29, 26, 31, 19]"]
hashed_data_table[5] = ["22", "MK DiBoux", "Small Forward", "[11, 0, 23, 17, 0]"]
index = 1
player_info = []
@rvbsanjose
rvbsanjose / binary_search.rb
Created October 10, 2012 00:20
Binary search
def binary_search(number, random_numbers)
middle = random_numbers.length / 2
until random_numbers[middle] == number
if random_numbers[middle] < number
middle += random_numbers[middle..-1].length / 2
end
if random_numbers[middle] > number
middle -= random_numbers[0..middle].length / 2
end
end
@rvbsanjose
rvbsanjose / object_privacy.rb
Created October 12, 2012 00:24 — forked from kunalbhatt/object_privacy.rb
Object Privacy
class BankAccount
def initialize(customer_name, type, acct_number)
@customer_name = customer_name
@type = type
@acct_number = acct_number
end
def customer_name=(customer_name)
@customer_name = customer_name
end
@rvbsanjose
rvbsanjose / cookies_and_oven.rb
Created October 15, 2012 07:30
Cookies and oven
class Cookie
def initialize
@baking_time = 0
end
def in_status
"#{name} cookies into the oven."
end
def bake_batch(time)
@rvbsanjose
rvbsanjose / todo1.rb
Created October 18, 2012 00:46
Todo 1.0
class Todo
def initialize(file_name)
@file_name = file_name
@tasks = []
load_file
end
def load_file
@task_file = File.read(@file_name)
@task_file.each_line { |line| @tasks << $1.strip if line =~ /^\d+. (.*)/ }
<?xml version="1.0" encoding="utf-8" ?>
<!-- SQL XML created by WWW SQL Designer, http://code.google.com/p/wwwsqldesigner/ -->
<!-- Active URL: http://socrates.devbootcamp.com/sql.html -->
<sql>
<datatypes db="mysql">
<group label="Numeric" color="rgb(238,238,170)">
<type label="Integer" length="0" sql="INTEGER" re="INT" quote=""/>
<type label="Decimal" length="1" sql="DECIMAL" re="DEC" quote=""/>
<type label="Single precision" length="0" sql="FLOAT" quote=""/>
<type label="Double precision" length="0" sql="DOUBLE" re="DOUBLE" quote=""/>