This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PS1='\u@\h \W$(__git_ps1 "(%s)[$(git config --get user.name)]")\$ ' | |
PS1='\h \W$(__git_ps1 "($(git config --get user.name)@%s)")\$ ' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export PATH=$PATH:~/Downloads/IAMCli-1.5.0/bin | |
export AWS_IAM_HOME=~/Downloads/IAMCli-1.5.0 | |
iam-servercertupload --aws-credential-file <credential.csv> -s <sname> -b <ssl.crt.txt> -k <ssl.key.txt> -c intermediate.crt.txt -p /cloudfront/<sname>/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# aws-ruby-sdk v1 API | |
def s3_multipart_upload_credentials(bucket, key, role_arn) | |
sts = AWS::STS.new | |
policy = AWS::STS::Policy.new | |
policy.allow(:actions => ["s3:PutObject", | |
"s3:GetObject", | |
"s3:AbortMultipartUpload", | |
"s3:ListMultipartUploadParts", | |
"s3:ListBucketMultipartUploads"], | |
:resources => "arn:aws:s3:::#{[bucket,key].join('/')}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bucket = <s3 bucket name> | |
s3key = <s3 file key> # use a random uniq key | |
{ | |
"data-aws-id" => ENV["S3_MULTIPART_UPLOAD_ACCESS_KEY_ID"], | |
"data-bucket" => bucket, | |
"data-key" => s3key, | |
"data-signer-url" => <your-data-signer-url> | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// need jQuery and EvaporateJS | |
var config = $("[data-signer-url]"); | |
var _e_ = new Evaporate({ | |
signerUrl: config.data("signer-url"), | |
bucket: config.data("bucket"), | |
aws_key: config.data("aws-id") | |
}); | |
var configuration = { | |
name: config.data("key"), | |
// see EvaporateJS document for other configurations need setup here |
OlderNewer