Tuesday, November 5, 2013

Rails Quiz 1


Rails Week 1 Quiz

  1. Why do they call it a relational database?
  2. What is SQL?
  3. There are two predominant views into a relational database. What are they, and how are they different?
  4. In a table, what do we call the column that serves as the main identifier for a row of data? We're looking for the general database term, not the column name.
  5. What is a foreign key, and how is it used?
  6. At a high level, describe the ActiveRecord pattern. This has nothing to do with Rails, but the actual pattern that ActiveRecord uses to perform its ORM duties.
  7. If there's an ActiveRecord model called "CrazyMonkey", what should the table name be?
  8. If I'm building a 1:M association between Project and Issue, what will the model associations and foreign key be?
  9. Given this code
    class Zoo < ActiveRecord::Base
      has_many :animals
    end
    • What do you expect the other model to be and what does database schema look like?
    • What are the methods that are now available to a zoo to call related to animals?
    • How do I create an animal called "jumpster" in a zoo called "San Diego Zoo"?
  10. What is mass assignment? What's the non-mass assignment way of setting values?
  11. What does this code do? Animal.first
  12. If I have a table called "animals" with columns called "name", and a model called Animal, how do I instantiate an animal object with name set to "Joe". Which methods makes sure it saves to the database?
  13. How does a M:M association work at the database level?
  14. What are the two ways to support a M:M association at the ActiveRecord model level? Pros and cons of each approach?
  15. Suppose we have a User model and a Group model, and we have a M:M association all set up. How do we associate the two?

Sunday, October 27, 2013

Starting over with git

I had some kind of screw up with my branching when trying to push to my github repository.  I never really figured out the exact issue, but since the repository had really minimal history i just removed it.  Here is what I did for the local repository;

From the terminal while in the correct directory i typed: rm -rf .git
Then I reinitialized the local repository with: git init

In github I removed the repository by going under settings when in the said repository and choosing remove.  I then created a new github repository and went back to the terminal to push files and all seems well.  It was an hour or two of cursing before i figured out what to do.

Saturday, October 5, 2013

inject method

I came across this method when doing a google search for how to sum in an array.  I'm using it now to try and build my blackjack game.  It seems to be working fine for what I want it to do for now.  I'm not too sure yet on what all this method can do or problems that can arise.   I took the info from a stack overflow post,
http://stackoverflow.com/questions/1538789/how-to-sum-array-members-in-ruby.

My blackjack game is a work in progress.  I tried building this mostly on my own before looking at the tealeaf videos that show building the program up.  I don't know if i'll get a chance to totally finish my own version of it.  Here is where i'm at to show how i'm using inject.  Note that this will run for most instances, but i haven't fixed a couple issues yet.  Note inject returns a fixnum.



deck = [1,2,3,4,5,6,7,8,9,10,10,10,10,'Ace']

deck.shuffle!

ph = []
dh =[]

2.times do
  ph << deck.pop
  dh << deck.pop
  
end

puts 'Hand'
puts ph
puts

if ph.include? 'Ace'
puts 'Ace in hand'
end
puts
if ph.include? 'Ace'
puts 'Choose ace high or low' i'm expecting a 1 or 11 response here
ace = gets.chomp
ace = ace.to_i
ph.map! {|x| x == 'Ace' ? ace : x}
puts
puts ph
end


puts 'Hand total'
sum = ph.inject(:+) here i use inject to get the total for the players hand
puts sum

puts 'Would you like a hit or stay?'
reply = gets.chomp

puts
if reply == 'hit'
ph << deck.pop
puts ph
puts
puts 'Hand total'
sum = ph.inject(:+) new total for player after hit
puts sum
end

if reply == 'stay' and dh.inject(:+)<17
dh << deck.pop
puts 'Dealer hand'
puts dh
puts
puts 'Dealer total'
sum = dh.inject(:+) dealer total. need to fix for aces
puts sum
end
puts
if ph.inject(:+) > dh.inject(:+) comparing hands
puts 'You win!'
elsif dh.inject(:+) >=22
puts 'You win'
else
puts 'Dealer wins :('
end

Thursday, October 3, 2013

Git it!


A reminder for me about pushing to github.  I'm sure this will become something i'll have memorized shortly, but i've already looked this up a couple times in the video from the precourse materials.  Now that it's posted here it will be much easier to get to.

Create a new repository on the command line

touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:jheaden/tealeaf.git
git push -u origin master

Push an existing repository from the command line

git remote add origin git@github.com:jheaden/tealeaf.git
git push -u origin master

Initial commit

Hello world.  I'm officially in week one of my Ruby on Rails online bootcamp!  This is an exciting, and a wee bit stressful, time.  I'm embarking and path to change careers from teaching mathematics to becoming a ruby/rails web developer.
  This blog is set up to document my progress over the next 4 months through the Tealeaf bootcamp.  I hope this turns out to be a useful way to keep notes on what i'm learning as I go.  My intention is to do some brief summaries of topics each week and what i've learned or am struggling with.  While this bootcamp will take a lot of time i hope to keep myself fit and active.  So i'll also post my weekly workouts, mostly running, as I go.  My weeks start on Monday.

Mon Sep 30  AM Easy run with Zola (2.5 miles).  PM Easy track.  4 400's between 6:15 and 5:45 effort (3 miles)

Tues Oct 1  PM CC practice.  Ran with kids (4 miles)

Wed Oct 2  AM Shevlin run with Zola (5.5 miles)

Thurs Oct 3  AM 45 min lap swim.  Running around cheering kids on at meet.  My first meet as cross country coach!  Tons of fun, very proud of my runners.

Fri Oct 4  AM Shevlin run with Zo (4 miles)


Well i doubt anyone will find and read this blog, but hey if you do comments are great!

Cheers