Skip to content

Instantly share code, notes, and snippets.

View tillsc's full-sized avatar

Till Schulte-Coerne tillsc

View GitHub Profile
@tillsc
tillsc / Linking Data style Rails applications
Created November 10, 2010 08:43
Add this to your ApplicationController to get a linking data style url handling (force usage of 'format' in URLs)
before_filter :ensure_extension
# Force an extension to every url. (LD)
def ensure_extension
redirect_to url_for(:format => (request.format && request.format.symbol) || :html) unless params[:format]
end
# Set a default value for the :format parameter in url_for and *_url/*_path methods.
def default_url_options(options = nil)
{:format => params[:format]}.merge(options || {})
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="de">
<head>
<title>HTML4 Dokument</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<div id="branding">
<h1>Der Header</h1>
</div>
<!DOCTYPE html>
<html lang="de">
<head>
<title>HTML5 Dokument</title>
<meta charset="utf-8">
</head>
<body>
<header>
<h1>Der Header</h1>
</header>
@tillsc
tillsc / gist:1250864
Created September 29, 2011 14:39
dm-oracle-adapter 1.2.0.rc2 -> rake spec
1)
'DataMapper::Adapters::OracleAdapter#create serial properties should not send NULL values' FAILED
expected: /\AINSERT INTO "ARTICLES" \("ID"\) VALUES \(DEFAULT\) RETURNING "ID"/,
got: " ~ (0,033) INSERT INTO \"ARTICLES\" (\"ID\") VALUES (DEFAULT) RETURNING \"ID\" INTO ?" (using =~)
2)
'DataMapper::Adapters::OracleAdapter#create properties without a default should not send NULL values' FAILED
expected: /^INSERT INTO "articles" \("id"\) VALUES \(('.{1,2}'|.{1,2})\)$/i,
got: " ~ (0,005) INSERT INTO \"ARTICLES\" (\"ID\") VALUES (?)" (using =~)
@tillsc
tillsc / gist:1284040
Created October 13, 2011 11:46
dm-oracle-adapter patch for indices with long table names
def create_index_statement(model, index_name, fields)
table_name = model.storage_name(name)
table_name_short = table_name.split("_").map{|s|s[0..3]}.join("_")
DataMapper::Ext::String.compress_lines(<<-SQL)
CREATE INDEX #{quote_name("i_#{table_name_short}_#{index_name}")} ON
#{quote_name(table_name)} (#{fields.map { |field| quote_name(field) }.join(', ')})
SQL
end
@tillsc
tillsc / gist:1898836
Created February 24, 2012 07:50
My ~/.irbrc
#libaries
require 'rubygems' rescue nil
require 'irb/completion'
begin
# load hirb
$: << '/Library/Ruby/Gems/1.8/gems/hirb-0.5.0/lib'
require "hirb"
# start hirb
@tillsc
tillsc / my_helper.rb
Created March 8, 2012 09:03
all_errors helper method for DataMapper 1.2
module DataMapper
module MyHelpers
def all_errors(seen=[])
return [] if seen.include?(self)
seen << self
res = self.errors
parent_relationships.each do |relationship|
association = relationship.get!(self)
@tillsc
tillsc / eager_loading.rb
Created July 23, 2012 07:02
Eager Loading DM associations
# Usage:
#
# customers = Customer.all
# customers.eager_load(Customer.orders.line_items.item, Customer.address)
#
module DataMapper
module EagerLoading
def eager_load(*query_paths)
@tillsc
tillsc / gist:4233025
Created December 7, 2012 12:42
Defining a JNDI OracleConnectionPool in JRuby for testing purposes
if RUBY_PLATFORM =~ /java/
require 'java'
# Add ojdbc to the Java classpath
$CLASSPATH << File.expand_path('../../lib/ojdbc5.jar', __FILE__)
# Simply add all apache tomcat libs (some juli.jar might need to be added too)
Dir.glob("/usr/local/Cellar/apache-tomcat/6.0.24/lib/*.jar") do |filename|
$CLASSPATH << filename
end
@tillsc
tillsc / index.html
Last active December 21, 2015 02:59
Discussion about RDFa vs. POSH with @tistre
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
<meta charset="UTF-8" />
<title>
Story: 1828128 from BAB / BNH, page 3 from Thursday, July 25, 2013 – DC-X 1.7.8.0 BTAG API
</title>
<link href="http://dcxtrunk.digicol.de/dcx_static/trunk/bootstrap/css/bootstrap.min.css" type="text/css" rel="stylesheet" />
</head>