T-6,3,1 to Course Start

Random Ruby

  • the chr and ord methods deal with integer ordinals of one character strings, the built in version of the OTP code I wrote, but without wrap around capability

Testing with RSpec

  • Level 2
    • Rails: include rspec in gemfile (development/test group), bundle install, rails generate rspec:install
      • Rails spec helper is unique
        • requires helper files within spec/support/
        • allows you to change default configuration with a configure block (change mocking and stubbing? mocha?)
      • Can put options like --color and --format documentation within the .rspec file to make them defaults
      • can specify line number when running :4
    • matchers
      • .match with regex
      • include
      • .have(number).thing_to_have  (_at_least or _at_most suffixes)
      • .from(num) to .to(num)
      • respond_to(method_name)be_within(range).of(value), exist, satisfy {block_returns_true}, be_kind_of(class), be_an_instance_of(class)
      • expect {block}.to change{fetched_attribute}.to change.from().to() (works with to and should)
  • Level 3 – DRY tips
    • respond_to checks for an instance method for an instance
    • if you start a block with:  describe ClassName do (must start with a class), then when you use the keyword subject inside an example, RSpec will insert Zombie
      • but really, you can omit a word completely: subject.respond_to(:name) == respond_to(:name)
      • alternatively, you could explicitly state the subject of a spec with a block
    • if you use an it block where you are checking the subject, you can use its
      • after describe ClassName do
        • it { subject.name.should == "a" } == its(:name) { should == "a"  }
          • also useful when using its in conjunction with an explicit subject
      • can put a string with its so that the string will be evaluated
    • context, use just like describe when nesting
      • then can just declare a subject: subject { block } and follow up with examples without indentation
    • What if you want to have multiple subjects?
      • make a subject-like variable: let(:var_name) { block }
      • a newer way: subject(:name) == subject { name }
    • RSpec only instantiates subjects and lets during a spec that calls for that subject/it, if you wanted to instantiate something every time no matter what:
      • could use let!

Math

  • Expectation Value / Mean value:Screen Shot 2013-06-10 at 11.46.52 AM
    • multiply each possibile value of X, xi by the probability of its occurrence, pi, and sum all these N possible values of X
      •  Screen Shot 2013-06-10 at 11.46.45 AM
    • when N is large, and xi values are closely spaced (X varies continuously), the probability of finding an X value between and x + dx is equal to f(x)dx
      • probability density f(x) , i.e. distribution of probability (derivative of cumulative probability), times an infinitesimally small interval of values
      • integral of f(x)dx conveniently represents the probability for finding a value of X between the limits of integration
        • so, just like in the sum above, we multiply the probability of finding a value of x, by the value of x
          • Screen Shot 2013-06-10 at 12.11.50 PM

Algorithms

  • Instructions take a constant amount of time to execute
  • Assume that in this book’s RAM model, inputs of size are represented by c lg n bits
    • why?
  • Theta n-squared: Θ(n2) is looking at the leading term of a worst case running time, concerned with the order of growth

Alternate sum solution

  • number system
    • base^index * 1st digit
    • 123: base is 10 for decimal. 10^0 *1st digit *3, 10^1 *2, 10^2 * 1:
    • if number system is 2: 2^0*3, 2^1*2, 2^3*1
Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s