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 / 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() {
@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 / _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 / 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 / firefox.js.coffee
Created January 9, 2012 20:16
Native Detection for FF Pre 3.5
if /Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)
ffversion = new Number(RegExp.$1)
if ffversion < 3.5
head = document.getElementsByTagName("head")[0]
el = document.createElement("link")
el.type = "text/css"
el.rel = "stylesheet"
el.href = "/assets/firefox.css"
el.media = "screen"
head.appendChild el
@tcmacdonald
tcmacdonald / application.js
Created March 12, 2012 15:47
Textile WYSIWYG Editor
$.each($('textarea.textile'),function(i,el){
TextileEditor.initialize($(el).attr('id'));
});
@tcmacdonald
tcmacdonald / index.html
Created April 4, 2012 13:56
Paycor OH Implementation Details
<!-- To be included directly before closing body tag -->
<script>
$(document).ready(function(){
var client_ids = $('select#ctl00_ctl00_placeHolderMain_cphMainContent_cbClient option').map(function() {
return /\d+/.exec($(this).val());
}).get().join(',')
var sp = document.createElement('script');
sp.type = 'text/javascript';
sp.src = "//www.paycor.com/syndicated/online-home.js?client_ids=" + client_ids;
@tcmacdonald
tcmacdonald / gist:2900977
Created June 9, 2012 13:30
VIM: Repeat Edit Commands
.. # last edit (magic dot)
:& # last substitute
:%& # last substitute every line
:%&gic # last substitute every line confirm
g% # normal mode repeat last substitute
g& # last substitute on all lines
@@ # last recording
@: # last command-mode command
:!! # last :! command
:~ # last substitute
@tcmacdonald
tcmacdonald / .vimrc
Last active October 6, 2015 00:08
.vimrc
set nocompatible " be iMproved
filetype off " required!
call pathogen#infect()
if has("gui_macvim")
" let Vundle manage Vundle
" set rtp+=~/.vim/bundle/vundle/
" call vundle#rc()
" Bundle 'gmarik/vundle'
@tcmacdonald
tcmacdonald / postgresql.rake
Created October 22, 2012 15:27
Rake tasks for Postgresql
require 'yaml'
namespace :pg do
namespace :mac do
def conf
@conf ||= YAML.load_file("#{Rails.root}/config/database.yml")
end
def username