Skip to content

Instantly share code, notes, and snippets.

View ppg's full-sized avatar

Peter P. Gengler ppg

View GitHub Profile
@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.
#
@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
@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
@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)
@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:
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