Skip to content

Instantly share code, notes, and snippets.

View binford2k's full-sized avatar

Ben Ford binford2k

View GitHub Profile

Typecasting or converting between data types

A strong data type system provides a lot of safety. It means that you cannot accidentally pass a String when a Number was expected, for example. This simplifies logic all throughout your code and means that you'll need to write a lot less boilerplate error checking and type validation code.

But it also introduces a few new challenges, namely in that you now have to pay attention to data types and convert between them intentionally. This page will show you the different ways you can do that.

Hi there!
Following is a sample of some GitHub pull requests that could use some love. It
would really help a ton if you'd help us out and clean up what you can. It's
easier than you think:
First, just do a sanity check; is the repository even maintained anymore? Can
it just be archived or deleted? See the end-of-life suggestions below:
* https://confluence.puppetlabs.com/display/OSP/End+of+Maintenance+proposal
define dir_perm ($path = $title) {
file { $path:
ensure => directory,
mode => '0755',
notify => Exec["dir_perm ${path}"],
}
exec { "dir_perm ${path}":
command => "find ${path} -type f -exec chmod 644 {} \;",
}

This year we're holding Puppetize PDX in Portland the first full week of October. And by some divine coincidence, the Portland Marathon is running just a few days prior. Clearly we're meant to make a full week of it! I'll be running, and it would be rad if you joined me.

You can run or walk either the full or half distance. I'll be hosting a virtual training plan to help you prepare for race day. Wanna join me?

Getting Started

@binford2k
binford2k / vp_active_2019.sql
Created May 21, 2019 22:47
Most active Vox Pupuli members
/* GitHub query to get the number of comments, PR, releases, etc. for Vox Pupuli */
/* Thanks to https://github.com/KrauseFx/krausefx.com/blob/master/_posts/2017-08-06-analyzing-your-public-github-contributions-using-google-big-query.md */
WITH
ProjectData AS (SELECT * FROM `githubarchive.day.2019*` WHERE repo.name LIKE 'voxpupuli/%'),
Actors AS (SELECT DISTINCT(actor.login) AS login FROM ProjectData)
SELECT * FROM (
SELECT
actors.login,
[root@ip-172-31-23-226 ec2-user]# yum search puppet
Loaded plugins: amazon-id, rhui-lb, search-disabled-repos
=========================================================================================== N/S matched: puppet ============================================================================================
puppet-agent.x86_64 : The Puppet Agent package contains all of the elements needed to run puppet, including ruby, facter, hiera and mcollective.
puppet-client-tools.x86_64 : PuppetDB CLI for querying Puppet data
puppet-release.noarch : Release packages for the Puppet repository
puppet5-release.noarch : Release packages for the Puppet5 repository
puppetdb.noarch : Puppet Labs puppetdb. Contains: Puppet-integrated catalog and fact storage (puppetlabs/puppetdb 5.2.7,puppetlabs/trapperkeeper-webserver-jetty9 2.3.1,org.clojure/clojure
: 1.8.0,org.clojure/core.async 0.2.391,org.clojure/core.match 0.3.0-alpha4,org.clojure/core.memoize 0.5.9,org.clojure/java.jdbc 0.6.2-alpha3,org.clojure/tool
@binford2k
binford2k / bulk_repo_nuke.rb
Created March 6, 2019 00:59
clean up stale git repos
#! /usr/bin/env ruby
require 'tempfile'
require 'io/console'
begin
require 'octokit'
rescue LoadError => e
puts "This requires the octokit gem"
exit 1
end
Puppet::Functions.create_function(:local_file) do
dispatch :load do
param 'String', :path
end
def load(path)
Puppet::FileSystem.read_preserve_line_endings(path)
end
end
# <module>/functions/deferred_epp.pp
# note: depends on puppetlabs/stdlib
function deferred_epp(String $template, Hash $variables) >> Deferred {
if($template[0] == '/') {
$path = $template
}
else {
$parts = $template.split('/')
$mod = get_module_path($parts[0])
$file = $parts[1,-1].join('/')
@binford2k
binford2k / agent_side_template.pp
Last active February 16, 2019 09:52
Generate a templated file on the agent, using secrets resolved agent side.
$variables = {
'password' => Deferred('vault_lookup::lookup',
["secret/test", 'https://vault.docker:8200']),
}
# use inline_epp(), and file() to compile the template source into the catalog
file { '/etc/secrets.conf':
ensure => file,
content => Deferred('inline_epp',
[file('mymodule/secrets.conf.epp'), $variables]),