Skip to content

Instantly share code, notes, and snippets.

View colewinans's full-sized avatar

Cole Winans colewinans

View GitHub Profile
@colewinans
colewinans / blockstackid.txt
Created November 8, 2017 22:20
Blockstack ID
Verifying my Blockstack ID is secured with the address 18nsbj4hQKPv8wY3ih4hToN8Rgms9PxXns https://explorer.blockstack.org/address/18nsbj4hQKPv8wY3ih4hToN8Rgms9PxXns
class VideoWorker
include Sidekiq::Worker
def perform(id, s3_key)
# Get the video
video = Video.find(id)
# Call ffmpeg to measure duration
duration = `ffmpeg -i '#{video.ffmpeg_url}' 2>&1 | grep Duration | awk '{print $2}' | tr -d ,`
@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' ),
# 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: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
@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: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 / 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 / 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 / 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;
}
}
?>