Skip to content

Instantly share code, notes, and snippets.

@zuazo
zuazo / gcm_core_aead_gem_compat.rb
Created June 18, 2014 22:00
Checks aead gem compatibility with OpenSSL core in ruby >= 2
# Requires Ruby >= 2
require "openssl"
require "aead"
key = Digest::SHA256.digest("key") # digest_length 32
algorithm = "aes-256-gcm"
data = "plaintext data"
auth_data = "authentication data"
@zuazo
zuazo / Chef-recipe-block-fork.rb
Last active August 29, 2015 14:07
Chef examples for recipe_block and recipe_fork implementations
def recipe_block_run(&block)
@run_context.resource_collection = Chef::ResourceCollection.new
instance_eval(&block)
Chef::Runner.new(@run_context).converge
end
def recipe_block(description, &block)
recipe = self
ruby_block "recipe_block[#{description}]" do
block do
@zuazo
zuazo / cookbook_name_from_directory.rb
Created July 27, 2015 18:19
Get Chef cookbook name from cookbook directory
#!/usr/bin/env ruby
#
# Syntax:
# $ cookbook_name_from_directory.rb [DIRECTORY]
#
require 'stringio'
require 'chef/cookbook/metadata'
@zuazo
zuazo / Chef-Berksfile.rb
Last active February 4, 2016 02:55
Berksfile template for a Chef Cookbook
# encoding: UTF-8
# -*- mode: ruby -*-
# vi: set ft=ruby :
# More info at http://berkshelf.com/#the-berksfile
source 'https://supermarket.chef.io'
my_cookbook = ::File.basename(Dir.pwd).sub(/[-_]?cookbook$/, '')
# Berkshelf helper to include a local cookbook from disk.
@zuazo
zuazo / Chef-Guardfile.rb
Last active February 4, 2016 03:01
Guardfile template for a Chef Cookbook
# encoding: UTF-8
# -*- mode: ruby -*-
# vi: set ft=ruby :
# More info at https://github.com/guard/guard#readme
# Style Tests
# ===========
# - Foodcritic
# - RuboCop

Keybase proof

I hereby claim:

  • I am zuazo on github.
  • I am zuazo (https://keybase.io/zuazo) on keybase.
  • I have a public key whose fingerprint is ADAE EEFC BD78 6CBB B76B 1662 2195 FF19 5324 14AB

To claim this, I am signing this object:

@zuazo
zuazo / Chef-metadata-environment-pattern.rb
Last active November 17, 2016 08:58
This Chef Cookbook metadata.rb example reads the dependencies from Berksfile.lock. (Experimental)
# metadata.rb
# This metadata.rb example reads the dependencies from Berksfile.lock. This can
# be used to implement the Environment Pattern with Chef Server.
#
# The Environment Cookbook:
# http://blog.vialstudios.com/the-environment-cookbook-pattern/
name 'my_face'
# [...]
import os
import os.path
import sys
from carbon.hashing import ConsistentHashRing
from carbon.conf import settings
## Settings
# Absolute path to the Graphite Data Directory
DATA_DIR = '/data/graphite/whisper'
@zuazo
zuazo / Chef-Rakefile.rb
Last active May 23, 2019 13:39
Rakefile template for a Chef Cookbook: YARD, RuboCop, foodcritic, ChefSpec, Test Kitchen
# encoding: UTF-8
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# Available Rake tasks:
#
# $ rake -T
# rake clean # Clean some generated files
# rake default # Run doc, style, unit and integration tests
@zuazo
zuazo / Chef-Gemfile.rb
Last active April 17, 2020 18:59
Gemfile template for a Chef Cookbook
# encoding: UTF-8
# -*- mode: ruby -*-
# vi: set ft=ruby :
# More info at http://bundler.io/gemfile.html
source 'https://rubygems.org'
# Used when running the tests against different Chef versions:
chef_version = ENV.key?('CHEF_VERSION') ? ENV['CHEF_VERSION'] : nil