Skip to content

Instantly share code, notes, and snippets.

View kares's full-sized avatar
💤

Karol Bucek kares

💤
View GitHub Profile
@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)
@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 / 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
@kares
kares / gammusms2android.rb
Created March 8, 2012 06:58
Gammu to Android SMS converter. Assumes your backup has been exported as XML.
#!/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
@kares
kares / jit_max_force.rb
Created September 27, 2019 12:29
force -Xjit.max setting on JRuby <= 9.2.8
# 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