Skip to content
This repository was archived by the owner on Dec 1, 2021. It is now read-only.

tic-tac-toe! #170

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
94d0a7e
Did my homework
tallbryan Oct 17, 2012
07a2a98
did my homework
tallbryan Oct 17, 2012
b059fd9
Merge branch 'master' of git://github.com/UWE-Ruby/RubyFall2012 into …
tallbryan Oct 23, 2012
0ac3146
finished week 2 homework
tallbryan Oct 23, 2012
dc3acef
finally finished week 1 HW
tallbryan Oct 23, 2012
5d3c495
Merge git://github.com/UWE-Ruby/RubyFall2012 into answers
tallbryan Oct 24, 2012
18904a7
week 3 homework
tallbryan Oct 30, 2012
bdf01d6
remerging week2
tallbryan Oct 30, 2012
72887a7
finished week3 homework
tallbryan Oct 30, 2012
dc85a16
Merge git://github.com/UWE-Ruby/RubyFall2012 into answers
tallbryan Oct 31, 2012
3e5149a
homework
tallbryan Nov 6, 2012
1df6770
completed week 4 homework
tallbryan Nov 6, 2012
ddf3c1f
removed my completed homework from the answers branch
tallbryan Nov 6, 2012
7fe5ba5
commiting everything
tallbryan Nov 6, 2012
da0b158
making sure
tallbryan Nov 6, 2012
1b1efe2
worked on rakefile
tallbryan Nov 11, 2012
2ba2ed5
changes
tallbryan Nov 11, 2012
7bfe1a7
bringing in week 6 stuff to master
tallbryan Nov 17, 2012
b00281c
my gem
tallbryan Nov 21, 2012
5f294d6
mid term
tallbryan Nov 27, 2012
fa7e8f6
merging in week 7
tallbryan Nov 27, 2012
b10e458
answered questions
tallbryan Nov 28, 2012
703f247
callchain added
tallbryan Nov 28, 2012
46bd65b
merging in week8
tallbryan Nov 28, 2012
66660e9
couch - make a class respond to anything
tallbryan Nov 29, 2012
897b5fe
brining in lastest week8
tallbryan Nov 29, 2012
55e3850
first 4 passed
tallbryan Nov 29, 2012
0edd8a4
still only 4 working
tallbryan Nov 29, 2012
a4d6c90
5 tests passing, i think
tallbryan Dec 1, 2012
487f913
suddenly 13 tests passing. better commit this one
tallbryan Dec 1, 2012
60b067a
good up through computers move
tallbryan Dec 2, 2012
c738579
22 tests passing
tallbryan Dec 2, 2012
0ec0080
25 passed
tallbryan Dec 3, 2012
f745383
33 tests passed
tallbryan Dec 3, 2012
068428c
36 passed
tallbryan Dec 3, 2012
e92663a
ATll tic-tac-toe scenarios passing
tallbryan Dec 3, 2012
3eea6d9
reverted tic-tac-toe steps to the original, unfixed the palyer typo
tallbryan Dec 3, 2012
59fd6c9
added a touch of meta programming for kicks
tallbryan Dec 3, 2012
8069bb2
did some refactoring
tallbryan Dec 8, 2012
97c867d
message
tallbryan Dec 8, 2012
12031c3
modified .gitignore
tallbryan Dec 8, 2012
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
./final
*.gem
*.rbc
.bundle
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ Week 5
Week 6
* Mid-term due!
* Projects intro
* Control
* Exceptions
* Gems
* CI

Week 7
* Cucumber
* Testing frameworks
* Refactoring

Week 8
* Gems
* CI

Week 9
* Metaprogramming
* Duck typing
* Monkey patching

Week 9
* Control
* Exceptions

Week 10
* Final due!
* Project due!
Expand Down
33 changes: 33 additions & 0 deletions callchain.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Class Object
def call_chain
"object"
end
end

Class Animal
def call_chain
"#{self}.#{super}"
end
end

module NamedThing
def call_chain
"#{self}.#{super}"
end
end

class Person < Animal
include NamedThing
def call_chain
"#{self}.#{super}
end
end

class Renee < Person
def call_chain
"#{self}.#{super}"
end
end



Binary file added final/Screen Shot 2012-12-03 at 12.34.21 AM.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions final/musicscrape.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#require 'rubygems'
#require 'crack'
#require 'open-uri'
require 'rest-client'

