Skip to content

Instantly share code, notes, and snippets.

View jamesyang124's full-sized avatar

James Yang jamesyang124

  • HTC
  • Richmond, California
View GitHub Profile
@jamesyang124
jamesyang124 / ruby_style_guide_notes.md
Last active August 29, 2015 14:04
Ruby style guide notes

Ruby Style Guide Notes

https://github.com/JuanitoFatas/ruby-style-guide

  • Always run the Ruby interpreter with the -w option so it will warn you if you forget either of the rules below!
  • Use ||= freely to initialize variables.
# set name to Bozhidar, only if it's nil or false

Friendly URLs

By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:

/people/6

But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.

@jamesyang124
jamesyang124 / confident_ruby_review.md
Last active August 29, 2015 14:05
Review of the book - Confident Ruby

Review of Confident Ruby

Read API doc

  1. any? [{ |obj| block }] → true or false means could either accept 0 or 1 { |obj| block } block.

  2. send(symbol [, args...]) → obj means could either accept 0 or many argumetns. if symobol method accept block, then may also appen that block to it, e.g. define_method.

Xor and Sum

You are given two positive integers a and b in binary representation. You should find the following sum modulo 10 ^ 9 + 7:

Summation(a xor (b shl i)) from i = 0 to 314159

where operation xor means exclusive OR operation, operation shl means binary shift to the left.

  • Item 6
  • Ruby find a method by searching its suplerclass until to the top, then back to original class then searching the hierachy for method_missing again.
// example object

var obj = {'property': 1234}

Object & Prototype

  1. Everything is object, except null and undefined.
@jamesyang124
jamesyang124 / ios_development.md
Last active August 29, 2015 14:25
Side notes from CS193P course in Stanford University.

Lecture 1

  1. Constraint and auto layout.
  • Auto Layout Concepts
  • The attributes leading and trailing are the same as left and right for left-to-right languages such as English, but in a right-to-left environment such as Hebrew or Arabic, leading and trailing are the same as right and left.
  • Constraints are cumulative, and do not override each other. Setting a second width constraint for a view does not remove or alter the first width constraint.
  1. @IBOutlet weak var prpoerty.
@jamesyang124
jamesyang124 / weird_part_of_js.md
Created September 17, 2015 23:07
notes from udemy online course.

#Weird Part Of JS

  1. this is global object if there does not have receiver. If so, it also imply it is a window object, document === window.document.

  2. JS engine create this execution context(window object) in bottom of execution stack and run other execution context which is in top of it for you.

  3. When you declare a var or define as a function(function expression or function statement), you can find it through window.func() or func() in global environment.

  4. Hoisting: var and func are all firstly initialize but not assigned its value yet until the later code assign it. Check code example below.

Process:

1. git clone git@github.com:rails/rails.git

2. git branch -b <new_branch>

3. git checkout <new_branch>

4. code work, add CHANGELOG.md

#Rails Routing

  1. We can define customed url helper by :as

    get "/photos/:id", to: "photos#show", as: :"show_photo"
    
    <%= link_to 'Photo Record', show_photo_path(15) %>
    
    show_photo_path(15)