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 / application_helper.rb
Created January 28, 2015 16:35
Newrelic Support
module ApplicationHelper
...
def present(object, klass = nil)
klass ||= "#{object.class}Presenter".constantize
presenter = klass.new(object, self)
yield presenter if block_given?
presenter
end
function batchImport(season, type) {
var script = "// Starting point \n $('.icon-btn-download').trigger('click'); \n\n";
var resourceType = type.toUpperCase();
var url
var timeout = 500;
console.log($(".resource-item[data-format=" + resourceType + "][data-season=" + season + "]").length);
$(".resource-item[data-format=" + resourceType + "][data-season=" + season + "]").each(function(index, element){
var $resourceItem = $(element);
@larryzhao
larryzhao / gist:7913394
Last active December 31, 2015 01:19
Grape on Goliath
require 'goliath'
require 'grape'
module Myapp
class API < Grape::API
version 'v1'
format :json
get '/ping' do
{ ping: "pong" }
@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
@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: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:4485068
Created January 8, 2013 16:17
phabricator error
PHABRICATOR SETUP
@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 / 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 / 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 ]]