Skip to content

Instantly share code, notes, and snippets.

View workmad3's full-sized avatar

David Workman workmad3

View GitHub Profile
# Generate your password in your preferred manner, such as SecureRandom.base64(30)
node[:my_super_secret_password] ||= NodeEncryption.encrypt_value("super_secret!")
# Later on, recover the password
my_super_secret_password = NodeEncryption.decrypt_value(node[:my_super_secret_password])
def foo(options={})
default_options = {
foo: "bar"
}
options = options.dup
options.default_proc = proc{|h,k| default_options[k] || (raise ArgumentError.new("No value for required option #{k}"))}
# Now access options as 'normal'
@workmad3
workmad3 / sort.rb
Last active August 29, 2015 13:56 — forked from chief/gist:8944843
#!/usr/bin/env ruby
require "benchmark"
Benchmark.bmbm(7) do |x|
iterations = 10_000
a = 4000.times.map { |i| rand(i * 100).to_i }
a.sort!
common_packages = %w(python-setuptools python-dev)
case node['platform']
when "centos", "redhat", "amazon"
platform_packages = common_packages + ['gcc']
when "debian", "ubuntu"
platform_packages = common_packages + ['build-essential']
end
platform_packages.each do |pkg|
namespace :scrape do
desc "Take a screenshot of a url using Phantomjs"
task :screenshots => :environment do
require 'capybara'
require 'poltergeist/capybara'
include Capybara::DSL
Capybara.default_driver = :poltergeist
articles = Article.order('zscore DESC').limit(3)
articles.each_with_index do |article, i|
@workmad3
workmad3 / Gemfile
Last active August 29, 2015 13:56 — forked from markfeedly/commit_msg.rb
source 'https://rubygems.org'
gem 'sinatra'
gem 'bundler'
gem 'pry'
gem 'pry-doc'
gem 'pry-byebug'

Keybase proof

I hereby claim:

  • I am workmad3 on github.
  • I am workmad3 (https://keybase.io/workmad3) on keybase.
  • I have a public key whose fingerprint is A828 9E82 5DF9 242F A7C5 7310 0504 58CC 0BB0 5509

To claim this, I am signing this object:

class ClassToAddMethodsTo
def self.special_attr_accessor(attr, set: ->(val){val}, get: ->(val){val})
define_method attr do
get.(instance_variable_get "@#{attr}")
end
define_method "#{attr}=" do |rhs|
instance_variable_set "@#{attr}", set.(rhs)
end
end
config.json goes in <chef-repo>/.berkshelf/api-server
berkshelf-api.sh script goes in <chef-repo>
If you use bundler in your chef-repo, add berkshelf-api to the Gemfile, otherwise 'gem install berkshelf-api'
= form_for([@forum, @topic]) do |f|
- if @topic.errors.any?
%div{id: 'error_explanation'}
%h2
= pluralize(@topic.errors.count, "error")
prohibited this topic from being saved:
- for message in @topic.errors.full_messages
%li
= message