Skip to content

Instantly share code, notes, and snippets.

View mlafeldt's full-sized avatar

Mathias Lafeldt mlafeldt

View GitHub Profile
@gilligan
gilligan / vimrc
Created February 7, 2013 20:10
mlafeldt vimrc fiddling
" Based on Gary Bernhardt's .vimrc file:
" https://github.com/garybernhardt/dotfiles/blob/master/.vimrc
" vim: set ts=2 sts=2 sw=2 expandtab:
"
" global settings {{{
"
" enter vim mode
set nocompatible
" allow unsaved background buffers and remember marks/undo for them
#!/usr/bin/env bash
#
# Wraps curl with a custom-drawn progress bar. Use it just like curl:
#
# $ curl-progress -O http://example.com/file.tar.gz
# $ curl-progress http://example.com/file.tar.gz > file.tar.gz
#
# All arguments to the program are passed directly to curl. Define your
# custom progress bar in the `print_progress` function.
#
@henrik
henrik / rules.md
Last active May 23, 2022 12:31
Sandi Metz' four rules from Ruby Rogues episode 87. Listen or read the transcript: http://rubyrogues.com/087-rr-book-clubpractical-object-oriented-design-in-ruby-with-sandi-metz/
  1. Your class can be no longer than 100 lines of code.
  2. Your methods can be no longer than five lines of code.
  3. You can pass no more than four parameters and you can’t just make it one big hash.
  4. When a call comes into your Rails controller, you can only instantiate one object to do whatever it is that needs to be done. And your view can only know about one instance variable.

You can break these rules if you can talk your pair into agreeing with you.

desc 'generate a class in lib/ and a spec in spec/lib/ for name=underscored_class_name'
task :genclass do
require 'erb'
filename = ENV['name']
raise 'must specify name=underscored_class_name' unless filename
classname = filename.camelize
class_file_template = ERB.new <<-EOF
class <%= classname %>
@fnichol
fnichol / 00_README.md
Created December 20, 2012 06:36
Chef Metadata Chopper!

MetadataChopper

MetadataChopper.extract('metdata.rb') # => [ "rvm", "0.9.1" ]
@rtomayko
rtomayko / testlib.sh
Last active April 29, 2022 07:23
Simple shell command language test library.
#!/bin/sh
# Usage: . testlib.sh
# Simple shell command language test library.
#
# Tests must follow the basic form:
#
# begin_test "the thing"
# (
# set -e
# echo "hello"
@ayosec
ayosec / gist:3800745
Created September 28, 2012 16:15 — forked from juanje/gist:3797207
Some useful lines for my Vagrantfiles
# To have the last stable version of Chef (10.14.4)
# with the official Vagrant boxes
config.vm.provision :shell,
:inline => "gem search -i chef -v 10.14.4 || gem install chef -v 10.14.4 --no-rdoc --no-ri"
# with the official Opscode boxes
config.vm.provision :shell,
:inline => "/opt/chef/embedded/bin/gem search -i chef -v 10.14.4 || /opt/chef/embedded/bin/gem install chef -v 10.14.4 --no-rdoc --no-ri"
@juanje
juanje / gist:3797297
Created September 28, 2012 00:38
Mount apt cache of a Vagrant box in the host to spin up the packages installation

This is a little trick I use to spin up the packages instalation on Debian/Ubuntu boxes in Vagrant.

I add a simple function that checks if a directory named something similar to ~/.vagrant.d/cache/apt/opscode-ubuntu-12.04/partial (it may have another path in Windows or MacOS) and create the directory if it doesn't already exist.

def local_cache(basebox_name)
  cache_dir = Vagrant::Environment.new.home_path.join('cache', 'apt', basebox_name)
  partial_dir = cache_dir.join('partial')
  partial_dir.mkdir unless partial_dir.exist?
 cache_dir
#!/bin/bash
#
# This is the script responsible for updating our Puppet master data,
# which includes modules, manifests, hiera data, etc. All of this data is
# managed in a git repository and upon "deploy" it is synced into the Puppet
# master.
#
# This script mirrors the remote git repository, looking for branches that
# match "env-*" (such as "env-production" or "env-test"). Each of these branches
# is setup as an environment into the Puppet master's data files. The
class Chef
class Recipe
def skip_unsupported_platform
unless supported_platform?
Chef::Log.info("Unsupported platform #{node[:platform]} in #{cookbook_name}::#{recipe_name}, skipping recipe")
Chef::Log.debug("You said to skip unsupported platforms in #{cookbook_name}::#{recipe_name}")
Chef::Log.debug("and #{node['platform']} is unsupported by cookbook #{cookbook_name}. Update the cookbook's metadata")
Chef::Log.debug("if this is a supported platform, or remove #{cookbook_name}::#{recipe_name} from the node.")
end
end