Skip to content

Instantly share code, notes, and snippets.

View kares's full-sized avatar

Karol Bucek kares

View GitHub Profile
@kares
kares / web.xml
Created October 9, 2010 16:46
jruby-rack web.xml for rails
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<context-param>
<param-name>rails.env</param-name>
<param-value>production</param-value>
</context-param>
<context-param>
@kares
kares / Gemfile
Created October 26, 2010 08:22
loading factory_girl correctly with Bundler (and Rails 2.3)
gem 'factory_girl', :require => nil
@kares
kares / integration_test_session_patch.rb
Created October 26, 2010 09:39
making sessions work in integration tests (broken since Rails 2.3.8)
# session is not preserved between requests in integration tests (since 2.3.8)
# https://rails.lighthouseapp.com/projects/8994/tickets/4941-session-is-not-preserved-between-requests-in-integration-tests
# this monkey-fix deals with the issue and is based on the provided patch from
# the above ticket. require in your test_helper or integration_test_helper ...
require 'action_controller/session/abstract_store'
module ActionController
@kares
kares / jquery.ui.dialog_auto_width_fix.js
Created December 8, 2010 13:13
jQuery UI dialog options.width == 'auto' partial support (for IE)
(function($) {
var fixDialogAutoWidth = $.noop;
if ( $.browser.msie ) {
fixDialogAutoWidth = function(content) {
var dialog = $(content).parent('.ui-dialog');
var width = dialog.innerWidth();
if ( width ) dialog.css('width', width);
}
}
@kares
kares / .bash_profile
Created December 12, 2010 12:49
$rvm_path upgrade
# 1. update rvm loading in .bash_profile, by default it looks like :
# [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
if [ -s "$HOME/.rvmrc" ]; then
source "$HOME/.rvmrc"
fi # to have $rvm_path defined if set
if [ -s "${rvm_path-$HOME/.rvm}/scripts/rvm" ]; then
source "${rvm_path-$HOME/.rvm}/scripts/rvm"
fi
@kares
kares / simpleFormat.js
Created December 14, 2010 08:56
simple_format Ruby on Rails helper in javascript
var simpleFormatRE1 = /\r\n?/g;
var simpleFormatRE2 = /\n\n+/g;
var simpleFormatRE3 = /([^\n]\n)(?=[^\n])/g;
function simpleFormat(str) {
var fstr = str;
fstr = fstr.replace(simpleFormatRE1, "\n") // \r\n and \r -> \n
fstr = fstr.replace(simpleFormatRE2, "</p>\n\n<p>") // 2+ newline -> paragraph
fstr = fstr.replace(simpleFormatRE3, "$1<br/>") // 1 newline -> br
fstr = "<p>" + fstr + "</p>";
return fstr;
module DelayedJobAware
def self.delayed_worker?
Thread.current[:delayed_worker_started]
end
# returns the Delayed::Worker.logger if inside a DJ process/thread
# otherwise returns the default Rails.logger
def self.current_logger
@kares
kares / jquery.autogrow.js
Created January 29, 2011 21:22
simple jQuery plugin that allows textareas to grow vertically when text is typed in
/*
* Adapted from Autogrow Textarea Plugin
* @see http://www.technoreply.com/autogrow-textarea-plugin/
*/
(function($) {
$.fn.autoGrow = function() {
return this.each(function() {
var txtArea = $(this);
var colsDefault = txtArea.attr('cols');
var rowsDefault = txtArea.attr('rows');
@kares
kares / jquery.changeformmethod.js
Created February 14, 2011 09:12
jQuery FORM method change plugin
/**
* Very handly (not just) for Rails :
*
* 1. setup RoR input method naming convention :
*
* $.fn.changeFormMethod.inputName = '_method';
*
* 2. Any time You need to change Your forms method :
* (e.g. re-using forms new forms for edit-ation)
*
@kares
kares / jruby_set_security_manager.rb
Created March 9, 2011 10:56
Set up a SecurityManager from JRuby
require 'java'
class JRubySecurityManager < java.lang.SecurityManager
def checkPermission( perm )
puts perm.inspect
end
end
java.lang.System.setSecurityManager( JRubySecurityManager.new )