Skip to content

Instantly share code, notes, and snippets.

View kares's full-sized avatar

Karol Bucek kares

View GitHub Profile
@kares
kares / jruby-10.0.5.0
Created May 7, 2026 09:51
numbers for Java "block-to-interface" improvements: https://github.com/jruby/jruby/pull/9401
jruby 10.0.5.0 (3.4.5) 2026-04-06 5db1ba72f3 Java HotSpot(TM) 64-Bit Server VM 21.0.9+7-LTS-338 on 21.0.9+7-LTS-338 +indy +jit [x86_64-linux]
----- single-threaded -----
Rehearsal ---------------------------------------------------------------------------
Supplier Optional#orElseGet 12.350000 0.440000 12.790000 ( 6.153782)
Function Optional#map 10.320000 0.300000 10.620000 ( 6.399324)
Predicate Optional#filter 9.130000 0.220000 9.350000 ( 5.944928)
IntConsumer OptionalInt#ifPresent 9.010000 0.230000 9.240000 ( 5.622397)
DoubleSupplier OptionalDouble#orElseGet 9.990000 0.180000 10.170000 ( 5.743960)
BiFunction Map#compute 9.050000 0.110000 9.160000 ( 5.596288)
BiFunction Map#computeIfPresent 8.960000 0.150000 9.110000 ( 5.528440)
# reproducer for https://github.com/jruby/jruby-openssl/issues/236
# If a certificate has two trust paths, jruby doesn't prioritize using non expired certificates, while CRuby (openssl 1.1.1+) does
# In this reproducer we have a leaf certificate with two possible chains:
# a) leaf -> intermediate cert A -> ISRG Root X1 cross-signed by (expired) DST ROOT CA X3 -> (expired) DST ROOT CA X3
# b) leaf -> intermediate cert B -> ISRG Root X1
# JRuby will produce chain a) causing an error, while CRuby produces a valid chain b)
require 'openssl'
require 'net/http'
def cert_from_url(url)
@kares
kares / logstash.conf
Last active June 2, 2021 10:34 — forked from andsel/sender.rb
Simple RabbitMQ sender
input {
rabbitmq {
codec => plain
host => "localhost"
key => "#"
exchange => "sysmsg" # string (optional)
queue => 'dur-no-policy-4'
durable => true
@kares
kares / jit_max_force.rb
Created September 27, 2019 12:29
force -Xjit.max setting on JRuby <= 9.2.8
# force -Xjit.max setting on JRuby <= 9.2.8
#
# forcing is not perfect -
# counter for existing methods will still keep incrementing but compilation is expected to halt
#
# @note -Xjit.max has no effect on JRuby 9K - its only enforced since 9.2.9
#
(Class.new do
require 'ffi'
module MemoryLock
extend FFI::Library
ffi_lib FFI::Library::LIBC
# int mlockall(int flags);
attach_function :mlockall, [:int], :int
# int munlockall(void);
attach_function :munlockall, [], :int
@kares
kares / to_bool.rb
Created July 23, 2019 16:53
`params[:foo].to_bool`, `ENV['bar'].to_bool` and others
# frozen_string_literal: true
class Object
# Convert to a boolean value (special cased for String/Numeric).
# @return [Boolean] false for nil and false ('true', '1' return true and 0 returns false)
# @see String#to_bool
# @see Numeric#to_bool
def to_bool
!!self
end
@kares
kares / stack.dump
Created January 24, 2019 11:03
left-over threads
Thread 0x1a1962 ():
/usr/local/rvm/rubies/jruby-9.1.17.0/lib/ruby/stdlib/monitor.rb:111:in `wait'
/usr/local/rvm/rubies/jruby-9.1.17.0/lib/ruby/stdlib/monitor.rb:111:in `wait'
/srv/phone/apptastic/shared/bundle/jruby/2.3.0/gems/future-resource-1.1.0/lib/future-resource.rb:66:in `resource'
/usr/local/rvm/rubies/jruby-9.1.17.0/lib/ruby/stdlib/monitor.rb:214:in `mon_synchronize'
/srv/phone/apptastic/shared/bundle/jruby/2.3.0/gems/future-resource-1.1.0/lib/future-resource.rb:65:in `resource'
/srv/phone/apptastic/shared/bundle/jruby/2.3.0/gems/future-resource-1.1.0/lib/future-resource.rb:64:in `timeout'
/srv/phone/apptastic/shared/bundle/jruby/2.3.0/gems/future-resource-1.1.0/lib/future-resource.rb:64:in `resource'
/srv/phone/apptastic/shared/bundle/jruby/2.3.0/bundler/gems/adhearsion-2676734110e0/lib/adhearsion/rayo/component/component_node.rb:56:in `complete_event'
/srv/phone/apptastic/shared/bundle/jruby/2.3.0/bundler/gems/adhearsion-2676734110e0/lib/adhearsion/call_controller.rb:230:in `execute_compon
@kares
kares / monitor_daemon.rb
Created January 23, 2019 08:17
Daemon thread that logs memory usage an load (for JRuby)
require 'logger'
class MonitorDaemon
LOG_FILE = 'monitor.log'
LOG_FILES_MAX = 10 * 1024 * 1024 # 10MB
LOG_FILES_KEEP = 10 # keep 10 (max 100MB)
LOGGER = begin
if $servlet_context && ENV_JAVA['catalina.base'] && # {tomcat_base}/logs
@kares
kares / assets.rb
Last active November 29, 2016 09:32
SASS (asset) path/url functions patch to make sure non absolute /assets URLs are returned (e.g. for bootstrap-sass)
if File.basename($0) == 'rake' && ARGV.include?('assets:precompile') # Rails.env.production?
puts "patching sass functions to return relative asset paths" if $VERBOSE
begin
require 'sprockets/sass/functions'
sass_functions = Sprockets::Sass::Functions
Autoload::Sass::Script rescue nil # loading
rescue LoadError # 2.x
require 'sprockets/sass_functions'
@kares
kares / heap-dump.backtrace.js
Last active November 24, 2016 05:50
Extract relevant (partial backtrace) information from heap-dump using OQL
map( heap.objects('org.jruby.runtime.ThreadContext'), function(ctx) {
var str = toHtml(ctx) + " oid: " + objectid(ctx);
str += " ";
var toHtmlObj = function(obj) { return "<br> " + toHtml(obj); };
try {
//return str + doObjPath(ctx, toHtmlObj, 'thread', 'threadImpl', 'nativeThread', 'referent');
str += resolveObjPath(ctx, 'thread', 'threadImpl', 'nativeThread', 'referent', 'name').toString();
str += '<br> backtraceIndex = ' + ctx.backtraceIndex;