Skip to content

Instantly share code, notes, and snippets.

View sidazhang's full-sized avatar

Sidney Zhang sidazhang

  • Facebook
  • San Francisco
View GitHub Profile
//------------------------------------------------------------------------------------------------------------------
// YOUR CODE: Create your Zoo "object literal" and Animal "constructor" and "prototypes" here.
//------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------
// DRIVER CODE: Do **NOT** change anything below this point. Your task is to implement code above to make this work.
//------------------------------------------------------------------------------------------------------------------
require 'rspec'
require_relative '../assessment_week2'
describe Vehicle do
subject { Vehicle.new(Hash[color: "black", wheels: 2]) }
it { should be_instance_of Vehicle }
its (:wheels) { should == 2 }
@sidazhang
sidazhang / gist:5298441
Created April 3, 2013 04:25
propositions and conjunctions
http://prendan.com/EssntlHandOuts/00aaPrepositionQuickListUpdated.pdf
@sidazhang
sidazhang / gist:5298421
Created April 3, 2013 04:19
punctuations
/[\]\[!"#$%&'()*+,./:;<=>?@\^_`{|}~-]/
@sidazhang
sidazhang / gist:5296024
Created April 2, 2013 20:46
numbers in words
def convert_to_english(num)
word_hash = {
1 => "one",
2 => "two",
3 => "three",
4 => "four",
5 => "five",
6 => "six",
7 => "seven",
8 => "eight",
@sidazhang
sidazhang / gist:5266787
Created March 28, 2013 21:05
Print out times table
def times_table(rows)
# Your code here!
column_count = 0
row_count = 1
output = 0
results = []
answer = 0
(rows).times do
(rows).times do
column_count += 1
@sidazhang
sidazhang / gist:5261229
Created March 28, 2013 06:59
Reverse Polish Notation Calculator
class RPNCalculator
def evaluate(string)
string_array = string.split(" ")
queue_array = []
calculations = []
string_array.each do |element|
if (element.match /[A-Za-z0-9_.]/)
queue_array.push(element)
else
calculations = queue_array.slice!(queue_array.length-2,2)
@sidazhang
sidazhang / gist:5260942
Created March 28, 2013 05:37
Exercise: Regular Expressions
# Determine whether a string contains a Social Security number.
def has_ssn?(string)
output = string.match(/\d{3}-\d{2}-\d{4}/)
end
# Return the Social Security number from a string.
def grab_ssn(string)
if string.match(/\d{3}-\d{2}-\d{4}/)
match1 = string.match(/\d{3}-\d{2}-\d{4}/)
match1.to_s
@sidazhang
sidazhang / gist:5251249
Created March 27, 2013 03:00
Exercise: Build a simple guessing game
class GuessingGame
def initialize(guess)
@guess = guess
end
def guess(attempt)
if attempt > @guess
@correctanswer = 'correct'
return :high
elsif attempt == @guess
@sidazhang
sidazhang / gist:5251137
Created March 27, 2013 02:40
Exercise: Create a method to pad an array
class Array
def pad!(min_size, value = nil)
if self.length >= min_size
return self
else
add_amount = (self.length - min_size)
add_amount.times {self.push(value)}