Skip to content

Instantly share code, notes, and snippets.

View christopherstyles's full-sized avatar

Chris Styles christopherstyles

View GitHub Profile
@christopherstyles
christopherstyles / archive_users.rake
Created July 27, 2014 21:42
Calling services from a rake task
namespace :archive do
task :users do
users.each do |user|
UnsubscribeUserFromList.call(user)
ArchiveUserComments.call(user)
end
end
end
@christopherstyles
christopherstyles / service_objects_noun_first.rb
Last active August 29, 2015 14:04
Service objects, noun-first
# Illustrate the usage of service objects named in the noun-first form.
# a test user
user = User.where(name: 'Oleg').first
UserListSubscription.subscribe(oleg, list)
# => "Oleg was added to the mailing list."
UserListSubscription.unsubscribe(oleg, list)
# => "Oleg was removed from the mailing list."
@christopherstyles
christopherstyles / service_objects_verb_first.rb
Last active August 29, 2015 14:04
Service objects, verb-first
# Illustrate the usage of service objects named in the verb-first form.
# a test user
user = User.where(name: 'Oleg').first
SubscribeUserToList.call(user)
# => "Oleg was added to the mailing list."
UnsubscribeUserFromList.call(user)
# => "Oleg was removed from the mailing list."
@christopherstyles
christopherstyles / notifications.rb
Created June 13, 2014 04:03
Nested classes versus compact style
# app/models/clubs/notification/invitation.rb
module Clubs
class Notification
class Invitation < Clubs::Notification
# snip
end
end
end
# Alternate
@christopherstyles
christopherstyles / invitations_controller.rb
Last active August 29, 2015 13:59
Move Clubs application invitation responsibilities to a controller
# app/controllers/admin/clubs/applications/invitations_controller.rb
module Admin
module Clubs
module Applications
# InvitationsController allows an application invitation to be sent, and
# to trigger subsequent actions, such as setting state on the application
# or sending an invitation email.
class InvitationsController < Admin::ApplicationController
respond_to :js
before_filter :set_application
<script type="text/javascript" id="">$(function(){$(".btn.btn-large.btn-action.btn-red").click(facebookTrackingSendClick)});function facebookTrackingSendClick(c){c.preventDefault();(function(){var a=document.createElement("script");a.async=!0;a.src="//connect.facebook.net/en_US/fp.js";a.onload=function(){};var b=document.getElementsByTagName("script")[0];b.parentNode.insertBefore(a,b)})()};</script>
<script type="text/javascript" id="">$(function(){$(".btn.btn-large.btn-action.btn-red").click(googleTrackingSendClick)});function googleTrackingSendClick(c){c.preventDefault();(function(){var a=document.createElement("script");a.async=!0;a.src="//www.googleadservices.com/pagead/conversion.js";a.onload=function(){};var b=document.getElementsByTagName("script")[0];b.parentNode.insertBefore(a,b)})()};</script>
@christopherstyles
christopherstyles / tire-search.rb
Last active December 19, 2015 02:09
Tire configuration for partial word matching.
tire.search(tire_params, load: true) do
query do
# Assumes +term+ is the text you're searching for
string term, default_field: 'title', default_operator: 'AND'
match :title, term, type: 'phrase_prefix', max_expansions: 10
end
end
#stories_list {
position: relative;
min-width: 960px;
li {
position: relative;
.item.cf {
padding: 0 5px;
.image {
margin-top: 5px;
}
$("#stories_list li").mouseenter ->
expandingClone = $(this).clone()
thisStory = $(this);
thisStory.addClass('original_story')
thisStoryWidth = thisStory.width();
thisStoryHeight = thisStory.height();
thisStoryWidthDouble = thisStory.outerWidth() * 2;
((window, $, App, undefined_) ->
App.homePage =
initialize: ->
# exit if we're not on the correct page
return if !$(document.body).hasClass('pages-home-view')
@bindElements()
bindElements: ->