Skip to content

Instantly share code, notes, and snippets.

looking for new opportunities - let's have them!

Karol Bucek kares

looking for new opportunities - let's have them!
Block or report user

Report or block kares

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
View adapter_compat.rb
# require 'active_record/connection_adapters/abstract_adapter'
# Adapter (connection) compatibility methods for AR 2.3 as required
# by the (AR 3.2) back-ported ConnectionPool implementation.
class ActiveRecord::ConnectionAdapters::AbstractAdapter
include MonitorMixin
# HACK: to initialize the monitor, in 3.2 #initialize calls the
# MonitorMixin#initialize by doing super() but in 2.3 it does not
# we do about the same here by overriding Adapter#new :
kares / talkaholic_logger.rb
Last active Aug 29, 2015
Silencing a Rails.logger is (still) not thread-safe ... these initializers will try it's best to avoid your loggers being silenced (and more)! Must have for JRuby.
View talkaholic_logger.rb
# put this under **#{Rails.root}/config/initializers** directory
# `silence` is like Chuck Norris you can't kill it, this biuty got yet again
# re-invented in Rails 4 right after Logger#silence got deprecated in 3.2 :)
require 'active_support/logger'
require 'active_support/logger_silence'
ActiveSupport::Logger.silencer = false # silence simply yields
# if 'active_support/core_ext/logger' is loaded
kares / Gemfile
Created Mar 7, 2014
Gemfile header for using JRuby (on Heroku) as well as MRI locally (first line to override RVM's parsing)
View Gemfile
# Gemfile header for using JRuby (on Heroku) as well as MRI locally
source ''
if ENV["JRUBY"] || RUBY_PLATFORM == "java"
ruby '1.9.3', engine: 'jruby', engine_version: '1.7.10'
ruby '1.9.3'
kares / jruby-profile-to-string.rb
Last active Aug 29, 2015 — forked from danlucraft/jruby-profile-to-string.rb
printing JRuby profiler data output (examples)
View jruby-profile-to-string.rb
require 'jruby/profiler'
profile_data = JRuby::Profiler.profile do
# code to be profiled....
# print data in flat format to STDOUT :
profile_printer =
kares / response_process.rb
Last active Aug 29, 2015
ActionController::Live::Response partial <code>process</code> that happens on every "live" request
View response_process.rb
error = nil
# This processes the action in a child thread. It lets us return the
# response code and headers back up the rack stack, and still process
# the body in parallel with sending data to the client {
rescue => e
if @_response.committed?
kares / serial_port_jruby.rb
Last active Aug 29, 2015
re-implementing "native" gem APIs (sample)
View serial_port_jruby.rb
# Emulates the SerialPort class that uses a native C extension.
class SerialPort < IO
load "java/jna.jar"
load "java/purejavacomm-0.0.21.jar"
java_import 'purejavacomm.CommPortIdentifier'
def initialize(port)
# do what SerialPort C does on Windows (for compat): 0 -> 'COM1'
port = "COM#{port + 1}" if port.is_a?(Integer) && windows?
View no-conn-pool.rb
# Monkeypatch to disable connection pooling in ActiveRecord
module ActiveRecord
module ConnectionAdapters
class ConnectionPool
def checkout
c = ActiveRecord::Base.send(spec.adapter_method, spec.config.dup)
kares /
Last active Aug 29, 2015
JRuby - (mostly) some of the concurrency related - changes since 1.7.4
kares / benchmark_java_lang_System_getProperty.rb
Created Dec 3, 2014
JRuby 1.7.16 benchmark for java.lang.System.getProperty
View benchmark_java_lang_System_getProperty.rb
require 'benchmark'
TIMES = 10_000
Benchmark.bmbm do |x|"java.lang.System.get_property [#{TIMES}x]") do
TIMES.times do
java.lang.System.get_property('jars.skip') == 'true'
kares / celluloid_stack_dump.rb
Created Dec 22, 2014
Celluloid.stack_dump tunings on JRuby
View celluloid_stack_dump.rb
require 'celluloid/stack_dump'
module Celluloid
class StackDump
class ActorState
attr_accessor :thread_name, :thread_id
def dump
You can’t perform that action at this time.