Thursday, January 22, 2015

how to contribute to a repository

1.  fork the repository you are interested in
2. use "git clone "repository url" to clone a rep locally
3. git branch -r ---> to check all branches
4. bundle install
5. bundle exec rake ---> to check if tests pass

if you just change a little in gemfile or something not important  but shows in git status
use git checkout .  to clear it

git diff ---> to see different

Good illustration

Sunday, January 18, 2015

Ruby on rails tutorial

How to use different versions of rails? source
always create a clean new gemset for new project. so
1. create a gemset, rvm gemset create <new_gemset_name>
2.choose the new gemset rvm gemset use <new_gemset_name>
3. install the rails u want gem install rails -v <version_number>
4. use it

rvm list ---》list all ruby versions
check server pid:ps aux | grep rails,  kill -9 pid


$git checkout master
$git checkout -b new_branch
$ git status
$ git add -A
$ git commit -m "Add a Static Pages controller"
$ git push -u origin static-pages

pull a request
mkdir repo
cd repo
git init
git remote add origin git://github.com/cmcculloh/repo.git
git fetch --all
git pull origin master
或者直接clone
git clone http//;;;
generating a static page controller





(The distinction between the two types of embedded Ruby is that <% ... %> executes the code inside, while <%= ... %> executes it and inserts the result into the template.)
<% provide(:title, "Home") %>
<!DOCTYPE html>
<html>
  <head>
    <title><%= yield(:title) %> | Ruby on Rails Tutorial Sample App</title>
  </head>
  <body>
    <h1>Sample App</h1>
    <p>
      This is the home page for the
      <a href="http://www.railstutorial.org/">Ruby on Rails Tutorial</a>
      sample application.
    </p>
  </body>
</html>

scaffold generators : rapidly generates an application, creates a large functionality automatically
$ rails generate scaffold User name:string email:string
creates the User model

$ bundle exec rake db:migrate 
This simply updates the database with our new users data model

git remote -v : check all git remote branches


















cameratag 第三方API, 添加环境变量


the default library for interacting with the database is called Active Record

1-20-2015
如何做一个类似craiglist email的功能

1-21-2015
[Q] where does params come from in ruby on rails? Answer

gem "devise" ---> 自动产生 current_user

stripe checkout

1-22-2015
如何替换html中 new line 为<br />  选中regular expression, option + return 为new line. reference


接着返回书中:
$ rails generate scaffold User name:string email:string
to proceed, we first need to migrate the database using rake
$ bundle exec rake db:migrate
Note that there is no need to include a parameter for id; it is created automatically by Rails for use as the primary key in the database.)
Variables that start with the @ sign, called instance variables, are automatically available in the views;
$ rails generate scaffold User name:string email:string
$ bundle exec rake db:migrate

validates the information in microposts:
Listing 2.10: Constraining microposts to be at most 140 characters.app/models/micropost.rb
class Micropost < ActiveRecord::Base
  validates :content, length: { maximum: 140 }
end
One of the most powerful features of rails is to form the association between different data models
Listing 2.11: A user has many microposts.app/models/user.rb
class User < ActiveRecord::Base
  has_many :microposts
end
Listing 2.12: A micropost belongs to a user.app/models/micropost.rb
class Micropost < ActiveRecord::Base
  belongs_to :user
  validates :content, length: { maximum: 140 }
end
$ git push heroku
$ heroku run rake db:migrate
Listing 2.18: Code to validate the presence of micropost content.app/models/micropost.rb
class Micropost < ActiveRecord::Base
  belongs_to :user
  validates :content, length: { maximum: 140 },
                      presence: true
end
Listing 2.19: Adding presence validations to the User model.app/models/user.rb
class User < ActiveRecord::Base
  has_many :microposts
  validates FILL_IN, presence: true
  validates FILL_IN, presence: true
end

bundle exec rake test
<% provide(:title, "About") %>
<%= yield(:title) %>

Monday, November 10, 2014

学习之路

算法篇:
head first java
data structure & algorithm in java
design pattern(只看了前两章)
课程: cs61b, coursera stanford.

****************************************
操作系统:
课程: berkerley operating system
****************************************
数据库:
课程:coursera stanford

****************************************
web:
w3school all contents
Ruby on rails tutorial
head first php

javascript:
首先看 javascript and DOM,对于js能干什么,怎么用,以及一切周边知识介绍的很好
想要了解jquery 看 javascript compressed, amazon上面4刀电子书
javascript tutorial  

javasciprt the good part 这两本其实不适于新手看, 主要是用来后期提高
javascript nijia road

****************************************
Mobile:
IOS apprentice.


~~~~~~~~~~~~~~~~~~~~~~~
11-11-14 看完jQuery compressed. 初步了解jQuery 对于javascript 程序的编写的帮助。