Skip to content

Instantly share code, notes, and snippets.

View kares's full-sized avatar
💤

Karol Bucek kares

💤
View GitHub Profile
@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,
/**
* @version 1.20 25 Mar 1998
* @author Cay Horstmann
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class MousePanel extends JPanel implements MouseMotionListener {
@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 / Caller.java
Created July 15, 2013 07:49
return the caller's method
/**
* inspired by JavaCPP's Loader utility
* @see http://bit.ly/loader-java
*/
public class Caller {
/**
* Returns the {@link Class} object that contains a caller's method.
*
* @param i the offset on the call stack of the method of interest
@kares
kares / Gemfile
Last active December 9, 2015 21:18
Gemfile snippet to speed-up therubyrhino on JRuby - you might gain up to 30% in speed (e.g. during assets:precompile) if your JavaScripts are Rhino bytecode-compilable ...
source 'https://rubygems.org'
gem 'rails', '3.2.16' # or whatever
# ...
group :assets do
# make sure you have the latest rhino :
gem 'therubyrhino', '>= 2.0.2', :platform => :jruby
@kares
kares / thread_dump.rb
Last active October 19, 2015 13:09
Thread dump-ing for JRuby (using MX)
require 'java'
module ThreadDump
def self.thread_dump(output = nil)
output ||= ''
thread_mbean = java.lang.management.ManagementFactory.getThreadMXBean
thread_ids = thread_mbean.getAllThreadIds # long[]
threads = thread_mbean.getThreadInfo(thread_ids, false, false) # ThreadInfo[]
threads.each do |thread_info|
@kares
kares / current_thread_aware_formatter.rb
Created October 19, 2015 13:08
Logger::Formatter aware of Thread.current for JRuby
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 October 14, 2015 17:47
AR 3.2 pool patch for less contention on release_connection
::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 / channels_test.rb
Created December 13, 2012 09:18
Java NIO file channels test with JRuby jruby 1.6.8 (ruby-1.8.7-p357) (2012-09-18 1772b40) (Java HotSpot(TM) Client VM 1.6.0_35) [linux-i386-java]
require 'java'
input = 'INPUT_FILE'
output = 'WHERE_TO_COPY'
input_file = nil; input_channel = nil; output_channel = nil
new_io_channels = Proc.new do
input_file = File.open(input, 'r') unless input_file
input_channel = input_file.to_channel
@kares
kares / waitUntilExists.js
Created December 10, 2012 11:37
$(document).ready() alternative from http://bit.ly/QAwxWG
/*
* Wait Until Exists Version v0.2 - http://javascriptisawesome.blogspot.com/
*
*
* TERMS OF USE - Wait Until Exists
*
* Open source under the BSD License.
*
* Copyright © 2011 Ivan Castellanos
* All rights reserved.