Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
2303 lines (1693 sloc) 108 KB
LEARNING LOG
============
-----WEEK 1-----
1/6/14
- Work more patiently. When you rush you not only make more mistakes, it's a disservice to your partner.
- When multiplying strings in ruby, the string must precede the integer:
"M" * 3 => "MMM"
3 * "M" => String can't be coerced into Fixnum
1/7/14
– regex named captures:
 /^(?<first_consonants>[^aeiouy\d\W_]+)(?<rest_of_word>.*)/ =~ english_word
 piglatin_word = first_consonants + rest_of_word + "ay"
– pass value:
copies object value to another variable (identifier), NON-DESTRUCTIVE
- pass reference:
copies object reference to another variable (identifier), can be DESTRUCTIVE
1/8/14
- Learned about the Benchmark module.
- Learned about the Prime module.
– Using File.new to read outside files within ruby:
my_dictionary = []
File.open("dictionary.txt").each_line do |line|
my_dictionary << line.rstrip
end
– How to write an iterative version of binary search; see algorithm-drill-binary-search-challenge.
1/9/14
- How to use pry and pry-nav as a debugging tool. You can put a "pause" in a program by inserting the following line, then test the state at that moment:
require 'pry'; binding.pry
- A good approach to the convert arabic number to english number problem, see numbers-in-words-challenge
- How to use command+D in sublime for quick search and replace.
- How to use command+shift+L in sublime for a giant cursor.
1/10/14
– Learned about the Matrix module.
- How to break down a complex problem into manageable psuedocode, e.g. the sudoku challenge. It seemed impossible at first but once we had a good algorithm psuedocoded we finished it in 3 hours.
1/11/14
– Learned the difference between primitive, composite, and abstract data structures:
primitive: provided by the language itself to serve as building blocks.
composite: composed of primitive datastructures. In Ruby arrays & hashes are composite.
abstract: defined by the operations that may be performed not how it is implemented.
- Learned how to implement a stack.
- Learned how to implement a queue.
- Learned how to implement a linked list.
- Learned how to write my own "each" methods using yield.
-----WEEK 2-----
1/13/14
- Learned about rspec and got a little practice using it.
– Learned how inheritance works in Ruby; see orange-tree-2-groves-challenge.
1/14/14
- Learned how to use ARGV to provide ruby with user input directly from the command line.
- Learned how to import and export .csv files in Ruby with the CSV class.
- Learned how to write and use my own modules.
- gets.chomp returns a string by default, convert it if you have to!
1/15/14
- Learned about Nokogiri and how to use it to parse/scrape HTML. See scraping-hn-1-building-objects-challenge, scraping-hn-2-building-objects-challenge.
- How to pass hashes as arguments to avoid argument-order dependency. See design-drill-argument-order-dependency-challenge.
– Learned about the Net Module; see http://www.rubyinside.com/nethttp-cheat-sheet-2940.html
1/16/14
- Learned about MVC design (Model/Viewer/Controller), more helpfully visualized as VCM:
Viewer --> Controller --> Model
HTML --> Ruby/Rails --> Database
- Learned about Object#send. Send can take a string/symbol as an argument, and convert that into a method call:
String.send("reverse").
It can be a useful way to avoid complicated conditional branching if we're interpreting input in an interface, but this also poses obvious security risks:
Interface.send(ARGV[0])
1/17/14
– Learned that gets.chomp won't work if there are already values stored in ARGV. #shift values out of ARGV before trying to use gets.
– Got some experience working with MVC design with the flash cards project.
1/18/14
– Learned about the colorize gem.
– Learned about the "abort" command.
– Reviewed how to use the SQLite gem in ruby. Databases are structured like arrays:
$db = SQLite3::Database.open "congress_poll_results.db"
az_reps = $db.execute("SELECT name FROM congress_members WHERE location = 'AZ'")
-----WEEK 3-----
1/20/14
– Reviewed SQL query syntax.
– WHERE won't work with aggregate functions:
WHERE count(*) > 3 nope.
HAVING count(*) > 3 yes.
– Learned how to use combined primary keys in SQL to enforce unique combinations of chosen fields in a table.
1/21/14
– Got a lot more practice using the sqlite3 gem, translating table records into ruby objects and vice versa.
– Learned about the different "layers" of data: raw data, relational databases, ruby interfaces on top of relational databases (e.g. sqlite3 gem), and ORM (object-relational mapping, e.g. ActiveRecord.)
1/22/14
– Introduced to ActiveRecord. First started learning about:
– Rake files
– Migrations
– Associations
– Validations
– Models
1/23/14
– More practice with ActiveRecord – wrote my own database from scratch!
– Learned a little about the twitter API gem.
1/24/14
– More practice with ActiveRecord and the MVC model – built a To Do List app with persistent state stored in an ActiveRecord database. Got practice writing migrations, models w/associations, and ActiveRecord queries.
– ActiveRecord associations, assuming "derp" associates with "herp":
– belongs_to one-to-one, derp has a herp_id
– has_one one-to-one, herp has a derp_id
– has_many one-to-many, herp has a derp_id
– has_many through: many-to-many, with through indicating the join table.
– has_one through: one-to-one, via a third table
– has_and_belongs_to_many many-to-many, with automatically generated join table.
1/25/14
– Learned the basics of Sinatra, a library and Domain Specific Language for making simple web apps. It's dependent on the Rack web server interface, which wraps HTTP requests and responses into forms that Ruby (or another abstract language) understands.
– Reviewed the basics of CSS positioning:
– Static: boxes is stacked and can't accept a coordinate system (top, left, etc.)
– Relative: box is stacked and CAN accept a coordinate system.
– Absolute: box is removed from normal flow, won't affect or be affected by others.
– Fixed: like absolute, but fixed in place and unaffected by scrolling.
– Inherit: inherits the position of its parent element.
-----WEEK 4-----
1/27/14
– Learned about request/response cycle.
– Got a lot more practice with Sinatra!
– Sinatra stores user input in hashes.
– params is local to each route.
– session (a cookie) is global for all routes.
– Sinatra can pass these values to ERB files to be rendered as HTML.
1/28/14
– Learned more about request/response cycle: how Rack translates requests and sends them down to middleware (Like Rails and Sinatra) for processing, which in turn send responses back up in a form that Rack understands and can send out as an HTTP response. See rack_fun and:
http://chneukirchen.org/blog/archive/2007/02/introducing-rack.html
– HTTP traffic is usually sent through port 80.
– How to get a local repo running on Heroku:
– TEST THE APP LOCALLY FIRST
– Add a Procfile; for a Sinatra project it will probably look like this:
bundle exec shotgun config.ru -p $PORT
– This will generate a random name for your app:
$ heroku create
If you want to change it, you can update your heroku remote address with the following:
$ git remote set-url heroku NEW_URL_HERE
– Push your master branch to heroku.
– Get your app up and running:
$ heroku ps:scale web=1
– To stop your app from running:
$ heroku ps:scale web=0
1/29/14
– Starting from a Sinatra skeleton I created a URL-shortening app, complete with users!
– Learned how to write a simple authentication method for a users database.
– Learned about the ruby Digest module, which can be used for hash encryption. Useful for hashing passwords:
Digest::SHA256.hexdigest("password") => as23df452...
– How to use sessions to keep track of a logged-in user.
1/30/14
– More about sessions in Sinatra: a session is a way of storing state between requests on a server. The session hash is stored on the server, and a cookie (rack.session) is stored on the client side. The client cookie stores a key that associates the client with a session on the server.
– HTML forms can only send GET and POST requests. If you want to send another request, like PUT or DELETE, you must include the following tag in your form:
<input type="hidden" name="_method" value="put">
– Learned about the z-index attribute in CSS. z-index allows you specify the stack order of elements (how they are layered on top of each other). An element with greater stack order is always in front of an element with a lower stack order.
1/31/14
– Got practice building a Flashcards web app from the ground up.
– Learned how to make my routes more RESTful!
– Learned a good git workflow for working in groups:
– Create a feature branch of the latest origin/master
– When you're done, rebase with origin/master:
$ git fetch
$ git rebase origin master
– Resolve merge conflicts in rebase BEFORE continuing!
– Push your branch, submit pull request .
-----WEEK 5-----
2/3/14
– Introduction to jQuery: manipulating objects in the DOM, event handlers.
– How to manipulate the DOM with both jQuery and vanilla Javascript.
– See jquery.txt
2/4/14
– Types of testing:
ATOMISTIC
– Unit: class level, does class x behave as expected?
– Functional/controller: controller level, do my controllers behave as expected?
– Integration: higher level, e.g. test controllers in actual browser (expensive testing)
– Acceptance: highest level, demo the product to match user expectations
SYSTEM-WIDE
– "Continuous Integration": common in actual practice, server that continuously runs tests and automatically notifies the team if the latest commit produced an error.
– A lot of testing vocabularly dates back to the days of JUnit (Java unit testing):
– setup: create the dummy classes for testing
– teardown: clean up the dummy classes
– assert: true/false test
– assert_eq: equality test
– The two main ruby domain specific languages for testing are Minitest & Rspec.
– For Rspec syntax, see "The Rspec book", ch. 16–18.
2/5/14
– AJAX: Asynchronous Javascript And XML (a set of techniques rather than a distinct language).
– Synchronous responses: Whole page reloads with each request/response.
– Asynchronous responses: Each request/response reloads only a portion of the same page.
– How to make an asynchronous request in vanilla Javascript:
// See docs on MDN:
var myRequest = XMLHttpRequest.new
– Making an asynchronous request in jQuery: see jquery.txt
– Scope types:
– Lexical (C, C++, Java)
– Block-level (Ruby)
– Functional (Javascript)
– Closure: a means for storing a particular scope for later use. Closures are functions that preserve any variables that were in their scope when stored, even if they were not explicitly placed inside the closure. In Ruby Procs and Lambdas are closures. In Javascript functions can be used like closures (module design pattern).
2/6/14
– Event delegation in jQuery. If you try to apply event handlers to dynamically generated elements, it won't work. This is because event handlers are only applied to elements on the screen when the script first loaded. You can work around this using event delegation, rather than this:
$("#myList li").on('click', function () {
    $(this).css('color', 'red')
});
Write this:
$("#myList").on('click', 'li', function () {
    $(this).css('color', 'red')
});
2/7/14
– Got practice writing unit tests for active record models using rspec.
– To get 'margin: 0 auto' to work with images, change 'display' to 'block'. Images are inline by default.
– How to make elements draggable; see http://www.html5rocks.com/en/tutorials/dnd/basics/
– The "data-" attribute in HTML is fully customizable; it could be "data-id" or "data-name", etc. Useful for DOM manipulation!
-----WEEK 6------
2/10/14
– Learned about a d3js, a javascript library for visualizing data using HTML, SVG, and CSS: http://d3js.org/
– More practice using the Twitter API via the ruby twitter gem.
– Learned about dotevn, a way to store global variables in your app, see https://github.com/bkeepers/dotenv
– Solution to N + 1 queries in ActiveRecord: use includes. For example, given two joined tables clients and addresses, don't do this:
clients = Client.all
clients.each do |client|
// Since addresses are lazy loaded, the following line requires a database query:
puts client.address.postcode
end
"
Do this:
clients = Client.includes(:address)
clients.each do |client|
// All associated addresses are "eager loaded" and stored in clients:
puts client.address.postcode
end
2/11/14
– How to set and use cookies in Sinatra, http://www.gittr.com/index.php/archive/sinatra-cookie-handling-in-0-9-4/.
– When you set a cookie on the server, you need to tell it which domains may access the cookie or Chrome prevents you from reading it with JavaScript. Make sure you set the domain to an empty string (""), e.g. in Sinatra:
response.set_cookie("color", {:value => params[:favorite_color], :domain => ""})
– "Monkey patching": adding behaviors/variables to classes on the fly.
– Nice prototype vs. class analogy:
- Class – Plato's forms; an abstract ideal upon which instances are based.
- Prototype – Aristotle's categories; no abstraction, real instances that share qualities
2/12/14
– Learned about the Strategy Design Pattern.
– Learned about server background processing; see tweet-later-challenge.
– Jobs are queued and worked on in the background so the user does not have to wait for a
job to finish to be redirected.
– We used Redis as our queue and Sidekiq as our workers.
– Learned about OAuth, implemented OAuth 1.0 with Twitter.
2/13/14
– Testing mock-ups to avoid actually writing to the DB: "stub" or "double", and "mock"
- stub/double - invite something to stand in for something else (like a DB model)
- Stub of 'Band' model Rspec:
band_double = double(:band, name: 'Beatles', awesome: true)
- mock – something associated with the thing you're testing that is changed by the test;
usually a simplified "mock" of the associated object, we're just testing behavior.
– Learned how to use the simplecov gem to test test coverage %.
2/14/14
– Learned how to use database caching to avoid repeat requests to an API.
– Got practice setting up background jobs using redis and sidekiq.
-----WEEK 7-----
2/16/14
– Basic introduction to rails!
– If you encounter the following error in rails:
ActionController::InvalidAuthenticityToken
try adding this to your controller:
skip_before_action :verify_authenticity_token
– Learned about resource routing in Rails. Resource routing allows you to quickly declare all of the common routes for a given resource. Instead of declaring separate RESTful routes for your index, show, new, edit, create, update and destroy actions, a resourceful route declares them in a single line of code in routes.rb:
resources :photo
– Route helpers are helper methods which automatically create the string for a resource's URL or path:
– photos_path – /photos
– new_photo_path – /photos/new
– edit_photo_path(:id) – /photos/:id/edit
– photo_path(:id) – photos/:id
– Learned about rails view helpers like link_to and image_tag
– Learned about rails form helpers: http://guides.rubyonrails.org/form_helpers.html
– There are two possible parameters in a web application:
– query string parameters; everything after '?' in the URL
– POST data
2/17/14
– Learned more formally about REST (Representational state transfer) architecture. REST is a set of ideas about how a well-designed Web application should behave. The core concept of REST is the existence of resources, each of which is referenced with a global URI. Clients and servers ("components") exchange stateful representations of these resources using a standardized interface (e.g. HTTP).
– Rails controller actions for corresponding resourceful routes:
– index (all resources)
– show (one resource)
– new (form for create)
– create
– edit (form for update)
– update
– destroy
– Using the link_to helper to generate links:
- link_to(photo.name, photo_path(photo))
- link_to("Edit", edit_photo_path(photo))
- link_to("Delete", photo_path(photo), method: :delete)
– #find_or_create_by method; Tag.find_or_create_by_name("vacation") – either finds or or creates a Tag with the matching name field, then returns it.
– Building within associations:
category = Category.new
@post = category.post.build(params)
– Learned about nested resources in Rails.
2/18/14
– How do you write controller tests for nested resources? You need to specify the id of the parent resource:
get :index, category_id: category.id
– Stubbing a controller method:
controller.stub(:current_user) { return this }
– Really useful helper methods you should put in ApplicationController:
def current_user
@current_user ||= User.find(session[:id]) if session[:id]
end
def check_authentication
redirect_to root_path if current_user.blank?
end
def login(user)
session[:id] = user.id
end
2/19/14
– RSpec: Why use let? What's the difference between let and let! ?
– let lazy-loads the assigned variable. That is, it is only assigned if it is specifically
referred to in an example. So it is preferable for memory reasons. It also assures that
each instance of the variable defined by let is totally new.
– let! eager-loads the assigned variable before running any of the examples. This is
preferable if we want to test actual changes to the database (for example, if we are
writing controller tests for #create).
– Got a lot more practice writing controller tests in RSpec.
– Learned how to write feature tests in RSpec with help from capybara.
2/20/14
– 'define_method(cat) do; end' is the same as 'def cat; end'
– When writing a class, wrapping methods in this block: 'class << self; end' Will make the enclosed methods class methods
– Metaprogramming! Or writing code that writes other code. You can do stuff like this:
METHODS = { say_hello: "hello", ... }
METHODS.each do |name, message|
define_method(name) do
puts message
end
end
Or even fancier stuff like this:
# Overriding the Object method #method_missing (this is dangerous stuff!)
def method_missing(method)
if METHODS.keys.include(method)
helper_to_run_method(method)
else
super
end
end
2/21/14
– Learned how to render partials in rails views and send rendered partials as responses in rails controllers. View syntax:
<%= render 'todo', todo: todo %>
Controller syntax:
render partial: todo, locals: { todo: todo }
– Learned how to integrate AJAX requests into rails by adding 'remote: true' to form_for helper and binding handlers to the 'ajax:success' and 'ajax:error' events.
$('form').on('ajax:success', someCallback);
$('form').on('ajax:error', differentCallback);
-----WEEK 8-----
2/24/14
– Refresher on double/stubs in Rspec:
double(:dog, bark: 'woof')
some_object.stub(:some_method?) { true }
Class.any_instance.stub(:some_method?) { false }
– Learned how to write custom rake tasks.
– Learned about database indices: they are a datastructure that stores 1.) the data from one column for all records in a table, 2.) a pointer to the actual record. The index is usually a B-Tree and is sorted, allowing your database to perform a binary search. This allows you to find a given column much faster than performing a linear search through all records. It's a good idea to create an index for:
– Columns that you search through regularly.
– Columns with high cardinality (i.e. variation, so it will benefit greatly from sorting)
– FOREIGN KEYS! This makes finding associations much, much faster.
– How to build a database index in rails. Add this to your migration:
add_index :table, :column, name: 'name_of_index'
– Learned the difference between '#update_attribute' and '#update_attributes'. As the names suggest, the former updates only one attribute, while the latter updates multiple. NOTE that #update_attribute DOES NOT perform any validations, so it may be preferred if speed is your goal.
Object.update_attribute(:only_one_field, "Some Value")
Object.update_attributes(:field1 => "value", :field2 => "value2", :field3 => "value3")
2/25/14
– Learned how to use the XMLHttpRequest javascript object.
– Practiced manipulating the DOM with vanilla javascript.
– Learned how to use the module design pattern in javascript; see miniQuery challenge and notes in javascript.txt
– Javascript is functionally scoped. Ruby is block scoped. This means that:
function() {
if (true) {
var message = "hi" // this identifier is "hoisted" to the top of the function
}
console.log(message) // this will print "hi"!
}
def function
if true
message = "hi" # this is local to the if block
end
puts message # this will NOT print the message
end
2/26/14
– Javascript callback: when you pass a function as an argument rather than an anonymous function. Note that you are not CALLING the function (someFunction()), but just passing the function itself (someFunction). In this sense a callback is kind of like a block in ruby.
– The scope method in rails. Adding this to your ActiveRecord model:
scope :red, where(color: 'red')
Allows you to do this:
Shirt.red # returns all red shirts.
– First time experimenting with the Handlebars.js templating language.
-----POST DBC PRACTICE-----
3/10/14
– Wrote binary search in ruby (29 minutes)
– Wrote binary search in javascript (17 minutes)
– Javascript does not perform integer division by default. Use Math.floor(n)
– Learned quicksort:
– Choose a 'pivot' from the list
– Place remaining elements into into 'greater' and 'less' arrays relative to the pivot.
– Repeat these steps recursively on the sublists.
– The base case is a list with a length of 0 or 1.
– typical return statement: quicksort(less) + [pivot] + quicksort(greater)
– Write quicksort in ruby (6 minutes)
3/11/14
– Wrote binary search in ruby (14 minutes)
– Wrote quicksort in ruby (3 minutes)
– Quicksort code kata in ruby (3 versions in 15 minutes)
– Wrote quicksort in javascript (29 minutes)
– Learned about Array.filter() in javascript.
– Read a useful guide to regular expressions: http://qntm.org/files/re/re.html
3/12/14
– Be proactive, not reactive – seek out the job you want. A job is an investment:
– Look for a company with: a good team, a growing market, and market traction.
– Attitude (personality and work ethic) and skills (portfolio) are key.
– Can you answer the question: why are you a good hire?
3/13/14
– Negotiation: "I want market value but I can't pick a number without a sense of the full compensation package."
– GET IT IN WRITING: How will I be evaluated? How often will I be evaluated? What would you consider to be a mark of success in this position?
3/14/14
– Big-O notation in increasing order of complexity:
– O(1) constant
– O(logn) logarithmic
– O(n) linear
– O(nlogn) linearithmic
– O(n^2) quadratic
– O(2^n) exponential
– O(n!) factorial
– CLR, "Introduction of Algorithms": http://www.amazon.com/Introduction-Algorithms-Thomas-H-Cormen/dp/0262033844/ref=sr_1_1?ie=UTF8&qid=1394838278&sr=8-1&keywords=Introduction+to+Algorithms
3/17/14
– Learned merge sort:
– Divide the unsorted list in sublists with a length of 1
– Repeatedly merge the sublists until there is only 1 list remaining (base case).
– Wrote merge sort in ruby (25 mins)
– Things you must know:
– Javascript variable hoisting
– Ruby block scope; javascript functional scope
– Closures in javascript
3/18/14
– Learned about #all? enumerable: returns true if all elements meet the condition passed in the block.
– Learned about #any? enumerable: returns true if any element meets the condition passed in the block.
– How to properly use Ruby's 'rescue':
begin
# something that might raise an exception
rescue
# ...
end
Within a method definition the 'begin' is not necessary:
def foo
# ...
rescue
# ...
end
3/24/14
– Portfolio 1 challenge, 'RESTful CRUD' (57 minutes)
– Read notes from week 1
3/25/14
– Portfolio 2 challenge, 'Active Record' (22 minutes)
– Read notes from week 2
3/26/14
– Portfolio 3 challenge, 'User authentication' (44 minutes)
– Read notes from week 3
3/28/14
– Portfolio 5 challenge, "Validations" (37 minutes, with validation tests)
– Read notes from week 4
– Applied to Quizlet
3/29/14
– Implemented insertion sort in Ruby (25 minutes)
– Read pp. 1–29 of "Introduction to Algorithms"
– Read notes from week 5
– Applied to Apartment List, Scribd
4/1/14
– Applied to Tapjoy, Gumroad
4/2/14
– Portfolio 6 challenge, OO Javascript (40 minutes)
– Read pp. 29–43 of "Introduction to Algorithms"
– Applied to Academia.edu
4/3/14
– http://paultyma.blogspot.ie/2007/03/howto-pass-silicon-valley-software.html
– Be humble. You won't be the smartest person at the company; you don't want to be.
– Know your data structures!
– https://gist.github.com/ryansobol/5252653
- "Fifteen questions to ask during a ruby interview"
- Good review of ruby fundamentals.
– Modules serve a mechanism for namespacing behaviors
– Applied to Nitro, InstaEDU
– Read notes from week 6
4/4/14
– Refactored Shadi's implementation of singly and doubly linked lists.
– Read about O-notation, stacks, queues, and linked lists in "Introduction to Algorithms" (pp. 43–49, 229–241).
– Applied to Class Dojo, Mind Snacks, VolunteerMatch
4/6/14
– Portfolio 7 challege, AJAX & jQuery (20 minutes)
– Added implementation of stack to Shadi's repo.
4/7/14
– Got in touch with Mirror Placement
– Got in touch with Graham Rath at Jivaro Inc (recruiter)
– Read notes from week 7
– Applied to IFTTT; met with David at Tapjoy.
– Read about binary trees in "Introduction to Algorithms" (pp. 286–294).
4/8/14
– Introduced myself to Graham Rath
– Read more about binary trees in "Introduction to Algorithms" (pp. 294–299).
– Started implementing a binary tree in ruby
– Refresher on how to use before(:each) hooks in rspec.
– Contacted Shadi about Change.org
– Applied to Entelo
4/9/14
- Scheduled phone interview with Sean Lindsay! (chief engineer at Tapjoy)
– Contacted Stephanie about Omada
– Contacted Spencer about his connection at Dropbox
– Practiced the following interview questions on paper:
– Implement a queue with two stacks
– In-place array reversal
– Parenthese order validator
– #getLargest stack element
– Started reading "JS The Right Way":
– https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript
– https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Closures
– Practiced behavioral questions
4/10/14
– Had a phone interview with Sean Lindsay!
– Practiced interview questions
– Applied to Edupath
4/11/14
– Practiced the following interview questions on paper:
– How to reduce the memory used by a hash of strings
– How to calculate the max profit from an array of stock prices
– Redid the "Intro to Rails" challenge
– Read about the rails asset pipeline: http://guides.rubyonrails.org/asset_pipeline.html
– the pipeline concatenates assets, so all .js and CSS files are rolled into one.
– the pipeline minifies all assets
– the pipeline can compile higher-level languages like Coffeescript or Sass
– get '/posts/:id', to: 'post#show', as: 'post'
– as: gives a name to the route that can be used inside the controllers and views.
4/12/14
– Prepared tech talk for the Tapjoy interview
4/13/14
– Refresher on the form_for helper: http://guides.rubyonrails.org/v3.2.13/form_helpers.html
– Continued working through the "Intro to Rails" challenge
– Practiced tech talk for the Tapjoy interview
4/14/14
– Finished working through the "Intro to Rails" challenge
– Practice for the Tapjoy interview with Bella
– Applied to Gravity
– authentication vs. authorization:
– authentication: identifying a user as who they really claim to be.
– authorization: the rules that determine what a given user is allowed to do.
4/15/14
– Interviewed at Tapjoy!
4/16/14
– Got in touch with Teach for America (via AngelList).
4/17/14
– Applied at Gravity
4/21/14
– Emailed Stephanie about Omada again
– Started working on "Green Businesses" project
– Applied to ePantry, Chalk
4/22/14
– Continued working on "Green Businesses" project
– AJAXified search
– Started styling
– Applied to Shelf
– Contacted Stephanie for an introduction to Jared Smith (intern at ZenPayroll)
4/23/14
– Contacted Jared Smith (works at ZenPayroll)
– Continued working on "Green Businesses" project
– Finished styling
– Applied to New Avenue; contacted Justin Martinez (head engineer)
4/24/14
– Finished "Green Businesses" project
– Integrated google maps
– Improved search with pg_search
– Deployed to Heroku
– Had phone interview with Justin Martinez (New Avenue)
– Read up about New Avenue in preparation for tomorrow's interview!
4/25/14
– Interviewed at New Avenue!
– Final tweaks to "Green Businesses" Project
4/26/14
– Met Jared Smith for lunch, got a referral at ZenPayroll
– Applied to ZenPayroll
4/28/14
– Sent a message to Prayag Narula, CTO of MobileWorks
– Made a contribution to Spencer's "NFL map" project
4/30/14
– Emailed Stephanie about Omada again...
– Applied to Liftopia
– Asked Stephanie for an introduction to Andrew Armenante (UClass)
– Started Treehouse iOS development track:
– Started introduction to C
5/1/14
– Arranged meeting with Austin Putman (Omada Health)
– Continued iOS learning:
– C loops, conditionals, functions
-----FIRST JOB-----
WEEK OF 5/6/14
– Learned about singular resources in rails.
– Learned about foreign key constraints (prevents the assignment of a foreign key that points to a non-existent resource)
– Started using tmux
– Learned how to use guard to keep on eye on tests
– The act_as_list gem adds functionality to your Rails models that makes it easier to create sortable lists that persist on the backend.
WEEK OF 5/11/14
– To eager load an association by default, assign a default scope:
default_scope includes(:comments)
– .html_safe can be used to tell rails that any html embedded in an interpolated variable is safe to render: <%= @info.html_safe %>
– When using the button_tag or submit_tag helpers, including disable_with in your data attributes will automatically disable the button after the form it is tied to is submitted:
  – <%= submit_tag "Create", data: { disable_with: "Creating..."} %>
 
 
