Skip to content

Instantly share code, notes, and snippets.

@hiveer
hiveer / recent_branches
Last active May 15, 2018 09:27
Easy way to find out your recent branch and checkout to them
Add below code to the file `~/.bashrc`
# this will file recent 10 branches
alias recent_branches="git for-each-ref --sort='-authordate:iso8601' --format='%(refname:short)' --count 10 refs/heads"
function recent() {
read -a arr <<< $(recent_branches)
for ((i = 0; i < ${#arr[@]}; ++i)); do
position=$(($i))
@hiveer
hiveer / generate code climate
Created April 25, 2018 07:42
code climate base on 'rails_best_practices'
#!/usr/bin/env ruby
REFERENCE = {
"add model virtual attribute" => "https://rails-bestpractices.com/posts/2010/07/21/add-model-virtual-attribute/",
"always add db index" => "https://rails-bestpractices.com/posts/2010/07/24/always-add-db-index/",
"check return value of save otherwise use save" => "https://rails-bestpractices.com/posts/2012/11/02/check-the-return-value-of-save-otherwise-use-save/",
"default_scope is evil" => "https://rails-bestpractices.com/posts/2013/06/15/default_scope-is-evil/",
"dry bundler in capistrano" => "https://rails-bestpractices.com/posts/2010/09/02/dry-bundler-in-capistrano/",
"isolating seed data" => "https://rails-bestpractices.com/posts/2010/07/24/isolating-seed-data/",
"keep finders on their own model" => "https://rails-bestpractices.com/posts/2010/07/23/keep-finders-on-their-own-model/",
@hiveer
hiveer / my vim config
Last active May 17, 2018 08:39
some features I used in my vim config
" 修改leader键
let mapleader = ','
let g:mapleader = ','
nnoremap <leader>tr :!ctags -R --languages=Ruby<CR>
nnoremap <leader>tj :!ctags -R --languages=Javascript<CR>
" set grepprg=ack\ --nogroup\ --column\ $*
set grepprg=ag\ --vimgrep
set grepformat=%f:%l:%c:%m
#!/usr/bin/env ruby
#
# Mac fix 1 - Install the Nokogiri gem on Mac OS 10.9 Mavericks
#
# Usage: to configure and install using Bundler, pass in 'bundle' as an argument to the script.
#
# Nokogiri works at a very low level, so it has many issues on various platforms.
# As a result, the command `install gem nokogiri` often will fail. This fix is for
# errors involving 'libiconv', such as the following one I encountered:
#

Routes

小心地使用 Match(Rails 3 已实现)

Rails 3 提供了 match 方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:

注:(r3 代表 Rails 3,r4 代表 Rails 4)

# routes.rb