I hereby claim:
- I am bayendor on github.
- I am dbayendor (https://keybase.io/dbayendor) on keybase.
- I have a public key ASB1V69Is1m_YenJTKqCUfMSmusHP5quka8emz0F5BjJNQo
To claim this, I am signing this object:
[inodes_alert:log11] 2017/02/28 20:39:40 I! {"Name":"disk","Database":"","RetentionPolicy":"","Group":"host=aws-nv-u-csadb02,path=/net/zfs1/export/analyticsbinning","Dimensions":{"ByName":false,"TagNames":["host","path"]},"Tags":{"host":"aws-nv-u-csadb02","path":"/net/zfs1/export/analyticsbinning"},"Fields":{"inodes_used_percent":0},"Time":"2017-02-28T20:39:40Z"} | |
[inodes_alert:log11] 2017/02/28 20:39:40 I! {"Name":"disk","Database":"","RetentionPolicy":"","Group":"host=aws-nv-u-csadb02,path=/net/zfs1/export/analyticsdigital","Dimensions":{"ByName":false,"TagNames":["host","path"]},"Tags":{"host":"aws-nv-u-csadb02","path":"/net/zfs1/export/analyticsdigital"},"Fields":{"inodes_used_percent":0},"Time":"2017-02-28T20:39:40Z"} | |
[inodes_alert:log11] 2017/02/28 20:39:40 I! {"Name":"disk","Database":"","RetentionPolicy":"","Group":"host=aws-nv-u-csadb02,path=/net/zfs1/export/analyticsprojects","Dimensions":{"ByName":false,"TagNames":["host","path"]},"Tags":{"host":"aws-nv-u-csadb02","path":"/net/zfs1/export/analyti |
// inodes_alert example | |
// DEFINE: kapacitor define inodes_alert -type stream -tick inodes_alert.tick -dbrp telegraf.ninety_days | |
// ENABLE: kapacitor enable inodes_alert | |
// Parameters | |
var period = 5m | |
var every = 30s | |
var warn = 90 | |
var crit = 95 |
I hereby claim:
To claim this, I am signing this object:
" Set up puppet manifest and spec options | |
au BufRead,BufNewfile *.pp | |
\ set filetype=puppet | |
au BufRead,BufNewfile *_spec.rb | |
\ nmap <F8 :!rspec --color %<CR> | |
" Enable indentation matching for =>'s | |
filetype plugin indent on | |
" turn off auto adding comments on next line |
/data/docker/containers/*/*-json.log { | |
daily | |
rotate 7 | |
size 100M | |
compress | |
delaycompress | |
missingok | |
} |
def flatten_clone(array, level = -1, result = []) | |
array.each do |element| | |
if element.is_a?(Array) && level != 0 | |
flatten_clone element, level - 1, result | |
else | |
result << element | |
end | |
end | |
result | |
end |
The cryptic Ruby function takes an array as an argument and returns an array of the items that occur more than once in the original array.
It does this using the inject
method specifying an empty Hash as the accumulator. It iterates over each item in the array by referencing the item index position, and passes the resulting item into the accumulator. This builds up a hash of key/value pairs with the key being the item from the initial collection and the value representing the number of times the item appears in the array. It then uses the reject
method on the resulting hash and iterates over the hash returning a new array containing the items in self
for which the given block is false.
Using idiomatic Ruby a cleaner way to write this function would be:
def show_duplicates(collection)
collection.select { |element| collection.count(element) > 1 }.uniq
end
# Find all the items that have the word "elegant" in it. | |
items = Item.where("name LIKE ?", "%elegant%") | |
# Add three orders to a user. | |
3.times do |i| | |
user = User.first | |
order = Order.create!(user_id: user.id) | |
order.items << Item.find(i + 1) | |
end | |
namespace :deploy do | |
desc "Deploys app to Github & production." | |
task all: :environment do | |
if system("rake test:all") == false | |
puts "The tests fail." | |
break | |
end | |
puts "The tests passed." |
require 'rspec' | |
def sum(numbers) | |
numbers.inject(0) { |sum, number| sum + number } | |
end | |
def product(numbers) | |
numbers.inject(1) { |sum, number| sum * number } | |
end |