Skip to content

Instantly share code, notes, and snippets.

View ppg's full-sized avatar

Peter P. Gengler ppg

View GitHub Profile
module AfterCommit
def self.included(base)
base.class_eval do
[:save, :save!].each do |method|
alias_method_chain method, :after_commit
end
end
base.define_callbacks :after_commit, :after_commit_on_create
end
@lukebayes
lukebayes / ERBResolver
Created October 21, 2009 16:55
A Rake Task that makes it stupid-easy to render ERB templates to disk
##################################
# MIT LICENSE
# Copyright (C) 2012 Luke Bayes
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@donnoman
donnoman / capistrano-filter.rb
Created December 7, 2009 20:29
capistrano skip NoMatchingServers
# Allows Tasks that have no servers to be skipped instead of raising a NoMatchingServersError
module Capistrano
class Configuration
module Connections
def execute_on_servers(options={})
raise ArgumentError, "expected a block" unless block_given?
if task = current_task
servers = find_servers_for_task(task, options)
@jtimberman
jtimberman / ec2_client.rb
Created March 2, 2010 03:38
generate user_data.json with knife, launch instance with it and magic!
# Author:: Adam Jacob <adam@opscode.com>
# Author:: Joshua Timberman <joshua@opscode.com>
#
# Copyright 2009-2010, Opscode, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
@deepak
deepak / require_tracking.rb
Created July 6, 2010 14:17
Gather memory usage per files required and the time taken - useful to reduce startup time
# ACK:
# modified from
# http://gist.github.com/264496 by github.com/eric
# http://gist.github.com/465293 by github.com/alexyoung
# USAGE:
# 1) > ruby -rrequire_tracking -e "require 'active_support'"
# 2) put in config/preinitializer.rb
# WHAT: Provides a simple overview of memory allocation occuring
@TylerRick
TylerRick / javascript_code.rb
Created October 6, 2010 23:40
Proc#to_json, JavascriptCode#to_json
# This allows you to represents a JavaScript function with a proc. When converted to JSON, it will
# automatically wrap the method body with "function(){" and "}" and list as many arguments as you
# had listed in your proc, automatically giving them the names a, b, c, etc.
#
# This is convenient when you want to create a Ruby hash representating options to be passed to
# a JavaScript method, which you plan to call to_json on when you actually output the method call
# to the web page. If you tried to represent your JavaScript function with a string value in the
# hash, then when you called to_json on the hash, it would in turn call String#to_json, which
# returns an escaped copy of the string surrounded by quotes.
#
@kineticac
kineticac / Example of a "cron" delayed_job
Created November 17, 2010 20:45
Here's a quick way to run a delayed_job job like a cron job. The ensure block is the key to making sure it runs again.
class SampleJob
def perform
begin
# do all your work in the begin block.
puts "hello world"
rescue Exception => e
# rescue any errors so that you know something went wrong. Email yourself the error if you need.
error_msg = "#{Time.now} ERROR (SampleJob#perform): #{e.message} - (#{e.class})\n#{(e.backtrace or []).join("\n")}"
puts error_msg
ensure
@botchagalupe
botchagalupe / gist:796787
Created January 26, 2011 15:02
Rundeck with Chef

Make sure the EC2 instance for the Rundeck server has ports 4440 and 4443

Get the JAR files from github

wget https://github.com/downloads/dtolabs/rundeck/rundeck-launcher-1.1.0.jar --no-check-certificate

Install Java

sudo apt-get install openjdk-6-jre 
@rdetert
rdetert / application.html.erb
Created March 1, 2011 06:28
How to logout completely from Facebook using Ruby on Rails and Devise + Omniauth. I'm just modifying the Omniauth Railscast http://railscasts.com/episodes/236-omniauth-part-2
<div id="user_nav">
<% if user_signed_in? %>
<img src="<%= user_avatar %>" id="main_avatar"> Signed in as <%= current_user.email %>.<br />
Not you?
<% if session[:fb_token].nil? %>
<%= link_to "Sign out", destroy_user_session_path %>
<% else %>
<%= link_to "Sign out", facebook_logout_path %>
<% end %>
@dblock
dblock / delayed_jobs_controller.rb
Created June 4, 2011 20:06
Delayed job view and controller
class Admin::DelayedJobsController < AdminController
# GET /admin/delayed_jobs
def index
@delayed_jobs = Delayed::Backend::Mongoid::Job.desc(:created_at)
.paginate :page => params[:page], :per_page => 20
end
end