View example.rb
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 |
View node.rb
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 |
View snsTestPayload.json
{ | |
"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", |
View sns2slack.js
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 + "*" |
View multiple-dialogs.js
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){ |
View simple_dialog.js
BootstrapDialog.show({ | |
title: 'Hello', | |
message: 'I love this blog!' | |
}); |
View deploy.rb
before 'deploy:started', "puma:phased-restart" | |
after 'deploy:started', 'reenable_phased_restart' | |
task :reenable_phased_restart do | |
::Rake.application['puma:phased-restart'].reenable | |
end |
View en.yml
en: | |
activerecord: | |
attributes: | |
issue: | |
statuses: | |
open: OMG A BUG | |
closed: YAH, WE FIXED IT | |
reopened: DOH! | |
inprogress: WERKIN' ON IT |
View new.html.haml
= form_for @issue do |form| | |
= form.select :status, options_for_enum(Issue, :status, @issue), {:include_blank => true} |
View enum_helper.rb
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) |
NewerOlder