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 / json_spec.rb
Last active December 21, 2015 11:19
single file rails app and test to display json, */* returns html
require 'rails'
require 'action_controller/railtie'
require 'rspec'
require 'rack/test'
class JsonTestApp < Rails::Application
config.root = File.dirname(__FILE__)
config.session_store :cookie_store, key: '****************************************'
config.secret_token = '****************************************'
config.secret_key_base = 'yup'
@dplummer
dplummer / .htaccess
Created August 21, 2013 17:35
same htaccess redirect
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.new-domain.com$ [NC]
RewriteRule ^(.*)$ http://www.new-domain.com/$1 [L,R]
@dplummer
dplummer / gist:5513903
Created May 3, 2013 20:40
Compare two nested hashes
def compare_hashes(hash_a, hash_b, parent_keys = [])
keys_in_both = hash_a.keys & hash_b.keys
parent_name = parent_keys.map{|k| "['#{k}']"}.join
keys_in_both.each do |key|
if hash_a[key] != hash_b[key]
if hash_a[key].is_a?(Hash) && hash_b[key].is_a?(Hash)
compare_hashes(hash_a[key], hash_b[key], parent_keys + [key])
else
@dplummer
dplummer / gist:3778624
Created September 24, 2012 21:46
Struct.new block and constancts
1.8.7 :001 > Foo = Struct.new(:id) do
1.8.7 :002 > BAR = 5
1.8.7 :003?> end
=> Foo
1.8.7 :004 > BAR
=> 5
1.8.7 :005 > Foo::BAR
(irb):5: warning: toplevel constant BAR referenced by Foo::BAR
=> 5
@dplummer
dplummer / gist:3409229
Created August 20, 2012 23:27
order status count triggers
CREATE TRIGGER ai_order_statuses AFTER INSERT ON orders
FOR EACH ROW UPDATE order_status_counts
SET total = total + 1
WHERE status = NEW.status
AND order_type = NEW.type
AND (NEW.on_hold != 1 OR NEW.on_hold IS NULL)
CREATE TRIGGER ad_order_statuses AFTER DELETE ON orders
@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 {
@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 / 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 / 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 / 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"},