WEEK OF 5/18/14
– Strong parameters: this has changed between Rails 3 and 4. 'attr_accessible' is no longer used, parameters are now always 'strong parameters,' that is they must be whitelisted for assignment within the controller itself. This means you'll have to make a conscious choice about which attributes to allow for mass updating and thus prevent accidentally exposing that which shouldn't be exposed. In your controller:
    def project_builder_exercise_params
      params.require(:comment).permit(:title, :body)
    end
– To skip an iteration in an enumerable or loop, use 'next if...'
– Learned how we deploy to staging and production using Capistrano
– Ansible saves "deployment states" or "playbooks" to make deployment easier (configuration management)
– Vagrant allows you to easily manage virtual machines so you can mock out server deployments for testing (virtual machine management)
– Horizontal scaling: to add more nodes to a system, such as adding a new computer to a distributed software application. 
– Vertical scaling:  to add resources to a single node in a system, typically involving the addition of CPUs or memory to a single computer.
WEEK OF 5/25/14
– the 'split' gem makes it easy to perform A/B testing: https://github.com/andrew/split
– Mailgun makes it easy to automatically send emails. The mailgun gem allows you to easily integrate it with Rails' built-in mailer, ActionMailer. You can use the #headers method to add custom headers to emails sent with ActionMailer. Then we can use mailgun routing to handle user responses.
– To copy your public ssh key to a server:
  ssh-copy-id -i ~/.ssh/id_rsa.pub root@<server-ip-address>
