Skip to content

Instantly share code, notes, and snippets.

View donv's full-sized avatar

Uwe Kubosch donv

View GitHub Profile
@donv
donv / ant output
Created August 2, 2012 11:45
Failure for "ant test"
[java] 1) nonblocking IO blocking behavior: JRUBY-5122 should not block for write
[java] Failure/Error: value.should == 3
[java] expected: 3
[java] got: 2 (using ==)
[java] # ./spec/regression/JRUBY-5122_nonblocking_io_spec.rb:244:in `(root)'
[java] # ./spec/regression/JRUBY-5122_nonblocking_io_spec.rb:218:in `(root)'
[java]
@donv
donv / MethodsExample.java
Created July 7, 2012 00:34
Find Ruby method from Java side
import org.jruby.embed.ScriptingContainer;
import java.util.Arrays;
class MethodsExample {
public static void main(String[] args) {
System.out.println("Hello world!");
ScriptingContainer sc = new ScriptingContainer();
MethodsExample me = new MethodsExample();
java.util.List<String> methods = (java.util.List<String>)sc.callMethod(me, "methods");
@donv
donv / image.rb
Created April 10, 2012 20:27
Large binary file upload with Rails
class Image < ActiveRecord::Base
after_create do |i|
next unless @content_file
conn = self.class.connection.raw_connection.connection
is = java.io.FileInputStream.new(java.io.File.new(@content_file))
file_length = is.available.to_i
st = conn.prepareStatement("UPDATE images SET content_data = ? WHERE id = ?")
st.java_send(:setBinaryStream, [Java::int , java.io.InputStream, Java::int], 1, is, file_length)
st.setInt(2, id)
st.executeUpdate
if `ant -version` !~ /version (\d+)\.(\d+)\.(\d+)/ || $1.to_i < 1 || ($1.to_i == 1 && $2.to_i < 8)
puts "ANT version 1.8.0 or later required. Version found: #{$1}.#{$2}.#{$3}"
exit 1
end
require 'time'
def manifest() @manifest ||= REXML::Document.new(File.read(MANIFEST_FILE)) end
def package() manifest.root.attribute('package') end
def build_project_name() @build_project_name ||= REXML::Document.new(File.read('build.xml')).elements['project'].attribute(:name).value end
@donv
donv / Using JRuby 1.6.7
Created March 24, 2012 21:24
HTTPS example
macbeth:jruby uwe$ jirb
>> RUBY_DESCRIPTION
=> "jruby 1.6.7 (ruby-1.8.7-p357) (2012-02-22 3e82bc8) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java]"
>> require 'net/https'
=> true
>> response = nil
=> nil
>> uri = URI("https://evening-ocean-4975.herokuapp.com/")
=> #<URI::HTTPS:0x6be54e00 URL:https://evening-ocean-4975.herokuapp.com/>
>> #uri = URI("https://docs.google.com/")
@donv
donv / Code to set "raw" trace type
Created December 22, 2011 23:11
Backtrace with Android SDK release 16
Class traceTypeClass = Class.forName("org.jruby.runtime.backtrace.TraceType", true, classLoader);
Method traceTypeForMethod = traceTypeClass.getMethod("traceTypeFor", String.class);
Object traceTypeRaw = traceTypeForMethod.invoke(null, "raw");
callScriptingContainerMethod(Void.class, "setTraceType", traceTypeRaw);
@donv
donv / gist:1215248
Created September 13, 2011 21:41
Stack trace for Ruboto exception
I/System.out( 292): NameError: uninitialized constant AndroidLogger
D/AndroidRuntime( 292): Shutting down VM
W/dalvikvm( 292): threadid=1: thread exiting with uncaught exception (group=0x40015560)
W/dalvikvm( 292): getStackTrace() called but no trace available
E/AndroidRuntime( 292): Error reporting crash
E/AndroidRuntime( 292): java.lang.NullPointerException
E/AndroidRuntime( 292): at java.lang.Throwable.countDuplicates(Throwable.java:226)
E/AndroidRuntime( 292): at java.lang.Throwable.printStackTrace(Throwable.java:315)
E/AndroidRuntime( 292): at android.util.Log.getStackTraceString(Log.java:307)
E/AndroidRuntime( 292): at android.util.Slog.e(Slog.java:77)
Last login: Fri Sep 2 18:07:19 on ttys000
macbeth:jruby uwe$ java --version
Unrecognized option: --version
Could not create the Java virtual machine.
macbeth:jruby uwe$ java -version
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03-383-11A511)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02-383, mixed mode)
macbeth:jruby uwe$ cd ../
macbeth:jruby uwe$ mv jruby jruby_with_error
private static Object ruby;
Log.d(TAG, "Setting up JRuby runtime");
System.setProperty("jruby.bytecode.version", "1.5");
System.setProperty("jruby.interfaces.useProxy", "true");
System.setProperty("jruby.management.enabled", "false");
String packagePath = "org.ruboto.core";
String apkName = null;
try {
@donv
donv / with evalScriptlet
Created March 29, 2011 21:26
with evalScriptlet
ruby.evalScriptlet(getContents(), scope)
W/System.err( 9479): org.jruby.exceptions.RaiseException: (NameError) uninitialized constant Intent
W/System.err( 9479): at org.jruby.RubyModule.const_missing(org/jruby/RubyModule.java:2528)
W/System.err( 9479): at #<Class:0x14776ff78>.(root)(<script>:38)