Skip to content

Instantly share code, notes, and snippets.

View kennyt's full-sized avatar

Kenny Tran kennyt

  • San Francisco, CA
View GitHub Profile
@kennyt
kennyt / gist:3963800
Created October 27, 2012 09:44
10_timer
class Timer
def initialize
@seconds = 0
end
def seconds= (seconds)
@seconds = seconds
end
@kennyt
kennyt / gist:3963802
Created October 27, 2012 09:45
11_dictionary
class Dictionary
def initialize
@dictionary = {}
end
def entries
@dictionary
end
def add (entry)
@kennyt
kennyt / gist:3963803
Created October 27, 2012 09:46
12_rpn_calculator
class RPNCalculator
attr_accessor :calculator
def initialize
@calculator = []
end
def push (number)
@calculator << number
end
@kennyt
kennyt / gist:3963805
Created October 27, 2012 09:47
14_array_extensions
class Array
def sum
answer = 0
self.each do |number|
answer = answer + number
end
answer
end
def square
@kennyt
kennyt / gist:3963816
Created October 27, 2012 09:47
event_manager
require "csv"
require "sunlight"
class EventManager
INVALD_ZIPCODE = '00000'
INVALID_PHONENUMBER = '0000000000'
Sunlight::Base.api_key = "e179a6973728c4dd3fb1204283aaccb5"
def initialize (filename)
puts "EventManager initialized."
@kennyt
kennyt / w1d2_review.rb
Created January 9, 2013 06:26
w1d2 review
## General Comments
## You guys didn't comment enough early on in the day, I felt kind of lost on some methods.
## Later on you guys turned on beast mode though, nice commenting.
##
##
##Below I took out pieces of code on which I commented on, instead of uploading all files
##
## I stringed together all the parts of code I commented on.
## In general, space your code more!
def my_sort
self.size.times do |variable|
self.each_with_index do |element, index|
unless self[index+1].nil?
result = yield(element, self[index+1]) # adding a default i.e. proc.nil? {|x,y| x<=>y} instead of yield would make it more sort-like
if result==1 || result == true # I don't understand. Isn't everything other than nil true? Therefore result == 1 adds nothing.
##
##
##
# Inside the Hangman class :
# move the attr_accessors to the beginning of the method
# also, why have attr_accessors when you introduce each of the instance variables with def initialize?
attr_accessor :secret_word, :dictionary_words, :player_string, :word_size_floor, :word_size_ceiling,
class Word
# this could be changed to attr_reader since you only use it to read the value
attr_accessor :word, :parent_word_obj
def initialize(word, parent_word_obj)
@word = word
@parent_word_obj = parent_word_obj
end
end
@kennyt
kennyt / sweeper.rb
Created January 16, 2013 06:08
review!
class Game
require 'colorize'
require 'json'
require 'yaml'
def initialize
@placed_mines = 0
@correct_flags = 0
@flags = 0