Skip to content

Instantly share code, notes, and snippets.

@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 / 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: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 / 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 / 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 / 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