Skip to content

Instantly share code, notes, and snippets.

View sandyxu's full-sized avatar
Working from office

Sandy Xu sandyxu

Working from office
  • Shanghai, China
View GitHub Profile

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@sandyxu
sandyxu / omniauth.rb
Last active December 21, 2015 04:08
OmniAuth should set config.on_failure
# 在OmniAuth时触发异常被web server捕获直接返回500页面,如果想捕获并处理要做如下设置
# config/initializers/omniauth.rb
OmniAuth.config.on_failure = AuthenticationsController.action(:failure)
# log 输出
OmniAuth.config.logger = Rails.logger
@sandyxu
sandyxu / why-new-issue-github
Created August 20, 2013 01:37
Why star from 'New Issue' on GitHub
在GitHub里 Issue是我们的任务管理,代码跟踪,意见反馈的根源。通过对 Issue, 添加 Milestones进行进度管理;
及时调整Issue的状态,便于了解进度;添加Label,有助于区分Issue的性质。每次代码的提交最好都有对应的Issue,
便于浏览任务对应的代码,直接对每行代码评论,反馈。尤其是对程序员永远的沟通能力和思维定式,减少了沟通中的上下文。
这样一套下了,会减少很多沟通成本。
建议每个提交代码的人先在GihHub 添加或找到一个 Issue,充分利用这套系统带给我们的便利。
提交代码,从 New Issue 开始!!!
@sandyxu
sandyxu / safe_continue_redirect.rb
Last active December 21, 2015 11:59
防止浏览器存在url跳转漏洞被利用钓鱼
# 来自wooyun的白帽子安全 http://www.wooyun.org/bugs/subtype-65/page/1
# 通过params[:continue] 的安全url进行跳转
def safe_continue_redirect(continue = params[:continue])
if continue
redirect_to safe_continue_url(continue)
else
redirect_to(root_path)
end
end
@sandyxu
sandyxu / git-diary.txt
Last active December 21, 2015 14:08
git, skills, expertise, config, autocomplete command
# git 命令自动提示 blog:
http://code-worrier.com/blog/autocomplete-git/
# 安装git命令自动提示后很爽,但是删除后的branch由于缓存,仍然提示出来,导致提示过多且混乱。通过查看
$ git remote show origin
* remote origin
Fetch URL: git@github.com/sandyxu/xx.git
Push URL: git@github.com/sandyxu/xx.git
HEAD branch (remote HEAD is ambiguous, may be one of the following):
master
next
@sandyxu
sandyxu / .gitconfig
Last active December 21, 2015 14:09
gitconfig
[user]
name = sandyxu
email = jyosuper@gmail.com
[core]
quotepath = false
[color]
interactive = auto
diff = auto
status = auto
branch = auto
@sandyxu
sandyxu / brew-uninstall.sh
Created August 23, 2013 09:21
brew uninstall
cd `brew --prefix`
rm -rf Cellar
brew prune
rm `git ls-files`
rm -r Library/Homebrew Library/Aliases Library/Formula Library/Contributions
rm -rf .git
rm -rf ~/Library/Caches/Homebrew
@sandyxu
sandyxu / models-should-be-organized-format.rb
Created August 23, 2013 09:25
All models should be organized using the following format
# All models should be organized using the following format.
class MyModel < ActiveRecord::Base
# extends ...
# includes ..
# security (i.e. attr_accessible) ......
# relationships ....
# validations ..
# callbacks
# scopes
# additional config
@sandyxu
sandyxu / time-format-string
Created August 23, 2013 09:29
strftime方法中可用的 ISO 8601 格式化符号
%a 星期的缩写,如Wed
%A 星期的全称,如Wednesday
%U 本星期在全年中所属的周数
%W
%H 小时(24小时制)
%M 分钟
%S 秒
%I 小时(12小时制)
%p PM 或 AM
%b 月份的缩写,如 Jan
@sandyxu
sandyxu / my.cnf
Created August 23, 2013 09:46
mysql config file /usr/local/etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8
[mysqld]
collation-server = utf8_unicode_ci
character-set-server = utf8
init-connect ='SET NAMES utf8'
max_allowed_packet = 64M