Skip to content

Instantly share code, notes, and snippets.

View djberg96's full-sized avatar

Daniel Berger djberg96

View GitHub Profile
@djberg96
djberg96 / fdwalk.rb
Created March 10, 2012 16:09
IO.fdwalk strangeness with ruby 1.9.3
require 'ffi'
class IO
extend FFI::Library
ffi_lib FFI::Library::LIBC
attach_function :fdwalk_c, :fdwalk, [:pointer, :pointer], :void
def self.fdwalk(lowfd)
func = FFI::Function.new(:int, [:pointer, :int]){ |cd, fd|
@djberg96
djberg96 / results.txt
Created March 23, 2012 19:56
JRuby test failures against 1.8 branch
1) Failure:
test_self_default_dir(TestGem) [./test/rubygems/test_gem.rb:577]:
Expected /\/[Rr]uby\/[Gg]ems\/[0-9.]+/ to match "/Library/Frameworks/JRuby.framework/Gems/1.8".
2) Error:
test_execute_build(TestGemCommandsCertCommand):
Errno::ENOENT: No such file or directory - gem-private_key.pem
org/jruby/RubyFile.java:694:in `chmod'
/Users/djberge/Repositories/rubygems/lib/rubygems/security.rb:719:in `build_self_signed_cert'
org/jruby/RubyIO.java:1139:in `open'
@djberg96
djberg96 / gist:2697948
Created May 14, 2012 22:53
ffi symbol failure
ruby 1.9.3-p194
OSX 10.6
dyld: lazy symbol binding failed: Symbol not found: _ruby_thread_has_gvl_p
Referenced from: /opt/local/lib/ruby/gems/1.9.1/gems/ffi-1.0.11/lib/ffi_c.bundle
Expected in: flat namespace
@djberg96
djberg96 / gist:2719037
Created May 17, 2012 13:49
gem search -r -d problem
>gem search -r -d
*** REMOTE GEMS ***
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
bad response Not Found 404 (http://production.cf.rubygems.org/quick/Marshal.4.8/ghostplus-0.0.1.gemspec.rz)
@djberg96
djberg96 / gist:2721257
Created May 17, 2012 20:00
REPARSE_JDATA_BUFFER
# The "old" way
buf_target = "\\??\\" << from_path
wide_string = multi_to_wide(buf_target)[0..-3]
# REPARSE_JDATA_BUFFER
rdb = [
"0xA0000003L".hex, # ReparseTag (IO_REPARSE_TAG_MOUNT_POINT)
wide_string.size + 12, # ReparseDataLength
0, # Reserved
0, # SubstituteNameOffset
@djberg96
djberg96 / byte_test.rb
Created May 19, 2012 22:40
CharArray vs String in FFI
require 'ffi'
class MyStruct < FFI::Struct
layout(:path, [:char, 2]) # wchar
end
s = "hello".encode("UTF-16LE")
m = MyStruct.new
m[:path].to_ptr.put_bytes(0, s, s.bytesize)
@djberg96
djberg96 / gist:2762101
Created May 21, 2012 12:26
ghostplus if ruining it for everybody
>gem search -r ghostplus
*** REMOTE GEMS ***
ghostplus (0.0.1)
>gem search -r -d ghostplus
*** REMOTE GEMS ***
@djberg96
djberg96 / def_external.rb
Created May 21, 2012 21:01
Default external encoding for MRI vs JRuby on Windows
jruby 1.6.7.2 (ruby-1.8.7-p357) (2012-05-01 26e08ba) (Java HotSpot(TM) Client VM 1.6.0_31) [Windows 7-x86-java]
c:\Users\djberge>jruby --1.9 -S jirb
irb(main):001:0> Encoding.default_external
=> #<Encoding:Windows-1252>
ruby 1.9.3p194 (2012-04-20 revision 35410) [i386-mswin32_100]
c:\Users\djberge>irb
irb(main):001:0> Encoding.default_external
@djberg96
djberg96 / folder.rb
Created May 23, 2012 12:12
JRuby's Encoding.default_external is causing trouble
require 'ffi'
class Windows
extend FFI::Library
ffi_lib :shell32
attach_function :SHGetFolderPath, :SHGetFolderPathW, [:ulong, :int, :ulong, :ulong, :buffer_out], :ulong
def self.folder
buf = 0.chr * 1024
@djberg96
djberg96 / scope_test.rb
Created May 25, 2012 14:46
Rescoping a class within a module
module Foo
end
class Bar
def initialize
puts "Hello, this is Bar"
end
end
class Baz