Skip to content

Instantly share code, notes, and snippets.

View marclove's full-sized avatar

Marc Love marclove

View GitHub Profile
class CommentsController
def create
@comment = Comment.create(params[:comment])
if @comment.previous_comment?
reply_to_user = comment.previous_comment.author
CommentCreatedWorker.perform_async(@comment.id, reply_to_user.id)
end
respond_with @comment
end
end
class CommentsController
def create
@comment = Comment.create(params[:comment])
CommentCreatedWorker.perform_async(@comment.id)
respond_with @comment
end
end
class CommentCreatedWorker
include Sidekiq::Worker
class CommentsController
def create
comment = Comment.new(params[:comment])
@comment = CommentCreator.new(comment).create!
respond_with @comment
end
end
class CommentCreator
def initialize(comment)
class CommentCreator
#...
def perform
ThreadParticipantsNotifier.new(@comment).notify
if comment.previous_comment?
in_reply_to_user = comment.previous_comment.author
ReplyMailer.notification(in_reply_to_user, comment).deliver
end
class CommentCreator
#...
def perform
ThreadParticipantsNotifier.new(@comment).notify
CommentReplyNotifier.new(@comment).notify
Kissmetrics.record(comment.author, 'Added Comment')
end
end
@marclove
marclove / gist:e93feefc1e72c663acb9
Created April 14, 2015 23:55
Xcode Build Script to automatically set Version & Build Number
git=$(sh /etc/profile; which git)
latest_tag=$("$git" describe --tags --always --abbrev=0)
version_string="${git_release_version#*v}" # assumes the following tag format: v1.2.3
number_of_commits=$("$git" rev-list <$$$$$$-YOUR DEVELOPMENT BRANCH NAME HERE-$$$$$$> | wc -l | tr -d ' ')
target_plist="$TARGET_BUILD_DIR/$INFOPLIST_PATH"
dsym_plist="$DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME/Contents/Info.plist"
for plist in "$target_plist" "$dsym_plist"; do
if [ -f "$plist" ]; then
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $number_of_commits" "$plist"
@marclove
marclove / sinatra_metal.rb
Created August 3, 2009 05:18 — forked from raggi/sinatra_metal.rb
How to mount Sinatra as Rails Metal
require 'sinatra/metal'
class SinatraMetal < Sinatra::Base
include Sinatra::Metal
get '/sinatra' do
'hello sinatra!'
end
end
@marclove
marclove / iterator.rb
Created October 31, 2009 16:00 — forked from tmm1/iterator.rb
EventMachine::Iterator
module EventMachine
# A simple iterator for concurrent asynchronous work.
#
# Unlike ruby's built-in iterators, the end of the current iteration cycle is signaled manually,
# instead of happening automatically after the yielded block finishes executing. For example:
#
# (0..10).each{ |num| }
#
# becomes:
#
namespace :harmony do
desc "Munges the data"
task :munge => :environment do
docs_with_publish = Item.collection.find({'publish' => {'$exists' => true}}).to_a
puts "Item count: #{Item.count}"
puts "Items with publish key: #{docs_with_publish.size}"
docs_with_publish.each do |hash|
hash.delete('publish')
@marclove
marclove / oauth2_example.rb
Created April 23, 2010 03:32 — forked from technoweenie/oauth2_example.rb
oauth2 facebook
# crappy server implementation using technoweenie/oauth2 (server branch)
# http://github.com/technoweenie/oauth2/compare/master...server
#
# ruby oauth2_example.rb -p 4568
# ruby oauth2_example.rb
# open http://localhost:4567/auth/facebook
require 'rubygems'
require 'sinatra'
require 'oauth2/client'