Skip to content

Instantly share code, notes, and snippets.

View dplummer's full-sized avatar
😀

Donald Plummer dplummer

😀
View GitHub Profile
@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 / 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: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 / .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 / 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 / sinewave_button.css
Created April 18, 2014 22:29
Sinewave button CSS
.sinewave-button {
-webkit-background-clip: border-box;
-webkit-background-origin: padding-box;
-webkit-background-size: auto;
-webkit-box-shadow: rgba(0, 0, 0, 0.2) 0px 1px 0px 0px;
background-attachment: scroll;
background-clip: border-box;
background-color: transparent;
background-origin: padding-box;
background-size: auto;
@dplummer
dplummer / defer_touching.rb
Created May 14, 2014 05:11
Delay and prevent multiple touches
module DeferTouching
def self.defer_touching(*klasses, &block)
to_touch = Set.new
old_methods = klasses.inject({}) do |acc, klass|
acc[klass] = klass.instance_method(:touch)
acc
end
klasses.each do |klass|
@dplummer
dplummer / bloggo.conf
Created August 4, 2014 03:55
running go binary as service on ubuntu
# donaldplummer.com bloggo
description "donaldplummer.com blog"
start on (local-filesystems and net-device-up IFACE=lo and runlevel [2345])
stop on runlevel [!2345]
respawn
respawn limit 3 30
@dplummer
dplummer / alley.md
Last active August 29, 2015 14:23
calculate what players get free hand-me-down tanks from Armageddon

A total of 133 players will receive a free tank outside of what the top 30 clans get Created at 2015-06-20 08:53:49 -0700

Position Clan Licenses Used Unused
1 OTTER 100 72 28
2 ESPRT 100 62 38
3 PBKAC 100 60 40
4 BULBA 85 72 13
5 CHAI 60 60 0
@dplummer
dplummer / application.rb
Last active August 26, 2015 21:06
log silencer
# config/application.rb
class Application < Rails::Application
require 'log_silencer'
config.middleware.insert_before Rails::Rack::Logger,
LogSilencer,
silenced: /^\/options/
end