Skip to content

Instantly share code, notes, and snippets.

@cedws
cedws / defer.sh
Last active June 23, 2023 13:26
Go-like defer 'keyword' for shell
#!/bin/sh
DEFER=
defer() {
DEFER="$*; ${DEFER}"
trap "{ $DEFER }" EXIT
}
#include <unistd.h>
#include <stddef.h>
#include <stdio.h>
#include <sys/prctl.h>
#include <sys/syscall.h>
#include <linux/bpf.h>
#include <linux/seccomp.h>
#include <linux/filter.h>
@halkeye
halkeye / sorted_json.rb
Created April 2, 2012 23:13
Puppet module for outputting json in a sorted consistent way
#
# sorted_json.rb
# Puppet module for outputting json in a sorted consistent way. I use it for creating config files with puppet
require 'json'
def sorted_json(json)
if (json.kind_of? String)
return json.to_json
elsif (json.kind_of? Array)
@sarva
sarva / buildfile.pp
Created May 10, 2011 08:23
Puppet defines to build a complex file across all nodes. Useful for creating config files containing IP addresses of nodes in distributed systems.
# Export a single line
#
# == Parameters
#
# [*namevar*]
# Line of text to include in the file to build
#
# [*file*]
# The file the supplied line will be included in
#