Skip to content

Instantly share code, notes, and snippets.

View JPACollision.java
public class JPACollision {
public static void main(String[] args) {
byte[] bytes1 = new byte[] {
0x58, (byte) 0xa1, (byte) 0x82, 0x6c, 0x00, 0x00, (byte) 0xb1, 0x3b
};
byte[] bytes2 = new byte[] {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
byte[] bytes12 = concat(bytes1, bytes2);
byte[] bytes21 = concat(bytes2, bytes1);
View gist:2951537
% cat Switch.java
public class Switch {
public static void main(String[] args) {
switch(args[0]) {
case "abc":
break;
default:
break;
}
}
View gist:2922421
% mkdir foo
% echo 'p [__FILE__, __LINE__, File.read(File.expand_path("./baz.txt", File.dirname(__FILE__)))]' > foo/bar.rb
% echo hello,world > foo/baz.txt
% jar -cf foo.jar foo
% rm -rf foo
% jruby -e '$LOAD_PATH << "foo.jar"; require "foo/bar"'
["jar:file:foo.jar!/foo/bar.rb", 1, "hello,world\n"]
% mkdir foo
@nahi
nahi / gist:2617669
Created May 6, 2012
23 is the magic number :)
View gist:2617669
# Run this with trunk (Tested with ae4fa795)
1.upto(24).each do |size|
p size
File.open(IO::NULL, "w") do |w|
File.open(__FILE__) do |r|
buf = ''
while !r.read(size, buf).nil?
w << buf # It works when you remove this line.
end
end
@nahi
nahi / CRuby
Created Apr 24, 2012 — forked from shugo/CRuby
new vs mutation in Ruby
View CRuby
% jruby -v --server -X+C benchmark_new.rb
jruby 1.7.0.dev (ruby-1.9.3-p139) (2012-04-24 6a30d22) (Java HotSpot(TM) 64-Bit Server VM 1.7.0_03) [linux-amd64-java]
Rehearsal ------------------------------------------
new 1.290000 0.110000 1.400000 ( 0.974000)
color= 0.200000 0.010000 0.210000 ( 0.172000)
--------------------------------- total: 1.610000sec
user system total real
new 0.760000 0.000000 0.760000 ( 0.663000)
color= 0.160000 0.000000 0.160000 ( 0.133000)
View gist:2425480
% bin/mruby -v
mruby: malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed.
zsh: abort bin/mruby -v
View gist:2342386
% ant clean install -DskipTests=true -DuseIndy=true
Buildfile: /home/nahi/git/groovy-git/build.xml
Trying to override old definition of task javac
clean:
[delete] Deleting directory /home/nahi/git/groovy-git/target
-excludeLegacyAntVersion:
-checkAntVersion:
View gist:2236839
diff --git a/src/org/jruby/runtime/invokedynamic/InvokeDynamicSupport.java b/src/org/jruby/runtime/invokedynamic/InvokeDynamicSupport.java
index 17e442c..13de470 100644
--- a/src/org/jruby/runtime/invokedynamic/InvokeDynamicSupport.java
+++ b/src/org/jruby/runtime/invokedynamic/InvokeDynamicSupport.java
@@ -426,8 +426,11 @@ public class InvokeDynamicSupport {
getValue = filterReturnValue(getValue, nullToNil);
// prepare fallback
- MethodHandle fallback = findStatic(InvokeDynamicSupport.class, "getVariableFallback", methodType(IRubyObject.class, VariableSite.class, IRubyObject.class));
- fallback = fallback.bindTo(site);
View gist:2225559
% for i in {1..5}; do JAVA_HOME=/home/nahi/java/jdk1.6.0_31 jruby --server -X+C bench/bench.rb resource/010000.csv; done
150.0
141.0
141.0
169.0
179.0
% for i in {1..5}; do JAVA_HOME=/home/nahi/java/jdk1.7.0_03 jruby --server -X+C bench/bench.rb resource/010000.csv; done
115.0
103.0
122.0
View gist:2203945
% sbt assembly
[info] Loading project definition from /home/nahi/git/javaone-tokyo-bof-scala/project
[info] Set current project to javaone-tokyo-2012-jvm-bof (in build file:/home/nahi/git/javaone-tokyo-bof-scala/)
[info] Updating {file:/home/nahi/git/javaone-tokyo-bof-scala/}default-6484a5...
[info] Resolving org.scala-lang#scala-library;2.9.1 ...
[info] Resolving com.twitter#util_2.9.1;1.12.13 ...
[info] Resolving com.twitter#util-codec_2.9.1;1.12.13 ...
[info] Resolving commons-codec#commons-codec;1.5 ...
[info] Resolving com.twitter#util-core_2.9.1;1.12.13 ...
[info] Resolving com.twitter#util-zk_2.9.1;1.12.13 ...