Skip to content

Instantly share code, notes, and snippets.

View kares's full-sized avatar
💤

Karol Bucek kares

💤
View GitHub Profile
@kares
kares / jruby-profile-to-string.rb
Last active August 29, 2015 13:58 — 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)
# 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 / sessions.rake
Created April 14, 2011 07:31 — forked from yaroslav/sessions.rake
rake task for cleaning up ActiveRecord session store table from expired sessions
namespace :db do
namespace :sessions do
desc "Clean up expired Active Record sessions (updated before ENV['UPDATED_AT'], defaults to 1 month ago)."
task :expire => :environment do
time = Time.parse( ENV['UPDATED_AT'] || 1.month.ago.to_s(:db) )
say "cleaning up expired sessions (older than #{time}) ..."
session = ActiveRecord::SessionStore::Session
rows = session.delete_all ["updated_at < ?", time]
say "deleted #{rows} session row(s) - there are #{session.count} session row(s) left"
end
@kares
kares / rackup.ru
Created May 23, 2012 09:12 — forked from Hakon/rackup.ru
JRuby::Rack with Rails send_file bug
require 'rubygems'
%w(action_controller/railtie).map &method(:require)
class JrubyRackTest < Rails::Application
config.secret_token = routes.append { root :to => 'send_file#deliver' }.inspect
initialize!
end
run JrubyRackTest
@kares
kares / postsql.sql
Created September 22, 2013 16:55 — forked from tobyhede/postsql.sql
-- PostgreSQL 9.2 beta (for the new JSON datatype)
-- You can actually use an earlier version and a TEXT type too
-- PL/V8 http://code.google.com/p/plv8js/wiki/PLV8
-- Inspired by
-- http://people.planetpostgresql.org/andrew/index.php?/archives/249-Using-PLV8-to-index-JSON.html
-- http://ssql-pgaustin.herokuapp.com/#1
-- JSON Types need to be mapped into corresponding PG types
--
@kares
kares / password.rb
Created January 12, 2016 08:53
get password - Ruby - any platform - no gems needed
# 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 / logstash.conf
Last active June 2, 2021 10:34 — forked from andsel/sender.rb
Simple RabbitMQ sender
input {
rabbitmq {
codec => plain
host => "localhost"
key => "#"
exchange => "sysmsg" # string (optional)
queue => 'dur-no-policy-4'
durable => true
# 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)