http://www.ithome.com.tw/news/88025
Create Your Own Private Docker Registry
$ docker run -p 5000:5000 -d registry
move docker image to disk directly
docker mysql
# Code is not reloaded between requests.
# config.cache_classes = true
config.cache_classes = false
# Disable Rails's static asset server (Apache or nginx will already do this).
#config.serve_static_assets = false
config.serve_static_assets = true
# Do not fallback to assets pipeline if a precompiled asset is missed.
# config.assets.compile = false
config.assets.compile = true
# Generate digests for assets URLs.
#config.assets.digest = true
config.assets.digest = false
- Straight merge 預設的合併模式,會有全部的被合併的 branch commits 記錄加上一個 merge-commit,看線圖會有兩條 Parents 線,並保留所有 commit log。
- Squashed commit 壓縮成只有一個 merge-commit,不會有被合併的 log。SVN 的 merge 即是如此。
- cherry-pick 只合併指定的 commit
- rebase 變更 branch 的分支點:找到要合併的兩個 branch 的共同的祖先,然後先只用要被 merge 的 branch 來 commit 一遍,然後再用目前 branch 再 commit 上去。這方式僅適合還沒分享給別人的 local branch,因為等於砍掉重練 commit log。
指令操作
- git merge <branch_name> # 合併另一個 branch,若沒有 conflict 衝突會直接 commit。若需要解決衝突則會再多一個 commit。
- git merge –squash <branch_name> # 將另一個 branch 的 commit 合併為一筆,特別適合需要做實驗的 fixes bug 或 new feature,最後只留結果。合併完不會幫你先 commit。
- git cherry-pick 321d76f # 只合併特定其中一個 commit。如果要合併多個,可以加上 -n 指令就不會先幫你 commit,這樣可以多 pick幾個要合併的 commit,最後再 git commit 即可。
def self.create_with_omniauth(auth)
create! do |user|
user.provider = auth["provider"]
user.uid = auth["uid"]
user.name = auth["user_info"]["name"]
end
end
data.select { |h| h[:sex] == sex}.all? { |a| a[:age] > age_is_greater_than }
all?() public
Passes each element of the collection to the given block. The method returns true if the block never returns false or nil. If the block is not given, Ruby adds an implicit block of {|obj| obj} (that is all? will return true only if none of the collection members are false or nil.)
ary = [0, 4, 7, 10, 12]
# try to find v such that 4 <= v < 8
ary.bsearch {|x| 1 - x / 4 } #=> 4 or 7
# try to find v such that 8 <= v < 10
ary.bsearch {|x| 4 - x / 2 } #=> nil
/Gemfile
gem "devise"
gem "omniauth-facebook"
/config/initializiers/devise.rb
config.omniauth :facebook, Settings.story.fb_app_id, Settings.story.fb_secret, {:provider_ignores_state => true}
/app/models/user.rb
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable, :omniauthable,
:recoverable, :rememberable, :trackable, :validatable
end
/routes.rb
devise_for :users, controllers: {omniauth_callbacks: "omniauth_callbacks"}
/app/controllers/omniauth_callbacks_controller.rb
1 class OmniauthCallbacksController < Devise::OmniauthCallbacksController
2
3 def all
4 user = User.from_omniauth(request.env["omniauth.auth"])
5 if user.persisted?
6 sign_in_and_redirect user, notice: "Signed in!"
7 else
8 session["devise.user_attributes"] = user.attributes
9 redirect_to new_user_registration_url
10 end
11 end
12
13 alias_method :facebook, :all
14 end
/app/models/user.rb
19 def self.from_omniauth(auth)
20 where(auth.slice(:provider, :uid)).first_or_create do |user|
21 user.provider = auth.provider
22 user.uid = auth.uid
23 user.email = auth.info.email
24 user.name = auth.info.name
25 user.remote_image_url = auth.info.image.gsub('http://','https://')
26 end
27 end
/app/models/user.rb
29 def self.new_with_session(params, session)
30 if session["devise.user_attributes"]
31 new(session["devise.user_attributes"], without_protection: true) do |user|
32 user.attributes = params
33 user.valid?
34 end
35 else
36 super
37 end
38 end
/app/models/user.rb
40 def update_with_password(params, *options)
41 if encrypted_password.blank?
42 update_attributes(params, *options)
43 else
44 super
45 end
46 end
47
48 def password_required?
49 super && provider.blank?
50 end
51
52 def email_required?
53 super && provider.blank?
54 end
$ rails generate uploader Avatar
$ rails g migration add_avatar_to_users avatar:string
class User < ActiveRecord::Base
mount_uploader :avatar, AvatarUploader
end
class MyUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
process :resize_to_fit => [800, 800]
version :thumb do
process :resize_to_fill => [200,200]
end
end
def likedPeople
@post = Post.find(params[:post_id]
respond_to do |format|
format.js
end
end
2 var template = $('#template').html();
3 Mustache.parse(template); // optional, speeds up future uses
4
5 var arr = <%= safe(@post.liked_people.to_json) %> ;
6
7 var rendered = Mustache.render(template, {rows: arr})
8
9 $('#target').html(rendered);
7 var rendered = Mustache.render(template, {rows: arr})
3 <script id="template" type="x-tmpl-mustache">
4 <ul class="list-like-group">
5 {{#rows}}
6 <li class="list-like-group-item" >
7 <img class="like-author-photo" src="{{image.url}}" />
8 <a href="/users/{{id}}/posts">
9 {{name}}
10 </a>
11 </li>
12 {{/rows}}
13 </ul>
14 </script>