Skip to content

Instantly share code, notes, and snippets.

# Put your answers here!
Last login: Sat Oct 6 16:04:39 on ttys001
JEFFREYs-MacBook-Pro:~ jeffrey$ rvm list
rvm rubies
ruby-1.8.7-p370 [ i686 ]
ruby-1.9.2-p290 [ x86_64 ]
ruby-1.9.3-p194 [ x86_64 ]
@idlehands
idlehands / roman_pt_I.rb
Created October 5, 2012 19:59
DBC Level 1 Roman numerals challenge PT 1
def roman_numerals(num)
arabic_numbers = [1000, 500, 100, 50, 10, 5, 1]
raw_roman_numbers = []
#POPULATE ARRAY WITH CORRECT NUMBERS IN ARABIC FORM
unless num == 0
arabic_numbers.each do |i|
if i <= num
(num/i).times do
@idlehands
idlehands / num_words_pair.rb
Created October 11, 2012 19:26
num_words_pair
@answer_string = ""
ONE_TO_NINETEEN = {1 => 'one', 2 => 'two', 3 => 'three', 4 => 'four', 5 => 'five', 6 => 'six',
7 => 'seven', 8 => 'eight', 9 => 'nine', 10 => 'ten', 11 => 'eleven', 12 => 'twelve',
13 => 'thirteen', 14 => 'fourteen', 15 => 'fifteen', 16 => 'sixteen',
17 => 'seventeen', 18 => 'eighteen', 19 => 'nineteen'
}
TENS = {100 => ' hundred ', 90 => 'nintey', 80 => 'eighty', 70 => 'seventy',
60 => 'sixty', 50 => 'fifty', 40 => 'forty', 30 => 'thirty', 20 => 'twenty', 1000 => " thousand "
}
@idlehands
idlehands / OrangeTree.rb
Created October 12, 2012 23:45
Young and Brent's OrangeTree with notes
class OrangeTree
HEIGHT_GROWTH = 10
FERTILE_AGE = 10
MAX_AGE = 100
=begin
Try setting up a method instead of a constant to avoid issues with over-defining if you ever
need need a sub-class.
example:
def height_growth
10
@idlehands
idlehands / blah.rb
Created October 15, 2012 20:09
instance fun
class BakingSheet
attr_accessor :cookies_on_the_sheet
def initialize
@cookies_on_the_sheet = []
end
def add_cookies(cookies)
@cookies_on_the_sheet << cookies
end
@idlehands
idlehands / todo2.rb
Created October 16, 2012 23:30
Todo 2.0 includes changes by Tanner Welsh
require 'time'
require 'yaml'
mylist = ToDoList.open('some_list.txt')
# => new list object
mylist.save
class ToDoList
attr_accessor :todos
@idlehands
idlehands / gist:3934434
Created October 22, 2012 21:17
color using ANSI escape codes

I have the bad habit of always using puts when I probably use print. As a a result, I was having trouble with the gems that were usable for colorizing my ToDo 3.0. I figured out a gem-free solution, using ANSI escape codes, and thought I'd share.

WARNING: don't be surprised if someone comes along and tells you this is the worst thing you could ever do. I have NO idea if it is a kosher solution, but it worked and it required VERY little change to my code. Additionally, this method works on the systems we have at DBC (and on mine) but I don't know if it is universal (I "think" it is).

A little set-up: I decided that I wanted to handle the color coding of priorities(and the keeping of the priorities) in my Todo class and not my TodoList class. Each todo keeps track of its own priority level, so I just modified the to_s method to include the color.

ANSI escape codes are used to send things to the output that aren't printed, not unlike the \ before the n of a new line. I'll show my code and then explai

@idlehands
idlehands / card.rb
Created October 24, 2012 23:29 — forked from dbc-challenges/card.rb
FlashCardinator
class Card
attr_reader :term, :definition
def initialize(term, definition)
@term = term
@definition = definition
end
def to_s
"#{term}: #{definition}"
@idlehands
idlehands / gist:4013455
Created November 4, 2012 20:09
Passing 'self' as a parameter when creating an instance of another class.
class Uber_class
attr_accessor :color
def initialize(color)
@color = color
@bob = Underling.new(self)
end
def run
@bob.test
end
@idlehands
idlehands / text.txt
Created May 25, 2013 22:09
Write a script that loads the file attached and counts the occurrence of each word and lists the 10 most common words. If you feel like doing a little more work, remove "common words" (your judgement, but I mean words like it, the, and and) from the list. HINT: You should use a hash to keep track of your counts. Arrays will likely be used to sol…
When is it okay to have repeating words or phrases, and when is it most definitely not? The distinction is an important element in your writing style.
Now, of course, I’m talking about repeating specific words, the key words of the sentence or paragraph. I’m not talking about repeating words or phrases such as, “It is,” or “and the”.
To give you a good example of what I mean, read the following:
When I got to the bottom of the stairs, I saw that the stairs were high and steep. I took a deep breath and began to climb the stairs. When I reached the top of the stairs I looked around me.
You’ll note of course that the word stairs was used four times in a short paragraph. It just doesn’t sound right to do that - it grates somehow. When you come across this in your work, you need to change it.
So, the above paragraph would be better written as something like: