Li Xiao xli

View gist:1592604
1 2 3
PS1='\u@\h \W$(__git_ps1 "(%s)[$(git config --get user.name)]")\$ '
 
PS1='\h \W$(__git_ps1 "($(git config --get user.name)@%s)")\$ '
View platform_config.rb
1 2 3 4 5 6 7 8 9 10
require 'fileutils'
require 'yaml'
require 'erb'
module PlatformConfig
def load(config_yml)
unless File.exists?(config_yml)
FileUtils.cp("#{config_yml}.example", config_yml)
end
 
if platform_config = YAML.load(ERB.new(File.read(config_yml)).result)[RUBY_PLATFORM]
View autoload_threadsafe.rb
1 2 3 4 5 6 7 8 9 10
# Load this file before load anything.
# JRuby-Rack will load rack before load rails, so should load this file when JRuby runtime initialized.
# Call AutoloadThreadsafe.eager_load_all! at the end of rails environment rb
 
module AutoloadThreadsafe
module Recorder
def self.included(base)
base.class_eval do
alias :unsafe_autoload :autoload
def autoload(m, filename)
View JRuby IRubyObject Adapter: JRubyObject
1 2 3 4 5 6 7 8 9 10
import static org.jruby.javasupport.JavaEmbedUtils.invokeMethod;
 
import org.jruby.Ruby;
import org.jruby.runtime.builtin.IRubyObject;
 
public class JRubyObject {
 
public static JRubyObject load(Ruby runtime, String dump) {
return new JRubyObject(((IRubyObject) marshalClass(runtime).send("load", dump)));
}
View gist:115935
1 2 3 4 5 6 7 8 9
//find out caller's class name (found from log5j)
public static void xxx() {
String name = new Exception().getStackTrace()[1].getClassName();
....
}
 
// or
 
String name = Thread.currentThread().getStackTrace()[3].getClassName()
View gist:77242
1 2 3 4 5 6 7 8 9 10
# How to find out where a method comes from.
# Learned this from Dave Thomas while teaching Advanced Ruby Studio
# Makes the case for separating method definitions into
# modules, especially when enhancing built-in classes.
module Perpetrator
def crime
end
end
 
class Fixnum
Something went wrong with that request. Please try again.