Skip to content

Instantly share code, notes, and snippets.

View larryzhao's full-sized avatar
🐱
Meow

Larry Zhao larryzhao

🐱
Meow
View GitHub Profile
@larryzhao
larryzhao / ie9_bug.js
Created June 17, 2012 15:11
IE9 bug reproduction
function func1(flag){
if(flag){
alert("Caller is here!");
}else {
func2();
}
}
function func2(){
arguments.callee.caller(true);
@larryzhao
larryzhao / deploy.rb
Created June 27, 2012 09:52 — forked from bkutil/deploy.rb
Start and Stop tasks for resque workers and resque scheduler with capistrano deploy hook (without God)
after "deploy:symlink", "deploy:restart_workers"
after "deploy:restart_workers", "deploy:restart_scheduler"
##
# Rake helper task.
# http://pastie.org/255489
# http://geminstallthat.wordpress.com/2008/01/27/rake-tasks-through-capistrano/
# http://ananelson.com/said/on/2007/12/30/remote-rake-tasks-with-capistrano/
def run_remote_rake(rake_cmd)
rake_args = ENV['RAKE_ARGS'].to_s.split(',')
@larryzhao
larryzhao / Capfile
Created June 27, 2012 16:29
Bundler::GemNotFound: Could not find rake-0.9.2.2 in any of the sources
load 'deploy'
# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets'
Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy' # remove this line to skip loading any of the default tasks
@larryzhao
larryzhao / gist:3016272
Created June 29, 2012 06:34
rvm install jruby-1.6.7.2 --1.9 --trace
$ rvm install jruby-1.6.7.2 --1.9 --trace
jruby-1.6.7.2 --1.9 --trace
rvm 1.14.3 (master) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
+ [[ -n '' ]]
+ export 'PS4=+ ${BASH_SOURCE##${rvm_path:-}} : ${FUNCNAME[0]:+${FUNCNAME[0]}()} ${LINENO} > '
+ PS4='+ ${BASH_SOURCE##${rvm_path:-}} : ${FUNCNAME[0]:+${FUNCNAME[0]}()} ${LINENO} > '
+ /scripts/cli : __rvm_parse_args() 795 > [[ -z install ]]
+ /scripts/cli : __rvm_parse_args() 797 > [[ 0 -eq 1 ]]
@larryzhao
larryzhao / test.rb
Created July 4, 2012 06:11
Twitter::Autolink breaks in jruby when text contains Chinese or Japanese
# encoding: utf-8
require 'twitter-text'
options = { :username_include_symbol => true }
text = "@baozi hi you are a dog #dog"
text_cn = "@baozi 嗨你是一条狗诶 #狗狗"
text_jp = "@baozi ねえ、あなたは犬だ #犬"
puts "=== original ==="
@larryzhao
larryzhao / result with jruby-1.6.7.2 1.9
Created July 5, 2012 09:28
MatchData.begin(n) always returns 0 on jruby with chinese/japanese characters in it
$ jruby --1.9 -S test.rb
==== Text in English ====
#<MatchData "@chichi dog dog" 1:"@" 2:"chichi" 3:" dog dog">
1. 11
2. 12
3. 18
==== Text in Chinese ====
#<MatchData "@chichi 狗狗" 1:"@" 2:"chichi" 3:" 狗狗">
1. 0
2. 0
@larryzhao
larryzhao / gist:4485068
Created January 8, 2013 16:17
phabricator error
PHABRICATOR SETUP
@larryzhao
larryzhao / gist:5901059
Created July 1, 2013 14:05
How to link to a image with parenthesis in the src url
![][1]
[1]: http://latex.codecogs.com/gif.latex?\prod%20\(n_{i}\)+1
@larryzhao
larryzhao / gist:6414124
Last active December 22, 2015 03:59
Devise+CanCan+RubyCAS

My solution is like the following:

I have a system called Central, in which I manage the users and their passwords using Devise, Ruby-CAS-Server system performs the authentication against this database, and CanCan and Ruby-CAS-Client is used to manage the authorizations and authentication.

And I have several other systems, for example called Satellite, which authenticates using CAS and only have a simple User Class to hold the properties coming from CAS after authentication, and CanCan to manage authorizations, and no Devise is used.

###Central ApplicationController in Central:

@larryzhao
larryzhao / gist:7350971
Created November 7, 2013 08:18
doT vs Eco
doT:
executed in 7964 milliseconds VM510:24
executed in 8042 milliseconds VM510:24
executed in 7716 milliseconds
Eco:
executed in 20901 milliseconds VM228:24
executed in 20539 milliseconds