This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Haddock | |
CURSES = [ | |
"Aardvark", | |
"Abecedarians", | |
"Addle-pated lumps of anthracite", | |
"Anachronisms", | |
"Anacoluthons", | |
"Antediluvian bulldozer", | |
"Anthracite", | |
"Anthropithecus", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Puppet::Functions.create_function(:env_data) do | |
# @since 4.8.0 | |
dispatch :env_data do | |
param 'Struct[{}]', :options | |
param 'Puppet::LookupContext', :context | |
end | |
def env_data(options, context) | |
ENV.to_h | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ 1000, 2000, 3000, "", 4000, "", 5000, 6000, "", 7000, 8000, 9000, "", 10000, | |
].reduce([0]) |$memo, $v| { if $v == "" { $memo << 0 } else { $memo[0,-2] << $memo[-1]+$v } } | |
.map() |$i,$x| { [$i,$x] } | |
.sort() |$a,$b| { compare($b[1], $a[1]) } | |
.then() |$x| { $x[0] } | |
.then() |$x| { "Elf ${x[0]} has ${x[1]} calories" } | |
.notice() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# When you need to process a hash with keys in sorted order | |
# you may have found the `sort()` function - but it only | |
# operates on an Array. | |
# | |
# Most of the time what is wanted is simply achieved | |
# by taking the keys of a hash and sorting those and | |
# then iterating over the keys. | |
# | |
# When, however the wanted result is a new Hash | |
# with all keys sorted recursively then this becomes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
# Example rspec_puppet function rspec test (i.e. subject is the function 'min') | |
# This works for other rspec subjects as well as a compiler is always involved. | |
# This kind of mocking can be required when it is not enough to simply override | |
# a function with another implementation (which can be done with a `let(:pre_condition) { 'function min($x, $y) { ... }'}` | |
# | |
# The main difficulty that this overcomes is the need to let the compiler initialize and | |
# create the context in which it will operate before making any mocks. | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
notice Integer[0,99].map |$x| { | |
case [$x % 3, $x % 5] { | |
[0, 0] : { fizzbuzz } | |
[0, default] : { fizz } | |
[default, 0] : { buzz } | |
default : { $x } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Puppet::Parser::Functions.newfunction(:default_content, | |
:type => :rvalue, | |
:doc => <<-'ENDOFDOC' | |
Takes an optional content and an optional template name and returns the | |
contents of a file. | |
Examples: | |
$config_file_content = default_content($file_content, $template_location) | |
file { '/tmp/x': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Puppet EBNF (kind of) | |
# Try with: http://www.bottlecaps.de/rr/ui | |
ACTOR ::= 'actor' ( '(' PARAMS ')')? ('inherits' NAME)? | |
'{' | |
(QUEUE | INBOX | ACTION | SEQUENCE | PARALLEL | FUNCTION | STATE | CONSTANT | LOCAL_TYPE)* | |
'}' | |
SEQUENCE ::= 'sequence' '{' (ACTION | SEQUENCE | PARALLEL)* '}' | |
PARALLEL ::= 'parallel' '{' (ACTION | SEQUENCE | PARALLEL)* '}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The latch function remembers what it was called with | |
# and returns what it was previously called with. | |
# | |
# This is using global namespace - in your code use a module namespace | |
# | |
Puppet::Functions.create_function(:latch) do | |
dispatch :example do | |
repeated_param 'Any', :arg | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
'name': 'bug', | |
'color': 'd63230', | |
'desc': 'Does not work (according to specification)' | |
}, | |
{ | |
'name': 'improvement', | |
'color': '39a9db', | |
'desc': 'improvement - neither bug nor new feature' |
NewerOlder