T-8,7 to Course Start


  • REST review
    • represent data as resources that can respond to the 4 HTTP actions: post, get, put, delete
    • resources: users endows Rails with all the actions needed for a RESTful Users resource
      • routing is done, but you still need the actions to be there in the controller, and have the method name of the view that they point to
      • in our case, use params[:id] is used to deliver the URI specification to the find method, even if we use find_by_name, the URI is still passed in with params[:id]
  • Sidebar
    • put into an <aside> tag, and include the Bootstrap classes row and span4
  • Signup Form
    • Capybara makes testing forms easy
      • expect { click_button button_name_from_let }.to change(User, :count).by(1)
    • form_for() do |f| method
      • should then be called with methods corresponding to html form elements
      • this will create the necessary html (label, text_field…)
    • Our form_for method takes @user as an argument, something that then needs to be initialized in the controller (again, creating a method with the same name as that model)
      • it also then calls the create method, which we also put in the controller, and happen to put a conditional so that we can respond accordingly to invalid/valid users
      • the create method takes in the argument: params[:user] which in this case is a hash of the hash values for the user (name, email, password)
    • we display error messages for the form with: <%= render 'shared/error_messages' %>
      • an example of how Rails uses a /shared directory for partials that are to be used in views from multiple controllers
  • More on Migrations
    • When you edit an already use migration, rollback, then edit, then db:migrate again.
    • Things to do
      • Create a brand new data model: rails g model
      • Add to an existing model: rails g migration AddColumnNameToTable
        • will put an add_column statement into a new change method
  • Built in debugging
    • <%= debug(params) if Rails.env.development? %>
      • the condition makes sure that the debug is only visible during development, by checking the Rails environment
      • console and local Rails server are both defaulted to development
        • rails console test
        • rails server --environment production
          • but you’ll also need to make a production database: bundle exec rake db:migrate RAILS_ENV=production
  • Factory Girl
    • a convenient way to create users for testing, can define a model object, and then use the let(:table) { FactoryGirl.create(:user) } command in RSpec
    • gem 'factory_girl_rails', '4.1.0'
  • BCrypt
  • MD5
    • Ruby’s hexdigest method in the Digest library implements the MD5 hashing algorithm
    • just pass something into: Digest::MD5::hexdigest(hash_me) , remember that its case sensitive


  • C on mac:
    • compile a .c file: gcc file_name.c
    • run the compiled a.out file with benchmarking: time ./a.out
  • The shell and Ruby
    • at the top: #!/usr/bin/env ruby
    • pbpaste makes the clipboard accessible to standard output/input
      • pbpaste > file.txt will pipe the current text into that file
    • made a file in ~/bin/ that I want to contain a command that I will access from the Terminal, so I added PATH="~/bin:$PATH" to my .bash_profile
      • also, made sure the permissions were okay: chmod ugo+rwx to add read/write/execute permissions to current user/group/others
    • IO.popen('pbpaste', 'r+').read will take in the contents of the clipboard
    • IO.popen('pbcopy','w').print(variable) will put the contents of some variable into the clipboard
  • RegEx
    • can group things with parentheses, and then later refer to them with literal numbers: gsub(/(<\/?)em(>)/, '\1code\2') makes sure to reinsert the pattern found in parentheses around the code string
  • Changed the bash prompt in my Terminal to something less lengthy
  • Sass
    • doing @mixin mixin_name { //and listing a bunch of attributes } allows a package of those attributes to be assigned all together later in some other class, just call @include mixin_name;
  • Math
    • In a set of n elements, the quantity of subset containing k of the n elements is represented as:
      • Screen Shot 2013-06-10 at 11.32.02 AMn choose k (n elements for k slots/bins), gives a number
      • in the expansion of a binomial, Screen Shot 2013-06-10 at 11.33.18 AM, you will get a bunch of terms Screen Shot 2013-06-10 at 11.33.22 AM(in fact you will get n+1 terms), b+c will always be equal to n for every term. The series of a coefficients will be Screen Shot 2013-06-10 at 11.33.27 AM
      • Going the other way…
        • the sum of a series of “n choose k” elements could represent all the possible ways to arrange n elements (ways to arrange elements into 0 bins, plus into 1 bin, plus into 2 bins, all the way to bins)
        • this sum of many a‘s, since x and y are irrelevant, and should be phased out by setting them equal to 1, remember Screen Shot 2013-06-10 at 11.33.22 AM, could also be represented simply as: Screen Shot 2013-06-10 at 11.33.11 AM
        • the result ends up looking like the amount of possibilities for a binary number of length n
      • You could also express a fraction where you divide the “n choose k” number of a particular scenario, by the sum of the “n choose k”s for all scenarios (all the ways to deal with n elements, from having k = 0 bins, to k = n bins)
        • in a case where (x+y) = 2 (for convenience, to take advantage of/adapt the binomial theorem), a plot of this fraction versus will show that the scenario k = n/2 shows the largest fraction, meaning that the k = n/2  provides a larger percentage of scenarios to arrange elements moreso than any other value of k

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s