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)
@kares
kares / simpleFormat.js
Created December 14, 2010 08:56
simple_format Ruby on Rails helper in javascript
var simpleFormatRE1 = /\r\n?/g;
var simpleFormatRE2 = /\n\n+/g;
var simpleFormatRE3 = /([^\n]\n)(?=[^\n])/g;
function simpleFormat(str) {
var fstr = str;
fstr = fstr.replace(simpleFormatRE1, "\n") // \r\n and \r -> \n
fstr = fstr.replace(simpleFormatRE2, "</p>\n\n<p>") // 2+ newline -> paragraph
fstr = fstr.replace(simpleFormatRE3, "$1<br/>") // 1 newline -> br
fstr = "<p>" + fstr + "</p>";
return fstr;
@kares
kares / scheduled_job.rb
Created June 14, 2011 11:31
Recurring Job using Delayed::Job
#
# Recurring Job using Delayed::Job
#
# Setup Your job the "plain-old" DJ (perform) way, include this module
# and Your handler will re-schedule itself every time it succeeds.
#
# Sample :
#
# class MyJob
# include Delayed::ScheduledJob
@kares
kares / jruby-profile-to-string.rb
Last active June 5, 2024 10:25 — forked from danlucraft/jruby-profile-to-string.rb
printing JRuby profiler data output (examples)
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 / google-translate.js
Created November 15, 2011 07:38
Google Translate automatic for the people !
/**
* Google Translate automatic for the people !
*
* - visit http://translate.google.com make sure instant translation is on
* - set source and target languages and open firebug
* - copy your JSON translation object in (string key/value pairs) :
* var input = { "hello.world": "Hello World !", ... };
* - make sure non of your values to be translated end with '...' !
* - declare and output object where translations will be stored :
* var output = {};
@kares
kares / jquery.parseparams.js
Created May 5, 2011 11:28
jQuery.parseParams - parse query string paramaters into an object
/**
* $.parseParams - parse query string paramaters into an object.
*/
(function($) {
var re = /([^&=]+)=?([^&]*)/g;
var decodeRE = /\+/g; // Regex for replacing addition symbol with a space
var decode = function (str) {return decodeURIComponent( str.replace(decodeRE, " ") );};
$.parseParams = function(query) {
var params = {}, e;
while ( e = re.exec(query) ) {
@kares
kares / override.rb
Created November 12, 2013 17:14
#override (method) annotation for Ruby
# Allows for an #override annotation for your methods.
# Thus might help you during refactoring (method renaming) to assure methods
# expected to call a super will fail early during loading instead of runtime.
#
# Sample :
#
# class Message
# extend Override
#
# def do_send; end
@kares
kares / slow_query_log.rb
Last active March 23, 2022 09:40
ActiveRecord slow query logging in Rails ... setup using: config.slow_query_log_threshold_in_ms = 500
require 'active_record/log_subscriber'
class SlowQueryLog < ActiveSupport::LogSubscriber
if Rails.configuration.respond_to?(:slow_query_log_threshold_in_ms)
if @@threshold = Rails.configuration.slow_query_log_threshold_in_ms
@@threshold = @@threshold.to_i == 0 ? nil : @@threshold.to_i
end
else
@@threshold = nil
@kares
kares / jsunity.js
Created June 21, 2010 07:52
jsUnity hacked to be usable in FBJS
/**
* jsUnity Universal JavaScript Testing Framework v0.6
* http://jsunity.com/
*
* Copyright (c) 2009 Ates Goral
* Licensed under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*
* Copyright (c) 2010 Karol Bucek - FBJS compatible
# 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)