– In your shell, ^R allows you to search through past commands.
WEEK OF 6/1/14
– In an Active Record model:
  alias_attribute :approved_at, :accepted_at
 
 
WEEK OF 6/8/14
– Docker, a platform for deploying and running applications. Docker provides a way to run an application securely isolated in a container in a way that is platform agnostic. https://docs.docker.com/
– Learned about the 'transition' CSS property for animated changes:
  h3:hover {
      background-color: #1a853b;
      transition: background-color 0.25s ease;
   }
– Learned how to secure requests made to an API you're building with a HMAC (key-hashed method authentication code): http://www.thebuzzmedia.com/designing-a-secure-rest-api-without-oauth-authentication/
WEEK OF 6/15/14
– Single table inheritance in rails (models inheriting other models): http://thibaultdenizet.com/tutorial/single-table-inheritance-with-rails-4-part-1/
  – Models that share a single table are distinguished by a "inheritance" column that specifies type:
In the superclass:
  self.inheritance_column = :type
– Different ways to mass/bulk insert data into your rails database: https://www.coffeepowered.net/2009/01/23/mass-inserting-data-in-rails-without-killing-your-performance/
inserts = ['(bob, bob@example.com)', '(mary, mary@example.com)', ...]
"INSERT INTO users ('name', 'email') VALUES #{inserts.join(', ')}""
WEEK OF 7/5/14
– You can use db:migrate:redo to rerun the last migration.
– The ActiveRecord methods #find_by and #where won't work if the model is 'dirty', i.e. if it hasn't been saved to the database yet, but merely instantiated. Use the enumerable method #find instead.
– http://nodeschool.io/ is a good resource for learning node.js
WEEK OF 7/12/14
– Started learning node.js, "a runtime environment and a library for running applications written in JavaScript outside the browser (for example, on the server)".
– Node use asynchronous (or "non-blocking") I/O, a form of input/output processing that allows other processing to continue before transmission is complete. This is in contrast to synchronous I/O, which requires all processing to pause until transmission is complete.
– Useful node guide: https://github.com/maxogden/art-of-node#callbacks
WEEK OF 7/27/14
- Learned a lot about Docker and how to use Docker images/containers to deploy services. Checkout your note 'docker.txt'
- Useful article on best practices for writing Dockerfiles: http://phusion.github.io/baseimage-docker/
– Learned how to create a node http server. See learning-node/learnyounode
– Padrino is a ruby web framework built on top of Sinatra: http://www.padrinorb.com/
WEEK OF 8/3/14
– Learned how to deploy rails/padrino apps using Capistrano: http://capistranorb.com/
– How to create and read cookies with jQuery-cookie:
$.cookie("test", 1);
$.cookie("test", 1, { expires : 10 });
var cookieValue = $.cookie("test"); => 1
$.removeCookie("test");
– Learned about the WebSocket protocol, a TCP protocol initiated by an HTTP request which allows a persistent connection between client and server, rather than a request-response cycle: http://blog.cloudflare.com/cloudflare-now-supports-websockets
– Note that HTTP 2.0 proposals call for a similar 'persistent connection' stream. It's unclear how WebSockets and HTTP 2.0 will be reconciled, as they seem to have similar aims.
WEEK OF 8/10/14
– Restart your brew-installed version of postgres:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
or more simply:
pg_ctl -D /usr/local/var/postgres
– If you want an active record model to be linked to a table with a name other than the model's, use self.tablename = some_other_name
– If you want a rails controller to choose a layout conditionally, you can pass a method to layout: 'layout :method_that_chooses_layout_string'
– Refresher on how to create Sidekiq workers:
class EmailWorker
include Sidekiq::Worker
sidekiq_options queue: "default"
def perform(recipient)
# send the email...
end
end
EmailWorker.perform_in(5.seconds, user)
– A counter cache is an integer column that is automatically incremented when, for example, a table gains an association. This is a way to improve performance if we must frequently query this number. For example, if we want to counter cache the number of orders associated with a customer:
class Order < ActiveRecord::Base
belongs_to :customer, counter_cache: true
end
class AddOrderCountToCustomers < ActiveRecord::Migration
def change
add_column :customers, :orders_count, :integer, default: 0
end
end
WEEK OF 8/24/14
– The Javascript 'Date' object is pretty useful: http://www.w3schools.com/jsref/jsref_obj_date.asp
– 'whenever' is a cool gem for writing ruby cron jobs: https://github.com/javan/whenever
– How to write tests for Rails mailers: http://blog.lucascaton.com.br/index.php/2010/10/25/how-to-test-mailers-in-rails-3-with-rspec/
– Scope to check to get a model that is a specific number of days old:
scope :n_days_old, ->(n = 1) do
where( "created_at <= ? AND created_at >= ?", Date.today - (n - 1), Date.today - n)
end
WEEK OF 8/31/14
– To get Redis and Sidekiq up and running:
redis-server &
bundle exec sidekiq &
WEEK OF 9/7/14
– CoreOS, a Linux distribution designed specifically for server deployments using docker: https://coreos.com/
– To deploy new_avenue/help: cap production deploy
WEEK OF 9/14/14
– Learned about 'state machines': http://en.wikipedia.org/wiki/Finite-state_machine
– a 'state' is the status of a system waiting to execute a 'transition'
– a 'transition' is an action to perform when a condition or event occurs.
– transitions often change the state of a system.
– A ruby gem that makes it easy to define states and transitions:https://github.com/pluginaweek/state_machine
– Learned the 'rails way' to separate model behavior into modules. Put modules in the 'app/model/concerns' folder and extend 'ActiveSupport::Concern' in each module: http://stackoverflow.com/questions/14541823/how-to-use-concerns-in-rails-4
– 'include' vs 'extend' in ruby: include adds instance methods, extend adds class methods.
– 'file' <filename> is a pretty cool bash/zsh command
WEEK of 9/21/14
– Learned about String#tr for easy character replacement - read the Ruby docs more often!: http://www.ruby-doc.org/core-2.1.3/String.html#method-i-tr
– To backup a database:
pg_dump -O some_database | gzip > ~/Desktop/database.gz
WEEK OF 9/28/14
– To dump and restore a postgres database:
pg_dump -O dbname > outfile or pg_dump -O dbname | gzip > filename.gz
dropdb dbname
createdb -T template0 dbname
psql dbname < infile
WEEK OF 10/5/14
– To grant a user permission to use a postgres database:
psql dbname
GRANT ALL ON DATABASE dbname to username
– You can force a link to open in a new page with the html attribute "target=_blank".
WEEK OF 10/12/14
– Learned about token-based authentication (authentication without a password).For an implementation in Node, check out passwordless: https://hacks.mozilla.org/2014/10/passwordless-authentication-secure-simple-and-fast-to-deploy/
– How to build a bar chart using D3, a step-by-step tutorial: http://bost.ocks.org/mike/bar/
– "General data update pattern" for D3: http://bl.ocks.org/mbostock/3808218
– Look over your D3 experiments in /qsymmachus/d3-experiments
– NVD3, reusable charts for D3. Saves a lot of time: http://nvd3.org/
– How to test Sidekiq using rspec:
Sidekiq::Testing.fake! # check queue
expect {
# do something that should create a worker
}.to change {
SomeWorker.jobs.size
}.by(1)
Sidekiq::Testing.inline! # execute workers immediately
# do something that should create a worker that sends an email
expect(ActionMailer::Base.deliveries.last.to.first).to eq user.email
– How to test around an error in rspec (i.e. you want to test something other than the mere fact that an error was raised):
expect {
# something that raises an error
}.to raise_error do |error|
expect(something_else).to eq "to have happened"
end
WEEK OF 10/19/14
– 'vh' and 'vw' allow you to size elements relative to the size of the client's viewport. For example, "height: 100vh" will set an element's height equal to the entire height of the viewport.
– Pure CSS parallax: http://keithclark.co.uk/articles/pure-css-parallax-websites/
– You should use this: https://cdnjs.com/
– A/B testing using 'split': https://github.com/andrew/split
WEEK OF 10/26/14
– Understanding callbacks: https://github.com/maxogden/art-of-node#callbacks
– Also see 'callbacks.txt'
– Started to learn how to develop an app using Node:
– Sequelize, a js ORM
– Mocha, for testing; Chai, an assertion library
– Supertest, an assertion library for HTTP requests
– Checkout the repo newavenue/vortex
– How to vertically align an element within its parent:
.element {
position: relative;
top: 50%;
transform: translateY(-50%);
}
WEEK OF 11/2/14
– Learned about 'full text search' in Postgres, a search across all columns in a table. This requires a 'document' (tsvector) of each record to be generated and stored as a column in the table, and an index is then generated for that column for rapid searching. http://www.postgresql.org/docs/8.3/static/textsearch-intro.html
– In a rails controller, you can quickly check if a request was sent using AJAX with 'request.xhr?'
– /[[:alnum:]]/ - regex for any single alphanumeric character, including accented characters.
WEEK OF 11/9/14
– Cross Origin Request Sharing (CORS) allows resources to to be requested from another domain other than the domain from which the resource originated. By default, web browsers forbid "cross domain" AJAX requests (the 'same-origin policy').
When a CORS-compatible browser makes a cross origin request, it first sends a "pre-flight" request with the following request headers:
Host: bar.com [domain request is sent to]
Origin: http://example.com [domain request was sent from]
The server response include headers that define what domains have cross domain access to a resource, and what type of requests they can make:
Access-Control-Allow-Origin: http://example.com [requests allowed from here]
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
If the `Access-Control-Allow-Origin` includes the request's domain, then subsequent request are permitted, within the guidelines defined by the other response headers.
– To get a list of TCP ports that are currently listening:
lsof -i -P | grep -i "listen"
=============================
lsof list open files
-i list TCP/IP connections (literally, "network files")
-P don't convert port numbers to port names
WEEK OF 11/16/14
– How to write a ruby gem: http://howistart.org/posts/ruby/1
– Nice article on REST best practices: https://bourgeois.me/rest
– Rspec mocks: https://github.com/rspec/rspec-mocks
– Some load testing tools: JMeter (http://jmeter.apache.org/) and Loader.io (http://loader.io/).
– Method stubbing in rspec:
allow(NeatModule).to receive(:neat_method).and_return {
"return this instead of what you usually do!"
}
– Static vs. Dynamic Typing:
Static typing: type checking is performed at compile-time; type is associated with variables not values.
– Pros: Allows type errors to be caught early; may result in more efficient runtime by omitting type checks at execution.
– Cons: Requires explicit type declaration of variables, duck typing is difficult to implement.
Dynamic typing: type checking is performed at run-time; type is associated with values not variables.
Pros: More flexible insofar as types and functionality can be determined at runtime, duck typing is easy to implement.
Cons: May result in runtime type errors.
– Imperative vs. Declarative programming paradigms, perhaps the most important contrasting paradigms:
Imperative: A programming paradigm that describes computations in terms of statements that change program state. In this respect it conceptually mirrors machine code, in which native machine language instructions alter the contents of memory.
– Object-oriented programming languages are imperative.
– e.g. C++, Ruby, Python.
Declarative: A programming paradigm describes WHAT computation should be performed and not HOW to compute it. It expresses the logic of a computation without describing its control flow. Functions have no side effects – they are idempotent and do not alter state.
– Logical and functional programming languages are declarative
– e.g. SQL, Haskell, Lisp.
WEEK OF 11/23/14
– Core Postgres Docs. Also see 'postgres.txt':
Part 1 Overview – http://www.postgresql.org/docs/9.3/static/tutorial.html
Part 2 SQL – http://www.postgresql.org/docs/9.3/static/sql.html
Part 3 Server – http://www.postgresql.org/docs/9.3/static/admin.html
– To pipe psql output to a file:
postgres=# \o ~/output.txt
postgres=# select * from foo;
– Object-oriented vs. Functional programming:
Object-oriented:
– Is imperative.
– Data and operations are tightly coupled.
– Objects hide their operations from other objects via interfaces.
– The central model of abstraction is the data itself.
– The central activity is composing new objects and extending existing objects by adding new methods to them.
Functional:
– Is declarative.
– Data is only loosely coupled to functions.
– Functions hide their implementation, and the language's abstractions speak to functions and they way they are combined or expressed.
– The central model of abstraction is the function, not the data structure.
– The central activity is writing new functions.
– Polymorphism: the provision of a single interface to objects of different types. Polymorphism has three main subtypes:
1. Ad hoc polymorphism: a function that has different implementations depending on a limited range of types. For example, in ruby '+' can be used to add both strings and fixnums.
2. Parametric polymorphism: a function that is written generically enough that it can handles parameters identically regardless of type. #push is an example of a parametric polymorphism.
3. Subtype/inclusion polymorphism: this is often simply described as "polymorphism" in object-oriented programming. Subtype polymorphism guarantees that subtypes have the same interface as their supertype.
WEEK OF 11/30/14
– Class vs. Type in OO programming:
Class: an object's class defines how it is implemented (its state and operations)
Type: an object's type refers only to its interface – the set of requests to which it responds.
– Referential integrity "requires every value of one attribute (column) of a relation (table) to exist as a value of another attribute in a different (or the same) relation (table)." Most commonly, this means a foreign key should points to a relation that actually exists.
– This is not always easy to enforce at the application level. See this very useful article: http://robots.thoughtbot.com/referential-integrity-with-foreign-keys
– In rails, `has_many :posts, dependent: :destroy` helps enforce referential integrity by destroying associated posts whenever the parent model is destroyed. But this `after_destroy` callback is only triggered if the parent model is actually instantiated, so it's not perfect.
– To work around this, you can use a migration to add a foreign key constraint at the database level: `add_foreign_key :posts, :users`. This will run the following SQL:
ALTER TABLE `posts`
ADD CONSTRAINT `posts_user_id_fk`
FOREIGN KEY (`user_id`) REFERENCES `users`(id);
– You can also mimic the behavior of an the `after_destroy` callback at the database level with cascading deletes (Rails 4.2 only): `add_foreign_key :posts, :users, on_delete: :cascade`. This will run the following SQL:
ALTER TABLE `posts`
ADD CONSTRAINT `posts_user_id_fk`
FOREIGN KEY (`user_id`) REFERENCES `users`(id)
ON DELETE CASCADE;
– Read more about foreign key constraints: http://www.postgresql.org/docs/9.3/static/ddl-constraints.html#DDL-CONSTRAINTS-FK
– The Unix philosophy in a nutshell: tools should be independently useful, but have clean integration points.
WEEK OF 12/7/14
– Understanding the node.js event loop: http://blog.mixu.net/2011/02/01/understanding-the-node-js-event-loop/
– Yet another 'app containerization' option, cf. Docker and Rocket: Travelling Ruby! Specifically designed for Ruby apps, works on both Linux and OS X:
http://phusion.github.io/traveling-ruby/
– Skeleton, a super lightweight CSS framework: http://getskeleton.com/
WEEK OF 12/14/14
– Rails polymorphic associations allow a model to belong to more than one other model, on a single association: http://guides.rubyonrails.org/association_basics.html#polymorphic-associations
– `zip` and `unzip` let you compress and uncompress files in the shell. You can also encrypt compressed files:
zip -e output_file.zip target_file
– Check out the node stream handbook: https://github.com/substack/stream-handbook
WEEK OF 1/4/15
– Ruby's built in binary search:
sorted_array.bsearch { |n| n > 1000 }
– 'Secure Secure Shell', a really interesting article on how to make ssh as secure as possible: https://stribika.github.io/2015/01/04/secure-secure-shell.html
– UML state diagrams, useful for modelling state machines: http://en.wikipedia.org/wiki/State_diagram_%28UML%29
– To validate unique combinations of columns (for example, if you want to ensure a user votes only once on a given question). In your 'vote' model:
validates :user_id, uniqueness: { scope: :question_id }
– A quicker way to write custom validations: `validate :some_custom_method`
class Invoice < ActiveRecord::Base
validate :paid_is_not_greater_than_owed
private
def paid_is_not_greater_than_owed
if paid > owed
errors.add(:paid, "cannot be greater than owed")
end
end
end
WEEK OF 1/11/15
– Icono, pure CSS icons: http://saeedalipoor.github.io/icono/
– '100 years of computer science' – the most important papers from each decade. This is amazing: http://www.thoughtworks.com/insights/blog/100-years-computer-science
– Neat CSS pseudo-selector: :nth-child
https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child
– Find yourself using the same setup over and over for some specs? Use shared context to DRY up your rspec: http://steven-ferguson.github.io/blog/2014/05/17/using-rspec-shared-context-for-dryer-specs/
WEEK OF 1/18/15
– Check out this Rails helper: time_ago_in_words(Time.now - 3.days) => "3 days"
– Learned how to use redis as a cache store. For example, if a method is expensive, you can cache the result and check the cache in future calls. A redis cache requires 3 things: a key, a value, and an expiration date.
class User < ActiveRecord::Base
def followers_count
# Check redis for a cache of the return value:
key = "User#{id}#followers_count"
value = $redis.get(key)
# If there is no cache, find the return value and cache it:
unless value
value = followers.count
$redis.set(key, value)
$redis.expire(key, 60*60*24) # expires in 1 day
end
value
end
end
WEEK OF 1/25/15
– Shorten github urls with this neat utility: curl -i http://git.io -F "url=https://github.com/..."
– Very interesting article on the history of databases: http://avant.org/media/history-of-databases
– Using ES6 today: http://robots.thoughtbot.com/replace-coffeescript-with-es6
– RFC index: http://www.rfc-editor.org/rfc-index2.html
For example, check out RFC 2616, the original spec for HTTP/1.1
WEEK OF 2/1/15
– DRY up your rspec with shared examples. Somewhere in `/spec/support`:
shared_examples "an object that can be added" do |num|
let(:object) { klass.new }
it "can be added" do
expect(object + num).to eq 2
end
end
Then in your spec:
it_behaves_like "an object that can be added", 5 do
let(:klass) { MyWidget }
end
– The 'satisfy' rspec matcher lets you test almost condition:
expect(sov.reload.status).to satisfy do |status|
status == "approved" || status == "queued_for_processing"
end
WEEK OF 2/8/15
– yEd Graph Editor, a useful apps for making diagrams and flowcharts: http://www.yworks.com/en/products/yfiles/yed/
– Cloud computing actually defined – "deploying groups of servers that allow centralized data storage and online access to services." Cloud computing service models, from lowest level to highest:
Infrastructure as a service (IaaS): the service is access to computers, whether they be servers, virtual machines, storage, etc.
– Provider: Responsible for the hardware.
– Client: Responsible for all software.
– e.g.: Amazon EC2
Platform as a service (PaaS): the service is access to a computing platform, including key software, such as the operating system and common dependencies.
– Provider: Responsible for hardware and much of the software layer.
– Client: Responsible for the application they deploy.
– e.g. Google App Engine, Microsoft Azure, Heroku.
Software as a service (SaaS): the service is access to a specific application and its data. Can be thought of as "on demand software".
– Provider: Responsible for the hardware and all software.
– Client: Not really responsible for anything – pure consumer.
– e.g. Wrike, Zoho, Google Docs.
WEEK OF 2/15/15
– If you're using `remote: true` to submit rails forms via an AJAX request, there are a variety of custom events you can use to trigger callbacks around the request: https://github.com/rails/jquery-ujs/wiki/ajax
For example, say you wanted to append some custom data to the request:
$('form').on('ajax:beforeSend', function(event, xhr, settings) {
settings.data += "&custom=" + encodeURIComponent("Here's some custom data!");
})
WEEK OF 2/22/15
– Higher order functions: Functions that operate on other functions, either by taking them as arguments or by returning them, are called higher-order functions.
– Getting started with Flux: http://ryanclark.me/getting-started-with-flux/
– Article on REST WORST practices: http://jacobian.org/writing/rest-worst-practices
– Article on REST BEST practices: http://phalt.co/rest-digested/
– Each resource should have one URI endpoint.
– The HTTP method sent to that endpoint should reflect the type of interaction with that resource.
– The status code returned by the response should accurately reflect the outcome of the interaction.
– When "scoping" requests, you should use URI parameters: /pokemon?type=fire
– It is stateless: each request happens in complete isolation of another. No state, such as cookies or sessions, should change how a request is processed.
– Contrasting SOAP (Simple Object Access Protocol) vs. REST:
– SOAP has one URI endpoint and one HTTP method. All method information and data is contained in the request body, usually XML.
– The advantage of REST is that URI endpoints are associated with specific resources, and the HTTP method describes how we interact with that resource. We can intuit what a request will do, without knowing anything about how it will be implemented. Moreover, the use of standard HTTP status codes also makes it easy to interpret the outcome of the interaction. Nothing is "bespoke".
WEEK OF 3/1/15
– Good article on HTTP caching: https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching?hl=en
– Depth vs. Breadth First Search (searching nodes in a tree or graph):
BREADTH FIRST: Begin at the root and inspect every neighbor node (nodes at the same level). Repeat the process for each level, working down until you reach the bottom.
– Advantages: Usually the shortest path to the node. Good for finding nodes you expect to find near the top of the tree.
– Disadvantages: Keeping track of neighbors can use a lot of memory if the tree is wide. Not good for finding nodes near the bottom of the tree.
– Algorithm (using a queue to track node neighbors):
1. Enqueue the node and inspect it.
2. Enqueue all the current node's children. Dequeue the current node.
3. Repeat until you find the required node.
DEPTH FIRST: Begin at the root and inspect one branch of the tree all the way to the bottom, then backtrack to the closest unexpected branch and repeat until you've inspected all branches.
– Advantages: Good for finding nodes you expect to find near the bottom of the tree.
– Disadvantages: Not good for finding nodes near top of the true. Usually won't find the shortest path to a node.
– Algorithm (using a stack to track the order we need to backtrack):
1. Start by putting the root node in a stack.
2. Until the stack is empty:
3. Pop the node, inspect it. Return if it's the required node.
4. Push each of the node's children in the stack.
– How does `this` work in javascript?:
Global context: it's the global object (usually `window`).
Function context: it depends on where the function is called.
– if it's called globally, it's the global object.
– if it's called within an object, `this` is that object.
Constructor context: `this` refers to the object that is constructed.
DOM event handler: when a function is used as an event handler, `this` is the element that fired the event.
– The 'flexbox' CSS property: "The main idea behind the flex layout is to give the container the ability to alter its items' width/height (and order) to best fill the available space" (http://flexboxin5.com/). Relevant properties:
– display: flex;
– flex-direction: row, column;
– flex-wrap: wrap [children pushed into next row as resized], nowrap [children always stay in row].
– justify-content: flex-start, flex-end, center, space-between, space-around [where to align children within a row, assuming flex-direction: row]
– align-items: flex-start, flex-end, center, baseline, stretch [where to align children within a column, assuming flex-direction: row]
– align-content: flex-start, flex-end, center, space-between, space-around, stretch [how to align the space between rows, if there is more than one row]
The real magic starts when we make the children of a flexbox flexible as well:
– flex-grow: [integer; size of child relative to other flexible children]
– flex-shrink: [integer, rate child shrinks relative to other flexible children]
– flex-basis: [min width, can be pixels, ems, etc.]
Plus you get dead simple vertical centering of an element within a flexbox, by giving the flexbox the following properties:
display: flex;
justify-content: center;
align-items: center;
WEEK OF 4/5/15
– CKVM, a CentOS virtual machine built with Vagrant, "provisioned dev environment". You do all your work here.
1. CentOS VM – runs the show
2. Salt – installs and manages all required packages
3. Supervisor – process monitoring
4. Gearman – background jobs
5. Memcached – key/value store, used primarily for session and method caching
– Workflow notes:
1. Git/repos – local machine
2. Supervisor/Salt – VM
3. Hostfiles – local machine directs CK traffic to VM
– Vagrant commands, within a directory with a vagrant file:
`$ vagrant up` Spin it up, this can take a LONG time
`$ vagrant status`
`$ vagrant ssh` Access the VM
– Supervisor commands (inside the VM):
`$ sudo supervisor status` Check active processes
`$ sudo supervisor restart all` Good quick fix
– Some funny SQL injection exploits:
– If your input is naively passed to a WHERE clauses, you can take on an additional select statement using UNION:
' UNION SELECT * FROM users--
WEEK OF 4/12/15
– Mockery, a mock library for PHPUnit. Mock objects like this:
$mockDatabase = Mockery::mock("Database");
$mockDatabase->shouldReceive("select")
->andReturn("here's some data");
$mockDatabase->shouldReceive("select")
->with("specify some arguments")
->andReturn("argument-specific data");
WEEK OF 4/19/15
– A very tiny intro to database systems:
http://blog.dancrisan.com/a-tiny-intro-to-database-systems
WEEK OF 4/26/15
– "What every computer science major should know":
http://matt.might.net/articles/what-cs-majors-should-know/
WEEK OF 5/3/15
– Let's learn some Clojure!
– In a nutshell, Clojure is
1. A Lisp
2. A functional language with immutable data structures
3. Runs on the JVM, dynamically compiled
4. Designed for concurrency
– Clojure is a functional programming language insofar as
– It provides tools to help avoid mutable state
– Its functions are first-class objects
– It emphasizes recursion over iteration
– Great resource, "Getting started with Clojure":
http://jrheard.tumblr.com/post/40024238467/getting-started-with-clojure
– S-expressions, or "symbolic expressions", are a notation for nested, tree-structured, list data. S-expressions are defined as either:
1. an atom (which may be a character, string, number, function), or
2. an expression of the form (x . y), where x and y are s-expressions.
Most modern s-expression notations use a simplified notation that renders this:
(x . (y . (z . NIL)))
Like this:
(x y z)
S-expressions are also easily represented as binary trees:
.
/ \
x .
/ \
y .
/ \
z nil
S expressions use prefix notation:
(* 2 (+ 3 4)) => 14
.
/ \
* .
/ \
2 .
/ \
. nil
/ \
+ .
/ \
3 .
/ \
4 nil
WEEK OF 5/10/15
– Cyclomatic complexity: a "quantitative measure of the number of linearly independent paths through a program" (control flow graph). Used to measure the complexity and maintainability of a program.
WEEK OF 5/17/15
– HMAC implementations in Go, Python, Ruby, PHP, and Node: http://blog.turret.io/hmac-in-go-python-ruby-php-and-nodejs/
WEEK OF 5/24/15
– `\p{L}` is a regex that will capture all unicode letter characters. `\p{N}` will capture all unicode numeric characters.
WEEK OF 5/31/15
– Parsing documents with Clojure: http://blog.juxt.pro/posts/xpath-in-transducers.html
– Faking a conditional assignment operator in PHP:
$name = $name ?: 'John Doe';
WEEK OF 6/7/15
– Reactive Programming: "a programming paradigm oriented around data flows and the propagation of change." Data flows should be easily expressed in the underlying language, and changes will automatically propagate through the dataflow at execution. For example, if we define 'a' as:
a = b + c
Any change to 'b' or 'c' will automatically change 'a', in contrast to purely imperative programming.
– Referential transparency: a function or expression is referentially transparent if it can be replaced with its value without changing program behavior. For example, a pure function with no side effects is referentially transparent.
WEEK OF 6/14/15
– The simplest definition of functional programming is programming with pure functions. A pure function
1. Has no side effects to program state,
2. Is referentially transparent; that is, it can be substituted for the value it returns, or vice versa, without affecting program behavior.
More formally,
f(a) = b
Given 'a', f() will always return 'b', regardless of program state. Every value of 'a' has exactly one value of 'b' that is returned by the function.
Using pure functions has two chief advantages:
1. It allows for a natural mode of reasoning about a program called the "substitution model" – we can imagine program processes like an equation, expanding or abbreviating expressions and functions that are referentially transparent. This is often easier than reasoning about procedural changes to program state.
2. Pure functions are more modular and composable, since they are defined purely by their inputs and outputs, and have no unexpected side effects.
WEEK OF 6/21/15
– "Currying": converting a function of two arguments into a function of one argument through partial application of the function. 'curry' is in effect a closure that contains one of the two arguments already. Take this polymorphic scala function as an example, which takes a function with two args as its arguments, and returns a function with one arg:
curry[A, B, C] (f: (A, B) => C): A => (B => C) =
a => b => f(a, b)
– Functional data structures: operated on only with pure functions. They are therefore immutable!
WEEK OF 6/28/15
– Non-strictness/laziness: non-strict functions may choose not to evaluate all of its arguments. This separates the _description_ of an expression from its _evaluation_.
WEEK OF 7/5/15
– When you make a POST request, the data that forms the body of the request is usually encoded in one of three ways:
application/x-www-form-urlencoded (the default)
multipart/form-data (used when including files with <input type='file'>)
text/plain (rarely used)
WEEK OF 7/12/15
– How do you nest a git repo within a git repo? For example, what if you are nesting plugins within a project that are themselves git repos? Use git submodules! https://git-scm.com/book/en/v2/Git-Tools-Submodules
- git submodule add <git-address> // add a repo as a submodule
- git submodule init // init the submodules of a project you just cloned
- git submodule update // update all submodules in your project
– Nice basic React tutorial: http://reactfordesigners.com/labs/reactjs-introduction-for-people-who-know-just-enough-jquery-to-get-by/
– One of the concrete advantages of HTTP/2 is decreased latency: HTTP headers will be compressed, and resources can be loaded in parallel over a single TCP connection.
WEEK OF 7/19/15
– Hexagonal architecture: an application that is "equally driven by users, programs, automated test or batch scripts...[and allowed] to be developed and tested in isolation from its eventual run-time devices and databases."
– The image of a "hexagon" is meant to illustrate the fact that the application has many sides or "ports" in
and out of the application (HTTP requests, database connections, key-value stores, etc.)
– The crux of hexagonal architecture is that each port can easily be mocked without affecting any other.
– Each port is a kind of interface, insofar as it encapsulates change!
– This is why hexagonal architecture is also often called "ports and adapters" architecture.\
– Code layers: each layer has code and "boundaries", which are interfaces!
– Dependencies should work "from the outside in"; that is, inner layers do not depend on outer layers.
--> Framework (request handling) --> Application (orchestration) --> Domain (business logic)
– An advantage of functional programming (i.e. programming with pure functions) is that they increase the number of invariants in a system, or things that do not change. This makes code easier to maintain.
WEEK OF 7/26/15
– Git tagging: used to tag specific points in history as important. Typically used to mark release versions (e.g. v1.2).
git tag
git tag -a v1.2 -m "this is version 1.4"
git show v1.2
git push origin v1.5
git push origin --tags
– Sequel, a nice alternative to ActiveRecord: http://twin.github.io/ode-to-sequel/
WEEK OF 8/2/15
– If you know there will a merge conflict, you can force git to favor the versions found on one or the other branch:
$ git merge branch ours favor the versions found on the branch you merging INTO
$ git merge branch theirs favor the versions found on the branch you are merging
WEEK OF 8/9/15
– Phing, a PHP task manager like Rake or Grunt: https://www.phing.info/
WEEK OF 8/16/15
– Continuous integration: "the practice of merging all developer working copies into a shared mainline several times a day". Intended to be done in conjuction with TDD and automated unit tests to ensure that each merge produces a working build.
WEEK OF 8/23/15
– A succinct definition of domain drive design: "being disciplined about separating business-specific domain logic from boilerplate logic".
WEEK OF 9/13/15
– JSON Web Token (JWT) session management: in traditional session management, a server will generate a session identifier and return it to the client as a cookie. Subsequent requests sent by the client include the session identifier. With JWT, a client's session data ('payload') is represented as a JSON string, including security factors such as the issuer of the token, intended audience, and token lifetime. The string is then base64 encoded, hashed with a private key known only to the server, and then sent to the client's browser in a cookie.
WEEK OF 9/20/15
– `tail` displays the last part of a file by putting it to standard output. With the `-f` option, it does not stop when the end of file of reached, but waits for additional data to be appended to the file. This is really useful if you want to keep an eye on a log file (e.g. tail -f some_log).
– `git mergetool` makes it dead simple to resolve merge conflicts.
WEEK OF 9/27/15
– Domain Events (in the context of Domain Driven Design) decouple actions from their triggers, similar to the pub-sub pattern.
– As their name suggests, domain events model part of the domain only.
– e.g. an Event 'UserDeactivated' holds the details of an event that just took place, like an instance of `$user`.
– A Listener 'SendDeactivationEmail' accepts the UserDeactivated event and uses the `$user` object to send the email.
– See: http://culttt.com/2014/09/22/implementing-domain-events/
WEEK OF 10/4/15
– Awesome little article on "How the Internet Works": https://thesquareplanet.com/blog/how-the-internet-works/
WEEK OF 10/11/15
– Richardson Maturity Model: levels of maturity for a RESTful service: http://martinfowler.com/articles/richardsonMaturityModel.html
– Level 0: HTTP is merely the transport layer, often to a single, black-box endpoint.
– Level 1: Resources are introduced, each represented by different endpoints.
– Level 2: HTTP verbs now have meaning, and reflect what is actually done to a resource.
– Level 3: HATEOAS (Hypertext As The Engine of Application State). Reponses include URIs ('hypermedia controls') that tell us what we can do next.
WEEK OF 10/18/15
– User stories should adhere to the INVEST acronym:
– Independent (Not tightly coupled to other stories)
– Negotiable (The start of a conversation, not a contract)
– Valuable
– Estimate-able
– Testable
WEEK OF 10/25/15
– Mystery solved! Here's how cookies get passed around in the HTTP protocol. With headers!
– Response – Set-Cookie: name=value
– Request – Cookie: name=value
WEEK OF 11/1/15
– git bisect uses binary search to find the commit that introduced a bug.
$ git bisect start
$ git bisect bad # current version is bad
$ git bisect good s4g93d # this commit is known to be good
For each subsequent commit, mark it either as `git bisect good` or `git bisect bad`. When done, `git bisect reset`.
WEEK OF 11/8/15
– Statement vs. Expression:
– A statement is executed with no return value, but purely for its side-effects.
– An expression is evaluates to a value (it has a return).
– Functional programming languages are expression-based, that is, core language constructs are themselves functions with returns. e.g. Scala if-else blocks.
– Uniform access principle: it should make no difference wehther a property is implemented through storage or computation (referential transparency). The fact that Ruby makes no distinction between object attributes and methods is a good illustration of this; as well as Scala fields.
– 'Persistent' data structures share data structurally – when you append a value to an immutable collection, all but the new element are simply pointers to the existing values in the original index. Of course, this only works if the underlying structure is immutable!
– Using 'get' with Scala maps returns an option:
val map = Map("cat" -> "meow", "dog" -> "woof", "cow" -> "moo")
map.get("cat") // Option[String] = Some(meow)
map.get("frog") // Option[String] = None
map.getOrElse("frog", "default growl") // String = default growl
WEEK OF 11/15/15
– Scala pattern matching types (`case <pattern> => <result>`):
1. `_` – wildcard pattern; matches everything.
2. `x` – variable pattern; matches everything and captures the value.
3. `x: Int` – typed pattern, matches and captures `x` if it is the correct type.
4. `2` – constant pattern; a stable identifier that captures the value if it is equal to 2 in this example.
5. ``foo`` – stable identifier; like variable pattern but surrounded by backticks, for using other values in scope.
6. `(x, y)` – tuple pattern; matches and decomposes tuples.
7. `Age(2)` – constructor pattern; matches and decomposes case classes with certain arguments.
8. `Seq(1, 2)` – sequence pattern; use sequences constructors or prepend/append operators to match sequences.
`x +: Nil`
`_ :+ x`
`x +: y +: _`
– Scala pattern binder: captures the pattern to the right of the `@`: `myAge @ Age(28)`
– Scala pattern guard: `Age(n) if n >= 21`
– The difference between compilers and interpreters: https://theantlrguy.atlassian.net/wiki/display/ANTLR3/The+difference+between+compilers+and+interpreters
WEEK OF 11/22/15
– docker-machine [manages linux VMS that run docker hosts] --> docker host [manages docker containers] --≥ docker container [runs your app]
– Docker swarm: provides a unified interface for a pool of docker hosts.
When you run containers on the swarm master, it runs them on the nodes, but NOT the swarm master itself.
swarm master [docker host that manages nodes] --> swarm mode [docker host running containers, managed by the swarm master]
$ docker run swarm create // returns a token used to identify the swarm
$ docker-machine create -d virtualbox --swarm --swarm-master --swarm-discovery token://<TOKEN> swarm-master
$ docker-machine create -d virtualbox --swarm --swarm-discovery token://<TOKEN> swarm-node-01
$ docker-machine create -d virtualbox --swarm --swarm-discovery token://<TOKEN> swarm-node-02 // etc...
$ docker-machine env --swarm swarm-master // make the swarm master your active docker machine
$ docker info // lists details on the swarm and its nodes
– Exposing a port of a docker container:
$ docker run -p 8080:8080 mycontainer
$ curl http://$(docker-machine ip mymachine):8080
– Using `sed` to perform substitutions:
$ sed 's/regexp/replacement/g' inputFileName > outputFileName
– React JSX is really just syntactic sugar for function calls:
<div className="section">Hello there</div> == React.DOM.div({ className: "section" }, "Hello there")
WEEK OF 11/29/15
– To loop over files in the shell:
for f in *; do mv "$f" "$f.jpg"; done
WEEK OF 12/13/15
– Bash academy, a useful series of bash exercises: http://www.bash.academy/
– WebAssembly, a new binary format for compilation to the web! WebAssembly is a AST (Abstract Syntax Tree) in binary format that future browers will understand. It's a new language that you can compile into that browsers will understand – Javascript is no longer the only option!
– https://hacks.mozilla.org/2015/12/compiling-to-webassembly-its-happening/
– https://medium.com/javascript-scene/what-is-webassembly-the-dawn-of-a-new-era-61256ec5a8f6#.56v0uvpa2
– Common Lisp koans: https://github.com/google/lisp-koans
WEEK OF 12/20/15
– "Let's encrypt" guide: https://timkadlec.com/2015/12/taking-lets-encrypt-for-a-spin/
WEEK 0F 1/3/16
– Angular 2 vs. React (javascript churn continues): https://medium.com/@housecor/angular-2-versus-react-there-will-be-blood-66595faafd51
– On that note, a learning React roadmap: https://github.com/petehunt/react-roadmap
WEEK of 1/10/16
– Laravel/Lumen Container: manages class dependencies and aids with dependency injection, by "binding" dependency interfaces to dependency implementations. These bindings are registered in Service Providers. An instance of Container is available in all Service Providers as `app`:
$this->app->bind(Mailer::class, function ($app) { return new MailgunMailer($app[Credentials::class]) })
Any time an object has `Mailer` injected as a dependency, the Container will inject this particular instance. As illustrated above, you can resolve bindings from the Container with the following syntax:
$this->app[SomeClass::class]
$this->app->make(SomeClass::class) // alternate syntax
Most of the time however, dependencies are resolved automatically when you typehint in a controller, event listener, or some other piece of middleware.
class MyController
{
public function __construct(Mailer $mailer)
{
$this->mailer = $mailer // automatically resolved to whatever the Container binding is
}
}
WEEK OF 1/17/16
– Nice defense of javascript "web apps", and a client-server architecture vs. a monolith: http://molily.de/javascript-web-apps/
– ES6 cheatsheet: https://github.com/DrkSephy/es6-cheatsheet
– Bitwise operations in PHP: http://php.net/manual/en/language.operators.bitwise.php
// Typically $bitfield and $somebit are integers
// "and" operator; i.e. is $somebit set in $bitfield?
$bitfield & $somebit;
// "inclusive or"; i.e. set $somebit in $bitfield
$bitfield = $bitfield | $somebit;
// "exclusive or"; i.e. unset $somebit in $bitfield
$bitfield = $bitfield ^ $somebit;
WEEK OF 2/21/16
– To generated case ids for integration tests:
`ruby scripts/testrail_util.rb -a -f path/to/file --suite regression --section Reach`
– LDAP (Lightweight Direct Access Protocol) is a protocol for accessing and maintaining directory information over IP.
– Commonly used to store usernames, passwords, and other auth* data.
– LDAP clients may add, delete, modify, compare, bind (authenticate), or search entries.
– LDAP entries consist of a set of attributes (name => value pairs) that are defined in a schema.
– Each entry has a 'distinguished name' (dn) that serves as unique identifier.
– Each entry is formally a set, so entry attribute order does not matter.
– The entry schema define rules of what kind of attributes an entry should have.
- 'objectClass' attribute points to a class defined in the schema, like 'person' or 'printer'.
– Object classes define what attributes an entry should have.
– Example entry:
dn: cn=John Olmsted,dc=example,dc=com
cn: John Olmsted
givenName: John
sn: Olmsted
mail: john@example.com
objectClass: person
– LDAP schema design: https://www.skills-1st.co.uk/papers/ldap-schema-design-feb-2005/ldap-schema-design-feb-2005.html
– LDAP directories are structured as trees of entries (Directory Information Tree, DIT).
– Each entry (node) has a 'relative distinguished name' (RDN), which is unique among peer nodes.
- Each entry has a 'distinguished name', which is unique within the whole tree (see earlier note above).
uid=john@example.com,dc=people,dc=example,dc=org
<entry RDN> <parent nodes>
- Note that this tree structure makes LDAP very similar to the DNS model.
– Authorization: users -> roles -> permissions. These can be represented w/multi-value entry attributes.
– One approach is to have an entry for each permission, and use a 'member' attribute to list users with that permission.
– To check if a user has a certain permission,
1. Find the user's DN,
2. Find the permission entry,
3. Check the permission's 'member' attribute to see if it has the user's DN.
WEEK OF 2/28/16
– Push notifications on iOS and Android
– Uses the pub/sub pattern between clients (devices) and providers (app servers).
– TCP socket is kept open between the client and provider, listens for notifications.
– Apple and Google serve as a middleman between the client and provider.
– Providers identify which client they are targeting with a unique token
– For iOS, tokens are _device_ specific. For Android, they are _user_ specific.
Provider APN Client
| | |
| |<--set up notifications--|
| | |
| |-----generated token---->|
| | |
|<----------token-------------------------------------|
| | |
|----token, notification--->| |
| | |
| | * check token |
| | |
| |------notification------>|
– How git works under the hood: http://wildlyinaccurate.com/a-hackers-guide-to-git/
– At its core, a repository is a key-value store.
– Each key is a SHA1 hash, and each value is an object of one of the following types:
1. Blobs: a bunch of bytes, usually a file.
2. Tree objects: like directories; nodes are either blobs or other tree objects.
3. Commit objects: point to a tree object with some extra metadata.
4. Tag objects: point to a commit object with some extra metadata.
5. References: pointers to any other object (usually commit or tag objects).
– `.git/objects` contains all the objects, and `.git/refs` contains all the references.
– Git represents your project directory as a tree object, with files as blobs and directories as trees.
– A commit is just a pointer to a tree object that represents the state of your project at commit time.
– Commit metadata also includes: a hash of its parent commit, author info, and the commit message.
– References are just pointers to other objects.
– A branch is a reference pointing to a commit.
– HEAD is a reference that points to the tip of the current branch, but it may point directly to a commit
(so-called "detached" HEAD).
– Tags are pointers to commits.
– A lightweight tag just points to a commit and no more.
– An annotated tag includes some metadata, with a tag message, author, and timestamp.
– When you merge, you move the branch pointer of the current branch ahead ('upstream') to tip of the branch
you're merging.
– When you rebase, you copy your working commits over ('upstream') to the tip of the branch you've rebased on.
– Note that these copied commits are true copies, and have new hashes.
WEEK OF 3/6/16
– Refresher on how to use `find`: `find /some/root/path -name '*.jpg'`
WEEK of 3/13/16
– Performance gains of PHP7: https://techblog.badoo.com/blog/2016/03/14/how-badoo-saved-one-million-dollars-switching-to-php7/
WEEK OF 3/27/16
– Build web application with Go: https://astaxie.gitbooks.io/build-web-application-with-golang/content/en/preface.html
WEEK OF 4/3/16
– What is Akka?
– a toolkit and runtime for developing concurrent, distributed, message-based applications.
– _not_ a framework, more properly a library.
– Akka provides:
1. Actors
– Asynchronous, non-blocking, message-driven model
– Actors form hierarchies, with parent actors (supervisors) delegating some tasks to child actors.
– "The quintessential feature of actor systems is that tasks are split up and delegated until they
become small enough to be handled in one piece."
2. Fault Tolerance
– 'let-it-crash' philosophy
– Systems are self-healing
WEEK OF 5/8/16
– Covariance vs. contravariance. "Variance" describes how subtyping works between complex types (like collections of a type, or typed functions).
1. Covariance: A child is a subtype of its parent, and can substitute its parent (in Scala, [+T]).
2. Contravariance: The parent is the subtype of its child, substitution is reversed (in Scala, [-T]).
WEEK OF 5/15/16
– Strangler Application vs. Re-write Application: rather than rewrite a key legacy application, get a foothold with a "strangler" application that starts on the edges of the old, slowly replacing it.
– For example, a strangler application might start by just intercepting RCP calls, then delegating it to the legacy domain
– Once you have a foothold with your strangler application, you can gradually begin replacing the old piece by piece.
– A strangler application reduces risk by slowly delivering value without breaking existing functionality.
- See http://www.martinfowler.com/bliki/StranglerApplication.html
WEEK OF 5/22/16
– Useful Jenkins shortcuts:
– /log/all
– /restart
– /job/<JOB NAME>/ws (job workspace)
WEEK OF 6/12/16
– Serverless architecture can mean one of two things (see http://martinfowler.com/articles/serverless.html):
1. Applications that offload server-side logic and state to third party services. These are typically client-heavy applications that treat back-end services "as a service" (BaaS).
2. Applications where some server-side logic is still written by the app developer, but that logic exist in stateless, ephemeral, event-driven containers that run that code on demand. AWS Lambda is currently the most popular version of this model of "functions as a service" (FaaS).
– FaaS is about running back-end code without managing server systems OR server applications.
– The lack of _server applications_ is what differentiates FaaS from PaaS (platform as a service, e.g. AWS).
– FaaS brings up and tears down an application on a per-request basis.
– Horizontal scaling is automatic and handled by the FaaS provider.
– FaaS calls are stateless, so your functions must either be pure to begin with or depend on a persistence layer.
WEEK OF 6/26/16
– Functional Relational Mapping (FRM), like ORM except with a functional rather than object-oriented paradigm. A good example is Slick (http://slick.lightbend.com/).
– Database connection pooling: opening a DB connection is an expensive process. A connection 'pool' keeps a set of connections ready for clients to use, even if there are no clients using the connection at a given moment. When a client accesses the DB, it is assigned a connection in the pool, when they're done, the connection is not closed but simply freed up for another client. Connection pools are usually fixed in size.
WEEK OF 7/10/16
– "Any organization that designs a system (defined broadly) will produce a design whose structure is a copy of the organization's communication structure." – Melvyn Conway
– Other effects of microservice architecture, aside from the technical benefit of modular, independently deployable services:
– Encourages cross-functional teams rather than (siloed) functional teams.
– Clearly defines the boundaries of a teams responsibilities, and encourages the team to take responsibility for the service _as a product_, not just a "project". This forces them to work more closely with actual users.
– "Smart endpoints, dumb pipes". Microservices aim to be as decoupled as possible. We avoid adding extra layers of logic at the messaging layer (the "pipes") and focus on isolating our business logic within the services themselvves (the "endpoints").
– Decentralized technology decisions. Since services work independently, they can use different stacks to solve different problems.
– Decentralized databases. If needed, services can have their own domain-specific database.
– Forces teams to design services for failure, in case a service they are dependent on is down. This adds complexity to the codebase, so it may also be considered a drawback of microservice architecture.
– See: http://martinfowler.com/articles/microservices.html
– How do we decide what constitutes a "microservice"? A good rule of thumb is a service that can be independently replaced or upgraded, without affecting dependent services.
– Important to note that Martin Fowler argues that you should always build "monolith first", then begin breaking it up into microservices once it becomes a problem. The risk with starting with microservices first is that you don't have a clear sense of the boundaries between services, and run the risk of building the wrong service ecosystem: http://martinfowler.com/bliki/MonolithFirst.html
– Yelp's real-time data pipeline, using Kafka as a message bus: http://engineeringblog.yelp.com/2016/07/billions-of-messages-a-day-yelps-real-time-data-pipeline.html?hn=hn
WEEK OF 7/17/16
– Covariance vs. contravariance in an image: https://i.imgur.com/IO3brhq.png
– Interesting article on the current state of Ruby web dev tools: http://rwdtow.stdout.in/
WEEK OF 7/31/16
– The Scala `Try` type as an alternative to throwing exceptions: http://danielwestheide.com/blog/2012/12/26/the-neophytes-guide-to-scala-part-6-error-handling-with-try.html
WEEK OF 8/7/16
– `sc_usage <pid>` will give you detailed stats about a running process.
WEEK OF 8/22/16
– The fundamental data structure in Lisp is the linked list, which are formed of "cons cells".
– 'car', a pointer which points to the cell's value,
– 'cdr', a point which points to the next cons cell in the list.
(24 67 93)
------------ ------------ ------------
| 24 | | ===> | 24 | | ===> | 24 | | ===> NIL
------------ ------------ ------------
car cdr car cdr car cdr
WEEK OF 9/4/16
– Apache vs Nginx: https://www.digitalocean.com/community/tutorials/apache-vs-nginx-practical-considerations
WEEK OF 9/11/16
– Welcome to javascript hell: https://segment.com/blog/the-deep-roots-of-js-fatigue/
– Learn C and build your own Lisp in the process: http://www.buildyourownlisp.com/contents
– You should definitely do this!
– `head -10` takes a bash stream and reduces it to just the first 10 lines. Change that argument as needed.
WEEK OF 10/9/16
– OAuth 2 refresher:
– OAuth delegates user authentication to a service (OAuth API) that hosts the user account.
– The hosting service also authorizes third parties (clients) to access the user account.
CLIENT USER AUTH SERVER USER SERVER
------ ---- ---------- -----------
| | | |
|---auth req---->| | |
| | | |
|<--auth grant---| | |
| | | |
|-------------------auth grant----->| |
| | | |
|<--access token--------------------| |
| | | |
|----------------------------------------access token------>|
| | | |
|<--user----------------------------------------------------|
1. The client application requests access from the end user ("resource").
2. If the end user grants the request, client receives an authorization grant.
3. The client requests an access token from the authorization server. The request is
verified by the inclusion of both the end user's authorization grant and the client's
own credentials (client secret).
4. The authorization server grants the client an access token. Authorization is complete.
5. The client requests the user resource from the user server (aka a "resource" server) uses
the recently acquired access token.
6. If the access token is valid, the user server sends back its resources.
– In steps 1 & 2 above, the type of "authorization grant" between end users and clients may vary.
The two most common approachs are:
a. Authorization code
– Most common. Used for server-side applications because the confidentiality of the client secret can
be guaranteed. Retrieving and storing the access token is all server-side.
– The end user is prompted to accept or deny authorization.
– If permission is granted, an authorization code is generated.
– The auth code can be used as an "authorization grant" to the authorization server (steps 3 & 4).
– Passing the authorization code and client secret to the auth server to retrieve the access token
all takes place server-side.
b. Implicit grant
– Used for mobile apps and client-side applications where the confidentiality of the client secret can't
be guaranteed. The access token is passed through user-agent, rather than hidden server-side.
– The end user is prompted to accept or deny authorization.
– The user-agent interacts with the auth server directly, retrieves the access token, and passes it off
to the client.
– Since the user-agent is handling the access token directly, it has very limited scope. It usually has
a very short time to live (TTL) and never includes a refresh token.
– Application/client registration: clients must register their application with the auth server.
– Once registered, clients receive a client id and client secret used to authorize requests to the auth server.
– Refresh tokens: auth servers may also send a refresh token as well as an access token to clients. When the
original access token expires, refresh tokens may be used to retrieve a fresh access token, without prompting
the end user for another authorization grant.
– Scope: when requesting an auth token, clients may specify a "scope" as part of the request. You can think of
scope as a level of permissions that will accompany the auth token.
– Update Finagle guide: http://vkostyukov.net/posts/finagle-101/
– You might not need Javascript! http://youmightnotneedjs.com
WEEK OF 10/16/16
– Managing modules in Vim v8 (no more pathogen): https://shapeshed.com/vim-packages/
WEEK OF 10/30/16
– How to lazy-load a web font so it doesn't block page rendering: http://meowni.ca/posts/web-fonts/
– Learning vim progressively: http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/
WEEK OF 12/3/16
– The Y-Combinator (cf. Friedman & Felleisen, "The Little Schemer", 4th ed., Ch.9, pp. 160–174):
– The Y-Combinator allows an anonymous function to call itself, that is, it allows anonymous function recursion.
– Since anonymous functions don't have names, they can't refer to themselves.
– The Y-Combinator is just a clever construct that works around this problem.
– Keep this simple goal in mind when you read confusing explanations of the Y-Combinator!
– Some (relatively) accessible derivations of Y:
http://www.catonmat.net/blog/derivation-of-ycombinator/
http://www.catonmat.net/blog/wp-content/uploads/2010/02/thewhyofywhyofy.pdf
– You have a pdf copy of GABRIEL, "The Why of Y".
WEEK OF 12/11/16
– Good summary of "what" functional programming is: http://degoes.net/articles/easy-monads
In the functional paradigm, functions are:
1. Total – A function yields a value for every possible input.
2. Deterministic (referentially transparent) – A function yields the same value for the same input.
3. Pure – A function must have no effect other than the computation of its return value.
WEEK OF 12/25/16
– Excellent programming languages reference guide: http://hyperpolyglot.org
WEEK OF 2/5/17
– Apache Samza, a stream processing framework that provides an alternative model to the database. Samza thinks of the database as a growing collection of immutable facts. You can query it at some point in time, but better yet, you can take the stream of facts as they come in and process them in real-time: https://www.confluent.io/blog/turning-the-database-inside-out-with-apache-samza/
– What do you mean you mean by "event driven" architecture?: https://martinfowler.com/articles/201701-event-driven.html
WEEK OF 2/12/17
– Wanna trace a packet? Use:
`$ traceroute <some host>`
– Wanna know how a DNS request works? Try:
`$ dig <some host>`
– You can see the results of a TCP connection with:
`$ sudo tcpdump host <some host>`
In another terminal:
`$ curl <some host>`
– Wanna send an HTTP request by hand? Write a request in plaintext:
```
GET / HTTP/1.1
Host: olmsted.io
User-Agent: me
```
Then you can use `nc` (netcat) to set up a TCP connection and send whatever you pipe to it:
`$ cat request.txt | nc olmsted.io 80`
WEEK OF 2/19/17
– `shasum` is an easy way to generate SHA hashes in the shell.
WEEK OF 5/14/17
– WebAssembly update (see your first entry on it in the week of 12/13/15).
– Its origins lie in the Javascript "performance wars", ca. 2008.
– One of the outcomes of this were Just In Time compilers (JITs) for Javascript.
– JITs keep track of blocks of code that executed most frequently, and run them through an
optimizing compiler. This makes execution much faster than simple interpreters.
– Going forward, we're reaching the limit of JIT optimization.
– WebAssembly starts off much closer to machine code (it's bytecode).
– Most optimization has already been down ahead of time, before the brower even executes it.
– WebAssembly is a _compiler target_. No human writes it (unless you're a masochist).
– This means developers can write in the language they want, and compile it to WebAssembly.
– Note however that WebAssembly doesn't currently have garbage collection.
– Tools for compiling to WebAssembly (.wasm) are still maturing.
– Read more: https://www.smashingmagazine.com/2017/05/abridged-cartoon-introduction-webassembly
WEEK OF 6/25/17
– Refresher on the CAP theorem:
– When working on a distributed system – a system that is (P)artitioned – you must choose
between (C)onsistency and (A)vailability, but you can't have both.
– (AP) High Availability
– Prioritizes availability over consistency.
– Every read receives a non-error response (99% of the time), but it does not guarantee
that that read is the most up-to-date.
– (CP) High Consistency
– Prioritizes consistency over availablity.
– Reads may returns errors, but successful reads are guaranteed to by the most up-to-date.
– What about "CA"? The only way to guarantee both availability and consistency is to not have
a Partition-tolerant (i.e. distributed) system.
– Note that the CAP theorem is a _theorem_ that describes a very specific kind of distributed system:
a single, read-write register. Most distributed systems are more complicated than this, for example
they probably have transactions that touch multiple objects. The CAP theorem often doesn't map
to the real-world that well.
WEEK OF 7/2/17
– Memory Heap
– Not to be confused with the heap data structure.
– A memory heap is where _dynamically_ allocated memory resides (i.e. memory allocated by `malloc`).
– Memory will remain allocated in the heap either until
1. The memory is `free`d
2. The program terminates.
– If all references to allocated memory are lost (e.g. you don't have a pointer to it anymore), you
have a memory leak!
– Contrast the memory heap with a memory _stack_ which is used by the callstack. Memory allocated in
the memory stack is specific to the callstack frame.
WEEK OF 7/9/17
– Javascript Service Workers
– A service worker is a simple script that your browser runs in the background.
– It runs on a separate thread from the main JS thread.
– It's asynchronous and does not have access to the DOM.
– Current supported by Chrome, Firefox, Opera.
WEEK OF 7/23/17
– Kubernetes, a tool for container orchestration.
– Docker containers provide an immutable artifact that works consistently across environments.
– What about the environments themselves? How can make them more consistent?
– Kubernetes provides a layer of abstraction over the underlying infrastructure in a given environment,
be it dev, test, or prod.
– It provides an API for orchestrating the deployment, scaling, and management of containerized applications,
independent of the infrastructure it's actually running on!
– Useful tutorial: https://kubernetes.io/docs/tutorials/kubernetes-basics/
WEEK OF 7/30/17
– What the hell is a monad you ask? You already know this, you just don't know the terminology.
– Scala `List`s, `Option`s, and `Either`s are all examples of monads. What they share in common is:
– They encapsulate some value of type A in some 'context' (like a List or an Option),
– They provide a means of 'mapping' over these contexts and transforming the encapsulated
value, for example by transforming them in some B. In the Scala context you are familiar with,
this is accomplished using `map` and `flatMap`.
– More formally and abstractly, a monad is a structure that defines
1. A data type, and how values of that datatype are combined
2. Functions that use the data type, and compose them together into actions.
– Monads all you to string together computations will abstracting away some part of the "context"
you're in. For example, Scala `Option`s all you to string together computations where a value
may or may not exist. `Future`s allow you to string together computations without worrying
about the fact that it's asynchronous.
WEEK OF 8/6/17
– Vim macros allow you to record repetitive tasks and replay them:
`qx` start recording to register "x"
(at this point you do whatever it is you want to record)
`q` stop recording
`@x` play back the macro
`5@x` play back the macro five times!
WEEK OF 9/17/17
– `seq` is a pretty cool CLI tool for generating sequences of numbers:
seq 100 # generates 1-100
seq 3 1 # generates 3 2 1
seq 25 50 # generates 25-25
WEEK OF 10/8/17
– Event-driven architecture – you can think of EDA as an extension of one of the important ideas of Object
Oriented Programming: components should be highly cohesive within themselves, but loosely coupled between
eachother, communicating via well-defined messages. In systems architecture, we extend this idea to the
service level. Services are highly cohesive, but loosely coupled, communicated via well-defined events.
EDA Use Cases:
1. Decouple components
* When component A needs to trigger some behavior in component B, instead of calling it directly,
it dispatches an event to an event dispatcher.
* This decouples the two components – A does not need to have any knowledge of B to do its job.
* New behaviors can be easily added or removed by adding or removing downstream components.
2. To perform async tasks
* Tasks that can be performed asynchronously lend themselves well to EDA.
* Rather than use a blocking request-response cycle, async tasks can be dispatched by events.
3. Keeping track of state change
* Traditionally when we change data in some persistence layer, we just update it in place.
* Sometimes however we want to be able to keep a record of these changes (an audit log).
* Event-driven state changes allow you to build a timeline of state changes.
* State change can be rolled back or replayed using this event log.
EDA Patterns:
This is discussed in greater detail in Martin Fowler's article:
https://martinfowler.com/articles/201701-event-driven.html
1. Event Notification
* This is the most typical case and was discussed in the 'decouple components' section above.
* Events are dispatched by some component A to trigger behavior in components B, C, and D.
* Pros:
* Greater resilience. Dispatched messages can be queued and retrieved in the event of an error.
* Reduced latency since theres no need for blocking requests.
* Teams can develop their components independently.
* Disadvantages
* Can be difficult to trace an event through the entire system. Behavior is 'emergent'.
2. Event-Carried State Transfer
* State changes can be dispatched to the entire ecosystem, and components that care about that state
can store it locally.
* State changes are captured proactively, rather than retrieved in a request-response cycle.
* Pros:
* Same as the general EDA advantages: greater resilience, reduced latency.
* State is distributed rather than stored in a single source, reducing load on that source.
* Cons:
* Several copies of the same data are maintained by multiple components.
* There is a risk of data-drift – components may have slightly different stored states.
3. Event Sourcing
* Sometimes we don't want to just tracking the _current_ state of some resource, but also maintain
a history (a 'transaction' or 'audit' log) of its state changes. This can be accomplished if we
use event-driven state changes and maintain a log of these events.
* In this pattern, the event store becomes the sole source of truth about the state of that resource.
* State changes can be replayed or rolled back as needed.
* Pros:
* It allows you to reconstruct and rollback states, and even experiment with alternate timelines.
* State is a pure function of the event store.
* Cons:
* When replaying the event store, what if slightly different logic needs to be applied at different times?
WEEK OF 11/5/17
– Good article on common patterns in React applications: http://lucasmreis.github.io/blog/simple-react-patterns/
1. Mixed Pattern – view logic and logic for managing state are mixed in the same component.
* State is managed internally using `this.state`
* Generally seen as an anti-pattern in all but the simplest applications.
* Pros: everything you need is contained in one component.
* Cons: View and state logic are tightly coupled.
2. Container/View Pattern – 'view' logic is in one component, and state logic is in a container component.
* State is managed by the container passing it down to the view component using props.
* This is probably the most common pattern.
* Pros: View and state logic are now loosely coupled.
* Cons: To fully understand what's going on, you need to look at two components.
3. Higher Order Components – functions that take a view component as a parameter, and pass state to it.
* A more abstract version of the Container/View pattern.
* Instead of a 'container' component managing state, you have a _function_ that takes a component as an argument,
and passes state to that component in the form of props.
* Pros: View and state logic are loosely coupled, and HOCs are generally more reusable.
* Cons: HOC is highly reusable, so you might be duplicating effort (for example, by making the same API call multiple times).
WEEK OF 11/12/17
– Great overview of Javascript and its runtime: http://dmitrysoshnikov.com/ecmascript/javascript-the-core-2nd-edition/
WEEK OF 12/10/17
– This is a _super_ useful general CS resource: https://github.com/jwasham/coding-interview-university
– This is also a great CS resource: https://teachyourselfcs.com/
WEEK OF 1/7/18
– By default, `|` pipes the stdout of the previous command to the stdin of the next command. But what if you need to use that stdout for something else, like as the argument of the next command? `xargs` is what you need!
Say you want to run `docker exec` on a particular container. You can get the container's ID with this command:
```
docker ps -aqf "name=my-container"
```
But how do we pass that container ID to the `docker exec` command? Like this:
```
docker ps -aqf "name=my-container" | xargs -o -I ID docker exec -it ID /bin/bash
```
`xargs -I FOO` takes the stdout of the previous command, and maps it to `FOO`.
Then you can put `FOO` wherever it needs to go in the next command.
WEEK OF 1/28/18
– Great article on the transition from IC role to leadership role: https://lcamtuf.blogspot.com/2018/02/on-leadership.html