Skip to content

Instantly share code, notes, and snippets.

View shugo's full-sized avatar

Shugo Maeda shugo

  • NaCl
  • Matsue, Shimane, Japan
View GitHub Profile
@shugo
shugo / test.rb
Created October 31, 2012 08:00
using example
module X
refine Fixnum do
def foo; p :foo; end
end
end
module Y
refine Fixnum do
def bar; p :bar; end
end
@shugo
shugo / gist:3998167
Created November 2, 2012 01:53
test_tls_v1_2 fails
$ ruby -v test/openssl/test_ssl.rb
ruby 2.0.0dev (2012-11-01 trunk 37417) [i686-linux]
Run options:
# Running tests:
...............test/openssl/test_ssl.rb:24: warning: SSL session is not started yet.
............/home/shugo/local/lib/ruby/2.0.0/openssl/buffering.rb:53: warning: SSL session is not started yet.
..E...
@shugo
shugo / t.rb
Created November 11, 2012 01:13
module_eval with refinements confuses inline method cache
class C
def foo
"original"
end
end
module M
refine C do
def foo
"refined"
@shugo
shugo / inline_method_cache_fix.diff
Created November 11, 2012 02:04
fix inline method cache for refinements
diff --git a/compile.c b/compile.c
index 16bfcef..eb824ca 100644
--- a/compile.c
+++ b/compile.c
@@ -954,6 +954,7 @@ new_callinfo(rb_iseq_t *iseq, ID mid, int argc, VALUE block, unsigned long flag)
}
}
ci->vmstat = 0;
+ ci->refinements = Qundef;
ci->blockptr = 0;
@shugo
shugo / gist:4224846
Created December 6, 2012 14:34
test_timeout_immediate2 fails
$ ./ruby test/test_timeout.rb
Run options:
# Running tests:
[6/6] TestTimeout#test_timeout_immediate2 = 0.50 s
1) Failure:
test_timeout_immediate2(TestTimeout) [test/test_timeout.rb:65]:
[RuntimeError] exception expected, not
Class: <#<Class:0x21da1fbc>>
@shugo
shugo / gist:4508172
Created January 11, 2013 05:27
RubySpec 0F1E
$ ~/src/mspec/bin/mspec -t ruby
ruby 2.0.0dev (2013-01-11 trunk 38771) [i686-linux]
.......................................................................................................................................................................................................................................E....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
@shugo
shugo / gist:4671992
Created January 30, 2013 09:40
rsock_unix_sockaddr_len
socklen_t
rsock_unix_sockaddr_len(VALUE path)
{
#ifdef __linux__
if (RSTRING_PTR(path)[0] == '\0') {
/* abstract namespace; see unix(7) for details. */
return (socklen_t) offsetof(struct sockaddr_un, sun_path) +
RSTRING_LEN(path);
}
else {
@shugo
shugo / gist:5794389
Last active December 18, 2015 13:59
= $SAFE=4を使わないでください
$SAFE=4は一部の方にサンドボックスとして利用されていますが、ブラックリスト方式であるため潜在的な脆弱性が存在します。
このため、doc/security.rdocにも記述されているとおり、サンドボックスとしての利用は推奨されていません。
また、Ruby 2.1では$SAFE=4の機能は削除され、$SAFEに4以上の値を代入すると例外が発生するようになります。
今後は、$SAFE=4を使用しないようにお願いします。
= Don't use $SAFE=4
@shugo
shugo / class_def_return_class.diff
Created September 28, 2013 06:26
A quick hack making class definitions to return classes
diff --git a/compile.c b/compile.c
index 2285d28..ace1296 100644
--- a/compile.c
+++ b/compile.c
@@ -547,6 +547,10 @@ rb_iseq_compile_node(VALUE self, NODE *node)
ADD_INSN1(ret, 0, throw, INT2FIX(0) /* continue throw */ );
}
else {
+ if (iseq->type == ISEQ_TYPE_CLASS) {
+ ADD_INSN(ret, iseq->compile_data->last_line, pop);
@shugo
shugo / ruby-build.20140125230823.3913.log
Created January 29, 2014 08:35
ruby-build failed on FreeBSD 10
/tmp/ruby-build.20140125230823.3913 ~
HTTP/1.1 200 OK
Content-Type: binary/octet-stream
Content-Length: 15076389
Connection: keep-alive
Date: Sun, 12 Jan 2014 22:08:31 GMT
Last-Modified: Wed, 25 Dec 2013 16:03:08 GMT
ETag: "9e6386d53f5200a3e7069107405b93f7"
Accept-Ranges: bytes
Server: AmazonS3