Skip to content

Instantly share code, notes, and snippets.

View marclove's full-sized avatar

Marc Love marclove

View GitHub Profile
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 CommentsController
def create
comment = Comment.new(params[:comment])
@comment = CommentCreator.new(comment).create!
respond_with @comment
end
end
class CommentCreator
def initialize(comment)
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.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
# Steps to implement:
# 1. Ensure you're using >= coffeescript-1.6.1
#
# 2. Put this file in an initializer.
#
# 3. Edit an environment's config to turn on source maps:
#
# `config.assets.sourcemaps = true`
#
# 4. Add /public/sourcemaps to your .gitignore
@marclove
marclove / gist:4080337
Created November 15, 2012 18:34 — forked from zenkay/gist:3237860
Installation tips for RVM/Ruby on OSX 10.8 Mountain Lion

Ruby, RVM and Mountain Lion

Key problems

Mountain Lion (10.8) has three main difference compared to Lion (10.7):

  • XCode 4.4 does not install Command Line Tools by default
  • X11 isn't available anymore
  • The installed version of OpenSSL has some bugs

How to work around

@marclove
marclove / theme.html
Created May 8, 2012 03:13 — forked from soemarko/theme.html
embed github gist to tumblr
<!-- Add the following lines to theme's html code right before </head> -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script src="http://static.tumblr.com/fpifyru/VCxlv9xwi/writecapture.js"></script>
<script src="http://static.tumblr.com/fpifyru/AKFlv9zdu/embedgist.js"></script>
<!--
Usage: just add <div class="gist">[gist URL]</div>
Example: <div class="gist">https://gist.github.com/1395926</div>
-->
@marclove
marclove / gist:2574131
Created May 2, 2012 05:36
RSpec matcher for JSON
# Will accept either a Hash or a JSON string as the expected value. Use it like this:
#
# @response.body.should be_json({:my => {:expected => ["json","hash"]}})
# @response.body.should be_json('{"my":{"expected":["json","hash"]}}')
RSpec::Matchers.define :be_json do |expected|
match do |actual|
actual = ActiveSupport::JSON.decode(actual).with_indifferent_access
expected = ActiveSupport::JSON.decode(expected) unless expected.is_a?(Hash)
expected = expected.with_indifferent_access
@marclove
marclove / Guardfile
Created April 12, 2012 07:41 — forked from drnic/Guardfile
An example Guardfile with the works for a Rails app
guard 'rspec', :version => 2 do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }