panicbus
10/30/2013 - 9:01 PM

test.md

Test

Ruby

  1. Print the text "Hello, world!"

     puts "Hello, world!"
    
  2. What data type did you print?

    string

  3. Print the result of the expression 2 + 2

    print 2 + 2
    
  4. What data type did you print?

    integer

  5. Assign the result of the expression 2 + 2 to a variable named result

     result = 2 + 2
     print result
    
  6. What data type is the value of result?

    integer

  7. Write a method which takes two parameters and adds them, returning the result.

     def adding(num1,num2)
         num1 + num2
     end 
     puts adding(1,2)
    
  8. On what datatypes will the function you wrote work correctly? Incorrectly?

    on an integer or float to work correctly, on a string to not work correctly

  9. What is the difference between testing for equality and assigning a value to a variable? (Show an example of both)

    testing for equality should use ==

    assigning a variable should use =

  10. What data type is [1, 2, 3, 4, 5]?

    array

  11. Iterate through the above data structure, printing each number multiplied by two.

     arr = [1, 2, 3, 4, 5]
     arr.each do |i|
         i * 2
     end
     p i
    
  12. Iterate through the above data structure, printing "I am the [n]th element", replacing 'n' with each element's index.

     arr = [1, 2, 3, 4, 5]
     i = arr.each
     for arr[i] do |i|
         puts "I am element #{i}"
     end
    
  13. What data type is {cats: 3, dogs: 2, fish: 13}?

    hash

  14. What is the data type and role of cats in the above structure?

    it's a element in a hash and the key of a key value pair

  15. What are the roles of the integers in the above structure?

    they're the values

  16. Iterate through the above data structure, printing "Kyle has [n] [thing]s", replacing 'n' and 'thing' with the appropriate values.

     pets = {cats: 3, dogs: 2, fish: 13}
     for pets {:v, :k}
         
     end
     puts "Kyle has #{v} #{k}"
    
  17. Write a method called max_animal that accepts a data structure like the above as a parameter, and returns which type of animal Kyle has the most of.

     m = pets.max
     puts m
    
  18. Write a class called Man with an instance method move, which prints walk, and an attribute name with a reader and writer method.

     class Man
     
         attr_reader :name
         attr_writer :name
     
         initialize (move, name)
             @move = move 
             @name = name
         end
         
     end
     
     man1 = Man.move("walk")
     puts = man1
    
  19. Write a subclass of Man called Superman, whose move method prints fly

     Man << Superman
         @move = fly
     end
     
     man2 = Superman.move
     puts man2 
    
  20. Add a class method to your Superman class called is_superhero? which returns true.

     Superman.is_superhero? == true
    
  21. Do you need to add the name attribute to Superman? If not, why?

    No, because name is inherited from the Man class

  22. Does Ruby have methods, functions, or both?

    Ruby has methods AND functions

  23. Whichever of the above (method/function) you decided, can it be stored in a variable?

    the object of methods can be stored in variable, but the actual method cannot. functions cannot be stored in a variable

  24. What is the name of this construct in Ruby: do |thing| thing * 2 end

    method

Javascript

  1. Print the text "Hello, world!"

     console.log("Hello, world!")
    
  2. Print the result of the expression 2 + 2

     console.log(2 + 2)
    
  3. Assign the result of the expression 2 + 2 to a local variable named result

     var result == (2 + 2)
     console.log(result)
    
  4. Write a function which takes two parameters and adds them, returning the result.

     var result = adding(num1, num2) {
         num1 + num2;
     }
     return (adding(1,2))
    
  5. On what datatypes will the function you wrote work correctly? Incorrectly?

    integers will work correctly strings will not

  6. What data type is [1, 2, 3, 4, 5]?

    array

  7. Iterate through the above data structure, printing each number multiplied by two.

     arr = [1, 2, 3, 4, 5]
     for (var i=0; i < arr.length; i++){
         return arr[i] * 2;
     };
    
  8. What data type is {cats: 3, dogs: 2, fish: 13}? (Hint: NOT the same as the Ruby answer)

    object

  9. In setTimeout(doStuff, 2000), what datatype should doStuff be and what do we call that datatype in this role?

    object, and in this role it's a method

  10. What datatype is foo in var foo = function() { alert("Hello"); };?

    foo is a variable

  11. Is a function a type of object?

    yep

  12. Show how you would use var Person = function(){}; to construct a Person.

  1. What is a prototype?

    an object that takes the place of (or stands in for) a different, probably more complicated object from earlier in the code

  2. What do I mean every time I say "In Javascript, functions are first-class values"?

    because they are executed first

  3. What is the difference between an AJAX request and a typical HTTP request?

    AJAX operates on the same page

Rails

  1. What type (three letter acronym) of framework is Rails?

    aaah, forget

  2. Define each of the three components

In your shell...

  1. Make a new rails project called blog

     rails new blog
    
  2. In that project, make a new controller PostsController

     rails g controller Posts
    
  3. Make a Post model

     rails g model Post
    
  4. Make PostsController and the Post model, as well as RESTful routes, in a single step.

     rails g contoller Posts, rails g model Post, scaffolding
    
  5. Run the migrations for Post

     rake db:migrate
    
  6. See all your app's routes

     rake routes
    
  7. Start the web server

    In general...

     rails s
    
  8. What is the name of the (default) superclass of all of our generated controllers?

     <b>Base</b>
    
  9. What do we call controller instance methods that respond to web requests?

    CRUD

  1. What, by default, would one such method (say, show) do if I leave its method body empty?

    print the page

  1. What kind of template is application.html.erb?

    view

  2. What kind of template is posts/_form.html.erb?

    partial

  3. In an ERB template, with a @post var available, how would I render a link to that post's show page?

     <%= link_to @post, "show#index" %>
    
  4. What relationships would you define in your models if a user can have multiple posts?

     has_many :posts
    
  5. What field would you need to add to post?

     belongs_to :user
    
  6. What relationships would you define in your models if a post could have multiple categories, and a category could belong to multiple posts? What tables would you need to add?

    In the Rails console...

     inner_join 
    
  7. How many Posts exist in the database?

    1

  8. How many Posts by user with id 1? (assuming I've properly associated a User model with the Post model)

    2

  1. Find the first post

     Post.first
    
  2. Destroy the last post

     Post.last(delete)
    
  3. Destroy all posts by user with id 5.

     Post.delete(5)
    
  4. Create a post with user id 1, title "My Post", and body "This is the body of my first post"

     Post.create(id: '1', title: 'My Post', body: 'This is the body of my first post')
    
  5. Find all the caterogies associated with the first post.

     Post.find.first.all
    
  6. Print out all the titles of the categories associated with the first post.

     Post.all.first
    

jQuery

#####fucking hell, without my notes or Google i don't know any of these :(

I do know there's probably $'s involved tho. :-/
  1. Select an element with id foo
  1. Select all elements with class bar
  1. Select all the <div>s on the page.
  1. Create a new div with id baz.
  1. Append that newly created div to a div with id foo
  1. Remove all input elements from the page.
  1. Remove all the children of the div with id foo
  1. Hide all divs with class oops
  1. Hide all the children of the div with id foo
  1. Perform an AJAX GET request to /thingList.json, iterating through the returned result set and logging each item to the console.