Skip to content

Instantly share code, notes, and snippets.

Chris Eppstein chriseppstein

View GitHub Profile
View general.sass
// Clearing floats without extra markup
// Based on How To Clear Floats Without Structural Markup by PiE
// [http://www.positioniseverything.net/easyclearing.html]
// From the official sass documentation.
=clearfix
display: inline-block
&:after
content: "."
display: block
height: 0
View sass_script_enhancements.sass
= spans(!columns)
- for !column from 1 through !columns by 2 // though = .., to = ..., by = incrementor
+span(!column,!columns)
= span(!column, !columns)
.span-#{!column}
:width= 45px * !column + 15px
- if !column != !columns
:margin-right 15px
View usage_example.rb
require 'ignoring_diff'
Hash.send(:include, IgnoringDiff)
h = {:foo => :bar}
h.diff({})
# => {:foo => :bar}
h.ignore_difference_for(:foo)
h.diff({})
# => {}
@chriseppstein
chriseppstein / tracer.rb
Created Aug 21, 2008
Trace method entrances and exists. Requires ActiveSupport.
View tracer.rb
module Tracer
def trace(method)
method, ending = split_method_name(method)
define_method "#{method}_with_trace#{ending}" do |*arguments|
puts "called #{self.class}##{method}#{ending}(#{arguments.map(&:inspect).join(', ')})"
returning(send("#{method}_without_trace#{ending}", *arguments)) do |v|
puts "#{self.class}##{method}#{ending} => #{v.inspect}"
end
end
alias_method_chain "#{method}#{ending}", :trace
View compass.css
.compass { margin: 1em auto; position: relative; width: 16em; height: 16em; font-size: 24px; font-family: "Academy Engraved LET", "Papyrus"; }
.compass .n, .compass .s, .compass .e, .compass .w { position: absolute; width: 4em; height: 4em; text-align: center; vertical-align: middle; }
.compass .w { left: 0px; }
.compass .n.w, .compass .s.w { left: 2em; }
.compass .n, .compass .s { left: 6em; }
.compass .n.e, .compass .s.e { left: 10em; }
.compass .e { left: 12em; }
.compass .n { top: 0px; }
.compass .n.w, .compass .n.e { top: 2em; }
.compass .w, .compass .e { top: 6em; }
View anonymizer.rb
module Anonymizer
def anonymize_attribute(attribute)
self.send(:include, Module.new do
define_method attribute do
a = @attributes[attribute.to_s]
a && attribute.to_s.ends_with?("_id") ? a.to_i : a
end
define_method "#{attribute}_with_anonymous" do
send("#{attribute}_without_anonymous") unless anonymous?
end
View content_for_helpers.rb
module ContentForHelpers
def content_for?(name, options = {}, &block)
has_content = (!instance_variable_get("@content_for_#{name}").strip.blank? rescue nil)
should_process = options[:negate] ? !has_content : has_content
if should_process && block_given?
concat(capture(&block), block.binding)
end
return should_process
end
View gist:13840
.field
Display Name:
= h @user.name
= link_to "edit", edit_user_url(@user, :field => "name")
.field
Your Email:
= h @user.email
= link_to "edit", edit_user_url(@user, :field => "email")
.field
Password:
View Fixed-bug-in-compass-initializer-.patch
From e2a475f33f822d0f5810f26fcc9e562997358326 Mon Sep 17 00:00:00 2001
From: Chris Eppstein <chris@eppsteins.net>
Date: Fri, 3 Oct 2008 14:23:25 -0700
Subject: [PATCH] Fixed bug in compass initializer.
---
config/initializers/compass.rb | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/config/initializers/compass.rb b/config/initializers/compass.rb
View commented.sass
//
This file is well documented with a silent comment that describes what it does.
In this comment we are testing mutli-line silent comments at the start of a document.
body
:margin 0
:font 0.85em "Lucida Grande", "Trebuchet MS", Verdana, sans-serif
:color #fff
:background url(/images/global_bg.gif)
You can’t perform that action at this time.