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
# 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" }
@marclove
marclove / node-and-npm-in-30-seconds.sh
Created September 9, 2011 01:45 — forked from isaacs/node-and-npm-in-30-seconds.sh
Use one of these techniques to install node and npm without having to sudo. Discussed in more detail at http://joyeur.com/2010/12/10/installing-node-and-npm/ Note: npm >=0.3 is *safer* when using sudo.
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl http://npmjs.org/install.sh | sh
@marclove
marclove / gist:1024592
Created June 14, 2011 09:42 — forked from dhh/gist:1014971
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
# Extend jQuery objects with Underscore collection methods.
#
# Each collection method comes in two flavors: one prefixed
# with _, which yields a bare DOM element, and one prefixed
# with $, which yields a jQuery-wrapped element.
#
# So if `this` is a jQuery object, instead of:
#
# _.max @, (el) -> $(el).height()
#