Skip to content

Instantly share code, notes, and snippets.

View mlafeldt's full-sized avatar

Mathias Lafeldt mlafeldt

View GitHub Profile
require "erb"
require "pathname"
DOT_TEMPLATE=<<-END
digraph {
size="20,20";
overlap=false;
sep=0.4;
graph [fontname=Helvetica,fontsize=10];
node [fontname=Helvetica,fontsize=10];
@rkh
rkh / game.rb
Created October 30, 2011 06:44
Rock, paper, scissors in Sinatra
require 'sinatra'
# before we process a route, we'll set the response as
# plain text and set up an array of viable moves that
# a player (and the computer) can perform
before do
content_type :txt
@defeat = {rock: :scissors, paper: :rock, scissors: :paper}
@throws = @defeat.keys
end
@mislav
mislav / readme.md
Created January 25, 2012 14:42
CLI tool that checks the build status of current branch on Travis CI

Check build status of a project on the command line

Install (copy & paste):

curl -sL raw.github.com/gist/1676577/travis.rb > ~/bin/travis \
  && chmod +x ~/bin/travis

gem install hub | tail -2
ruby -e 'require "json"' 2&gt;/dev/null || gem install json
# Save this in an empty directory as Vagrantfile and run:
#
# gem install vagrant
# vagrant up
# vagrant ssh
#
# You need to have a recent VirtualBox installed.
Vagrant::Config.run do |config|
config.vm.box = "travis-ruby"
config.vm.box_url = "http://files.travis-ci.org/boxes/provisioned/travis-ruby.box"
begin
require 'highline/import'
rescue LoadError
puts "we need highline, please run:", "", "\tgem install highline", ""
exit 1
end
begin
require 'gh'
rescue LoadError
# encoding: binary
# Removes any bytes from a string that are not valid UTF-8
class Cleaner
attr_reader :bytes, :buffer, :outstanding
def self.clean(str)
new.tap { |c| c << str }.to_s
end
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
@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"
@fnichol
fnichol / 00_README.md
Created December 20, 2012 06:36
Chef Metadata Chopper!

MetadataChopper

MetadataChopper.extract('metdata.rb') # => [ "rvm", "0.9.1" ]
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 %>