Skip to content

Instantly share code, notes, and snippets.

View colewinans's full-sized avatar

Cole Winans colewinans

View GitHub Profile
@colewinans
colewinans / gforms_dependent_values.js
Created November 12, 2012 15:05
Gravity Forms conditionally dependent values in jQuery
$("#input_1_9").change(function() {
if ($(this).val() == "" ) {
$("#input_1_16").val("Other (Non-US)");
} else {
$("#input_1_16").val($(this).val());
}
});
@colewinans
colewinans / jquery_equal_heights.js
Created November 15, 2012 22:07
Equalize Div Heights
$.fn.setAllToMaxHeight = function(){
return this.height( Math.max.apply(this, $.map( this , function(e){ return $(e).height() }) ) );
}
$(document).ready(function() {
$("div.equal").setAllToMaxHeight();
});
@colewinans
colewinans / wordpress_role_detection.php
Created December 5, 2012 20:42
WordPress Role Detection
<?php
if ( is_user_logged_in() ) {
$user = new WP_User( $user_ID );
if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
foreach ( $user->roles as $role )
echo $role;
}
}
?>
@colewinans
colewinans / synchronized_scrolling.js
Created December 28, 2012 04:18
Synchronized scrolling between two divs
$(document).ready(function(){
var topdivPos = $(".table-top").position();
$(".table-bottom").css("position","absolute").css("top",topdivPos.top).css("left",topdivPos.left).show();
$(".table-top").scroll(function(){
$(".table-bottom").scrollTop($(".table-top").scrollTop());
});
});
@colewinans
colewinans / swiftype_boosting.php
Created June 27, 2013 15:01
Swiftype boosting
switch($post->post_type):
case "glossary":
$type_value = 1;
break;
case "page":
$type_value = 2;
break;
case "book_section":
$type_value = 3;
break;
@colewinans
colewinans / gist:5891716
Last active December 19, 2015 03:39
has_many and has_many :through?
class User < ActiveRecord::Base
has_many :subscriptions
has_many :threads, :through => :subscriptions
has_many :threads
end
class Thread < ActiveRecord::Base
has_many :subscriptions
has_many :users, :through => :subscriptions
belongs_to :user
@colewinans
colewinans / gist:5892353
Created June 29, 2013 19:32
has_many :through issue
class User < ActiveRecord::Base
attr_accessible :email, :password, :password_confirmation, :remember_me, :username, :profile_image, :first_name, :last_name
has_many :publications
has_many :threads, :through => :publications
end
class Publication < ActiveRecord::Base
attr_accessible :thread_id, :user_id
belongs_to :thread
belongs_to :user
@colewinans
colewinans / gist:5895213
Last active December 19, 2015 04:09
null user_id has_many :through
#### User Model ####
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable, :confirmable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :email, :password, :password_confirmation,
:remember_me, :username, :profile_image,
:first_name, :last_name
# Creates 'x' categorizations with null category_id's
def create
@user = current_user
@post = @user.posts.create(params[:post])
@categories = @user.categories.all
@post.categorizations.build(:category_id => params[:categorization_ids])
params[:categorization_ids].each do |categorization|
@post.categorizations.build(params[:categorization_id])
end
end
@colewinans
colewinans / gist:7914695
Created December 11, 2013 17:24
WooCommerce – Tax Exempt
/**
* Add tax exempt fields to checkout
**/
add_action('woocommerce_before_order_notes', 'taxexempt_before_order_notes');
function taxexempt_before_order_notes( $checkout ) {
woocommerce_form_field( 'tax_exempt_checkbox', array(
'type' => 'checkbox',
'class' => array('tiri taxexempt'),array( 'form-row-wide', 'address-field' ),