Skip to content

Instantly share code, notes, and snippets.

(function($) {
$.fn.clippy = function(text, bgcolor) {
if (!bgcolor) {
var node = $(this);
while (node.css('background-color') == 'transparent' && node.length) {
node = node.parent();
}
if (!node.length) {
bgcolor = '#ffffff';
} else {
@HungYuHei
HungYuHei / rails-template.rb
Created July 28, 2011 14:25 — forked from xslim/rails-template.rb
Rails 3 App Template with JQuery, Mongoid, Compass, HAML & Barista
# rails new NAME -OJ -m https://gist.github.com/raw/903515/rails-template.rb
remove_file 'README'
remove_file 'public/index.html'
remove_file 'public/images/rails.png'
prepend_file 'config/boot.rb' do <<-RB
begin
require 'yaml'
YAML::ENGINE.yamler = 'syck'
@HungYuHei
HungYuHei / import_file_to_gridfs.rake
Created September 8, 2011 06:19 — forked from huacnlee/import_file_to_gridfs.rake
将 File System 的上传文件导入到 Mongodb 的 GridFS 里面
# coding: UTF-8
#
# 以下为 Rake 任务,功能是将普通文件系统里面的东西转移到 MongoDB GridFS 里面
# 此代码片段来自于 Homeland 项目: https://github.com/huacnlee/homeland/tree/mysql
# 场景:
# 老架构 Linux File Store, Paperclip, hash 目录:"https://github.com/huacnlee/homeland/blob/ca0bdd8ab26da7b780e2dae7eba12b79f41e6d65/config/initializers/paperclip_hashpath.rb"
# 新架构 Mongodb GridFS, Garrierwave, 继续沿用 Paperclip 目录兼容: https://github.com/huacnlee/homeland/tree/7100ce4c506cc2c4387f25e50c533e5bbcac6cc2/app/uploaders
# 整个过程不会修改任何原始数据库和上传文件
#
require 'mongo'
@HungYuHei
HungYuHei / .gitconfig
Created September 9, 2011 15:41
Useful gitconfig aliases
[alias]
st = status
rso = remote show origin
# e.g. git graphviz --first-parent master | dotty /dev/stdin
graphviz = "!f() { echo 'digraph git {' ; git log --pretty='format: %h -> { %p }' \"$@\" | sed 's/[0-9a-f][0-9a-f]*/\"&\"/g' ; echo '}'; }; f"
# Pretty log
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
# Print out all commits whose hash starts with a given string
abbr = "!sh -c 'git rev-list --all | grep ^$1 | while read commit; do git --no-pager log -n1 --pretty=format:\"%H %ci %an %s%n\" $commit; done' -"
# Two little tweaks to diff
@HungYuHei
HungYuHei / setup.sql
Created September 20, 2011 04:35 — forked from iwinux/setup.sql
Set up a database in MySQL
CREATE DATABASE `databasename` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'user'@'localhost' IDENTIFIED BY 'mypass';
GRANT ALL ON databasename.* TO 'user'@'localhost';
@HungYuHei
HungYuHei / gist:1280335
Created October 12, 2011 05:00 — forked from lxneng/gist:1003770
git dropbox
~/project $ git init
~/project $ git add .
~/project $ git commit -m "first commit"
~/project $ cd ~/Dropbox/git
~/Dropbox/git $ mkdir project.git
~/Dropbox/git $ cd project.git
~/Dropbox/git $ git init --bare
~/Dropbox/git $ cd ~/project
@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
@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: "已经激活,请重新登录."
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: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