Skip to content

Instantly share code, notes, and snippets.

Chen Chia Yang Unayung

Block or report user

Report or block Unayung

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View flash_at_same_request.rb
class ClientsController < ApplicationController
def create
@client =[:client])
# ...
else[:error] = "Could not save client"
render action: "new"
View gist:3772142
# coding: utf-8
class User
module OmniauthCallbacks
["github","google","twitter","douban"].each do |provider|
define_method "find_or_create_for_#{provider}" do |response|
uid = response["uid"]
data = response["info"]
if user = User.where("authorizations.provider" => provider , "authorizations.uid" => uid).first
Unayung / gist:3772406
Created Sep 23, 2012
View gist:3772406
# -*- encoding : utf-8 -*-
class User
module OmniauthCallbacks
["facebook"].each do |provider|
define_method "find_or_create_for_#{provider}" do |response|
uid = response["uid"]
data = response["info"]
if user = User.where( :fb_id => uid).first
Unayung / gist:3772442
Created Sep 23, 2012
View gist:3772442
# -*- encoding : utf-8 -*-
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def self.provides_callback_for(*providers)
providers.each do |provider|
class_eval %Q{
def #{provider}
if !current_user.blank?
current_user.bind_service(env["omniauth.auth"])#Add an auth to existing
redirect_to setting_path, :notice => "Bind #{provider} account successfully."
Unayung / gist:0c13f9c9a5f63e7f5703
Created Nov 24, 2015
Nokogiri installing
View gist:0c13f9c9a5f63e7f5703
gem install nokogiri -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib/
View gist:4547283
def render_submenu_root(roots)
s = ""
roots.each do |root|
s += content_tag("li", link_to(, , :class => "dropdown-toggle", :data => { :toggle => "dropdown"} )+render_submenu_children(root), :class => "dropdown")
Unayung / parser.rb
Created Feb 26, 2013
kanmeiju parser
View parser.rb
require "nokogiri"
require "open-uri"
url = ARGV[0]
list = Nokogiri::HTML(open(url))
list = list.css('div.vpl').first"result.txt", "w") do |file|
list.css("a").each do |a|
link = a.attr('href')
file.puts link
View posts_controller_spec.rb
require 'spec_helper'
describe PostsController do
describe "GET show" do
post = Post.create(:title => "blog title", :body => "blog body")
it "should have assign a post and render show" do
get :show, :id => post
assign(:post).should == post
View gist:6118957
  1. rails generate devise:install
  2. rails generate devise user
  3. rake db:migrate
  4. powder restart
  5. Gemfile 裡的 jquery-rails 行,改為 gem 'jquery-rails', '~> 2.3.0'

這樣就可以開啟專案了. 但 facebook 登入會有問題. 建議是先用 rvm install 1.9.3, rvm use 1.9.3 使用 ruby 1.9.3 版 然後 gem install bootstrappers 用一般版本的 bootstrappers 產生專案, 專案網站可以開啟之後再手動去 Gemfile 裡切換成 Rails 4

View gist:6147113
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
"draw_minimap_border": true,
"font_face": "Source Code Pro Light",
"font_size": 16.0,
"tab_size": 2,
You can’t perform that action at this time.