Skip to content

Instantly share code, notes, and snippets.

View johnnaegle's full-sized avatar
🐈
I'm here live, I'm not a cat

John Naegle johnnaegle

🐈
I'm here live, I'm not a cat
View GitHub Profile
@johnnaegle
johnnaegle / sns2slack.js
Last active December 15, 2020 21:46
Posts an Amazon Autoscaling SNS message to a slack webhook
var https = require('https');
var util = require('util');
var webhook = '/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX';
exports.handler = function(event, context) {
console.log(JSON.stringify(event, null, 2));
console.log('From SNS:', event.Records[0].Sns.Message);
var postData = {
"text": "*" + event.Records[0].Sns.Subject + "*"
root = Node.create!
child = Node.create!(:parent => root, :value => 12)
grandchild = Node.create!(:parent => child)
root.effective_value # nil
child.effective_value # 12
grandchild.effective_value # 12 -- inherited from child
@johnnaegle
johnnaegle / node.rb
Last active September 7, 2016 18:10
ActiveRecord::Schema.define do
create_table :nodes, :force => true do |t|
t.string :name
t.string :value
t.string :ancestry, :index => true
end
end
class Node < ActiveRecord::Base
has_ancestry
{
"Records": [
{
"EventSource": "aws:sns",
"EventVersion": "1.0",
"EventSubscriptionArn": "arn:aws:sns:us-east-1:XXX",
"Sns": {
"Type": "Notification",
"MessageId": "XXX",
"TopicArn": "arn:aws:sns:us-east-1:XXX",
BootstrapDialog.show({
title: 'Yo DAWG! A popup on your popup',
message: function(dialog) {
return $('<div>I heard you like that</div>');
},
buttons: [
{
label: 'Close',
cssClass: 'btn btn-default btn-sm',
action: function(dialogItself){
BootstrapDialog.show({
title: 'Hello',
message: 'I love this blog!'
});
@johnnaegle
johnnaegle / deploy.rb
Created May 27, 2016 14:08
restart puma before a deploy to free memory
before 'deploy:started', "puma:phased-restart"
after 'deploy:started', 'reenable_phased_restart'
task :reenable_phased_restart do
::Rake.application['puma:phased-restart'].reenable
end
@johnnaegle
johnnaegle / log_formatting.rb
Last active December 21, 2015 01:09
A Rails 3.2 initializer that adds formatted time and process IDs to the log file
class ActiveSupport::BufferedLogger
def formatter=(formatter)
@log.formatter = formatter
end
end
class Formatter
SEVERITY_TO_COLOR_MAP = {'DEBUG'=>'0;37', 'INFO'=>'32', 'WARN'=>'33', 'ERROR'=>'31', 'FATAL'=>'31', 'UNKNOWN'=>'37'}
def call(severity, time, progname, msg)
@johnnaegle
johnnaegle / spec_helper.rb
Last active December 17, 2015 03:48
Spec Helper Modifications
ENV["RAILS_ENV"] = "test"
require File.expand_path("../dummy/config/environment.rb", __FILE__)
require "rails/test_help"
require 'scratch' # Replace this with the name of your gem
Rails.backtrace_cleaner.remove_silencers!
@johnnaegle
johnnaegle / gist:5545373
Created May 9, 2013 03:34
Convert from test-unit to rspec
~/projects/scratch> rspec --init
create spec/spec_helper.rb
create .rspec
~/projects/scratch> mv test/dummy spec/
~/projects/scratch> rm -rf test