Skip to content

Instantly share code, notes, and snippets.

@HungYuHei
HungYuHei / gist:2817696
Created May 28, 2012 06:32
Get ssh-copy-id in Mac OS X
By default ssh-copy-id is missing on Mac OS X, but since it’s just a simple bash script you can install it quickly from the official Portable OpenSSH CVS repository:
$ sudo bash -c "cvs -d [email protected]:/cvs \
get -p openssh/contrib/ssh-copy-id > /usr/local/bin/ssh-copy-id"
$ sudo chmod +x /usr/local/bin/ssh-copy-id
@HungYuHei
HungYuHei / gist:2515224
Created April 28, 2012 02:40 — forked from mgraupner/gist:1859298
MacOS X 10.7.3 and XCode 4.3: Installing Ruby
- Install "Command Line Tools for XCode" (Get it from Apple Developer Program) or Install XCode via Appstore
where option one is the faster one, 170MB vs 1.xGB
- Install https://github.com/sstephenson/rbenv
git clone into your home folder;
set environment variables, see install docs of rbenv;
- Get libyaml
wget http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz
configure
@HungYuHei
HungYuHei / gist:2145703
Created March 21, 2012 09:00
rail_routes_url_helper
include Rails.application.routes.url_helpers
@HungYuHei
HungYuHei / gist:2132090
Created March 20, 2012 06:51
convert file-encoding from gb2312 to utf-8
perl -MEncode -pi -e '$_=encode_utf8(decode(gb2312=>$_))' FILE_NAME
class PostsController < ActionController::Base
def create
Post.create(post_params)
end
def update
Post.find(params[:id]).update_attributes!(post_params)
end
private
@HungYuHei
HungYuHei / gist:1947718
Created March 1, 2012 06:11
one-line-multi-validates-for-rails
validates :name, :format => { :with => /^[A-Za-z0-9]+$/, :message => '只支持英文及数字' }, :length => { :in => 3..20 }, :presence => true, :uniqueness => { :case_sensitive => false }
@HungYuHei
HungYuHei / quiet_assets.rb
Created February 4, 2012 06:41
disable logging of asset pipeline messages
# config/initializers/quiet_assets.rb
Rails.application.assets.logger = Logger.new('/dev/null')
Rails::Rack::Logger.class_eval do
def call_with_quiet_assets(env)
previous_level = Rails.logger.level
Rails.logger.level = Logger::ERROR if env['PATH_INFO'].index("/assets/") == 0
call_without_quiet_assets(env).tap do
Rails.logger.level = previous_level
end
@HungYuHei
HungYuHei / gist:1709001
Created January 31, 2012 05:17
multi-parameter(datetime_select field) support with mongoid
class Post
include Mongoid::Document
include Mongoid::MultiParameterAttributes
field :published_at, type: DateTime
end
@HungYuHei
HungYuHei / devise.zh-CN.yml
Created January 28, 2012 08:49 — forked from acenqiu/devise.zh-CN.yml
# Chinese (China) translations for Devise 2.0
# Chinese (China) translations for Devise 2.0
# by HungYuhei (https://github.com/HungYuHei)
# forked from https://gist.github.com/1319590
zh-CN:
errors:
messages:
expired: "您已过期,请重新申请"
not_found: "没有找到"
already_confirmed: "已经激活,请重新登录."
@HungYuHei
HungYuHei / gist:1681581
Created January 26, 2012 07:48 — forked from ZhangHanDong/gist:1033906
MongoId Counter Cahce
#
# lib/mongoid/counter_cache.rb
# ruby
#
# Created by Zhang Alex on 2011-06-17.
# Copyright 2011 __ZhangHanDong__. All rights reserved.
#
# ===================================
# class Forum
# references_many :topics