Skip to content

Instantly share code, notes, and snippets.

View kares's full-sized avatar

Karol Bucek kares

View GitHub Profile
@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 / 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.
@kares
kares / snippet.web.xml
Created October 31, 2012 10:28
jruby-rack-worker/trinidad configuration (snippets) for Resque
<?xml version="1.0" encoding="UTF-8"?>
<web-app> <!-- NS and Schemas omitted -->
<!-- Rails (filter/servlet) configuration ... -->
<listener>
<listener-class>
org.jruby.rack.rails.RailsServletContextListener
</listener-class>
</listener>
require 'rhino'
Rhino::Context.open do |context|
context.eval "function bar(foo) { return foo + 'bar'; }"
bar = context[:bar]
if bar.is_a?(org.mozilla.javascript.Function)
puts bar.call('foo')
end
end
@kares
kares / code_source.rb
Created August 21, 2012 07:51
Java class source location with JRuby
klass = org.apache.catalina.startup.Tomcat # change me
java_class = klass.java_class.to_java
code_source = java_class.getProtectionDomain.getCodeSource
puts code_source.getLocation.toString
@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 / Gemfile
Created April 15, 2012 12:01
Less on Rails with V8 (CRuby) or Rhino (JRuby)
group :assets do
#gem 'sass-rails', '~> 3.1.4'
#gem 'coffee-rails', '~> 3.1.1'
#gem 'uglifier', '>= 1.0.3'
gem 'less', :git => 'git://github.com/kares/less.rb.git', :submodules => true
gem 'less-rails', '>= 2.2.1'
gem 'less-rails-bootstrap' # optional
gem 'therubyracer', :platforms => :ruby