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
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",
@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 + "*"
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
en:
activerecord:
attributes:
issue:
statuses:
open: OMG A BUG
closed: YAH, WE FIXED IT
reopened: DOH!
inprogress: WERKIN' ON IT
= form_for @issue do |form|
= form.select :status, options_for_enum(Issue, :status, @issue), {:include_blank => true}
module EnumHelper
def enum_to_translated_option(klass, enum, enum_value, default = enum_value.to_s.titleize)
key = "activerecord.attributes.#{klass.to_s.underscore.gsub('/', '_')}.#{enum}.#{enum_value}"
translated = I18n.t(key, :default => default)
end
def enums_to_translated_options_array(klass, enum)
enum_values = klass.send(enum)
enum_values.map do |enum_value, db_value|
translated = enum_to_translated_option(klass, enum, enum_value)