url='http://www.thestranger.com/seattle/Music' #The url for the web page we want

puts (RestClient.get(url))
41 changes: 41 additions & 0 deletions final/musicscrape_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require "#{File.dirname(__FILE__)}/musicscrape"

describe Scrape do
before do
@scrape = Scrape.new(:strangermusic)
@scrape.url = "http://www.thestranger.com/seattle/Music"
end
it "Should load the stranger music page" do
@scrape.load_page.should not eq "" #I mean the string shouldn't be empty
end
it "Should Identify the beginning of the recommended shows"do
end
it "Should Idenfify the end of the recommended shows" do
end
it "Should throw away the rest of the text" do
end
end

describe Parse do
it "Should pick out all the event names" do
end
it "Should pick out all the event locations" do
end
it "Should pick out all the dates" do
end
it "Should pick out all the prices" do
end
end

describe PushToGoogle do
it "Should send each event to your google calendar" do
end
end


describe GetUserInfo do
it "Should get your username" do
end
it "Should get your password" do
end
end
48 changes: 48 additions & 0 deletions final/prep_notes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
this month's calendar
http://www.seattle.gov/UTIL/WARP/home/alp?openApp=CC&address=6408%2044TH%20AVE%20S

Print next year's calendar
www.seattle.gov/UTIL/WARP/PrintCollectionCalendar/Index?Account=&WhichYear=Next&Address=6408~~44TH~AVE~S~~~100~6408%2044TH%20AVE%20S

Recycling Icon <img src="/UTIL/WARP/images/FYIcon32.gif" width="30px" height="35px">
Garbage Icon <img src="/UTIL/WARP/images/GarbageIcon32.gif" width="30px" height="35px">
Recycle Icon <img src="/UTIL/WARP/images/RecycleIcon32.gif" width="30px" height="35px">

require 'rubygems'
require 'crack'
require 'open-uri'
require 'rest-client'

url='http://en.wikipedia.org/w/api.php?action=opensearch&search=At&namespace=0'

puts Crack::JSON.parse(RestClient.get(url))

I don't really want to publish that gem on the web, and it's a little too ambitious. I'm going to practice my web scraping with something similar.

http://www.thestranger.com/seattle/Music

pull all the recommended events and push them to your google calendar.

sudo gem install googlecalendar
Usage
Adding an Event
require 'googlecalendar'
g = GData.new
g.login('[email protected]', 'REPLACE_WITH_YOUR_PASSWORD')
event = { :title => 'title',
:content => 'content',
:author => 'pub.cog',
:email => '[email protected]',
:where => 'Toulouse,France',
:startTime => '2007-06-06T15:00:00.000Z',
:endTime => '2007-06-06T17:00:00.000Z'}
g.new_event(event)

require 'rubygems'
require 'crack'
require 'open-uri'
require 'rest-client'

url='http://en.wikipedia.org/w/api.php?action=opensearch&search=At&namespace=0'

puts Crack::JSON.parse(RestClient.get(url))
21 changes: 21 additions & 0 deletions mid_term/even_number.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class EvenNumber
include Comparable
attr_reader :value

def self.new(value)
return false if value.odd?
super
end

def initialize(value)
@value = value
end

def succ
EvenNumber.new(@value + 2)
end

def <=> (other)
@value <=> other.value
end
end
27 changes: 27 additions & 0 deletions mid_term/even_number_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# - Write a passing rspec file called even_number_spec.rb that tests a class
# called EvenNumber.
# - The EvenNumber class should:
# - Only allow even numbers
# - Get the next even number
# - Compare even numbers
# - Generate a range of even numbers

require './even_number.rb'

describe EvenNumber do
it "should only allow even numbers" do
EvenNumber.new(5).should be_false
end

it "should get the next even number" do
EvenNumber.new(2).succ.should == EvenNumber.new(4)
end

it "should compare even numbers" do
(EvenNumber.new(2) < EvenNumber.new(4)).should be_true
end

it "should generate a range of even numbers" do
(EvenNumber.new(2)..EvenNumber.new(8)).should be_a Range
end
end
34 changes: 17 additions & 17 deletions mid_term/mid_term_spec.rb
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
require "#{File.dirname(__FILE__)}/turkey"

describe Turkey do

before do
@turkey = Turkey.new(10)
end

