Skip to content

Instantly share code, notes, and snippets.

View realjenius's full-sized avatar

R.J. Lorimer realjenius

View GitHub Profile
# Patched bench file from master running without fix
# jruby-2810 patch contains fixes to benchmarks & code changes.
# Mine was screwy because of bench file changing when I applied patch (not apples to apples)
rj-lorimers-macbook-pro:bench rjlorimer$ ../bin/jruby --server bench_io_foreach.rb
user system total real
IO.foreach(file) 15.171000 0.000000 15.171000 ( 15.107000)
user system total real
IO.foreach(file) 13.667000 0.000000 13.667000 ( 13.667000)
user system total real
IO.foreach(file) 13.144000 0.000000 13.144000 ( 13.144000)
With JRUBY-1.5.0-DEV, no patches:
rj-lorimers-macbook-pro:bench rjlorimer$ ../bin/jruby --server bench_io_foreach.rb
user system total real
IO.foreach(file) 15.171000 0.000000 15.171000 ( 15.107000)
user system total real
IO.foreach(file) 13.667000 0.000000 13.667000 ( 13.667000)
user system total real
IO.foreach(file) 13.144000 0.000000 13.144000 ( 13.144000)
user system total real
IO.foreach(file) 14.110000 0.000000 14.110000 ( 14.110000)
@realjenius
realjenius / HelloWorld.java
Created November 24, 2011 04:29
Spark Hello World
import static spark.Spark.*;
import spark.*;
public class HelloWorld {
public static void main(String[] args) {
get(new Route("/hello") {
@Override
public Object handle(Request request, Response response) {
@realjenius
realjenius / try1.java
Created November 24, 2011 04:41
try-with-resources-1
InputStream in;
try {
in = loadInput(...);
OutputStream out;
try {
out = createOutput(...);
copy(in, out);
}
finally {
if(out != null) {
@realjenius
realjenius / try2.java
Created November 24, 2011 04:41
try-with-resources-2
try (InputStream in = loadInput(...);
OutputStream out = createOutput(...) ){
copy(in, out);
}
catch (Exception e) {
// Problem reading and writing streams.
// Or problem opening one of them.
// If compound error closing streams occurs, it will be recorded on this exception
// as a "suppressedException".
}
@realjenius
realjenius / try3.ruby
Created November 24, 2011 04:42
try-with-resources-3
begin
File.open("myInput.txt", "r") do |in|
File.open("myOutput.txt", "w") do |out|
in.each_line do |line|
out << line.upcase << "\n"
end
end
end
rescue exc
# Exception occurred reading/writing!
@realjenius
realjenius / try4.java
Created November 24, 2011 04:42
try-with-resources-4
try {
File.read("myInput.txt", #{ in ->
File.write("myOutput.txt", #{ out ->
in.eachLine( #{ line ->
out.write(line.toUpperCase() + "\n");
});
});
});
}
catch(IOException e) {
@realjenius
realjenius / try5.java
Created November 24, 2011 04:42
try-with-resources-5
for(String line : in.eachLine()) {
out.write(line.toUpperCase() + "\n");
}
@realjenius
realjenius / mirah1.java
Created November 24, 2011 17:42
mirah-1
HashMap<String,String> myMap = new HashMap<String,String>();
@realjenius
realjenius / mirah2.java
Created November 24, 2011 17:43
mirah 2
var myMap = new HashMap<String,String>();