Skip to content

Instantly share code, notes, and snippets.

View donv's full-sized avatar

Uwe Kubosch donv

View GitHub Profile
SqldroidConnection con;
private PreparedStatement getTypeInfo = null;
public ResultSet getTypeInfo() throws SQLException {
if (getTypeInfo == null) {
getTypeInfo = con.prepareStatement(
"select "
+ "tn as TYPE_NAME, "
+ "dt as DATA_TYPE, "
+ "0 as PRECISION, "
I/System.out( 1605): ********************************************************************************
I/System.out( 1605): Exception:
I/System.out( 1605): --------------------------------------------------------------------------------
I/System.out( 1605): java.nio.CharSequenceAdapter.<init>(CharSequenceAdapter.java:45)
I/System.out( 1605): java.nio.CharBuffer.wrap(CharBuffer.java:108)
I/System.out( 1605): java.nio.charset.Charset.encode(Charset.java:472)
I/System.out( 1605): org.jruby.RubyEncoding.encode(RubyEncoding.java:179)
I/System.out( 1605): org.jruby.RubyEncoding.encodeUTF8(RubyEncoding.java:168)
I/System.out( 1605): org.jruby.RubyString.newUnicodeString(RubyString.java:488)
I/System.out( 1605): arjdbc.jdbc.RubyJdbcConnection.stringToRuby(RubyJdbcConnection.java:991)
@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)
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 {
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
@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)
@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 / 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/")
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 / 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