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
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 :)
begin
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
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
#ruby=1.9.3
# Gemfile header for using JRuby (on Heroku) as well as MRI locally
source 'https://rubygems.org'
if ENV["JRUBY"] || RUBY_PLATFORM == "java"
# https://devcenter.heroku.com/articles/ruby-support#ruby-versions
ruby '1.9.3', engine: 'jruby', engine_version: '1.7.10'
else
ruby '1.9.3'
end
@kares
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....
end
# print data in flat format to STDOUT :
profile_printer = JRuby::Profiler::FlatProfilePrinter.new(profile_data)
profile_printer.printProfile(STDOUT)
@kares
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
Thread.new {
begin
super(name)
rescue => e
if @_response.committed?
begin
@kares
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)
c.verify!
c
end
@kares
kares / changes.md
Last active Aug 29, 2015
JRuby - (mostly) some of the concurrency related - changes since 1.7.4
View changes.md
@kares
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|
x.report("java.lang.System.get_property [#{TIMES}x]") do
TIMES.times do
java.lang.System.get_property('jars.skip') == 'true'
end
@kares
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.