Skip to content

Instantly share code, notes, and snippets.

Charles Oliver Nutter headius

Block or report user

Report or block headius

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@headius
headius / flip_flop_fractal.rb
Created Feb 18, 2020
Julia set fractal generated using Ruby flip-flops
View flip_flop_fractal.rb
w, h = 44, 54
c = 7 + 42 * w
a = [0] * w * h
g = d = 0
f = proc do |n|
a[c] += 1
o = a.map {|z| " :#"[z, 1] * 2 }.join.scan(/.{#{w * 2}}/)
puts "\f" + o.map {|l| l.rstrip }.join("\n")
d += 1 - 2 * ((g ^= 1 << n) >> n)
c += [1, w, -1, -w][d %= 4]
@headius
headius / LambdaStack.java
Created Feb 17, 2020
Example stack trace for a simple lambda
View LambdaStack.java
public class LambdaStack {
public static void main(String[] args) {
Runnable r = () -> { java.util.concurrent.locks.LockSupport.park(); };
r.run();
}
}
@headius
headius / gist:1cc69ace1dbfffa1f4339b97ad85f810
Created Jan 26, 2020
Caching compiled script bytecode for subsequent runs
View gist:1cc69ace1dbfffa1f4339b97ad85f810
[] ~/projects/jruby $ CLASSPATH=~/.ir jruby -Xcompile.cache.classes -X+C -S gem -v
no class found for script uri:classloader:/jruby/java.rb
saved compiled script as /Users/headius/.ir/uri_3a_classloader_3a_/jruby/java.class
no class found for script uri:classloader:/jruby/java/core_ext.rb
saved compiled script as /Users/headius/.ir/uri_3a_classloader_3a_/jruby/java/core_ext.class
no class found for script uri:classloader:/jruby/java/core_ext/module.rb
saved compiled script as /Users/headius/.ir/uri_3a_classloader_3a_/jruby/java/core_ext/module.class
no class found for script uri:classloader:/jruby/java/core_ext/object.rb
saved compiled script as /Users/headius/.ir/uri_3a_classloader_3a_/jruby/java/core_ext/object.class
no class found for script uri:classloader:/jruby/java/java_ext.rb
@headius
headius / gist:39cafe3307db887285aba3000ad3c19f
Created Jan 24, 2020
Using JDB to debug Ruby and JRuby code together
View gist:39cafe3307db887285aba3000ad3c19f
[] ~/projects/jruby $ jdb -Djruby.home=`pwd` -sourcepath `pwd` -classpath lib/jruby.jar
Initializing jdb ...
> stop at blah:1
Deferring breakpoint blah:1.
It will be set after the class is loaded.
> run org.jruby.Main blah.rb
run org.jruby.Main blah.rb
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
>
@headius
headius / tikka_masala.md
Last active Mar 1, 2020
Chicken Tikka Masala
View tikka_masala.md

Chicken tikka masala

Time: 50 minutes

Serves: 4-6

Ingredients

@headius
headius / gist:a412702789dfd1d321a594269866bb46
Created Jan 22, 2020
Example of JRuby 9k AOT without JVM bytecode compilation
View gist:a412702789dfd1d321a594269866bb46
[] ~/projects/jruby $ cat blah.rb
def foo
puts "hello"
end
foo
[] ~/projects/jruby $ jruby --dev -S jrubyc blah.rb
[] ~/projects/jruby $ javap -c -private blah
@headius
headius / .diff
Created Jan 14, 2020
Change RubyBasicObject.to_a to IRubyObject return
View .diff
diff --git a/core/src/main/java/org/jruby/RubyBasicObject.java b/core/src/main/java/org/jruby/RubyBasicObject.java
index 5ec44d5129..c0e5121211 100644
--- a/core/src/main/java/org/jruby/RubyBasicObject.java
+++ b/core/src/main/java/org/jruby/RubyBasicObject.java
@@ -2571,7 +2571,7 @@ public class RubyBasicObject implements Cloneable, IRubyObject, Serializable, Co
*
* The default to_a method is deprecated.
*/
- public RubyArray to_a(ThreadContext context) {
+ public IRubyObject to_a(ThreadContext context) {
@headius
headius / output.txt
Created Jan 8, 2020
Comparison of JRuby stack traces with and without Java frames
View output.txt
[] ~/projects/jruby $ jruby -e 'def foo; bar; end; def bar; 1.times { eval "raise" }; end; foo'
RuntimeError: No current exception
bar at (eval):1
eval at org/jruby/RubyKernel.java:1048
bar at -e:1
bar at -e:1
foo at -e:1
<main> at -e:1
[] ~/projects/jruby $ jruby -Xbacktrace.style=full -e 'def foo; bar; end; def bar; 1.times { eval "raise" }; end; foo'
@headius
headius / synchronize.diff
Created Dec 2, 2019
Patch to naively synchronize RubyHash to protect direct-addressing data store
View synchronize.diff
diff --git a/core/src/main/java/org/jruby/RubyHash.java b/core/src/main/java/org/jruby/RubyHash.java
index 231971b6be..a17a473e0a 100644
--- a/core/src/main/java/org/jruby/RubyHash.java
+++ b/core/src/main/java/org/jruby/RubyHash.java
@@ -697,7 +697,7 @@ public class RubyHash extends RubyObject implements Map {
IRubyObject otherKey = entryKey(entries, index);
int otherHash = hashes[index];
- if (internalKeyExist(key, hash, otherKey, otherHash)) return bin;
+ if (internalKeyExist(key, hash, otherKey, otherHash, isComparedByIdentity())) return bin;
View ack_problem.md

The problem:

For an HTTP 1.1 request. JRuby's packet sequence goes like this:

  1. The request is sent from the client
  2. The server sends a packet back with the 200 OK, headers, and ack of the request
  3. The client sends an ack of the headers
  4. The server sends the body of the request

On Linux with delayed ACK, there's around 0.04 seconds between (2) and (3), which drastically reduces throughput.

You can’t perform that action at this time.