From 3f3e8d07daa4826aa379cc79d666488bf80d84d5 Mon Sep 17 00:00:00 2001 From: onecarna Date: Tue, 20 May 2014 20:14:02 -0700 Subject: [PATCH 1/3] added blog --- Marija.txt | 0 Marijablog.txt | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 Marija.txt create mode 100644 Marijablog.txt diff --git a/Marija.txt b/Marija.txt new file mode 100644 index 0000000..e69de29 diff --git a/Marijablog.txt b/Marijablog.txt new file mode 100644 index 0000000..e69de29 From 1a18f7d62df4c242e42b8abebabb9a80100bc9e6 Mon Sep 17 00:00:00 2001 From: onecarna Date: Tue, 20 May 2014 20:18:33 -0700 Subject: [PATCH 2/3] done --- Marijablog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Marijablog.txt b/Marijablog.txt index e69de29..c23d30e 100644 --- a/Marijablog.txt +++ b/Marijablog.txt @@ -0,0 +1 @@ +Marija myblog.ca \ No newline at end of file From fee4a1933b3ed9b664648a6bd6d380cdd5bb7aa1 Mon Sep 17 00:00:00 2001 From: onecarna Date: Thu, 12 Jun 2014 18:20:40 -0700 Subject: [PATCH 3/3] committing --- .../starter_code/Sec 6 of rubby book.rb | 21 + .../starter_code/SecNumHW.rb | 29 + .../starter_code/SecNumHWv2.rb | 38 ++ .../starter_code/calc.rb | 37 ++ .../starter_code/class 05272014.rb | 2 + .../starter_code/code_demo_boolean.rb | 39 ++ .../starter_code/ex_teddit_conditionalv2.rb | 35 ++ .../starter_code/ruby calc.rb | 1 + 02_Variables_Conditionals/starter_code/test | 0 .../ex_apartment_objects/Apt_code.rb | 19 + .../ex_apartment_objects/Bldg_code.rb | 12 + .../ex_apartment_objects/Person_code.rb | 16 + .../ex_apartment_objects/SecNumObj | 9 + .../ex_apartment_objects/lib/apartment.rb | 13 + .../ex_apartment_objects/lib/building.rb | 6 + .../ex_apartment_objects/lib/person.rb | 6 + .../starter_code/ex_apartment_objects/main.rb | 6 +- .../secret_number_objects/lib/game.rb | 47 +- .../secret_number_objects/lib/person.rb | 12 +- .../lib/secret_number.rb | 15 +- .../secret_number_objects/main.rb | 12 + 06_Sharing_Behavior/Midterm.rb | 38 ++ 06_Sharing_Behavior/MidtermV2.rb | 57 ++ 06_Sharing_Behavior/MidtermV3.rb | 58 ++ 06_Sharing_Behavior/Rails.rb | 2 + 06_Sharing_Behavior/practice.rb | 38 ++ 07_First_Rails_App/starter_code/ex_users.md | 2 + 11_Lab_Session/slides/slides_11.md | 48 +- 12_Authentication/slides/slides_12.md | 556 +++++++++--------- Some_Folder/0529.rb | 131 +++++ Some_Folder/06052014 | 0 Some_Folder/06052014.rb | 36 ++ Some_Folder/APIs | 40 ++ Some_Folder/SF | 0 Some_Folder/SF.rb | 65 ++ Some_Folder/apartment ex.rb | 47 ++ Some_Folder/apt_exer.rb | 51 ++ Some_Folder/class 0602 | 37 ++ Some_Folder/class 0602.rb | 55 ++ Some_Folder/class apt.rb | 47 ++ Some_Folder/hello.rb | 61 ++ Some_Folder/lab 05302014 | 37 ++ Some_Folder/r | 0 43 files changed, 1470 insertions(+), 311 deletions(-) create mode 100644 02_Variables_Conditionals/starter_code/Sec 6 of rubby book.rb create mode 100644 02_Variables_Conditionals/starter_code/SecNumHW.rb create mode 100644 02_Variables_Conditionals/starter_code/SecNumHWv2.rb create mode 100644 02_Variables_Conditionals/starter_code/calc.rb create mode 100644 02_Variables_Conditionals/starter_code/class 05272014.rb create mode 100644 02_Variables_Conditionals/starter_code/ex_teddit_conditionalv2.rb create mode 100644 02_Variables_Conditionals/starter_code/ruby calc.rb create mode 100644 02_Variables_Conditionals/starter_code/test create mode 100644 05_Classes_Objects/starter_code/ex_apartment_objects/Apt_code.rb create mode 100644 05_Classes_Objects/starter_code/ex_apartment_objects/Bldg_code.rb create mode 100644 05_Classes_Objects/starter_code/ex_apartment_objects/Person_code.rb create mode 100644 05_Classes_Objects/starter_code/ex_apartment_objects/SecNumObj create mode 100644 06_Sharing_Behavior/Midterm.rb create mode 100644 06_Sharing_Behavior/MidtermV2.rb create mode 100644 06_Sharing_Behavior/MidtermV3.rb create mode 100644 06_Sharing_Behavior/Rails.rb create mode 100644 06_Sharing_Behavior/practice.rb create mode 100644 Some_Folder/0529.rb create mode 100644 Some_Folder/06052014 create mode 100644 Some_Folder/06052014.rb create mode 100644 Some_Folder/APIs create mode 100644 Some_Folder/SF create mode 100644 Some_Folder/SF.rb create mode 100644 Some_Folder/apartment ex.rb create mode 100644 Some_Folder/apt_exer.rb create mode 100644 Some_Folder/class 0602 create mode 100644 Some_Folder/class 0602.rb create mode 100644 Some_Folder/class apt.rb create mode 100644 Some_Folder/hello.rb create mode 100644 Some_Folder/lab 05302014 create mode 100644 Some_Folder/r diff --git a/02_Variables_Conditionals/starter_code/Sec 6 of rubby book.rb b/02_Variables_Conditionals/starter_code/Sec 6 of rubby book.rb new file mode 100644 index 0000000..c57ee85 --- /dev/null +++ b/02_Variables_Conditionals/starter_code/Sec 6 of rubby book.rb @@ -0,0 +1,21 @@ +puts 'Hello player! Welcome to Marija\'s Magnificant Test of Psychic Abilities game! You will have 3 attempts to guess a number, 1 through 10. What is your name?' +name = gets.chomp +puts 'Hello, ' + name.capitalize + '!' + +puts 'Let us begin! I am thinking of a number between 1 and 10, please guess what number this is!' + +number = (rand(1..10)) +guess = gets.to_i +attempts = 3 + + if guess == number + puts 'You are correct, the number is ' + number.to_s + '!' + elsif guess < number + puts "Wrong, aim higher and please try again!" + elsif guess > number + puts "Wrong, aim lower and please try again!" + end +end + + + diff --git a/02_Variables_Conditionals/starter_code/SecNumHW.rb b/02_Variables_Conditionals/starter_code/SecNumHW.rb new file mode 100644 index 0000000..a687822 --- /dev/null +++ b/02_Variables_Conditionals/starter_code/SecNumHW.rb @@ -0,0 +1,29 @@ +# Marija Ringwelski Homework Assignment answers: + +puts 'Hello player! Welcome to Marija\'s Magnificant Test of Psychic Abilities game! What is your name?' +name = gets.chomp.capitalize # .capitalize will make the first letter of the name capitalized. +puts 'Hello, ' + name + '!' +puts 'Let us begin! You get 3 guesses. I am thinking of a number between 1 and 10, please guess what number this is!' + +number = (rand(1..10)) # rand(1..10) will privide a range between 1 and 10. rand(10) might include zero and we dont want that. +guess_remainder = 3 # this prompt will allow for the number of attempts the respondent can make. + +loop do # this command will allow for repeated actions of the program for guess_remainder number indicated. + guess = gets.to_i # .to_1 method will allow for the conversion of the guess into an integer + guess_remainder -= 1 # -= 1 will allow the program to subtract by one guess after each response. + if guess == number + puts 'You are correct, the number is ' + number.to_s + '!' + break + elsif guess != number and guess_remainder != 0 + if guess < number + puts "Wrong, aim higher and please try again! Number of attempts left: " + guess_remainder.to_s + '.' # .to_s will return a string for guess_remainder. + elsif guess > number + puts "Wrong, aim lower and please try again! Number of attempts left: " + guess_remainder.to_s + '.' # .to_s will return a string for guess_remainder. + end + else puts "Sorry, you lost and have zero psychic abilities! The number was " + number.to_s + '.' # .to_s will return a string for guess_remainder. + break + end +end + + + diff --git a/02_Variables_Conditionals/starter_code/SecNumHWv2.rb b/02_Variables_Conditionals/starter_code/SecNumHWv2.rb new file mode 100644 index 0000000..f07aedb --- /dev/null +++ b/02_Variables_Conditionals/starter_code/SecNumHWv2.rb @@ -0,0 +1,38 @@ +# Marija Ringwelski Homework Assignment answers: + +puts 'Hello player! Welcome to Marija\'s Magnificant Test of Psychic Abilities game! What is your name?' +name = gets.chomp.capitalize # .capitalize will make the first letter of the name capitalized. +puts 'Hello, ' + name + '!' +puts 'Let us begin! You get 3 guesses. I am thinking of a number between 1 and 10, please guess what number this is!' +guess = gets.to_i # .to_1 method will allow for the conversion of the guess into an integer + +number = (rand(1..10)) +# number = (rand(1..10)) # rand(1..10) will privide a range between 1 and 10. rand(10) might include zero and we dont want that. +guess_remainder = 3 # this prompt will allow for the number of attempts the respondent can make. + +# this command will allow for repeated actions of the program for guess_remainder number indicated. +while guess_remainder > 0 + + if guess < number + # .to_s will return a string for guess_remainder. + puts "Wrong, aim higher and please try again! Number of attempts left: " + guess_remainder.to_s + '.' + guess = gets.to_i + elsif guess > number + # .to_s will return a string for guess_remainder. + puts "Wrong, aim lower and please try again! Number of attempts left: " + guess_remainder.to_s + '.' + guess = gets.to_i + end + guess_remainder -= 1 # -= 1 will allow the program to subtract by one guess after each response. + +end + +if guess == number + puts 'You are correct, the number is ' + number.to_s + '!' + +else + # .to_s will return a string for guess_remainder. + puts "Sorry, you lost and have zero psychic abilities! The number was " + number.to_s + '.' +end + + + diff --git a/02_Variables_Conditionals/starter_code/calc.rb b/02_Variables_Conditionals/starter_code/calc.rb new file mode 100644 index 0000000..57e9fb8 --- /dev/null +++ b/02_Variables_Conditionals/starter_code/calc.rb @@ -0,0 +1,37 @@ +puts 1+2 +puts 3*4 +puts (24*365) +puts (60*24)*(365*10) +puts (60*60*24)*(365*30) + +my_string = "say my name" +puts my_string +puts my_string + +name = "Marija Ringwelski" +puts "My name is " + name + '.' +var1 = 2 +var2 = '5' +puts var1.to_s + var2 +puts var1 + var2.to_i + +puts 'Hello there, and what\'s your name?' +name = gets.chomp +puts 'Your name is ' + name + '? What a lovely name!' +puts 'Pleased to meet you, ' + name + '. :)' + +puts 'Hello there, what\'s your first name?' +first_name = gets.chomp +puts 'What is your middle name?' +middle_name = gets.chomp +puts 'What is your last name?' +last_name = gets.chomp +puts 'Pleased to meet you, ' + first_name + ' ' + middle_name + ' ' + last_name + '!' + + +puts 'What is your fav number?' +fav_number = gets.chomp.to_i +bet_number = fav_number + 1 +puts "that is okay, but is not " +bet_number.to_s+ ' bigger and better?' + + diff --git a/02_Variables_Conditionals/starter_code/class 05272014.rb b/02_Variables_Conditionals/starter_code/class 05272014.rb new file mode 100644 index 0000000..139597f --- /dev/null +++ b/02_Variables_Conditionals/starter_code/class 05272014.rb @@ -0,0 +1,2 @@ + + diff --git a/02_Variables_Conditionals/starter_code/code_demo_boolean.rb b/02_Variables_Conditionals/starter_code/code_demo_boolean.rb index ea3d367..45be6a9 100644 --- a/02_Variables_Conditionals/starter_code/code_demo_boolean.rb +++ b/02_Variables_Conditionals/starter_code/code_demo_boolean.rb @@ -2,15 +2,54 @@ #Let the computer do the work for you! puts "Is 7 greater than 8?" +if 7 > 8 + puts true + else + puts false +end puts "Is 8 x 77 greater than 600?" +if (8 * 77) > 600 + puts true +else + puts false +end + puts "Is 1 equal to (7 - 6)?" +if 1 == (7-6) + puts true +else + puts false +end + + puts "Is 77 greater than 50 AND (88 / 3) less than 30?" +if 77 > 50 and (88/3)<30 + puts true +else + puts false +end + puts "Is the length of the word 'wheelbarrow' more than 10 characters long?" +if "wheelbarrow".length > 10 + puts true +else + puts false +end puts "Are the amount of seconds in an hour greater than or equal to 3000?" +if (60 ==3000) or > 3000 + puts true +else + puts false +end puts "Does the word 'slaughter' include the word laughter?" +if "slaughter".include? "laughter" + puts true +else + puts false +end diff --git a/02_Variables_Conditionals/starter_code/ex_teddit_conditionalv2.rb b/02_Variables_Conditionals/starter_code/ex_teddit_conditionalv2.rb new file mode 100644 index 0000000..795344c --- /dev/null +++ b/02_Variables_Conditionals/starter_code/ex_teddit_conditionalv2.rb @@ -0,0 +1,35 @@ +# Teddit Contionals - Starter Code. + +# Let's add a new Teddit feature. Upvotes! +# Complete the application below. +# Where you see comments (lines that begin with #) replace it with code so that the program works. + +def get_input + gets +end + +def calculate_upvotes(story, category) + upvotes = 1 + if story.include? "cats" or category.include? "cats" + upvotes.to_i*5 + elsif story.include? "bacon" or category.include? "bacon" + upvotes.to_i*8 + elsif story.include? "Food" or category.include? "Food" + upvotes.to_1*3 + end + + +# If the Story is about cats multiply the upvotes by 5 +# If the Story is about bacon multiply the upvotes by 8 +# If the Story is about Food it gets 3 times the upvotes. + #For example: + # "Cats frolic despite tuna shortage" should give you 5 times the upvotes! +end + +puts "Welcome to Teddit! a text based news aggregator. Get today's news tomorrow!" +puts "Please enter a News story:" +story = get_input +puts "Please give it a category:" +category = get_input +upvotes = calculate_upvotes(story, category) +puts "New story added! #{story}, Category: #{category.capitalize}, Current Upvotes: #{upvotes}" \ No newline at end of file diff --git a/02_Variables_Conditionals/starter_code/ruby calc.rb b/02_Variables_Conditionals/starter_code/ruby calc.rb new file mode 100644 index 0000000..f76dd36 --- /dev/null +++ b/02_Variables_Conditionals/starter_code/ruby calc.rb @@ -0,0 +1 @@ +puts 1+2 diff --git a/02_Variables_Conditionals/starter_code/test b/02_Variables_Conditionals/starter_code/test new file mode 100644 index 0000000..e69de29 diff --git a/05_Classes_Objects/starter_code/ex_apartment_objects/Apt_code.rb b/05_Classes_Objects/starter_code/ex_apartment_objects/Apt_code.rb new file mode 100644 index 0000000..b5890dc --- /dev/null +++ b/05_Classes_Objects/starter_code/ex_apartment_objects/Apt_code.rb @@ -0,0 +1,19 @@ +#This is the apartment code for lab exercise on 06022014 + +def create_apartment + puts "This is a new apartment." + puts "What is the apartment number / name?" + name = gets.strip + + puts "How many square feet is apartment #{name}?" + apt_sqft = gets.to_i + + puts "How many bedrooms does apartment #{name} have?" + apt_bedrooms = gets.to_i + + puts "How many bathrooms does apartment #{name} have?" + apt_bathrooms = gets.to_i + + Apartment.new(name, apt_sqft, apt_bedrooms, apt_bathrooms) +end + diff --git a/05_Classes_Objects/starter_code/ex_apartment_objects/Bldg_code.rb b/05_Classes_Objects/starter_code/ex_apartment_objects/Bldg_code.rb new file mode 100644 index 0000000..09a688e --- /dev/null +++ b/05_Classes_Objects/starter_code/ex_apartment_objects/Bldg_code.rb @@ -0,0 +1,12 @@ +#This is the building code for lab exercise on 06022014 + +def create_building + puts "This is a new building." + puts "What is the building's name?" + building_name = gets.strip + + puts "What is the building's address?" + building_address = gets.strip + + Building.new(building_name, building_address) +end diff --git a/05_Classes_Objects/starter_code/ex_apartment_objects/Person_code.rb b/05_Classes_Objects/starter_code/ex_apartment_objects/Person_code.rb new file mode 100644 index 0000000..35a69ee --- /dev/null +++ b/05_Classes_Objects/starter_code/ex_apartment_objects/Person_code.rb @@ -0,0 +1,16 @@ +#This is the renter's code for lab exercise on 06022014 + +def create_renter + puts "There is a new renter" + puts "What is the renter's name?" + name = gets.strip + + puts "What is the #{name}'s credit score?" + credit_score = gets.to_i + + puts "Is #{name} male or female?" + gender = gets.strip + + Person.new(name, credit_score, gender) +end + diff --git a/05_Classes_Objects/starter_code/ex_apartment_objects/SecNumObj b/05_Classes_Objects/starter_code/ex_apartment_objects/SecNumObj new file mode 100644 index 0000000..dcd024f --- /dev/null +++ b/05_Classes_Objects/starter_code/ex_apartment_objects/SecNumObj @@ -0,0 +1,9 @@ +#the object is +#player object +#sec num object + +random - method used + +class - instead of ifs and else, create methods for the check work + +user class \ No newline at end of file diff --git a/05_Classes_Objects/starter_code/ex_apartment_objects/lib/apartment.rb b/05_Classes_Objects/starter_code/ex_apartment_objects/lib/apartment.rb index 80f73f0..0eaa858 100644 --- a/05_Classes_Objects/starter_code/ex_apartment_objects/lib/apartment.rb +++ b/05_Classes_Objects/starter_code/ex_apartment_objects/lib/apartment.rb @@ -1,4 +1,17 @@ #Apartment class. class Apartment +attr_accessor :name, :apt_sqft, :apt_bedrooms, :apt_bathrooms, :renter, :rent + def initialize(name, apt_sqft, apt_bedrooms, apt_bathrooms) + @name = name + @apt_sqft = apt_sqft + @apt_bedrooms = apt_bedrooms + @apt_bathrooms = apt_bathrooms + @renter = nil + @rent = nil + end end + +# apartment + + \ No newline at end of file diff --git a/05_Classes_Objects/starter_code/ex_apartment_objects/lib/building.rb b/05_Classes_Objects/starter_code/ex_apartment_objects/lib/building.rb index 56c3dfb..bc8c7ac 100644 --- a/05_Classes_Objects/starter_code/ex_apartment_objects/lib/building.rb +++ b/05_Classes_Objects/starter_code/ex_apartment_objects/lib/building.rb @@ -1,4 +1,10 @@ #Building Class class Building + attr_accessor :building_name, :building_address, :apartments + def initialize(building_name, building_address) + @building_name = building_name + @building_address = building_address + @apartments = [] + end end diff --git a/05_Classes_Objects/starter_code/ex_apartment_objects/lib/person.rb b/05_Classes_Objects/starter_code/ex_apartment_objects/lib/person.rb index b7c1667..765d2c6 100644 --- a/05_Classes_Objects/starter_code/ex_apartment_objects/lib/person.rb +++ b/05_Classes_Objects/starter_code/ex_apartment_objects/lib/person.rb @@ -1,4 +1,10 @@ #Person Class. class Person + attr_accessor :name, :credit_score, :gender + def initialize(name, credit_score, gender) + @name = name + @credit_score = credit_score + @gender = gender + end end diff --git a/05_Classes_Objects/starter_code/ex_apartment_objects/main.rb b/05_Classes_Objects/starter_code/ex_apartment_objects/main.rb index 246352e..f6977f2 100644 --- a/05_Classes_Objects/starter_code/ex_apartment_objects/main.rb +++ b/05_Classes_Objects/starter_code/ex_apartment_objects/main.rb @@ -7,9 +7,9 @@ # => We've also provided a png file of the terminal output from the completed version. # => Hint: Think before you code. Annotate code and comment out sections as you test different sections -require_relative 'lib/building' -require_relative 'lib/apartment' -require_relative 'lib/person' +require_relative 'lib/building' #create a separate file +require_relative 'lib/apartment' #create a separate file +require_relative 'lib/person' #create a separate file ## First, define our methods diff --git a/05_Classes_Objects/starter_code/ex_secret_number_objects/secret_number_objects/lib/game.rb b/05_Classes_Objects/starter_code/ex_secret_number_objects/secret_number_objects/lib/game.rb index 1a21a56..d58a57a 100644 --- a/05_Classes_Objects/starter_code/ex_secret_number_objects/secret_number_objects/lib/game.rb +++ b/05_Classes_Objects/starter_code/ex_secret_number_objects/secret_number_objects/lib/game.rb @@ -2,8 +2,47 @@ require 'lib/secret_number' class Game -# this class will be complex -# we need to write logic to initialize a new game, and run the game loop -# we'll want to write a few separate methods for unique tasks so that our -# code is structured properly +def initialize(player, sec_num) + @player = player + @sec_num = sec_num end + +player = Person.new(name) +sec_num = SecretNumber.new + +game = Game.new(player, secret_number) + +end + +number = (rand(1..10)) +guess_remainder = 3 + +while guess_remainder > 0 + + if guess < secret_number + puts "Wrong, aim higher and please try again! Number of attempts left: " + guess_remainder.to_s + '.' + guess = gets.to_i + + elsif guess > secret_number + + puts "Wrong, aim lower and please try again! Number of attempts left: " + guess_remainder.to_s + '.' + guess = gets.to_i + end + guess_remainder -= 1 + +end + +if guess == number + puts 'You are correct, the number is ' + number.to_s + '!' +else + puts "Sorry, you lost and have zero psychic abilities! The number was " + number.to_s + '.' +end + +#Game +# This class holds most of the game logic and should: +# Welcome players and inform them of the game rules. +# Initialize the Player class. +# Initialize the Secret Number class. +# Prompt the user to choose a number, verify if the user guessed correctly. +# If the user guesses incorrectly let them know if they were too high or too low. +# Monitor how many guesses the player has before the game is over. \ No newline at end of file diff --git a/05_Classes_Objects/starter_code/ex_secret_number_objects/secret_number_objects/lib/person.rb b/05_Classes_Objects/starter_code/ex_secret_number_objects/secret_number_objects/lib/person.rb index 5cd9b4e..30e8b57 100644 --- a/05_Classes_Objects/starter_code/ex_secret_number_objects/secret_number_objects/lib/person.rb +++ b/05_Classes_Objects/starter_code/ex_secret_number_objects/secret_number_objects/lib/person.rb @@ -1,3 +1,13 @@ + class Person -# this class will likely be simple, and just remember its name + + attr_accessor :name + + def initialize(name) + @name = name + end end + + +#Player +# Should initialize the player's name. \ No newline at end of file diff --git a/05_Classes_Objects/starter_code/ex_secret_number_objects/secret_number_objects/lib/secret_number.rb b/05_Classes_Objects/starter_code/ex_secret_number_objects/secret_number_objects/lib/secret_number.rb index 48edd8e..f038e82 100644 --- a/05_Classes_Objects/starter_code/ex_secret_number_objects/secret_number_objects/lib/secret_number.rb +++ b/05_Classes_Objects/starter_code/ex_secret_number_objects/secret_number_objects/lib/secret_number.rb @@ -1,3 +1,16 @@ class SecretNumber -# this class will generate our secret number for us + + attr_accessor :sec_num + + def initialize(sec_num) + @sec_num = rand(1..10) + end end + + + + +# SecretNumber +# This class should initiate an array of numbers that range between 1 - 10. +# Use a method from the array class to select a random element from that array. This random number will be the secret number. +# This way the secret number is also a secret to you. \ No newline at end of file diff --git a/05_Classes_Objects/starter_code/ex_secret_number_objects/secret_number_objects/main.rb b/05_Classes_Objects/starter_code/ex_secret_number_objects/secret_number_objects/main.rb index bc9eaa8..dacaa89 100644 --- a/05_Classes_Objects/starter_code/ex_secret_number_objects/secret_number_objects/main.rb +++ b/05_Classes_Objects/starter_code/ex_secret_number_objects/secret_number_objects/main.rb @@ -1,3 +1,15 @@ + +require_relative 'lib/game' +require_relative 'lib/person' +require_relative 'lib/secret_number' + +def intro + puts 'Hello player! Welcome to Marija\'s Magnificant Test of Psychic Abilities game! What is your name?' + name = gets.chomp.capitalize # .capitalize will make the first letter of the name capitalized. + puts 'Hello, ' + name + '!' + puts 'Let us begin! You get 3 guesses. I am thinking of a number between 1 and 10, please guess what number this is!' + guess = gets.to_i + ############################################################################### # # Introduction to Ruby on Rails diff --git a/06_Sharing_Behavior/Midterm.rb b/06_Sharing_Behavior/Midterm.rb new file mode 100644 index 0000000..c8d1559 --- /dev/null +++ b/06_Sharing_Behavior/Midterm.rb @@ -0,0 +1,38 @@ +require 'rest-client' +require 'pry' +require 'json' + +puts "How would you like to search?" + +puts "1: Title" +puts "2: Content Type" + +choice = gets.chomp.to_i + +if choice == 1 + puts "what is the title?" + title = gets.chomp.gsub(" ", "-") + response = RestClient.get("https://www.healthcare.gov/#{title}.json") + parsed = JSON.load(response) + # binding.pry + puts parsed + +elsif choice == 2 + + puts "Select a content_type" + content_type = gets.chomp + response = RestClient.get("https://www.healthcare.gov/api/#{content_type}.json") + parsed = JSON.load(response) + # binding.pry + puts parsed + +else + puts "error!" +end + + +# response = RestClient.get("https://www.healthcare.gov/#{title}.json") + +# parsed = JSON.load(response) + +# binding.pry \ No newline at end of file diff --git a/06_Sharing_Behavior/MidtermV2.rb b/06_Sharing_Behavior/MidtermV2.rb new file mode 100644 index 0000000..87a617a --- /dev/null +++ b/06_Sharing_Behavior/MidtermV2.rb @@ -0,0 +1,57 @@ +require 'rest-client' +require 'pry' +require 'json' + +class MyArticle + + attr_accessor :title, :published, :bite + + def initialize (title, published, bite) + @title = title + @published = published + @bite = bite + end + + def my_article + puts "The article entitled #{title} was published as #{published} with the following destription: " + puts "#{bite}" + end + +end + +puts "How would you like to search? You may search by the options below:" + +puts "1: Title" +puts "2: Content Type" +puts "please enter a numerical value for your choice." + +choice = gets.chomp.to_i + +while true + if choice == 1 + puts "What is the title name?" + title = gets.chomp.gsub(" ", "-") + response = RestClient.get("https://www.healthcare.gov/#{title}.json") + parsed = JSON.load(response) + # binding.pry + puts parsed + + elsif choice == 2 + puts "What is the content type?" + content_type = gets.chomp + response = RestClient.get("https://www.healthcare.gov/api/#{content_type}.json") + parsed = JSON.load(response) + # binding.pry + puts parsed + break + else + puts "error! Please enter a valid number." + end +end + + +# response = RestClient.get("https://www.healthcare.gov/#{title}.json") + +# parsed = JSON.load(response) + +# binding.pry \ No newline at end of file diff --git a/06_Sharing_Behavior/MidtermV3.rb b/06_Sharing_Behavior/MidtermV3.rb new file mode 100644 index 0000000..e21c21f --- /dev/null +++ b/06_Sharing_Behavior/MidtermV3.rb @@ -0,0 +1,58 @@ +# Midterm + +require 'rest-client' +require 'pry' +require 'json' + +class Person + + attr_accessor :name + + def initialize(name) + @name = name + end +end + +def age_check (age) + return "That is very old!" if age.to_i >= 30 + return "That is very young!" if age.to_i <=20 + return "Cool." +end + +def check_name (name) + return "Hello, #{name}! That's a very long name!" if name.length >= 10 + return "Hello, #{name}!" +end + +puts "What is your name?" +name = gets.chomp + +puts check_name(name) +puts + +puts "What is your age?" +age = gets.chomp + +puts age_check(age.to_i) +puts + +puts "Let us get started! I want to test your reading abilities." +puts "What is the title of the article? " + +title = gets.chomp.gsub(" ", "-") +response = RestClient.get("https://www.healthcare.gov/#{title}.json") +parsed = JSON.load(response) +puts parsed + +# I would like to get the code below to work also but I have not been successful. + +# puts "Alright, let us begin! Enter a key word in the title of the article please!" +# input = gets.chomp +# response = RestClient.get("http://healthcare.gov/#{input}/.json") +# parsed = JSON.load(response) + +# parsed["title"].each do |post| +# puts post ["title"] +# end + + diff --git a/06_Sharing_Behavior/Rails.rb b/06_Sharing_Behavior/Rails.rb new file mode 100644 index 0000000..139597f --- /dev/null +++ b/06_Sharing_Behavior/Rails.rb @@ -0,0 +1,2 @@ + + diff --git a/06_Sharing_Behavior/practice.rb b/06_Sharing_Behavior/practice.rb new file mode 100644 index 0000000..7c8f872 --- /dev/null +++ b/06_Sharing_Behavior/practice.rb @@ -0,0 +1,38 @@ +class House + + attr_accessor :bedrooms, :bathrooms, :residents + + def initialize (bedrooms, bathrooms, residents) + @bedrooms = bedrooms + @bathrooms = bathrooms + @residents = residents + end + + def rooms_total + puts "This house has #{bedrooms} bedrooms and #{bathrooms} bathrooms." + end + + def family + puts "This house also has #{residents} family members inside!" + end + +end + +H1 = House.new(4, 2, 5) +puts H1.rooms_total +puts H1.family + +# ________________________ +# require 'pry' +# require "json" +# require 'rest-client' + +# input = gets.chomp +# subred = RestClient.get("http://reddit.com/r/#{input}/.json") +# sub_post = JSON.load(subred) + +# sub_post["data"]["children"].each do |post| +# puts post ["data"]["title"] +# end + + diff --git a/07_First_Rails_App/starter_code/ex_users.md b/07_First_Rails_App/starter_code/ex_users.md index 5c372e8..3769b55 100644 --- a/07_First_Rails_App/starter_code/ex_users.md +++ b/07_First_Rails_App/starter_code/ex_users.md @@ -1,6 +1,8 @@ ![GeneralAssemb.ly](http://studio.generalassemb.ly/GA_Slide_Assets/Exercise_icon_md.png) + + ##Scaffold Users ###Time: 30 min diff --git a/11_Lab_Session/slides/slides_11.md b/11_Lab_Session/slides/slides_11.md index 3a6648a..227e874 100644 --- a/11_Lab_Session/slides/slides_11.md +++ b/11_Lab_Session/slides/slides_11.md @@ -1,40 +1,40 @@ -![GeneralAssemb.ly](https://github.com/generalassembly/ga-ruby-on-rails-for-devs/raw/master/images/ga.png "GeneralAssemb.ly") - -#BEWD - Review Lab Session - -###Instructor Name - ---- - - -##Agenda +![GeneralAssemb.ly](https://github.com/generalassembly/ga-ruby-on-rails-for-devs/raw/master/images/ga.png "GeneralAssemb.ly") + +#BEWD - Review Lab Session + +###Instructor Name + +--- + + +##Agenda * Review * Lab Time ---- - - +--- + + ##Review ###Request-response ![Request Response Diagram](../../assets/rails/response_request.png) - ---- - - +--- + + + ##Review ###Routes, Views, Controllers and Forms Instructors, you know your class best. What do your students need to review? - + --- - + ##Lab Time ####Ritly @@ -42,13 +42,13 @@ Instructors, you know your class best. What do your students need to review? ####Rewsly 45 min - + --- - -## Homework + +## Homework Complete Rewsly - + --- - + diff --git a/12_Authentication/slides/slides_12.md b/12_Authentication/slides/slides_12.md index 59fe4cf..059c9b8 100644 --- a/12_Authentication/slides/slides_12.md +++ b/12_Authentication/slides/slides_12.md @@ -1,278 +1,278 @@ -![GeneralAssemb.ly](https://github.com/generalassembly/ga-ruby-on-rails-for-devs/raw/master/images/ga.png "GeneralAssemb.ly") - - -https://github.com/plataformatec/devise#getting-started - - -#BEWD - Authentication - -###Instructor Name - - ---- - - -##Agenda - -* Review - * Rewsly Solution - * Rity Solution (Briefly) -* Authentication - * Authentication Explained - * Devise Gem -* Lab - * Authenticated Ritly - ---- - - -##Review -###Rewsly & Ritly - -* Let's review Rewsly solution from last class. -* Since we're going to work on Ritly, let's review that (briefly) as well. - ---- - - -##Authentication - -![GitHub Sign Up Page](../../assets/rails/login_screen.png) - ---- - - -##Authentication - -* Use of a combination of username and password to validate user identity. (Obvious I know…) -* Tracking a user's identity on our app through the __session__. - ---- - -##Authentication -###Security - -![lock image](../../assets/rails/digital_security.jpeg) - ---- - -##Security -* Can I view users' passwords in my app? - -####NO! - ---- - -##Security -###Storing Passwords - -Bad practice to keep passwords in “clear text” - -* Passwords can't be stored in plain text in your database. -If your database is compromised then passwords are compromised as well. - * Don't use the same password for all sites. - ---- - - -##Security -###Hashing - -Use one way hash - -``` -Digest::SHA2.hexdigest("secret") -# => "e5e9fa1ba31ecd1ae84f75caaa474f3a663f05f4" -``` ---- - - -##Security -###Adding Salt - -Salt is random data that are used as an additional input to a one-way function that hashes a password. - - -``` -salt = "a761ce3a45d97e41840a788495e85a70d1bb3815" -password = "secret" -Digest::SHA2.hexdigest(salt+password) -# =>"7963ca00e2e48ea80c615d037494de00a0964682" -``` - ---- - - -##Authentication -###Managing Users - -* When the user is authenticated we store the user_id in the __session__. - ---- - - -##Managing Users -###Session - -* Session data commonly includes the browser user’s identity (name, login, shopping cart, etc.). - -* To work, the web server must uniquely identify each browser’s particular HTTP requests while the session lasts. - -* Commonly, web servers identify browsers by asking them to store a __cookie__. - ---- - -##Managing Users -###Cookie - -* Used to store small bits of information (maximum size about 4k). -* Cookies allow web servers to provide a temporary unique ID to a browser, to enable session management. - * Browser storage is not secure. - * Sensitive data (credit card numbers, etc.) should never be set in a cookie - ---- - - -##Authentication -###Gems -Creating authentication from scratch is a complex process (see resources for more info). However Developers have created Gems to make authentication "easy". - -* __Devise__ -* CanCan -* Clearance -* OmniAuth -* DoorKeeper - ---- - - -##Authentication -###Devise GEM -[https://github.com/plataformatec/devise](https://github.com/plataformatec/devise) - -* Straight-forward to implement, integrate and customize. -* Handles complex security, so you don't have to. -* Provides controller filters and view helpers (more on that in the code along). -* Recently updated (v3.0.0) with Rails 4 support! - - ---- - - - - -##Rewsly - Adding Devise - ---- - - -##Devise -###Recap - -* Adding Devise Gem to the Gemfile - - gem 'devise', '~> 3.0.0' - ---- - - -##Devise -###Recap - -* Using Devise - - rails g devise:install # creates all the devise Controllers, views and initializers - rails g devise user # creates User model (or modifies it if it exists) - rake db:migrate # Let's Go! - - ---- - - -##Devise -###Recap - -* View helpers - - <%= user_is_logged_in? %> - <%= current_user %> - ---- - - -##Authentication -###Recap - -* View helpers - - <%= user_is_logged_in? %> - <%= current_user %> - ---- - -##Devise -###Recap - -* Blocking Access - - class ApplicationController ... - before_action :authenticate_user! - end - - class HomeController < ApplicationController - skip_before_action :authenticate_user! - end - ---- - -##Devise -###Recap - -* Changing the default Route names - - devise_for :users, :path_names => { sign_in: 'login', sign_out: 'logout' } - ---- - - - -##Lab Time - Authenticated Ritly - ---- - - -## Homework - -Write a list of information/data you want to store about your user. - ---- - - -
-## Resources - -###Cheat Sheet - -No cheat sheet this class. Remember, Google is your friend! - - -###Tips, Tricks & Advanced Reading - -* If you want to expand your knowledge about Rails authentication gems visit [Ruby Toolbox](https://www.ruby-toolbox.com/categories/rails_authentication) for a few more authentication gem options. - -* Great [article](http://scientopia.org/blogs/goodmath/2013/03/02/passwords-hashing-and-salt/) explaining passwords, hashing, and salt. - - -* Advanced [article](http://edapx.com/2012/04/18/authorization-and-user-management-in-rails/) about authorization and users management in rails. - -* [Tutorial](http://everydayrails.com/2012/07/31/rails-admin-panel-from-scratch.html) on how to create an advanced admin panel. - -* [Authentication From Scratch](http://railscasts.com/episodes/250-authentication-from-scratch) Rails Cast - - - -###Still Feel Lost? -####Catch Up With These Resources - -* [Devise](http://railscasts.com/episodes/209-introducing-devise) Rails Cast - +![GeneralAssemb.ly](https://github.com/generalassembly/ga-ruby-on-rails-for-devs/raw/master/images/ga.png "GeneralAssemb.ly") + + +https://github.com/plataformatec/devise#getting-started + + +#BEWD - Authentication + +###Instructor Name + + +--- + + +##Agenda + +* Review + * Rewsly Solution + * Rity Solution (Briefly) +* Authentication + * Authentication Explained + * Devise Gem +* Lab + * Authenticated Ritly + +--- + + +##Review +###Rewsly & Ritly + +* Let's review Rewsly solution from last class. +* Since we're going to work on Ritly, let's review that (briefly) as well. + +--- + + +##Authentication + +![GitHub Sign Up Page](../../assets/rails/login_screen.png) + +--- + + +##Authentication + +* Use of a combination of username and password to validate user identity. (Obvious I know…) +* Tracking a user's identity on our app through the __session__. + +--- + +##Authentication +###Security + +![lock image](../../assets/rails/digital_security.jpeg) + +--- + +##Security +* Can I view users' passwords in my app? + +####NO! + +--- + +##Security +###Storing Passwords + +Bad practice to keep passwords in “clear text” + +* Passwords can't be stored in plain text in your database. +If your database is compromised then passwords are compromised as well. + * Don't use the same password for all sites. + +--- + + +##Security +###Hashing + +Use one way hash + +``` +Digest::SHA2.hexdigest("secret") +# => "e5e9fa1ba31ecd1ae84f75caaa474f3a663f05f4" +``` +--- + + +##Security +###Adding Salt + +Salt is random data that are used as an additional input to a one-way function that hashes a password. + + +``` +salt = "a761ce3a45d97e41840a788495e85a70d1bb3815" +password = "secret" +Digest::SHA2.hexdigest(salt+password) +# =>"7963ca00e2e48ea80c615d037494de00a0964682" +``` + +--- + + +##Authentication +###Managing Users + +* When the user is authenticated we store the user_id in the __session__. + +--- + + +##Managing Users +###Session + +* Session data commonly includes the browser user’s identity (name, login, shopping cart, etc.). + +* To work, the web server must uniquely identify each browser’s particular HTTP requests while the session lasts. + +* Commonly, web servers identify browsers by asking them to store a __cookie__. + +--- + +##Managing Users +###Cookie + +* Used to store small bits of information (maximum size about 4k). +* Cookies allow web servers to provide a temporary unique ID to a browser, to enable session management. + * Browser storage is not secure. + * Sensitive data (credit card numbers, etc.) should never be set in a cookie + +--- + + +##Authentication +###Gems +Creating authentication from scratch is a complex process (see resources for more info). However Developers have created Gems to make authentication "easy". + +* __Devise__ +* CanCan +* Clearance +* OmniAuth +* DoorKeeper + +--- + + +##Authentication +###Devise GEM +[https://github.com/plataformatec/devise](https://github.com/plataformatec/devise) + +* Straight-forward to implement, integrate and customize. +* Handles complex security, so you don't have to. +* Provides controller filters and view helpers (more on that in the code along). +* Recently updated (v3.0.0) with Rails 4 support! + + +--- + + + + +##Rewsly - Adding Devise + +--- + + +##Devise +###Recap + +* Adding Devise Gem to the Gemfile + + gem 'devise', '~> 3.0.0' + +--- + + +##Devise +###Recap + +* Using Devise + + rails g devise:install # creates all the devise Controllers, views and initializers + rails g devise user # creates User model (or modifies it if it exists) + rake db:migrate # Let's Go! + + +--- + + +##Devise +###Recap + +* View helpers + + <%= user_is_logged_in? %> + <%= current_user %> + +--- + + +##Authentication +###Recap + +* View helpers + + <%= user_is_logged_in? %> + <%= current_user %> + +--- + +##Devise +###Recap + +* Blocking Access + + class ApplicationController ... + before_action :authenticate_user! + end + + class HomeController < ApplicationController + skip_before_action :authenticate_user! + end + +--- + +##Devise +###Recap + +* Changing the default Route names + + devise_for :users, :path_names => { sign_in: 'login', sign_out: 'logout' } + +--- + + + +##Lab Time - Authenticated Ritly + +--- + + +## Homework + +Write a list of information/data you want to store about your user. + +--- + + +
+## Resources + +###Cheat Sheet + +No cheat sheet this class. Remember, Google is your friend! + + +###Tips, Tricks & Advanced Reading + +* If you want to expand your knowledge about Rails authentication gems visit [Ruby Toolbox](https://www.ruby-toolbox.com/categories/rails_authentication) for a few more authentication gem options. + +* Great [article](http://scientopia.org/blogs/goodmath/2013/03/02/passwords-hashing-and-salt/) explaining passwords, hashing, and salt. + + +* Advanced [article](http://edapx.com/2012/04/18/authorization-and-user-management-in-rails/) about authorization and users management in rails. + +* [Tutorial](http://everydayrails.com/2012/07/31/rails-admin-panel-from-scratch.html) on how to create an advanced admin panel. + +* [Authentication From Scratch](http://railscasts.com/episodes/250-authentication-from-scratch) Rails Cast + + + +###Still Feel Lost? +####Catch Up With These Resources + +* [Devise](http://railscasts.com/episodes/209-introducing-devise) Rails Cast + diff --git a/Some_Folder/0529.rb b/Some_Folder/0529.rb new file mode 100644 index 0000000..4d5344e --- /dev/null +++ b/Some_Folder/0529.rb @@ -0,0 +1,131 @@ +while true + puts "Is steak your favorite food?" + answer = gets.chomp.downcase + if (answer == 'yes' || answer == 'no') + break + else + puts "Please answer yes or no." + end +end + +puts "Thank you for the response!" + +#FizzBuzz exercise + +1.upto(100) do |num| + + if num%3 == 0 and num%5 != 0 + puts "fizz" + + elsif num%5 == 0 and num%3 != 0 + puts "buzz" + + elsif num%3 == 0 and num%5 == 0 + puts "FizzBuzz" + + else puts "#{num}" + + end +end + +____________________ + +100.downto(10) do |num| + + if num%2 == 0 and num%5 != 0 + puts "Pretty" + elsif num%5 == 0 and num%2 != 0 + puts "So pretty" + elsif num%2 == 0 and num%5 == 0 + puts "So pretty pretty" + else + puts num + end +end + +# 1.upto(100).each do |num| +# case +# when num % 15 == 0 then puts "Fizzbuzz" +# when num % 3 == 0 then puts "Fizz" +# when num % 5 == 0 then puts "Buzz" +# else puts num +# end +# end + +# end +# _____________ + +require 'pry' + +name = "Rusty" +binding.pry # adding this line will not allow for changing of name to Wyatt +name = "Wyatt" +puts name +# type "exit" to exit pry + +#programmableweb.com to see APIs + +#JSON - how API's talk to each other + +#http://www.reddit.com/.json - this is saying send us top 25 posts + +#install Chrome extension adapter for json viewer + +#no kimono - for scrapping, right click and go to inspect elements + +#gem install rest-client +#require 'pry' +#require 'rest-client' +#require 'json' + +response = RestClient.get("URL") +movies = JSON.load(response) +binding.pry +response + +exit + +Puts "enter a search term: " +input = chomp + +movies["Search"].each do |film| + puts film["Title"] +end + + +#require 'pry' +#require 'rest-client' +#require 'json' + +puts "These are my top REDDIT posts!" +puts "Select an option to continue." + +post = RestClient.get("http://reddit.com/.json") +clean_post = JSON.load(post) + +clear_post ["data"]["children"].each do |post| + puts post ["data"]["title"] +end + + +_____________ + + +subred = RestClient.get("http://reddit.com/r/aww/.json") +sub_post = JSON.load(subred) + +sub_post ["data"]["children"].each do |post| + puts post ["data"]["title"] +end + +________________ +input = gets.chomp +subred = RestClient.get("http://reddit.com/r/#{input}/.json") +sub_post = JSON.load(subred) + +sub_post ["data"]["children"].each do |post| + puts post ["data"]["title"] +end + + + diff --git a/Some_Folder/06052014 b/Some_Folder/06052014 new file mode 100644 index 0000000..e69de29 diff --git a/Some_Folder/06052014.rb b/Some_Folder/06052014.rb new file mode 100644 index 0000000..812eb13 --- /dev/null +++ b/Some_Folder/06052014.rb @@ -0,0 +1,36 @@ + +# dict_hash = {} + +# dict_hash['shaia'] = 'candle' +# dict_hash['shoo'] = 'food' + +# dict_hash.each do |c_word, word| +# puts "#{c_word}: #{word}" +# end +# ____________ + +# weird_hash = Hash.new + +# weird_hash[12] = 'monkeys' +# weird_hash[[]] = 'emptiness' +# weird_hash[Time.new] = 'no time like the present' + +# _____________ + +class Die + + def roll + @number_showing = 1 + rand(6) + end + + def showing + @number_showing + end +end + +die = Die.new +die.roll +puts die.showing +puts die.showung +die.roll +puts die.showing diff --git a/Some_Folder/APIs b/Some_Folder/APIs new file mode 100644 index 0000000..5dae7b6 --- /dev/null +++ b/Some_Folder/APIs @@ -0,0 +1,40 @@ +require "json" +require 'rest-client' + +# response = RestClient.get("http://www.omdbapi.com/?s=potter?") +# movies = JSON.load(response) + +# movies["Search"].each do |film| +# puts film ["Title"] +# end + +puts "Here are the top 25 REDDIT posts!" + +response = RestClient.get("http://www.reddit.com/.json") +top_responses = JSON.load(response) + +top_responses["data"]["children"].each do |posts| + puts posts ["data"]["title"] +end + +# _________________ + +# subred = RestClient.get("http://reddit.com/r/aww/.json") +# sub_post = JSON.load(subred) + +# sub_post["data"]["children"].each do |post| +# puts post ["data"]["title"] +# end + +# ________________ + +input = gets.chomp +subred = RestClient.get("http://reddit.com/r/#{input}/.json") +sub_post = JSON.load(subred) + +sub_post["data"]["children"].each do |post| + puts post ["data"]["title"] +end + +up - last code +cntrl + command + up - reverse lines in code \ No newline at end of file diff --git a/Some_Folder/SF b/Some_Folder/SF new file mode 100644 index 0000000..e69de29 diff --git a/Some_Folder/SF.rb b/Some_Folder/SF.rb new file mode 100644 index 0000000..6d2b058 --- /dev/null +++ b/Some_Folder/SF.rb @@ -0,0 +1,65 @@ +# command = '' + +# while command != 'bye' +# puts command +# command = gets.chomp +# end + +# puts 'Come again soon!' + +# _____________ + +# 1.upto(3) do |num| +# puts "#{num} and more!" +# end + +# _____________ + +# while true +# input = gets.chomp +# puts input +# if input == 'bye' +# break +# end +# end + +# puts 'come again soon!' + +# _____________ + +# puts 'What is your name?' +# name = gets.chomp.capitalize +# puts 'Hello ' + name.to_s + '.' + +# if name == 'Chris' || name == 'Katy' +# puts 'What a lovely name!' +# else +# puts "That is an okay name." +# end + +# _____________ + +# num_at_start = 8 + +# num_now = num_at_start + +# while num_now > 2 +# puts num_now.to_s + ' bottles of beer on the wall, ' + +# num_now.to_s + ' bottles of beer!' +# num_now = num_now - 1 + +# puts 'Take one down, pass it around ' + +# num_now.to_s + ' bottles of beer on the wall!' +# end +# puts "2 bottles of beer on the wall, 2 bottles of beer!" +# puts "Take one down, pass it around, 1 bottle of beer on the wall" +# puts "1 bottle of beer on the wall, 1 bottle of beer!" +# puts 'Take one down, pass it around, no more bottles of beer n the wall!' + +# ______________________ + + +1.upto(100) do +puts + + diff --git a/Some_Folder/apartment ex.rb b/Some_Folder/apartment ex.rb new file mode 100644 index 0000000..0b4c69f --- /dev/null +++ b/Some_Folder/apartment ex.rb @@ -0,0 +1,47 @@ +class Apartment + #name, rent, square_footage, number_bedrooms + attr_accessor :name, :rent, :square_footage, :number_bedrooms, :renters # variables that have meaning in this class + + def initialize(name, rent, square_footage, number_bedrooms) + @name = name + @rent = rent + @square_footage = square_footage + @number_bedrooms = number_bedrooms + @renters = [] + end + + def is_occupied? + @renters.any? + end + + def add_renters(renter) + @renters << renters_name + end + + def delete_renters(renter_name) + @renters.delete (renters_name) + end +end + +my_apartment = Apartment.new("SF SOMA", 2000, 800, 1) + + +if my_apartment.is_occupied? + puts "This apartment is not for rent" +else + puts my_apartment + puts "This apartment is for rent" +end + +my_apartment.renters = ["Mari", "Sally"] +puts my_apartment.renters +my_apartment.add_renters("Greg") +puts my_apartment.renters +my_apartment.delete_renters("Mari") +puts my_apartment.renters + + +# def to_s +# puts my_apartment +# end +# ___________ \ No newline at end of file diff --git a/Some_Folder/apt_exer.rb b/Some_Folder/apt_exer.rb new file mode 100644 index 0000000..d850ae1 --- /dev/null +++ b/Some_Folder/apt_exer.rb @@ -0,0 +1,51 @@ +class Apartment + #name, rent, square_footage, number_bedrooms + attr_accessor :name, :rent, :square_footage, :number_bedrooms, :renters # implies getter and setter if in here. variables that have meaning in this class +# what are getters and setters? there is attr_reader and attr_writer. + def initialize(name, rent, square_footage, number_bedrooms) + @name = name + @rent = rent + @square_footage = square_footage + @number_bedrooms = number_bedrooms + @renters = [] + @taxes = 1000 + end + + def is_occupied? + @renters.any? + end + + def add_renters(renter) + @renters << renters_name + end + + def delete_renters(renter_name) + @renters.delete (renters_name) + end + + def get_taxes + @taxes +end + +my_apartment = Apartment.new("SF SOMA", 2000, 800, 1) + + +if my_apartment.is_occupied? + puts "This apartment is not for rent" +else + puts my_apartment + puts "This apartment is for rent" +end + +my_apartment.renters = ["Mari", "Sally"] +puts my_apartment.renters +my_apartment.add_renters("Greg") +puts my_apartment.renters +my_apartment.delete_renters("Mari") +puts my_apartment.renters + + +# def to_s +# puts my_apartment +# end +# ___________ \ No newline at end of file diff --git a/Some_Folder/class 0602 b/Some_Folder/class 0602 new file mode 100644 index 0000000..4d63e6d --- /dev/null +++ b/Some_Folder/class 0602 @@ -0,0 +1,37 @@ +# jimmy = {} +# jimmy[:name] = "Jimmy J" +# jimmy[:major] = "Math" +# jimmy[:course] = "Math" +# jimmu[:grade] = "A" + +# ed = {} +# ed[:name] = "Ed E" +# ed[:major] = "English" +# ed[:course] = "English" +# ed[:grade] = "C" + +# carl = {} +# carl[:name] = "Carl C" +# carl[:major] = "History" +# carl[:course] = "History" +# carl[:grade] = "D" + +class Student + attr_accessor :name, :major, :course, :grade +end + +jimmy = Student.new +jimmy.name = "Jimmy J" +jimmy.major = "Math" +jimmy.course = "Math" +jimmu.grade = "A" + +def grade_status(student) + if student.grade == "F" + "failed" + elsif ["D", "F"].inclde?(student.grade) and student.major == student.course + "failed" + else + "passed" +end +end \ No newline at end of file diff --git a/Some_Folder/class 0602.rb b/Some_Folder/class 0602.rb new file mode 100644 index 0000000..525c8f9 --- /dev/null +++ b/Some_Folder/class 0602.rb @@ -0,0 +1,55 @@ +# jimmy = {} +# jimmy[:name] = "Jimmy J" +# jimmy[:major] = "Math" +# jimmy[:course] = "Math" +# jimmu[:grade] = "A" + +# ed = {} +# ed[:name] = "Ed E" +# ed[:major] = "English" +# ed[:course] = "English" +# ed[:grade] = "C" + +# carl = {} +# carl[:name] = "Carl C" +# carl[:major] = "History" +# carl[:course] = "History" +# carl[:grade] = "D" + +class Student + attr_accessor :name, :major, :course, :grade, :enrolled + +def initialize(n, major, course, grade) + @name = n + @major = major + @course = course + @grade = grade + @enrolled = true +end + +def grade_status + if @grade == "F" + "failed" + elsif ["D", "F"].inclde?(@grade) and @major == @course + "failed" + else + "passed" +end + def to_s + "#{@name} has #{@grade} #{@course}" +end + +jimmy = Student.new("Jimmy J", "Math", "Math", "D") +# jimmy.name = "Jimmy J" +# jimmy.major = "Math" +# jimmy.course = "Math" +# jimmy.grade = "D" + +ed = Student.new("Ed E", "English", "Math", "A") +# ed.name = "Ed E" +# ed.major = "English" +# ed.course = "Math" +# ed.grade = "A" + +puts "#{jimmy.name} has #{jimmy.grade_status} #{jimmy.course}" +puts jimmy.to_s \ No newline at end of file diff --git a/Some_Folder/class apt.rb b/Some_Folder/class apt.rb new file mode 100644 index 0000000..d7b6690 --- /dev/null +++ b/Some_Folder/class apt.rb @@ -0,0 +1,47 @@ +class Apartment + #name, rent, square_footage, number_bedrooms + attr_accessor :name, :rent, :square_footage, :number_bedrooms, :renters + + def initialize(name, rent, square_footage, number_bedrooms) + @name = name + @rent = rent + @square_footage = square_footage + @number_bedrooms = number_bedrooms + @renters = [] + end + + def is_occupied? + @renters.any? + end + + def add_renters(renter) + @renters << renters_name + end + + def delete_renters(renter_name) + @renters.delete (renters_name) + end +end + +my_apartment = Apartment.new("SF SOMA", 2000, 800, 1) + + +if my_apartment.is_occupied? + puts "This apartment is not for rent" +else + puts my_apartment + puts "This apartment is for rent" +end + +my_apartment.renters = ["Mari", "Sally"] +puts my_apartment.renters +my_apartment.add_renters("Greg") +puts my_apartment.renters +my_apartment.delete_renters("Mari") +puts my_apartment.renters + + +# def to_s +# puts my_apartment +# end +# ___________ \ No newline at end of file diff --git a/Some_Folder/hello.rb b/Some_Folder/hello.rb new file mode 100644 index 0000000..38a5500 --- /dev/null +++ b/Some_Folder/hello.rb @@ -0,0 +1,61 @@ +# 1.upto(3) do |num| +# puts '#{num}' +# end + +# 2.upto(9) do |number| +# puts "Loop is on #{number} iteration" +# end + +# puts 'What is your name?' + +# name = gets.chomp + +# puts.name.inspect +# puts name + +# 1.upto(1000) do |number| +# if number%2 == 0 +# puts number +# end +# end + +# x = 100 +# while x > 0 and x < 1000 +# x -= 1 +# puts "This loop will run #{x} more times." +# end + +# command = '' + +# while command != 'bye' +# puts command +# command = gets.chomp +# end + +# puts 'Come again soon!' + + +#Arrays +# countries = ["Croatia", "France", "Denmark", "Poland", "UK", "Macedonia"] + +# countries.each do |entry| +# puts entry +# end + +# countries.each {|countries| puts countries} + +# menu = {"soup" => 3.50, "steak" => 35} + +# phone_book = {} +# phone_book["Colt"] = "999-999-9999" +# phone_book["Tim"] = "222-222-2222" + +# phone_book["Colt"] + +# puts "Tim\'s phone number is: #{phone_book['Tim']}" + + + + + + diff --git a/Some_Folder/lab 05302014 b/Some_Folder/lab 05302014 new file mode 100644 index 0000000..b9dfa7e --- /dev/null +++ b/Some_Folder/lab 05302014 @@ -0,0 +1,37 @@ +require "json" +require 'rest-client' + +# response = RestClient.get("http://www.omdbapi.com/?s=potter?") +# movies = JSON.load(response) + +# movies["Search"].each do |film| +# puts film ["Title"] +# end + +# puts "Here are the top 25 REDDIT posts!" + +# response = RestClient.get("http://www.reddit.com/.json") +# top_responses = JSON.load(response) + +# top_responses["data"]["children"].each do |posts| +# puts posts ["data"]["title"] +# end + +# _________________ + +# subred = RestClient.get("http://reddit.com/r/aww/.json") +# sub_post = JSON.load(subred) + +# sub_post["data"]["children"].each do |post| +# puts post ["data"]["title"] +# end + +# ________________ + +input = gets.chomp +subred = RestClient.get("http://reddit.com/r/#{input}/.json") +sub_post = JSON.load(subred) + +sub_post ["data"]["children"].each do |post| + puts post ["data"]["title"] +end \ No newline at end of file diff --git a/Some_Folder/r b/Some_Folder/r new file mode 100644 index 0000000..e69de29