Skip to content

Instantly share code, notes, and snippets.

@zhongfox
zhongfox / base.rb
Last active Feb 20, 2017
Data Service Ruby Core
View base.rb
module DataService
RELATION_ID = 'relation'
module DataApi
def self.included base
base.singleton_class.send :attr_accessor, # private method
:json_attributes, # 数据模型的json属性定义
:expire_time, # 数据模型的过期时间
:model_class, # 数据模型对应的Activerecord, 默认值是根据类名推断, 可以在这里覆盖
:cache_key # 缓存的key, 有默认值, 通常不需要设置
View jshint_pre-commit
#!/bin/sh
files=$(git diff --cached --name-only --diff-filter=ACM | grep ".js$")
if [ "$files" = "" ]; then
exit 0
fi
if ! type "jshint" > /dev/null; then
echo "\t\033[31mPlease install jshint first: npm install jshint -g\033[0m"
exit 1
@zhongfox
zhongfox / quick_sort
Last active Aug 29, 2015
javascript quick sort
View quick_sort
var rawNumbers = [4,4,3,1,8,5,13,9,2,7,18,10,4];
function qsort(numbers, startIndex, endIndex) {
var first = startIndex,
last = endIndex,
key = numbers[first];
if(first >= last) {
View prepare-commit-msg
#!/bin/sh
BRANCH=`git rev-parse --abbrev-ref HEAD`
RM_NUMBER=`echo $BRANCH | grep -o -e 'rm[0-9]*' || echo $BRANCH`
echo "[$RM_NUMBER]" > "$1.msg"
cat "$1" >> "$1.msg"
cat "$1.msg" > "$1"
@zhongfox
zhongfox / blame_after_grep
Created May 8, 2014
use git grep, and then blame to get the author, line number and detail
View blame_after_grep
#!/usr/bin/env ruby
grep = `git grep -n #{ARGV[0]} #{ARGV[1]}`
interrupt = false
grep.lines.each do |file_with_line|
exit if interrupt
file, line_number, line = file_with_line.split(':', 3)
You can’t perform that action at this time.