Skip to content

Instantly share code, notes, and snippets.

View jamesyang124's full-sized avatar

James Yang jamesyang124

  • HTC
  • Richmond, California
View GitHub Profile

A foreign key is a column (or columns) that references a column (most often the primary key) of another table.

Add index to foreign key is a good practice if that foreign key is read a lot.

# 1 to 1 association
# create :another_model_id foreign_key in that model
belongs_to :another_model

# 1 to m association
@jamesyang124
jamesyang124 / angular1_note.md
Created November 10, 2015 06:33
udemy course

#AngualrJS Note

  1. Angular leverage dependency injection to import modules. The key concept is using Function.toString() to track params. Inject by its params to achieve loosley coupling architecture also help with the js minify issue.

    app.controller("MyController", function($scope, $service){
    	// code in here
    }); 
    
    // better use for minify
@jamesyang124
jamesyang124 / vagrant_osx_zsh_tricks.md
Last active December 18, 2015 16:10
Setup vagrant on OSX.
install virtualbox 4.3.12
install vagrant 1.6.3

vagrant add box_name /hashicorp/precise64
vagrant init box_name
vagrant up

//in Vagrantfile
config.vm.synced_folder "hots/directory", "geust_directory/app", type: "nfs"

Ruby Week 2 Quiz

  1. Name what each of the below is:
a = 1    # => ex. a is a local variable, and is a Fixnum object with value 1
    @a = 2            # => @a is instance vairiable, Fixnum object.
    user = User.new   # => local instance, is an User object.
    user.name         # => instance getter method
    user.name = "Joe" # => instance setter method, set something to String object
  1. How does a class mixin a module?
  • By inculde a module, and module provides the instance method for that instance object.
  1. What's the difference between class variables and instance variables?

Rails Week 1 Quiz

  1. Why do they call it a relational database?
  • The database composite by tables and each table relate to other tables via the foreign keys. The tables composite by attribute column and data row to express a collection of data. By the way, primary key is for table itself quering.
  1. What is SQL?
  • Structural query language. A standard syntax to qurey and operate the database.
  1. There are two predominant views into a relational database. What are they, and how are they different?
  • Schema is one of the view to describe the data sctructre, data types, another view is the rows in each table to describe a value collection[row] of attributes[column], which is data view.
  • Data view describes data with its value and attribute name, Schema view desrcibes attributes' types and structure.

Rails Week 2 Quiz

  1. Name all the 7 (or 8) routes exposed by the resources keyword in the routes.rb file. Also name the 4 named routes, and how the request is routed to the controller/action.
  helpers         Http Verb   URI pattern       Controller#action
  posts_path      GET         /posts            post#index
  new_post_path   GET         /posts/new        post#new
  post_path       GET         /posts/:id        post#show
  edit_post_path  GET         /posts/:id/edit   post#edit
                  POST        /posts            post#create
PUT /posts/:id post#update

Rails Week 3 Quiz

  1. What's the difference between rendering and redirecting? What's the impact with regards to instance variables, view templates?
  • Render only refresh by templates, redirect_to will go the action controller methods. So the instance variables and params will reset by redirect_to, and render will not reset instance variable and params.
  1. If I need to display a message on the view template, and I'm redirecting, what's the easiest way to accomplish this?
  redirect_to @post, notice: 'message' 
@jamesyang124
jamesyang124 / git_resources.md
Last active January 6, 2016 03:08
Review git commands again.
@jamesyang124
jamesyang124 / css_learning_note.md
Last active January 11, 2016 11:00
85+% correct CSS notes.

#Learning CSS Note

###1. Class Selector

If two class selector rules ovelap same properties, the later rule in css file will take it. So it is called css.

If rule selector select element, then more restrictive element will apply that rule. ex: div prior then body.

The precedence is more specific selector will take the higer priority.

doctype html
| <!--[if lt IE 8 ]><html class="no-js preload lt-ie10 lt-ie9 lt-ie8 ie-suck"><![endif]-->
| <!--[if IE 8 ]><html class="no-js preload lt-ie10 lt-ie9 ie-8"><![endif]-->
| <!--[if IE 9 ]><html class="no-js preload lt-ie10 ie-9"><![endif]-->
| <!--[if gt IE 9]><!-->
html.no-js
| <!--<![endif]-->
head
meta(charset='utf-8')
meta(http-equiv='X-UA-Compatible' content='IE=edge,chrome=1')