Skip to content

Instantly share code, notes, and snippets.

View TrevorHinesley's full-sized avatar

Trevor Hinesley TrevorHinesley

View GitHub Profile
@TrevorHinesley
TrevorHinesley / gist:639591dd3aaaaa0571facdd097c38bbe
Created July 2, 2019 23:40
StackPath CDN Private Bucket Read-Only Policy
{
"Id": "S3PolicyId1",
"Version": "2012-10-17",
"Statement": [
{
"Sid": "StackPathReadOnly",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
@TrevorHinesley
TrevorHinesley / mime_types.rb
Created July 27, 2018 18:06
Fast JSON API MIME type configuration
# JSONAPI_MEDIA_TYPE = 'application/vnd.api+json'
Mime::Type.register JSONAPI_MEDIA_TYPE, :jsonapi
ActionController::Renderers.add :jsonapi do |json, options|
json = json.to_json(options) unless json.is_a?(String)
self.content_type ||= Mime[:jsonapi]
self.response_body = json
end
ActionDispatch::Request.parameter_parsers[:jsonapi] = lambda do |body|
@TrevorHinesley
TrevorHinesley / render_jsonapi.rb
Last active July 27, 2018 18:01
Fast JSON API render simplifier
# Include this concern in your ApplicationController
# Must implement links_object and paginate_collection
module RenderJsonapi
extend ActiveSupport::Concern
included do
def render_jsonapi(*args)
options = args.extract_options!
collection = args.first
def helmet_distance_from_the_left team, index
width_of_largest_sideline = 850
midfield = width_of_largest_sideline / 2
helmet_starting_line_offset = index*3.8
distance_from_far_left_edge_to_one_yard_line = 130
distance_from_left = distance_from_far_left_edge_to_one_yard_line +
((team.num_of_hashtag_shares / team.offset) / days_until_campaign_ends)
if distance_from_left >= midfield
distance_from_midfield_to_current_position = distance_from_left - midfield
divisor = midfield / distance_from_midfield_to_current_position
@TrevorHinesley
TrevorHinesley / untitled
Last active August 29, 2015 13:56
Preferred College athlete_ids
athlete_ids = {}
PreferredCollege.all.each do |pc|
athlete_ids[pc.athlete_id.to_s].blank? ? athlete_ids[pc.athlete_id.to_s] = [pc.college_id] : athlete_ids[pc.athlete_id.to_s] << pc.college_id end
end