Skip to content

Instantly share code, notes, and snippets.

View gogogarrett's full-sized avatar

Garrett Heinlen gogogarrett

  • Netflix
  • San Francisco, CA
View GitHub Profile
class TermsAndCondition < ActiveRecord::Base
include CommonScopes
include CheckBannedWords
include ReachRoleExtensions
belongs_to :program
has_reach
has_paper_trail
is_hierarchable
is_dynamically_translatable title: { required: true }, content: { required: true }, mcf_content: { required: false }, accept_text: { required: true }, decline_text: { required: true }, decline_message: { required: true }
def send_custom_email email, email_translation, recipient, context_variables
# ...
fields = %w|{{user.first_name}} {{user.last_name}} {{user.username}} {{user.site_name}}
{{initiative.name}} {{initiative_methodology.name}} {{user_award.points}} {{user_award.disbursed_at}}
{{user_award.reason}} {{user_award.message}} {{user_award.link}} {{file_upload_job.status}}|
if recipient.present?
fields.each do |f|
@gogogarrett
gogogarrett / engine_routes.rb
Created February 21, 2013 17:33
How to namespace routes in RefineryCMS Engine to a resource outside of refinery.
Refinery::Core::Engine.routes.draw do
# Frontend routes
resources :core_topics do
namespace :articles, :path => '/articles' do
resources :articles, :path => '', :only => [:index, :show]
end
end
# Admin routes
<script type="text/javascript">
var SubmissionForm = {
edit_link: "/find_submission_option_contents",
edit_option_link: "/find_submission_option_settings",
save_sort_url: "/save_submission_sort",
finished_content: false,
finished_type: false,
current_locale: $("#meth_locale").val(),
@gogogarrett
gogogarrett / old_code.rb
Last active December 14, 2015 12:28
Refactor bad methods..into one much smaller method.
def can_upload_awards?
self.secondary_roles.each do |role|
return true if role.can_upload_awards?
end
false
end
def can_shop?
self.secondary_roles.each do |role|
return true if role.can_shop?
def can_receive_award_according_to_restrictions? user, award
remaining_restriction_points(user) >= award[:points].to_i &&
remaining_restriction_game_tokens(user) >= award[:game_tokens].to_i &&
remaining_restriction_gift_tokens(user) >= award[:gift_tokens].to_i
end
currencies = ["points", "game_tokens", "gift_tokens"]
currencies.each do |currency|
define_method "remaining_restriction_#{currency}" do |user|
currency_points = find_currency_of_submissions(user, currency)
@gogogarrett
gogogarrett / equalization_steps.rb
Created March 10, 2013 02:50
Given an array [11, 3, 7, 1], this will compute how many steps it takes in order to make every element the same value. [6,6,6,6]
def equalization_steps(a)
array, steps = a, 0
begin
a.each_with_index do |v, i|
if v > a[ (i + 1) % a.length ]
array[i] -= 1
else
array[i] += 1
end
def heavy_decimal_count(a, b)
total = 0
(a..b).each do |value|
values = value.to_s.split('')
array_size = values.size
if (values.map(&:to_i).inject{|sum,n| sum += n }.to_f / array_size.to_f) > 7.0
total += 1
end
<% page = Refinery::Page.find_by_path("about") %>
<ul>
<% page.children.each_with_index do |child, i| %>
<li>
<%= image_tag(asset_path("hex-#{i + 1}.png")) %>
</li>
<% end if page.children %>
</ul>
SlideShow =
current_image: 0,
max_images: 0,
init: ->
$slideshow = $('#slideshow > div ul')
$slideshow.find('li').hide().eq(0).show()
this.max_images = $slideshow.find('li').length
@changeSlide($slideshow)