Skip to content

Instantly share code, notes, and snippets.

View jtimberman's full-sized avatar
🚀

Joshua Timberman jtimberman

🚀
View GitHub Profile
@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
@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
@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
@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
@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
@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
#

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

if ENV['ES_CACHE']
puts "Shared cache enabled"
if ENV['ES_CACHE_TYPE'] == 'yum'
FileUtils.mkdir_p(File.join("cache","yum")) unless Dir.exists?(File.join("cache","yum"))
config.vm.share_folder("yum", "/var/cache/yum", "cache/yum")
else
FileUtils.mkdir_p(File.join("cache","apt","partial")) unless Dir.exists?(File.join("cache","apt", "partial"))
config.vm.share_folder("apt", "/var/cache/apt/archives", "cache/apt")
end
end
@jtimberman
jtimberman / default.rb
Created May 2, 2013 20:56
When should I use a platform predicate method (#platform?, #platform_family?) vs a case statement?
# If you have a simple conditional, use a predicate:
if platform?("ubuntu")
# do things only applicable on Ubuntu
else
# do things on everything else
end
# If you have a complicated conditional for multiple platforms, use a case statement:
function table() {
case "$1" in
flip)
echo "(╯°□°)╯︵ ┻━┻ "
;;
set)
echo "┬─┬ ノ( ゜-゜ノ)"
;;
man)
echo "(╯°Д°)╯︵ /(.□ . \)"