Skip to content

Instantly share code, notes, and snippets.

@stevendanna
stevendanna / gist:1230032
Created September 20, 2011 19:14
Example of extending Package::Apt to prohibit service start-up. Warning: Unreliable.
class Chef::Provider::Package::Apt
def install_package(name, version)
package_name = "#{name}=#{version}"
package_name = name if @is_virtual_package
run_command_with_systems_locale(:command => "printf '#!/bin/sh\n\exit 101' > /usr/sbin/policy-rc.d && chmod +x /usr/sbin/policy-rc.d") if @new_resource.prohibit_start
begin
run_command_with_systems_locale(:command => "apt-get -q -y#{expand_options(@new_resource.options)} install #{package_name}",
:environment => {
"DEBIAN_FRONTEND" => "noninteractive"
}
@stevendanna
stevendanna / gist:1254950
Created September 30, 2011 20:57
Delete node named "new"
# Run the following commands in Shef
sillynode = nodes.all { |n| n if n.name == "new" }
sillynode.compact!
sillynode = sillynode[0]
sillynode.destroy
@stevendanna
stevendanna / default.rb
Created October 11, 2011 16:33
Monkey patching the Template resource to do validation
#
# Cookbook Name:: template_checker
# Recipe:: default
#
# Copyright 2011, Opscode, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
ac-R 0.2 available Autocompletion routines for R
ac-ja 0.0.1 available auto-complete-mode source for Japanese
ac-slime 0.1 available An auto-complete source using slime completions
ace-jump-mode 1.0 available a quick cursor location minor mode for emacs
ahg 0.99 available Alberto's Emacs interface for Mercurial (Hg)
all 1.0 available Edit all lines matching a given regexp
alpha 1.0 available increase frame transparency
android-mode 0.1 available Minor mode for Android application development
anything 1.287 available open anything / QuickSilver-like candidate-selection framework
anything-R 0.1.2010 available anything-sources and some utilities for GNU R.
# Install Dependencies
sudo yum-builddep emacs
sudo yum install
# Get source
cd ~/src
git clone git://git.savannah.gnu.org/emacs.git
cd emacs
# Install
./autogen.sh

./configure

chef:recipe > puts (:this => "that")
SyntaxError: (irb#1):38: syntax error, unexpected tASSOC, expecting ')'
puts (:this => "that")
^
(irb#1):38: syntax error, unexpected ')', expecting $end
chef:recipe > puts(:this => "that")
{:this=>"that"}
=> nil
chef:recipe > puts ({:this => "that"})
require 'chef/knife'
class Chef
class Knife
class CheckBootstrap < Knife
deps do
require 'chef/knife/bootstrap'
require 'chef/knife/core/bootstrap_context'
require 'erubis'
chef > recipe
chef:recipe > node.default['foo'] = "bar"
=> "bar"
chef:recipe > node.set_unless['foo'] = "baz"
=> "baz"
chef:recipe > node['foo']
=> "baz"
chef:recipe > node.normal['boo'] = "bar"
=> "bar"
chef:recipe > node.set_unless['boo'] = "baz"
@stevendanna
stevendanna / summarize
Created March 11, 2012 01:35
summarize: A script to generate summarize statistics from input
#!/usr/bin/Rscript
#
# Quickly generate some basic descriptive
# statistics from stdin
#
library('optparse', quietly=TRUE)
option_list <- list(make_option(c("-H", "--header"), action="store_true", default=FALSE,
error() {
echo "$1" >&2
return 1
}
is_integer() {
case "$1" in
''|*[!0-9]*)
return 1