Skip to content

Instantly share code, notes, and snippets.

View dplummer's full-sized avatar
🚘
robot cars!

Donald Plummer dplummer

🚘
robot cars!
View GitHub Profile
@dplummer
dplummer / extend_response_time_logging.rb
Created January 5, 2011 23:35
Include in ApplicationController to bench calls and log them (like Rails does with View and DB)
module ExtendResponseTimeLogging
def self.included(base)
base.class_eval do
alias_method_chain :perform_action, :extra_benchmark
end
end
def bench(name, &block)
@additional_response_times[name] ||= 0.0
@additional_response_times[name] += Benchmark.ms {yield}
@dplummer
dplummer / table engine snippets
Created March 20, 2011 19:32
checking and altering table engines in mysql
# Find out what table engine your tables are using
select table_name, engine from information_schema.TABLES WHERE TABLE_SCHEMA = 'DATABASENAME';
# From bash, set the engine on all tables in a database to InnoDB
# Where /etc/mysql/debian.cnf has the root password for your mysql box
# Taken from http://kevin.vanzonneveld.net/techblog/article/convert_all_tables_to_innodb_in_one_go/
DATABASENAME="test"
for t in `echo "show tables" | mysql --defaults-file=/etc/mysql/debian.cnf --batch --skip-column-names $DATABASENAME`; do mysql --defaults-file=/etc/mysql/debian.cnf $DATABASENAME -e "ALTER TABLE $t ENGINE = InnoDB;"; done
@dplummer
dplummer / gist:1057203
Created June 30, 2011 20:48
Fix for rvm install 1.8.7 with glibc 2.14
glibc 2.14 breaks the install process for ruby 1.8.7 and ree 1.8.7.
Fix for ruby 1.8.7 install with rvm:
1. Run `rvm install ruby-1.8.7-p334`
2. Wait for it to fail.
3. Fix the broken files with:
cd ~/.rvm/src/ree-1.8.7-2011.03/source/ext/dl
rm callback.func
touch callback.func
ruby mkcallback.rb >> callback.func
@dplummer
dplummer / tcmalloc.patch
Created June 30, 2011 20:50
ree tcmalloc patch fix for glibc 2.14
diff -urB a/distro/google-perftools-1.7/src/tcmalloc.cc b/distro/google-perftools-1.7/src/tcmalloc.cc
--- a/distro/google-perftools-1.7/src/tcmalloc.cc
+++ b/distro/google-perftools-1.7/src/tcmalloc.cc
@@ -137,6 +137,13 @@
# define WIN32_DO_PATCHING 1
#endif
+// GLibc 2.14+ requires the hook functions be declared volatile, based on the value of the
+// define __MALLOC_HOOK_VOLATILE. For compatibility with older/non-GLibc implementations,
+// provide an empty definition.
@dplummer
dplummer / frontend.conf.patch
Created July 15, 2011 16:51
Patch for frontend.conf dev site rewrite
--- frontend.conf.original 2011-07-15 09:49:50.468952712 -0700
+++ frontend.conf 2011-07-15 09:55:06.948947048 -0700
@@ -39,6 +39,10 @@
if ($host ~* (.*)\.crystalcommerce\.com) {
set $client $1;
}
+ # get the client name if it matches client.crystalcommerce.com
+ if ($host ~* (.*)\.dev\.crystalcommerce\.com) {
+ set $client $1/dev;
+ }
@dplummer
dplummer / hash_of_arrays_permutations.rb
Created September 13, 2011 17:08
Permutations of a hash of arrays
# Input:
# choices = {
# 'color' => %w(blue red green),
# 'sizes' => %w(small medium large extra-large),
# 'style' => %w(tshirt longsleeve)
# }
#
# Output:
# [{"sizes"=>"small", "color"=>"blue", "style"=>"tshirt"},
# {"sizes"=>"small", "color"=>"blue", "style"=>"longsleeve"},
@dplummer
dplummer / deploy_assets.rb
Created June 11, 2012 15:49
vlad precompile assets locally task
namespace :vlad do
namespace :assets do
remote_task :symlink, :roles => :app do
run <<-CMD
rm -rf #{latest_release}/public/assets &&
mkdir -p #{latest_release}/public &&
mkdir -p #{shared_path}/assets &&
ln -s #{shared_path}/assets #{latest_release}/public/assets
CMD
end
@dplummer
dplummer / libstdcpp3.hpp.patch
Created June 12, 2012 16:58
passenger BOOST patch for gcc 4.7
# From https://svn.boost.org/trac/boost/ticket/6165
# Attempting to run passenger-install-nginx-module on a system with
# GCC 4.7 (like archlinux) will halt with BOOST thread errors.
# Update the file in ~/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/ext/boost/config/stdlib/libstdcpp3.hpp
Index: boost/config/stdlib/libstdcpp3.hpp
===================================================================
--- boost/config/stdlib/libstdcpp3.hpp (revision 75635)
+++ boost/config/stdlib/libstdcpp3.hpp (working copy)
@@ -33,7 +33,8 @@
@dplummer
dplummer / hmac_request_signing.rb
Created June 17, 2012 19:40
Hmac request signing
require 'base64'
require 'openssl'
require 'cgi'
module HmacRequestSigning
def inject_signature_header(headers, signature)
headers['X-Hmac-Sha256'] = signature
headers
end
@dplummer
dplummer / CFBFeatures.js
Created June 27, 2012 23:20 — forked from anonymous/CFBFeatures
Ajax from PHP
var count = 2;
var loader = $('.infinite-loader');
$(window).scroll(function() {
if($(window).scrollTop() == $(document).height() - $(window).height()) {
if(count > total) {
return false;
} else {