Skip to content

Instantly share code, notes, and snippets.

Lance Pollard lancejpollard

Block or report user

Report or block lancejpollard

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Recursively Symbolize Keys in Ruby.rb
class Hash
def recursively_symbolize_keys!
self.values.each do |v|
if v.is_a? Hash
elsif v.is_a? Array
View Cross Browser CSS Opacity (with and without Sass).css
// css
.opacity {
opacity: .80;
filter: alpha(opacity=80);
-ms-filter: "alpha(opacity=$value)";
-khtml-opacity: .80;
-moz-opacity: .80;
// sass
View Cross Browser CSS Box Shadow with Sass.css
@mixin shadow($color: #333333) {
-moz-box-shadow: 0px 1px 2px $color;
-webkit-box-shadow: 0px 1px 2px $color;
box-shadow: 0px 1px 2px $color;
-ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=90, Color='$color')";
filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=90, Color='$color');
.shadow {
@include shadow(#111111);
View Cross Browser CSS Rotation with and without Sass.css
// css
.rotate {
-moz-transform: rotate(-30deg);
-o-transform: rotate(-30deg);
-webkit-transform: rotate(-30deg);
filter: progid:DXImageTransform.Microsoft.Matrix(sizingMethod='auto expand', M11=0.154, M12=-0.988, M21=0.988, M22=0.154);
-ms-filter: "progid:DXImageTransform.Microsoft.Matrix(sizingMethod='auto expand', M11=0.154, M12=-0.988, M21=0.988, M22=0.154)";
zoom: 1;
View Cross Browser CSS Gradients with Sass.css
@mixin gradient($first, $second) {
background: $second;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='$first', endColorstr='$second');
background: -webkit-gradient(linear, left top, left bottom, from($first), to($second));
background: -moz-linear-gradient(top, $first, $second);
.gradient {
@include gradient(black, white);
View Regular Expression to Create URL Permutations in Ruby.rb
# return 4 urls, with and without trailing slash, with and without www
# useful for matching urls passed as params into some function,
# "does this url exist?"... need to make sure you check permutations
def url_permutations(url)
url, params = url.split("?")
# without_trailing_slash, with www
a = url.gsub(/\/$/, "").gsub(/http(s)?:\/\/([^\/]+)/) do |match|
protocol = "http#{$1.to_s}"
domain = $2
domain = "www.#{domain}" if domain.split(".").length < 3 # == 3, == 2
View After Callbacks and alias_method.rb
require 'rubygems'
require 'active_model'
class BaseModel
extend ActiveModel::Callbacks
define_model_callbacks :save
before_save { puts "[save:before]"}
after_save { puts "[save:after]"}
View Ruby Metaprogramming - Subclassable Callback Module.rb
require 'rubygems'
require 'active_model'
# use this if you want to create before and after filters around a commonly used
# method, but still want to define the method in subclasses.
module SubclassableCallbacks
def self.included(base)
base.extend ClassMethods
View Return Array of Overridden Methods in Ruby Subclasses.rb
# thanks to the answer here:
class Object
def self.overridden_methods(parent_class = Object, within_tree = true)
if within_tree
defined_methods = ancestors[0..ancestors.index(parent_class) - 1].map { |object| object.instance_methods(false) }.flatten.uniq
parent_methods = superclass.instance_methods
defined_methods = instance_methods(false)
parent_methods = parent_class.instance_methods
You can’t perform that action at this time.