Skip to content

Instantly share code, notes, and snippets.

🐱
Meow

Larry Zhao larryzhao

🐱
Meow
Block or report user

Report or block larryzhao

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View application_helper.rb
module ApplicationHelper
...
def present(object, klass = nil)
klass ||= "#{object.class}Presenter".constantize
presenter = klass.new(object, self)
yield presenter if block_given?
presenter
end
View gist:1260e1f22abb57a51574
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 Dec 31, 2015
Grape on Goliath
View gist:7913394
require 'goliath'
require 'grape'
module Myapp
class API < Grape::API
version 'v1'
format :json
get '/ping' do
{ ping: "pong" }
View gist:7350971
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 Dec 22, 2015
Devise+CanCan+RubyCAS
View gist:6414124

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 Jul 1, 2013
How to link to a image with parenthesis in the src url
View gist:5901059
![][1]
[1]: http://latex.codecogs.com/gif.latex?\prod%20\(n_{i}\)+1
View gist:4485068
PHABRICATOR SETUP
@larryzhao
larryzhao / result with jruby-1.6.7.2 1.9
Created Jul 5, 2012
MatchData.begin(n) always returns 0 on jruby with chinese/japanese characters in it
View result with jruby-1.6.7.2 1.9
$ 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 Jul 4, 2012
Twitter::Autolink breaks in jruby when text contains Chinese or Japanese
View test.rb
# 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 Jun 29, 2012
rvm install jruby-1.6.7.2 --1.9 --trace
View gist:3016272
$ 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 ]]
You can’t perform that action at this time.