Skip to content

Instantly share code, notes, and snippets.

View fermion's full-sized avatar
👋

Rob Sterner fermion

👋
View GitHub Profile
def layouts
PageTemplate::LAYOUTS.inject({}) do |hash, layout|
hash.merge(layout.to_s.sub('_', ' ').capitalize] = layout)
end
end
@fermion
fermion / validate_boolean_fields.rb
Created July 8, 2011 12:18
required MM Boolean field w/ :default => false solution
module ValidateBooleanFields
extend ActiveSupport::Concern
included do
class_eval(<<-EOS, __FILE__, __LINE__)
cattr_accessor :boolean_fields
EOS
validate :validate_boolean_fields
ruby-1.9.2-p180 :002 > true.blank?
false
ruby-1.9.2-p180 :003 > false.blank?
true
class Foo < ActiveRecord::Base
has_one :bar
end
class Bar < ActiveRecord::Base
belongs_to :foo
def something?
# lol
end
# USAGE: Hash.from_xml:(YOUR_XML_STRING)
require 'nokogiri'
# modified from http://stackoverflow.com/questions/1230741/convert-a-nokogiri-document-to-a-ruby-hash/1231297#1231297
class Hash
class << self
def from_xml(xml_io)
begin
result = Nokogiri::XML(xml_io)
return { result.root.name.to_sym => xml_node_to_hash(result.root)}
@fermion
fermion / jquery.ba-detach.js
Created May 19, 2011 13:46 — forked from cowboy/jquery.ba-detach.js
jQuery Detach+: Improve .detach to allow optional reattaching!
/*!
* jQuery Detach+ - v0.1pre - 5/18/2011
* http://benalman.com/
*
* Copyright (c) 2011 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function($){
Rails CMS alternatives
======================
Note: project activity was checked on 11/26/09 for most of these projects, and the "last update" field has not been kept up to date since then.
Active projects:
---------------
adva-cms
repo: http://github.com/svenfuchs/adva_cms/
site: http://adva-cms.org/
Last update: 11/24/09
@fermion
fermion / gist:774390
Created January 11, 2011 13:11 — forked from remy/gist:350433
if (!window.localStorage || !window.sessionStorage) (function () {
var Storage = function (type) {
function createCookie(name, value, days) {
var date, expires;
if (days) {
date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires="+date.toGMTString();
var like = "this\
for\
multiline strings\
in javascript";
// 1: how could you rewrite the following to make it shorter?
if (foo) {
bar.doSomething(el);
} else {
bar.doSomethingElse(el);
}