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
@kares
kares / jit_max_force.rb
Created Sep 27, 2019
force -Xjit.max setting on JRuby <= 9.2.8
View jit_max_force.rb
# 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
View memory_lock.rb
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 / jquery.parseparams.js
Created May 5, 2011
jQuery.parseParams - parse query string paramaters into an object
View jquery.parseparams.js
/**
* $.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 / to_bool.rb
Created Jul 23, 2019
`params[:foo].to_bool`, `ENV['bar'].to_bool` and others
View to_bool.rb
# 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 / scheduled_job.rb
Created Jun 14, 2011
Recurring Job using Delayed::Job
View scheduled_job.rb
#
# 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 / stack.dump
Created Jan 24, 2019
left-over threads
View stack.dump
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 Jan 23, 2019
Daemon thread that logs memory usage an load (for JRuby)
View monitor_daemon.rb
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 / slow_query_log.rb
Last active Jan 10, 2019
ActiveRecord slow query logging in Rails ... setup using: config.slow_query_log_threshold_in_ms = 500
View slow_query_log.rb
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 / FileGlob.groovy
Created Feb 21, 2010
Globbing implemented in Groovy
View FileGlob.groovy
// Licensed under the "Apache License, Version 2.0" (c) 2010
/**
* Returns filenames found by expanding the passed pattern which is String or
* a List of patterns.
* NOTE: that this pattern is not a regexp (it’s closer to a shell glob).
* NOTE: that case sensitivity depends on your system.
*
* <code>*</code> Matches any file. Can be restricted by other values in
* the glob pattern (same as <code>.*</code> in regexp).
* <code>*</code> will match all files,
@kares
kares / gammusms2android.rb
Created Mar 8, 2012
Gammu to Android SMS converter. Assumes your backup has been exported as XML.
View gammusms2android.rb
#!/usr/bin/evn ruby
# (Not just) Nokia 2 Android SMS converter script.
#
# This tool assumes you've backed up your SMS messages from your device using
# Gammu (Wammu) http://wammu.eu/wammu/ in XML format e.g.
#
# * open Wammu and connect your phone: Phone -> Connect
# * retrieve messages (or all) using: Retrieve -> Messages
# * backup as XML using: Backups -> Export messages to XML
You can’t perform that action at this time.