Skip to content

Instantly share code, notes, and snippets.

🎯
many things to get none

Karol Bucek kares

🎯
many things to get none
View GitHub Profile
@kares
kares / password.rb
Created Jan 12, 2016 — forked from steakknife/password.rb
get password - Ruby - any platform - no gems needed
View password.rb
# Copyright 2012-2013 Barry Allard <barry.allard@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
@kares
kares / current_thread_aware_formatter.rb
Created Oct 19, 2015
Logger::Formatter aware of Thread.current for JRuby
View current_thread_aware_formatter.rb
require 'jruby'
class CurrentThreadAwareFormatter < Logger::Formatter
FORMAT = "%s [%5s] {%s} -- %s\n".freeze
def call(severity, time, progname, msg)
thread = Thread.current
thread_id = JRuby.reference(thread).getNativeThread.to_s
thread_id << ' ' << ( thread[:name] || thread.to_s )
FORMAT % [format_datetime(time), severity, thread_id, msg2str(msg)]
end
end
@kares
kares / pool.rb
Last active Oct 14, 2015
AR 3.2 pool patch for less contention on release_connection
View pool.rb
::ActiveRecord::ConnectionAdapters::ConnectionPool.class_eval do
def release_connection(with_id = current_connection_id)
#synchronize do
conn = @reserved_connections.delete(with_id)
checkin conn, true if conn
#end
end
def checkin(conn, on_release = nil)
@kares
kares / celluloid.rb
Last active Aug 29, 2015
celluloid InternalPool backport from master (due inproper synchronization) http://git.io/9NV23Q
View celluloid.rb
require 'celluloid/internal_pool'
# NOTE: this also avoids JRuby bug with ThreadGroup#list !
# require 'celluloid' likely happened already :
if Celluloid.internal_pool
Celluloid.internal_pool.shutdown
Celluloid.internal_pool = nil
end
View 0_logging_unnecesary_synchronize.rb
require 'logging'
module Logging
# require 'logging/repository'
# class Repository
# # include Singleton
#
# def initialize; require 'thread_safe'
# # @h = {:root => ::Logging::RootLogger.new}
# @h = ThreadSafe::Cache.new
@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
@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 / changes.md
Last active Aug 29, 2015
JRuby - (mostly) some of the concurrency related - changes since 1.7.4
View changes.md
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 / 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
You can’t perform that action at this time.