Skip to content

Instantly share code, notes, and snippets.

View dekz's full-sized avatar
🐒
β šβ β ‰β •β ƒ

Jacob Evans dekz

🐒
β šβ β ‰β •β ƒ
View GitHub Profile
@dekz
dekz / socket_http.rb
Created November 24, 2012 11:36
God using drbhttp
module God
class Socket
def self.socket_file(port)
"localhost:#{port}"
end
def self.socket(port)
"drbhttp://#{self.socket_file(port)}"
end
end
@dekz
dekz / autoviv.rb
Created November 10, 2012 00:37
autovivify
z = {}
z[:b][:c][:d] = 'e'
# NoMethodError: undefined method `[]' for nil:NilClass
hash_new = proc { Hash.new { |hash, key| hash[key] = Hash.new(&hash.default_proc) } }
a = hash_new.call
a[:b][:c][:d] = 'e'
a
# => {:b=>{:c=>{:d=>"e"}}}
/Users/dekz % irb
irb(main):001:0> IRB.CurrentContext.io
=> #<IRB::ReadlineInputMethod:0x007fd723025420 @file_name="(line)", @line_no=1, @line=[nil, "IRB.CurrentContext.io\n"], @eof=false, @stdin=#<IO:fd 0>, @stdout=#<IO:fd 1>, @prompt="irb(main):001:0> ">
{"job"=>:start, "id"=>"CsgL2Asw8gUjFCs", "run"=>{"proc"=>"proc { |name, word| puts(\"Hi \#{name} you \#{word.read}\") }", "args"=>["jacob", #<File:./utils.rb>]}}
worker::goO3G1bP4HORHhX: Run CsgL2Asw8gUjFCs
Hi jacob you require 'openssl'
class Utils
def self.repeat_every(interval)
Thread.new do
loop do
start_time = Time.now
@dekz
dekz / eval_hacks2.rb
Created September 5, 2012 23:29
Executing a proc in an eval scope
# We need sourcify to turn the Proc into a string which can then be evaluated in the binding itself.
require 'sourcify'
b = nil
eval "a='hello there';b=binding"
def eval_with binding, &b
binding.eval "#{b.to_source}.call"
end
@dekz
dekz / eval_hacks.rb
Created September 5, 2012 23:00
Accessing eval scope
# 1.9 eval executes in its own scope, no way to get local variables which may have been assigned.
# Thankfully eval has access to its parent execution scope, so we can assigned it inside eval!
b = nil
eval "a=:b;b=binding"
p b.eval "a"
# => :b
# puts a # will fail
@dekz
dekz / jre-7u6-macosx-x64.dmg.tree
Created August 14, 2012 22:44
jre-7u6-macosx-x64.dmg Contents
.
β”œβ”€β”€ Java\ 7\ Update\ 06\ Folder
β”‚Β Β  └── Contents
β”‚Β Β  β”œβ”€β”€ Frameworks
β”‚Β Β  β”‚Β Β  └── Sparkle.framework
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ Headers -> Versions/Current/Headers
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ Resources -> Versions/Current/Resources
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ Sparkle -> Versions/Current/Sparkle
β”‚Β Β  β”‚Β Β  └── Versions
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ A
@dekz
dekz / jdk-7u6-macosx-x64.dmg.tree
Created August 14, 2012 22:41
jdk-7u6-macosx-x64.dmg contents
.
β”œβ”€β”€ JDK\ 7\ Update\ 06\ Folder
β”‚Β Β  └── Contents
β”‚Β Β  β”œβ”€β”€ Home
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ COPYRIGHT
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ LICENSE
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ README.html
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ THIRDPARTYLICENSEREADME-JAVAFX.txt
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ THIRDPARTYLICENSEREADME.txt
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ bin
@dekz
dekz / jruby-1.6.7
Created July 16, 2012 03:22
JRuby __jtrap
done
#<NoMethodError: undefined method `__jtrap' for #<Zab:0x153b2cb>>
#<NoMethodError: undefined method `__jtrap' for #<Zab:0x3c63e8c>>
#<NoMethodError: undefined method `__jtrap' for #<Zab:0x2e694f12>>
#<NoMethodError: undefined method `__jtrap' for #<Zab:0x26dfe303>>
~/tmp % ruby -v
jruby 1.6.7 (ruby-1.8.7-p357) (2012-02-22 3e82bc8) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_31) [darwin-x86_64-java]
~/tmp % ruby zz.rb
Decimal.new is a Decimal object?: false
Modulo op class is BigDecimal
Times op class is BigDecimal
Div op class is BigDecimal