Skip to content

Instantly share code, notes, and snippets.

View jtimberman's full-sized avatar
🚀

Joshua Timberman jtimberman

🚀
View GitHub Profile

Immutable Ruby

Libraries I talked about

  • ice_nine: Deep freeze ruby objects
  • Values: Simple immutable value objects for ruby
  • immutable_attributes: specify attributes within an ActiveRecord model that can be set but not modified
  • hamster: Efficient, Immutable, Thread-Safe Collection classes for Ruby

Next Steps

@jtimberman
jtimberman / build.sh
Last active December 15, 2015 16:38
A jenkins build script for cookbook jobs. Totally untested.
#!/bin/bash
#
# Author:: Joshua Timberman <joshua@opscode.com>
#
# Copyright (c) 2013, Opscode, Inc. <legal@opscode.com>
#
# 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
#
@jtimberman
jtimberman / Thorfile
Last active December 15, 2015 16:38
This Thor task should get you all set up to run test kitchen 1.0.0.alpha.2 with vagrant 1.1.
#
# Author:: Joshua Timberman <joshua@opscode.com>
#
# Copyright (c) 2013, Opscode, Inc. <legal@opscode.com>
#
# 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
#
# http://www.apache.org/licenses/LICENSE-2.0
@ranjib
ranjib / clone_opscode_cookbooks.rb
Created March 19, 2013 20:56
Clone all opscode cookbooks
require 'nokogiri'
require 'restclient'
Nokogiri::HTML(RestClient.get('https://github.com/opscode-cookbooks/')).
css('ul.repolist h3 a').collect{|n| n.attribute('href').value}.each do |s|
system "git clone http://github.com#{s}"
end
@arangamani
arangamani / chef_attribute_converge.rb
Last active February 20, 2023 02:44
Dynamically update attribute of a Chef resource during converge phase (Node variable assignment in Compile vs Converge)
# In Chef, when a resource is defined all its variables are evaluated during
# compile time and the execution of the resource takes place in converge phase.
# So if the value of a particular attribute is changed in converge
# (and not in compile) the resource will be executed with the old value.
# Example problem:
# Let's consider this situation where there are two steps involved in a recipe
# Step 1 is a Ruby block that changes a node attribute. Rubyblocks get executed
# in converge phase
# Step 2 is a Chef resource that makes use of the node attribute that was
@ahoward
ahoward / dsl.rb
Created November 8, 2012 18:45
this is how to build dsls that don't fuck the global namespace
# the entire concept of building a dsl means defining domain terms on an
# object, it's so much simpler to start with the dsl itself being a blank
# slate that simply relays certain methods to a scope
#
class DSL
instance_methods.each do |m|
undef_method m unless m[%r/\A__|\Aobject_id\Z/]
end
@teknogeek0
teknogeek0 / block_world_iptables.sh
Created September 30, 2012 19:52
block ips from around the world.
IPTABLES="/sbin/iptables"
### block all Asian/APNIC IPs (includes NZ, AU)
$IPTABLES -A bad_stuff -s 58.0.0.0/8 -j DROP
$IPTABLES -A bad_stuff -s 59.0.0.0/8 -j DROP
$IPTABLES -A bad_stuff -s 60.0.0.0/8 -j DROP
$IPTABLES -A bad_stuff -s 61.0.0.0/8 -j DROP
$IPTABLES -A bad_stuff -s 110.0.0.0/8 -j DROP
$IPTABLES -A bad_stuff -s 111.0.0.0/8 -j DROP
$IPTABLES -A bad_stuff -s 112.0.0.0/8 -j DROP
@btm
btm / load_expanded_node.rb
Created September 28, 2012 01:24
script for loading a node from json, expanding the run list and saving.
#!/usr/bin/env ruby
# Copyright 2012 Opscode <legal@opscode.com>
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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
@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
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this: