Skip to content

Instantly share code, notes, and snippets.

context 'when using sudo' do
let(:accessor) { :sudo }
it 'sets itself to true' do
let(:value) { true }
should eql(value)
end
end
@adamhjk
adamhjk / mono_v_mono.md
Created July 28, 2014 21:23
mono_v_mono

monlith

cookbooks/apache2: 1.2.1, depends: { app 0.7.0 }
cookbooks/app: 0.8.0
cookbooks/french_fries: 1.1.1

^ The above is not an acceptable thing

cookbook-as-repo

fn main() {
let args: Vec<String> = os::args();
let mut washed_args = Vec::new();
for arg in args.iter() {
washed_args.push(arg.as_slice())
}
match washed_args.as_slice() {
[_, “review”, opts..] => { review(opts) }
_ => { usage() }
fn review(opts: &[&str]) {
let target = match opts {
[ "--for", p ] => p,
_ => "master"
};
let cwd = os::getcwd();
let have_dot_git = have_dot_git(cwd.clone());
let dot_git_dir: &Path = match have_dot_git.as_ref() {
Some(path) => path,
func dot_git_dir(dir string) string {
git_dir := path.Join(dir, ".git")
_, dir_error := os.Stat(git_dir)
if dir_error != nil {
if git_dir == "/.git" {
log.Fatal("Cannot find a .git directory")
}
return dot_git_dir(path.Dir(dir))
} else {
return git_dir
func current_branch(git_dir string) string {
head_bytes, err := ioutil.ReadFile(path.Join(git_dir, "HEAD"))
head := string(head_bytes)
if err != nil {
log.Fatal("Cannot open HEAD from ", git_dir)
}
r, _ := regexp.Compile("ref: ref/heads/(.+)")
match := r.FindStringSubmatch(head)
branch := match[1]
return branch
fn current_branch(path: &Path) -> String {
let head_ref = head_ref(path);
println!("The ref for HEAD is {}", head_ref);
let r = regex!(r"refs/heads/(.+)");
let caps_result = r.captures(head_ref.as_slice());
let branch: String = match caps_result {
Some(cap) => { String::from_str(cap.at(1)) },
None => { panic!("You must be somewhere on refs/heads, and you aren't") }
};
branch
@adamhjk
adamhjk / chef.rs
Created November 19, 2014 00:56
Chef in rust
extern crate chef;
use chef::{client};
use chef::resource::{Package, Service, Template};
// Total Strawman
fn main() {
let mut chef = client.new();
chef.r(
Package{
#![feature(phase)]
#![feature(old_orphan_check)]
extern crate regex;
#[macro_use] extern crate regex_macros;
extern crate "rustc-serialize" as rustc_serialize;
extern crate docopt;
#[macro_use] extern crate docopt_macros;
#[macro_use] extern crate log;
use std::os;
#![feature(plugin)]
extern crate regex;
#[plugin] extern crate regex_macros;
extern crate "rustc-serialize" as rustc_serialize;
#[macro_use] extern crate docopt;
#[plugin] extern crate docopt_macros;
#[macro_use] extern crate log;