Skip to content

Instantly share code, notes, and snippets.

View kares's full-sized avatar
💤

Karol Bucek kares

💤
View GitHub Profile
@kares
kares / gist:161328
Created August 4, 2009 16:08
globalize2 bug tracking
#test "makes sure interpolation does not break even with False as string" do
# assert_equal "translation missing: en, support, array, skip_last_comma", I18n.translate(:"support.array.skip_last_comma")
#end
test "returns missing translation string for missing key" do
assert_equal "translation missing: hu, foo, bar, huu", I18n.translate(:"foo.bar.huu", :locale => :hu)
end
test "returns false translation" do
@kares
kares / trim_blob_logging.rb
Created August 23, 2009 11:39
trim blobs from ActiveRecord's log
ActiveRecord::ConnectionAdapters::AbstractAdapter.class_eval do
def log_with_blobs_trimmed(sql, name, &block)
sql = sql.gsub(/x'([^']+)'/) do |blob|
blob.size > 32 ? "x'#{$1[0,32]}... (#{blob.size} bytes)'" : $0
end if sql
log_without_blobs_trimmed(sql, name, &block)
end
alias_method_chain :log, :blobs_trimmed
@kares
kares / gist-embed_twilight.css
Created August 30, 2009 11:30
a twilight theme for gists
.gist {
color: /* #000 */ #9B703F;
}
.gist div {
padding: 0;
margin: 0;
}
.gist .gist-file {
border: 1px solid #dedede; /* gray */
font-family: Monaco, "Courier New", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace;
@kares
kares / request_exception_fix.rb
Created September 6, 2009 09:41
action pack request exception patching for the pre 2.3 era
# Patch request to receive exceptions from body parsing (e.g. XML parsing)
ActionController::AbstractRequest.class_eval do
alias_method :parse_formatted_request_parameters_unsafely, :parse_formatted_request_parameters
def parse_formatted_request_parameters
begin
parse_formatted_request_parameters_unsafely #super
rescue Exception => e # YAML, XML or Ruby code block errors
self.env['EXCEPTION'] = e # there will be a before filter to check for this and re-raise
@kares
kares / application_controller.rb
Created September 6, 2009 11:29
request_exception_handler plugin usage sample
class ApplicationController < ActionController::Base
rescue_from 'REXML::ParseException' do |exception|
render :text => exception.to_s, :status => 422
end
end
@kares
kares / weblogic.xml
Created October 25, 2009 21:13
weblogic descriptor snippet
<!-- @see docs http://bit.ly/41H6jr -->
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
@kares
kares / assert_json_parse_exception.rb
Created December 28, 2009 20:05
assert an error is caused by JSON parsing for rails 2.x.x
def assert_json_parse_exception(error)
if ActiveSupport::JSON.respond_to?(:parse_error) # 2.3.5
parse_error_class = ActiveSupport::JSON.parse_error
assert_instance_of parse_error_class, error
else
assert_instance_of ActiveSupport::JSON::ParseError, error
end
end
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>webapp</display-name>
<context-param>
<param-name>SOME_PORT</param-name>
<param-value>8080</param-value>
</context-param>
<!-- ... rest omited ... -->
</web-app>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.kares</groupId>
<artifactId>webapp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>webapp</name>
<dependencies>
<dependency>
def overrideResourcesDir = project.properties["override.resources.dir"]
if (new File( overrideResourcesDir ).exists()) {
log.info("cleaning contents of directory $overrideResourcesDir")
ant.delete { fileset(dir: overrideResourcesDir, includes: "**") }
}
else {
new File( overrideResourcesDir ).mkdirs() // webResource - should exist
}
def SOME_PORT = project.properties["SOME_PORT"]
if (SOME_PORT) { // if not set don't touch the web.xml