1. 关于Prefix Tree和平衡二叉树


  1. HTTP: Hyper Text Transfer Protocol
Hypertext: 可以代表link,超链接。
transfer: 把hypertext 来回传递。
Protocol: 有一定的传递规则。
transfer: request and responseHTTP REQUEST1. action: get/post/delete/patch
2. path: /cats; /posts; /users/:id
3. http version: HTTP/1.1
4. headers of the metadata(higher level data):
language; server; choose from difference load ba …

by Liz Houle

QUESTION: When do we use before_action?


1. what are AR associations?

In Rails, an association is a connection between two Active Record models. Associations make common operations simpler and easier in your code.class Movie < ApplicationRecord
has_many :actors
end
has_many is a typical AR association. The common associations are has_one, has_many, belongs_to, has_one_through, has_many_through...

2. Understanding associations in a SQL perspective

what does the association do in a SQL level?class User < ApplicationRecord
has_many :tokens
end
say if a User has_many tokes, tokens table will have a column to store user_id, and if we want to find out which are the tokens owned by a user whose id is "123", we can write a query like…

Learning Objectives

  • Explain the basics of an HTTP request-response cycle
  • Explain how the request-response cycle works with respect to Rails & MVC
  • Explain what a RESTful API is
  • Build Rails Routes, Controllers & Actions corresponding to the 7 RESTful routes

What is a server?

  • The term ‘server’ is used to refer to both software and hardware.
  • Speaking in terms of software, the server is what runs all the code of your application. Most often, servers follow a request-response pattern where it is constantly ‘listening’ for requests, and then uses the application code to create or serve a response to the client(machine…

Learning Objectives

  • Define metaprogramming
  • Identify self in:
  • class definitions
  • class methods
  • instance methods
  • Describe the difference between class variables and class instance variables
  • Know how to use send and define_method (and method_missing if time allows) ********这个是重点。

Agenda

  • What is metaprogramming? 用program来创建program

What is Metaprogramming?

  • What is programming?
  • The essence of programming is defining behavior
  • Metaprogramming is defining behavior that will define future behavior
  • A program is a set of instructions with some goal, ie a plan
  • ex: an exercise program, television programming, the 12 step program
  • Meta just means self-referential

Metaprogramming

  • Often used to dynamically define a suite of similar methods based…

Learning Objectives

  • Understand how powerful active record is
  • AR是什么?一个rails的built-in ORM to manipulate the database, 本质是一个Class, 作用就是以OOP的形式来query database。
  • Understanding its limitations
  • How to avoid N+1 queries,直接通过includes调取连接数据,避免多次query 数据库。
  • Recognizing we don’t need to memorize everything

ActiveRecord Querying vs SQL

  • Ruby interface for querying database
  • Mirrors SQl queries
  • Pros: less overall database access code, more convenient

Rails: A server-side MVC web-application framework

  • ****full stack framework*****

ActiveRecord - an ORM Framework (The M in MVC)


create table plays (
id integer primary key,
title text not null,
year integer not null,
playwright_id integer not null,
foreign key (playwright_id) references playwrights(id)
);
create table playwrights (
id integer primary key,
name text not null,
birth_year integer
);
insert into playwrights (name, birth_year …

Learning Goals

  • Understand why we need databases
  • 存取数据,数据保存ACID, atomic/consistent/independent/durable
  • Explain “Relational DataBase Management System”
  • 类似mysql,Postgresql这种数据库管理软件
  • Be able to access data in a database and perform basic operations on the data
  • select from where a=b
  • select from (select from)
  • select name, count* from table group by 1
  • select name, count* from table group by 1 order by count* desc having count* > 5

How do websites store information?

关系型数据库的话就是表,每个有primary key作为id,互相有联系,可以通过id来回join,得到关联。然后连接到一块得到数据,通过用户id,连接transaction表,找到用户的所有transactions​,找到transaction中的所有refund,看是否有没ship回来的。

Answer: Databases!

  • There are different models of databases
  • They differ in how they store data and how that data can therefore be accessed
  • We’re going to use a relational database model. …

Yizhe Wang

Designer transforming into a developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store