Skip to content

Instantly share code, notes, and snippets.

ruby-1.8.7-p174 > WeakRef.public_instance_methods(false)
=> ["__setobj__", "__getobj__", "weakref_alive?"]
ruby-1.8.7-p174 >
Loaded suite /Users/cowboyd/Projects/rdom/test/rdom/jquery_test
Started
F
Finished in 0.14056 seconds.
1) Failure:
test_can_load_jquery:15
Exception raised:
Class: <V8::JSError>
Message: <"Cannot read property 'addEventListener' of undefined">
legolas:cucumber cowboyd$ RUBYLIB=/Users/cowboyd/Projects/therubyrhino/lib jruby -S bin/cucumber -v -i examples/v8/features
Using the default profile...
Code:
* examples/v8/features/support/env.js
Features:
* examples/v8/features/fibonacci.feature
Parsing feature files took 0m0.084s
Code:
require 'v8'
include V8::C
print = FunctionTemplate::New() do |arguments|
for i in 0..arguments.Length() - 1
print case arg = arguments[i]
when TrueClass,FalseClass, nil
arg
else
@cowboyd
cowboyd / RubyExtensionFinder.java
Created October 29, 2010 11:55
Why can't JRuby find it's
@Extension
public class RubyExtensionFinder extends ExtensionFinder {
public RubyExtensionFinder() {
ScriptingContainer jruby = new ScriptingContainer();
/**
* When run in the maven test suite, this line executes just fine
* but when instantiated by the Hudson server at runtime, gets the
* following error: no such file to load -- builtin/core_ext/symbol
*
@cowboyd
cowboyd / MyExtensionFinder.java
Created October 30, 2010 03:08
Why does Hudson only ask for certain extension points?
@Extension
public class MyExtensionFinder extends ExtensionFinder {
public <T> Collection<ExtensionComponent<T>> find(Class<T> tClass, Hudson hudson) {
System.out.printf("find(%s)\n", tClass.getName());
return new ArrayList<ExtensionComponent<T>>();
}
}
/**
import hudson.Launcher;
import hudson.Extension;
import hudson.util.FormValidation;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.AbstractProject;
import hudson.tasks.Builder;
import hudson.tasks.BuildStepDescriptor;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.DataBoundConstructor;
@cowboyd
cowboyd / list.rb
Created November 30, 2010 22:43
convert native java arraylist to ruby array.
require 'java'
list = java.util.ArrayList.new
list.add(1)
list.add(2)
puts list.inspect #=> <Java::JavaUtil::ArrayList:0x7dc21ece>
puts list.to_a.inspect #=> [1, 2]
@cowboyd
cowboyd / Fooby.java
Created December 3, 2010 21:28
try to get a top-level constant
package foo;
import org.jruby.embed.ScriptingContainer;
import org.jruby.embed.LocalContextScope;
import org.jruby.embed.LocalVariableBehavior;
import org.jruby.embed.internal.LocalContext;
public class Fooby {
public static void main(String[] args) {
A 5 vol% ethanol solution needs to be converted to wt% for the table in the
CRC Handbook of Chemistry and Physics, 62nd Ed, pg D-207.
The density of pure alcohol is 0.791 times that of water at 20 C.
Basis 100 ml solution:
alcohol = 5x0.791 = 3.955 grams
water = 95x1.00 = 95.000
Total = 98.955 g
Wt% alcohol = 3.955/98.955 = 0.0400 -> 4.00 wt% alcohol.