it "should report the turkey weight" do
@turkey.weight.should equal 10
end

it "should be a kind of animal" do
@turkey.kind_of?(Animal).should be_true
end

it "should gobble speak" do
@turkey.gobble_speak("Hello I Am a Turkey. Please Don't Eat Me.").should eq "Gobble Gobble Gobble gobble Gobble. Gobble Gobb'le Gobble Gobble."
end

end

require "#{File.dirname(__FILE__)}/thanksgiving_dinner"

describe ThanksgivingDinner do

before do
before do
@t_dinner = ThanksgivingDinner.new(:vegan)
@t_dinner.guests = ["Aunt Petunia", "Uncle Vernon", "Aunt Marge", "Dudley", "Harry"] # I know I just made a British family celebrate Thanksgiving, but it could be worse: It could have been the 4th of July! :)
end

it "should be a kind of dinner" do
@t_dinner.kind_of?(Dinner).should be_true
end

# Use inject here
it "should sum the letters in each guest name for the seating chart size" do
@t_dinner.seating_chart_size.should eq 45
end

it "should provide a menu" do
@t_dinner.respond_to?(:menu).should be_true
end

context "#menu" do

it "should have a diet specified" do
@t_dinner.menu[:diet].should eq :vegan
end

it "should have proteins" do
@t_dinner.menu[:proteins].should eq ["Tofurkey", "Hummus"]
end

it "should have vegetables" do
@t_dinner.menu[:veggies].should eq [:ginger_carrots , :potatoes, :yams]
end

# Dinners don't always have dessert, but ThanksgivingDinners always do!
it "should have desserts" do
@t_dinner.menu[:desserts].should eq({:pies => [:pumkin_pie], :other => ["Chocolate Moose"], :molds => [:cranberry, :mango, :cherry]})
end

end

# Use String interpolation, collection methods, and string methods for these two examples
it "should return what is on the dinner menu" do
@t_dinner.whats_for_dinner.should eq "Tonight we have proteins Tofurkey and Hummus, and veggies Ginger Carrots, Potatoes, and Yams."
end

it "should return what is on the dessert menu" do
@t_dinner.whats_for_dessert.should eq "Tonight we have 5 delicious desserts: Pumkin Pie, Chocolate Moose, and 3 molds: Cranberry and Mango and Cherry."
end
Expand Down
19 changes: 18 additions & 1 deletion mid_term/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,33 @@ Instructions for Mid-Term submission and Git Review (10pts):

Questions (20pts):
- What are the three uses of the curly brackets {} in Ruby?
1. String interpolation: "#{1+1}"
2. Hash instantiation: {:key => "value"}
3. Block/lambda notation: {puts "hello"}

- What is a regular expression and what is a common use for them?
A Regular expression is a pattern used to search text. A common use for them is for verifying the format of user input, like email addresses or phone numbers.

- What is the difference between how a String, a symbol, a FixNum, and a Float are stored in Ruby?
A String is stored as a collection of characters (bytes) and the value of a string instance can change. A Symbol is a fixed name in ruby and is stored as an integer, so it takes up much less space than a string. A FixNum is an integer in Ruby and does not change its value. It is stored the same way as a symbol (you can think of symbols as Fixed Strings). Floats can have their value change and are stored like a string: each byte of the float is stored and can change individually.

- Are these two statements equivalent? Why or Why Not?
1. x, y = "hello", "hello"
2. x = y = "hello"
No, in the first example x and y point to different objects, in the second they point to the same object. In # 2 if y changes x will change and vice versa. In # 1 if y changes x does not change and vice versa.

- What is the difference between a Range and an Array?
A Range is an object that denotes a sequence between two objects (lower/min and higher/max). It does not store every element of the sequence, only the min and max. An array is an ordered list of many objects. Each object in an array is stored and cannot necessarily be determined by the prior object in the array.

- Why would I use a Hash instead of an Array?
If I had data which I wanted to reference by meta-data instead of by order I would use a hash. For example, if I had a set of attributes common to a collection of things, I would use a hash so I could look across my data (or search) by the data's attribute dimensions.

- What is your favorite thing about Ruby so far?
.map

- What is your least favorite thing about Ruby so far?

nil.object_id => 4

Programming Problems (10pts each):
- Write a passing rspec file called even_number_spec.rb that tests a class called EvenNumber.
- The EvenNumber class should:
Expand Down
Loading