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 / jffi.diff
Last active May 7, 2020
Naive support for LD_PRELOAD in jffi and jnr-posix
View jffi.diff
diff --git a/src/main/java/com/kenai/jffi/Library.java b/src/main/java/com/kenai/jffi/Library.java
index 9ce61fd..6ec78e3 100644
--- a/src/main/java/com/kenai/jffi/Library.java
+++ b/src/main/java/com/kenai/jffi/Library.java
@@ -149,12 +149,17 @@ public final class Library {
* null if the library cannot be opened.
*/
public static final Library openLibrary(String name, int flags) {
+ final Foreign foreign = Foreign.getInstance();
+
@headius
headius / example.txt
Last active Apr 28, 2020
Example of module appearing to be open when it is not (https://github.com/jruby/jruby/issues/6189)
View example.txt
[] ~/projects/jruby $ cat ModuleThing.java
public class ModuleThing {
public static void main(String[] args) throws Exception {
Class cls = sun.nio.ch.NativeThread.class;
java.lang.reflect.Method method = cls.getDeclaredMethod("signal", long.class);
System.out.println("isOpen: " + cls.getModule().isOpen(cls.getPackage().getName(), ModuleThing.class.getModule()));
method.setAccessible(true);
}
}
@headius
headius / gist:36cfe66789f9bc1cf98c0ffac0265271
Last active Apr 17, 2020
Zero-cost oneshot line coverage in JRuby 9.3
View gist:36cfe66789f9bc1cf98c0ffac0265271
[] ~/projects/jruby $ jruby -Xcompile.invokedynamic -Xfixnum.cache=false -e 'load "../bench2018/bench_mandelbrot.rb"'
0.14059200000000002
0.14031
0.14225
0.139491
0.132145
0.143139
0.132212
0.134711
0.13967700000000002
@headius
headius / famous_chili.md
Last active Apr 15, 2020
Famous Chili by Marlys Nutter
View famous_chili.md

Ingredients:

  • 1 lb ground meat
  • 30 oz canned kidney beans
  • (2) 14.5 oz cans Del Monte diced tomatoes with onion and green pepper
  • 1 1/2 tsp cumin
  • 1/2 tsp garlic powder
  • 1 green pepper chopped to taste
  • 1 onion chopped to taste
  • 1 can butter beans
@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
You can’t perform that action at this time.