Skip to content

Instantly share code, notes, and snippets.

💭
looking for new opportunities - let's have them!

Karol Bucek kares

💭
looking for new opportunities - let's have them!
Block or report user

Report or block kares

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@kares
kares / gist:161328
Created Aug 4, 2009
globalize2 bug tracking
View gist:161328
#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 Aug 23, 2009
trim blobs from ActiveRecord's log
View trim_blob_logging.rb
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 Aug 30, 2009
a twilight theme for gists
View gist-embed_twilight.css
.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 Sep 6, 2009
action pack request exception patching for the pre 2.3 era
View request_exception_fix.rb
# 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 Sep 6, 2009
request_exception_handler plugin usage sample
View application_controller.rb
class ApplicationController < ActionController::Base
rescue_from 'REXML::ParseException' do |exception|
render :text => exception.to_s, :status => 422
end
end
@kares
kares / weblogic.xml
Created Oct 25, 2009
weblogic descriptor snippet
View weblogic.xml
<!-- @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 Dec 28, 2009
assert an error is caused by JSON parsing for rails 2.x.x
View assert_json_parse_exception.rb
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
View web.xml
<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>
View pom.xml
<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>
View overrides.groovy
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
You can’t perform that action at this time.