Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <setjmp.h>
#define TEST(name, e) printf("%s\n", name); if((result = setjmp(j)) == 0) { e; longjmp(j, 2); } else { printf("%d\n", result); };
#define ASSERT(exp, act, msg)\
if(exp != act) { printf("Failure! %s\nAt line %d\n", msg, __LINE__); longjmp(j, 1); }
#define SUITE(setup, teardown, e)\
int main() { jmp_buf j; int result; setup; e; teardown; printf("!!!! All tests pass !!!!\n"); return 0; }
@zaphod42
zaphod42 / gist:119f2d5c55742f8672de
Last active August 29, 2015 14:08
Module stats
// Not so much a pretty picture, but a breakdown of what AST expressions show up in forge modules (the data below is the totals across all forge module releases that I was able to parse: 8492 modules).
//"expressions_per_resource" is a very rough measure of how many expressions are needed to put a single resource in the catalog. It isn't done through any kind of path analysis and so can be pretty far off, it is simply the number of ResourceExpressions divided by the total number of expressions.
{
"most_common_expressions": [
"Puppet::Pops::Model::QualifiedName",
"Puppet::Pops::Model::LiteralString",
"Puppet::Pops::Model::VariableExpression",
"Puppet::Pops::Model::AttributeOperation",
63 <<<<<<< HEAD
64 Suggests: apache2 | nginx, puppet-el, vim-puppet,
65 =======
66 Conflicts: puppet-common (<< 3.3.0-1puppetlabs1)
67 Suggests: apache2 | nginx, puppet-el, vim-puppet, stompserver, ruby-stomp | libstomp-ruby1.8,
68 >>>>>>> upstream/stable
69 rdoc, ruby-ldap | libldap-ruby1.8, puppetdb-terminus
70 Description: Puppet master common scripts
71 This package contains common scripts for the puppet master,
72 which is the server hosting manifests and files for the puppet nodes.
class testing {
$a = [1]
}
include testing
$testing::a += [2]
notice(inline_template('<%= @testing__a %>'))
notice($testing::a)
notice($a)
@zaphod42
zaphod42 / gist:9f781ca85f37883c5177
Created July 10, 2014 22:22
files from modules
> be puppet apply -e 'notice(file("load/testing"))'
Notice: Scope(Class[main]): Wow!
Such text!
So ASCII!
Notice: Compiled catalog for aparker.corp.puppetlabs.net in environment production in 0.04 seconds
Notice: Finished catalog run in 0.05 seconds
@zaphod42
zaphod42 / sigh.pp
Last active August 29, 2015 14:03
Fun with resource collection
@notify { there: message => "string" }
@notify { again: message => ["string"], tag => ["different"] }
# This will get both of the above resources
Notify <| message == "string" |>
# This will, surprise, surprise, get the second resource
Notify <| message != "string" |>
@zaphod42
zaphod42 / search.pp
Created June 26, 2014 21:43
Search the what?
class a::c {
notice(c)
}
class b {
search(a)
include c
}
include b
@zaphod42
zaphod42 / error.pp
Created June 23, 2014 17:55
Math is hard 'n stuff
# This gives an error:
notice('- 1' + 2)
# The error is "Error: left operand of + is not a number"
# create a resolution (instrument. It observes facts about the world) without any externally visible fact
Facter.instrument(:network) do
description "..."
confine ...
observe do
...
end
end
# Create a specific composition, which is the final fact. Without the
1.9.3p392 :001 > require 'puppet'
=> true
1.9.3p392 :002 > require 'puppet/network/http'
=> true
1.9.3p392 :003 > require 'puppet/network/http/handler'
=> true
1.9.3p392 :004 > class Foo
1.9.3p392 :005?> include Puppet::Network::HTTP::Handler
1.9.3p392 :006?> end
=> Foo