Skip to content

Instantly share code, notes, and snippets.

@cbeier
cbeier / Devecot fail2ban config
Created November 13, 2009 09:42
Devecot fail2ban config
# -> /etc/fail2ban/filter.d/devecot.conf
# Fail2Ban configuration file
#
# Author: burner
#
# $Revision: 1 $
#
[Definition]
# Option: failregex
@cbeier
cbeier / general cucumber paths (restful).rb
Created November 18, 2009 08:14
general cucumber paths (restful)
# Request in the feature -> ... the user show "foo" page by "login"
# -> features/support/paths.rb
when /^the (.*) (edit|show)( "([^\"]*)")? page by "([^\"]*)"$/i
case $2
when "edit","show"
klass = $1.singularize.capitalize.constantize
obj = klass.send("find_by_#{$5.singularize}", $4) if $4 && $5
raise "could not find #{$3} #{$1}" unless obj
return self.send("edit_#{$1.downcase.singularize}_path",obj) if $2=="edit"
@cbeier
cbeier / deploy.rb
Created December 13, 2009 11:13
Capistrano Deploy Template
# This defines a deployment "recipe" that you can feed to capistrano
# (http://manuals.rubyonrails.com/read/book/17). It allows you to automate
# (among other things) the deployment of your application.
# =============================================================================
# REQUIRED VARIABLES
# =============================================================================
# You must always specify the application and repository for every recipe. The
# repository must be the URL of the repository you want this recipe to
# correspond to. The deploy_to path must be the path on each machine that will
@cbeier
cbeier / gist:271149
Created January 7, 2010 10:26
find polymorphic
# controller
private
def find_polymorphic
params.each do |name, value|
if name =~ /(.+)_id$/
return $1.classify.constantize.find(value)
end
end
nil
end
@cbeier
cbeier / detect_cleartype.js
Created January 22, 2010 11:08
detect ClearType using javascript
/*
* TypeHelpers version 1.0
* Zoltan Hawryluk, Nov 24 2009.
* @see http://www.useragentman.com/blog/2009/11/29/how-to-detect-font-smoothing-using-javascript/
*
* Released under the MIT License. http://www.opensource.org/licenses/mit-license.php
*
* Works for
* - IE6+ (Windows),
* - Firefox 3.5+ (Windows, Mac, Linux),
@cbeier
cbeier / gist:343311
Created March 25, 2010 08:26
Convert XML to Ruby Hash (using Nokogiri)
# USAGE: Hash.from_libxml(YOUR_XML_STRING)
require 'xml/libxml'
# adapted from
# http://movesonrails.com/articles/2008/02/25/libxml-for-active-resource-2-0
class Hash
class << self
def from_libxml(xml, strict=true)
begin
XML.default_load_external_dtd = false
@cbeier
cbeier / gist:344692
Created March 26, 2010 08:58
calculate the exact age
def age(birthday)
y = Date.today.year - birthday.year
m = Date.today.month - birthday.month
d = Date.today.day - birthday.day
case
when m < 0
age = y-1
when m = 0
case
when d = 0
@cbeier
cbeier / patch_building_forms.css
Created April 6, 2010 08:30
Fix for YAML sup/sub bug (IE6 / IE7)
/**
* Bugfix for line-height bug on sup/sub element
*
* @bugfix
* @affected IE 5.x/Win, IE6, IE7
* @css-for IE 5.x/Win, IE6, IE7
* @yalid yes
*/
html sup,
<?php
// Ersetze template mit dem Namen deines Templates
template_preprocess_node(&$variables) {
$variables['content']['body]['#items'][0]['summery']['#prefix'] = '<p>;
$variables['content']['body]['#items'][0]['summery']['#prefix'] = '</p>;
}
?>
@cbeier
cbeier / gist:1669002
Created January 24, 2012 09:05
Settings for Environment Indicator module
/**
* Settings for Environment Indicator module
*
* Text:
* - DEVELOPMENT ENVIRONMENT
* - STAGING ENVIRONMENT
* - PRODUCTION ENVIRONMENT
*
* Color (based on http://ethanschoonover.com/solarized):
* - Development: #268bd2