Skip to content

Instantly share code, notes, and snippets.

View BanzaiMan's full-sized avatar

Hiro Asari BanzaiMan

View GitHub Profile
irb(main):003:0> LDAP.methods-Class.methods => ["entry2hash", "mod",
"err2string", "dn2ufn", "hash2mods"]
irb(main):005:0> LDAP::Conn.methods-Object.methods => ["set_option",
"get_option", "open"]
irb(main):008:0> l=LDAP::Conn.new; (l.methods-Object.methods).sort => ["add",
"add_ext", "bind", "bound?", "compare", "compare_ext", "controls", "delete",
"delete_ext", "err", "err2string", "get_option", "modify", "modify_ext",
"modrdn", "perror", "referrals", "result2error", "sasl_bind", "sasl_quiet",
@BanzaiMan
BanzaiMan / ruby_ffi.rb
Created February 3, 2009 14:26
Trying to get FFI to work
$ gcc -dynamiclib -o libsimplemath.dylib simple_math.c
$ ruby ruby_ffi.rb
243.0
9.0
3628800
$ cc -m64 -dynamiclib -install_name libsimplemath.dylib -o libsimplemath.dylib simple_math.c
$ jruby -v ruby_ffi.rb jruby 1.2.0 (ruby 1.8.6 patchlevel 287) (2009-02-03 rev 8978) [x86_64-java]
243.0
9.0
@BanzaiMan
BanzaiMan / gist:57802
Created February 3, 2009 22:25
Check if we're on 32-bit or 64-bit architecture
integer_size = 32
if defined?(JRUBY_VERSION)
require 'java'
integer_size = java.lang.Integer.getInteger("sun.arch.data.model")
else
# http://groups.google.com/group/ruby-talk-google/browse_thread/thread/fe3bde8257d7e773?pli=1
if (-1.size) == 8
integer_size = 64
end
#
# .autotest
# Autotest Growl Notifications for Rspec and Test::Unit
#
# Created by Rein Henrichs on 2007-09-12.
# Copyright 2007 Rein Henrichs.
# http://pastie.caboo.se/96573/download
#
require 'logger'
$ irb
>> require 'lib/ldap-ffi'
=> true
>> l=LDAP.init('localhost',389); s=LDAP::Struct.new(l); s[:ld_sizelimit]
=> 0
>> s[:ld_matched]
=> nil
$ nm /usr/lib/libldap.dylib | grep ^[0-9]
0000500d T _ber_alloc
00004fbe T _ber_alloc_t
0000108b T _ber_bprint
000066e9 T _ber_bvarray_add
0000660f T _ber_bvarray_free
00006115 T _ber_bvdup
00006007 T _ber_bvecadd
00005f3f T _ber_bvecfree
00005d52 T _ber_bvfree
surfboard:jruby asari$ bin/jruby -ve 'eval ":\"\\0\" "'
jruby 1.3.0RC2 (ruby 1.8.6p287) (2009-05-20 7e3114e) (Java HotSpot(TM) Client VM 1.5.0_16) [i386-java]
(eval):1 warning: Useless use of a literal in void context.
(eval):1: symbol cannot contain '\0' (SyntaxError)
surfboard:jruby asari$ ruby -ve 'eval ":\"\\0\" "'
ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0]
-e:1: (eval):1: compile error (SyntaxError)
(eval):1: symbol cannot contain '\0'
(eval):1: empty symbol literal
surfboard:src asari$ ruby19 -ve ':"\u0000"'
ruby 1.9.2dev (2009-05-22 trunk 23524) [i386-darwin9.7.0]
-e:1: symbol cannot contain '\u0000'
:"\u0000"
^
surfboard:src asari$ jruby --1.9 -ve ':"\u0000"'
jruby 1.3.0RC2 (ruby 1.9.1p0) (2009-05-21 19418c2) (Java HotSpot(TM) Client VM 1.5.0_16) [i386-java]
-e:1 warning: Useless use of a literal in void context.
# some hints from http://drnicwilliams.com/2006/10/12/my-irbrc-for-consoleirb/
require 'irb/completion'
require 'pp'
require 'rubygems'
require 'wirble'
require 'map_by_method'
require 'what_methods'
Wirble.init
Wirble.colorize
@BanzaiMan
BanzaiMan / gist:148167
Created July 16, 2009 04:03
Tests of sqlite3 via FFI in JRuby
$ SQLITE3_DRIVERS=FFI jruby -v -rubygems -I lib -I test test/tc_database.rb
jruby 1.4.0dev (ruby 1.8.6p287) (2009-07-10 6586) (Java HotSpot(TM) Client VM 1.5.0_19) [i386-java]
Loaded suite test/tc_database
Started
.........................
Finished in 0.414 seconds.
25 tests, 37 assertions, 0 failures, 0 errors
$ SQLITE3_DRIVERS=FFI jruby -v -rubygems -I lib -I test test/tc_errors.rb
jruby 1.4.0dev (ruby 1.8.6p287) (2009-07-10 6586) (Java HotSpot(TM) Client VM 1.5.0_19) [i386-java]