Skip to content

Instantly share code, notes, and snippets.

View nrk's full-sized avatar
🤔
はい、猫のように見えます。

Daniele Alessandri nrk

🤔
はい、猫のように見えます。
View GitHub Profile
@nrk
nrk / gist:13191
Created September 26, 2008 20:12
all_foos = []
class Foo
def initialize(foos)
foos << self
end
end
p all_foos # => []
C:\ironruby\bin>ir
IronRuby 1.0.0.0 on .NET 2.0.50727.1433
Copyright (c) Microsoft Corporation. All rights reserved.
Note that local variables do not work today in the console.
As a workaround, use globals instead (eg $x = 42 instead of x = 42).
>>> ENV['GEM_PATH'] = 'C:\\Programmi\\Ruby\\lib\\ruby\\gems\\1.8\\'
=> "C:\\Programmi\\Ruby\\lib\\ruby\\gems\\1.8\\"
>>> require 'rubygems'
@nrk
nrk / gist:31175
Created December 2, 2008 16:53
A function in Lua similar to PHP's print_r
-- A function in Lua similar to PHP's print_r, from http://luanet.net/lua/function/print_r
function print_r ( t )
local print_r_cache={}
local function sub_print_r(t,indent)
if (print_r_cache[tostring(t)]) then
print(indent.."*"..tostring(t))
else
print_r_cache[tostring(t)]=true
if (type(t)=="table") then
handlers := Map clone
handlers atPut("reset", method(
"reset"
))
handlers atPut("compile", method(fun_source,
Compiler messageForString(fun_source) doInContext(self)
))
@nrk
nrk / gist:34875
Created December 11, 2008 21:10
The "forward" slot in the io language has the same purpose of "method_missing" in Ruby
Nrk := Object clone do (
forward := method("Method called: #{call message name}" interpolate println)
)
Nrk foo("bar") # prints "Method called: foo"
@nrk
nrk / T002.rb
Created January 2, 2009 11:49
Problems with Mutex and ConditionVariable under IronRuby
# code taken from http://www.rubycentral.com/pickaxe/tut_threads.html#UF
require 'thread'
mutex = Mutex.new
cv = ConditionVariable.new
a = Thread.new {
mutex.synchronize {
puts "A: I have critical section, but will wait for cv"
cv.wait(mutex)
@nrk
nrk / gist:45276
Created January 9, 2009 20:55
Wrong behaviour of $_ in IronRuby SVN r182
Ruby 1.8.6 (expected behaviour)
irb(main):001:0> gets
hello
=> "hello\n"
irb(main):002:0> $_
=> "hello\n"
Error 1 Friend access was granted to 'ClassInitGenerator,
PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9',
but the output assembly is named 'ClassInitGenerator, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null'. Try adding a reference to 'ClassInitGenerator,
PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9'
or changing the output assembly name to match. c:\Development\ironruby\Merlin\Main\bin\Debug
\IronRuby.dll ClassInitGenerator
Er
@nrk
nrk / ironruby_signing_cleaner.rb
Created January 23, 2009 15:38
Quickly-hacked script to remove all the signing stuff from the IronRuby VS solution
require 'rexml/document'
require 'ftools'
include REXML
# ---------------------------------------------------------------------------------------- #
GIT_ROOT = 'C:/Development/ironruby'
SUPPORT_DIR = File.join(GIT_ROOT, 'Merlin/Main/Support')
# ---------------------------------------------------------------------------------------- #
@nrk
nrk / hpricot_scan.rb
Created January 27, 2009 14:31
Hpricot on IronRuby
require 'hpricot'
xml =<<XML
<items>
<item number="1">
<name>item #1</name>
</item>
<item number="2">
<title>item #2</title>
</item>