Skip to content

Instantly share code, notes, and snippets.

View jespada's full-sized avatar

jespada jespada

View GitHub Profile
@kachayev
kachayev / concurrency-in-go.md
Last active May 4, 2025 05:48
Channels Are Not Enough or Why Pipelining Is Not That Easy
@john2x
john2x / 00_destructuring.md
Last active April 10, 2025 15:15
Clojure Destructuring Tutorial and Cheat Sheet

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors and Sequences

@obazoud
obazoud / oneshot.rb
Last active August 29, 2015 14:04
Chef: How to remove a recipe dynamically ?
ruby_block 'remove_dynamically_oneshot' do
block { node.run_list.remove('recipe[mycookbook::oneshot]') }
end

Why?

The chef-zero or "local-mode" of chef-client should be used to apply a cookbook to the server that you run it on without involving a full blown Chef Server of any kind. It does this by firing up a mini chef server that requires zero configuration in the background and uploding your cookbooks to it and doing a real chef-client converge against it, completely transparently. This allows you to use all the features of Chef without the need to think about running a server.

Other Options

There is also the chef-solo utility that is similar, but is limited in that it cannot talk to a chef server at all, and therefore features like search are architecturally broken. Ideally, it should not be used for new development work.

The chef-apply utility that can be used to converge resources in a single file against a host without a server and without any cookbook structure at all. Since there is no available structure other than the recipe file features like search, data bags, templates and other res

ChefDK, Test Kitchen Driven NTP Cookbook

This gist uses TK+Berkshelf to drive creating a vagrant virts and converging a simple recipe to install and configure NTPd. This is a simple cookbook that has one recipe, one template (for ntp.conf) and one attribute file. It works on Ubuntu 12.04 and CentOS 6.4 (and derviatives) and the attribute file is used to support both distros.

This should work on Mac (where I developed it) and any chef-supported Linux that you can get Vagrant onto (Ubuntu/CentOS).

Because I use ChefDK and Test Kitchen, I can largely ignore setting up Vagrant and Berkshelf and can get right to work on writing recipe code.

NOTE: Modern (7/6/2014) Recipe Generation

my application cookbooks define attribute like this which define node data in the node['sk_services'] namespace which is designed to be searchable by other nodes and give information (in this case information that an nginx proxy needs to know).

% cat attributes/default.rb
default['sk_services']['www.visibility-project.com']['normal_port'] = 80
default['sk_services']['www.visibility-project.com']['ssl_port'] = 443
default['sk_services']['www.visibility-project.com']['listen_port'] = 8080
default['sk_services']['www.visibility-project.com']['cache_dirs'] = [
  'assets',
]

To use a knife plugin programmatically, from any ruby script, you need first know the source of the plugin. you have to know the config options for all the command line arguments you are interested to use. All knife plugin use mixlib-cli interface, and the command line options can be found at the beginning of the file (convention), declared using option method. if you are curious take a look at mixlib-cli readme

1.require the corresponding plugin file

require '/path/to/plugin'
deploy_cookbook ()
{
EXPECTED_ARGS=2;
BAD_ARGS_ERROR_CODE=65;
if [ $# -ne $EXPECTED_ARGS ]; then
echo 'Usage: deploy_cookbook ${ENV} ${COOKBOOK}';
return $BAD_ARGS_ERROR_CODE;
fi;
environment=$1;
cookbook=$2;
@apbendi
apbendi / core_functions_in_depth.clj
Last active October 22, 2021 02:16
Solutions: Clojure for the Brave and True (braveclojure.com)
; In Clojure for the Brave and True (braveclojuure.com),
; at the end of the chapter "Core Functions in Depth", the author
; prevents several challanges to build on top of some sample code
; he has provided
; This code is provided by the author:
;; In ns below, notice that "gen-class" was removed
(ns fwpd.core
;; We haven't gone over require but we will.

My basic point is that currently, configuration management code manifests as a giant, unverifiable pile of mud. The languages we use lack types and are weak at making non-runtime assertions. With the modicum of sanity that a proper module system and types can bring to the table, we would be considerably better off.