Skip to content

Instantly share code, notes, and snippets.

View tcmacdonald's full-sized avatar
🪕

Taylor MacDonald tcmacdonald

🪕
  • Ample
  • Cincinnati, OH
View GitHub Profile
@tcmacdonald
tcmacdonald / jquery.valign.js.coffee
Created January 3, 2012 16:06
Vertically Align Children
(($) ->
$.fn.valign = (max_width, max_height) ->
@each (i) ->
$.each $(this).children(), (j,el) ->
img = $(el).children()[0]
ph = Math.floor((max_width - $(img).width()) / 2)
pv = Math.floor((max_height - $(img).height()) / 2)
div = $('<div></div>').css('padding',"#{pv}px #{ph}px")
$(img).wrap(div)
@tcmacdonald
tcmacdonald / _form.html.erb
Created December 22, 2011 16:26
Grouped Select Box for Polymorphic Associations
<%= form_for(@promotion, :html => { :multipart => true }) do |f| %>
<%= select_tag 'owner', grouped_owners_for_select %>
<% end %>
@tcmacdonald
tcmacdonald / application.rb
Created June 27, 2011 13:54
Loading an Engine's Classes First in Rails
# make sure engine classes load first.
# @see http://stackoverflow.com/questions/5045068/extending-controllers-of-a-rails-3-engine-in-the-main-app/5100825
require 'active_support/dependencies'
module ActiveSupport::Dependencies
alias_method :require_or_load_without_multiple, :require_or_load
def require_or_load(file_name, const_path = nil)
if file_name.starts_with?(Rails.root.to_s + '/app')
relative_name = file_name.gsub(Rails.root.to_s, '')
@engine_paths ||= CologyCom::Application.railties.engines.collect{|engine| engine.config.root.to_s }
@engine_paths.each do |path|
@tcmacdonald
tcmacdonald / application.js
Created April 22, 2011 16:28 — forked from ryanahamilton/application.js
cross-browser input placeholder attribute support with jQuery and Modernizr
$(function(){
if (!Modernizr.input.placeholder){
$('input[type=text]').clearValue();
}
});
$.fn.clearValue = function() {
var element = this;
var defaultStr = $(this).attr('placeholder');
$(this).val(defaultStr);
return this.focus(function() {