Skip to content

Instantly share code, notes, and snippets.

View mlafeldt's full-sized avatar

Mathias Lafeldt mlafeldt

View GitHub Profile
@mlafeldt
mlafeldt / create-release.rb
Last active March 13, 2017 01:45
Accessing GitHub Releases API with Ruby -- http://developer.github.com/v3/repos/releases/
require "net/https"
require "json"
gh_token = ENV.fetch("GITHUB_TOKEN")
gh_user = ARGV.fetch(0)
gh_repo = ARGV.fetch(1)
release_name = ARGV.fetch(2)
release_desc = ARGV[3]
uri = URI("https://api.github.com")
@mlafeldt
mlafeldt / Vagrantfile
Last active December 23, 2015 07:09
Install Chef 11 with Vagrant's shell provisioner
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu-12.04"
config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box"
# Install Chef version 11
config.vm.provision :shell, :inline => <<EOS
set -e
if ! command -V chef-solo >/dev/null 2>/dev/null; then
curl -L https://www.opscode.com/chef/install.sh | bash -s -- -v 11.6.0
fi
@mlafeldt
mlafeldt / Vagrantfile
Created September 6, 2013 11:42
Provision a VM with Vagrant that can run the Cucumber scenarios in the current folder
# vi: set ft=ruby :
# Install Cucumber and dependencies, and run scenarios.
$script = <<SCRIPT
set -e -x
test -f /var/lib/apt/periodic/update-success-stamp || sudo apt-get update -y
sudo apt-get install -y update-notifier-common ruby rubygems ruby-bundler git
bundle install --gemfile=/vagrant/Gemfile
cd /vagrant
bundle exec rake features
@mlafeldt
mlafeldt / Rakefile
Created August 22, 2013 21:35
Encrypt environment variables for Travis
desc 'Encrypt environment variables for Travis'
task :travis_encrypt, [:aws_key_id, :aws_secret] do |t, args|
raw_vars = "AWS_ACCESS_KEY_ID=#{args[:aws_key_id]} AWS_SECRET_ACCESS_KEY=#{args[:aws_secret]}"
sh 'travis', 'encrypt', raw_vars
end
@mlafeldt
mlafeldt / Rakefile
Created August 14, 2013 15:08
Validate CloudFormation templates with aws-sdk
require 'aws-sdk'
def validate_template(body)
cfn = AWS::CloudFormation.new
cfn.validate_template(body)
end
desc 'Validate CloudFormation template files'
task :test do
Dir.glob('*.json').each do |template|
bundle package
mkdir /tmp/gem_server
mv vendor/cache/ /tmp/gem_server/gems
gem generate_index -d /tmp/gem_server/
cd /tmp/gem_server/gems
python -m SimpleHTTPServer
@mlafeldt
mlafeldt / Gemfile.lock
Last active December 12, 2015 03:38
Fun with ChefSpec dependencies
PATH
remote: .
specs:
chefspec (1.0.0)
chef (>= 0.9.12)
erubis
fauxhai (~> 0.1)
minitest-chef-handler (~> 0.6.0)
moneta (< 0.7.0)
rspec (~> 2.12.0)
@mlafeldt
mlafeldt / rules.rb
Created December 4, 2012 12:08
BP001 foodcritic rule
# Bigpoint's foodcritic rules
rule 'BP001', 'Missing poem in README' do
tags %w(style readme poem)
cookbook do |path|
file = File.join(path, 'README.md')
# XXX FC011 already checks that the README exists.
if File.file?(file) && (File.read(file) !~ /^Poem/)
[ file_match(file) ]
end
@mlafeldt
mlafeldt / berkshelf.patch
Created November 30, 2012 16:17
Patch Berkshelf to keep a cookbook's .git folder
--- a/vendor/gems/ruby/1.9.1/gems/berkshelf-1.0.4/lib/berkshelf/berksfile.rb
+++ b/vendor/gems/ruby/1.9.1/gems/berkshelf-1.0.4/lib/berkshelf/berksfile.rb
@@ -38,10 +38,6 @@
# Dir.glob does not support backslash as a File separator
src = cb.path.to_s.gsub('\\', '/')
FileUtils.cp_r(Dir.glob(File.join(src, "*")), dest)
+
+ # Copy .git dir if present
+ git_dir = File.join(src, ".git")
+ FileUtils.cp_r(git_dir, dest) if File.exists?(git_dir)
@mlafeldt
mlafeldt / Cheffile.rb
Created November 28, 2012 12:11
Add github method to Cheffile (similar to Berkshelf's github shortcut)
# vi: set ft=ruby :
def github(user, repo, protocol = :git)
prefix = {
:git => 'git://github.com/',
:ssh => '[email protected]:',
:https => 'https://github.com/'
}[protocol]
"#{prefix}#{user}/#{repo}.git"
end