Skip to content

Instantly share code, notes, and snippets.

View natemccurdy's full-sized avatar

Nate McCurdy natemccurdy

View GitHub Profile
@natemccurdy
natemccurdy / example-config.json
Created April 26, 2024 18:41
T-Mobile 5G gateway - Advanced configuration
{
"2.4ghz": {
"airtimeFairness": true,
"channel": "1",
"channelBandwidth": "Auto",
"isMUMIMOEnabled": true,
"isRadioEnabled": true,
"isWMMEnabled": true,
"maxClients": 128,
"mode": "auto",
@natemccurdy
natemccurdy / .zshrc
Last active February 27, 2023 16:16
A Powerlevel10k prompt segment for your VAULT_ADDR
# Create a Powerlevel10k prompt segment that shows that value of $VAULT_ADDR if set.
function prompt_my_vault_addr() {
if [[ -n $VAULT_ADDR ]]; then
p10k segment -i '🔐' -f brightwhite -b blue -t "$VAULT_ADDR"
fi
}
# Add it to the right prompt.
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS+=my_vault_addr
@natemccurdy
natemccurdy / write_only_json.rb
Created October 18, 2021 19:52
A write_only_json catalog cache terminus for Puppetserver
require 'puppet/indirector/catalog/json'
# This is a write-only catalog cache terminus for saving compiled catalogs to disk as JSON.
#
# It extends the built-in JSON catalog terminus:
# * https://github.com/puppetlabs/puppet/blob/6.19.1/lib/puppet/indirector/catalog/json.rb
# * https://github.com/puppetlabs/puppet/blob/6.19.1/lib/puppet/indirector/json.rb
#
class Puppet::Resource::Catalog::WriteOnlyJson < Puppet::Resource::Catalog::Json
desc 'A write-only terminus that stores catalogs as flat, serialized JSON files.'
# This is: ben_weird_sort/functions/sort_hiera_roles.pp
#
# Returns a list of hiera role paths in sorted order
#
# Strings are returned in lexical order, unless one path is a substring
# of another, in which case the longer string appears first.
#
# This is so that child roles are checked before parent roles
#
function ben_weird_sort::sort_hiera_roles($list) {
@natemccurdy
natemccurdy / googleapi-netblocks
Created December 3, 2019 22:47
Show the network blocks used by googleapis.com
#!/usr/bin/env bash
netblocks=$(dig TXT _spf.google.com +short | grep -E -o "include:_netblocks\d?\.google\.com" | sed 's/include://')
{
for net in $netblocks; do
dig TXT "$net" +short
done
} | grep -E -o "ip4:[0-9\./]+" | sed 's/ip4://' | sort -V
@natemccurdy
natemccurdy / common.yaml
Last active July 25, 2019 00:18
system_updates module: Example for Mark in Slack
---
message: "this is data in common.yaml"
@natemccurdy
natemccurdy / get_module_files.rb
Created May 16, 2019 18:13
Puppet function to list the files in a module's 'files' directory
#
# get_module_files.rb
#
module Puppet::Parser::Functions
newfunction(:get_module_files, :type => :rvalue, :doc => <<-DOC
Returns an array of relative files names for a given module and optional
sub directory. Do not include 'files' in the optional relative path as it
is assumed.
Returns an empty array if no files are found.
Errors if the requested module does not exist.
@natemccurdy
natemccurdy / ways_to_slice_a_string.pp
Last active March 21, 2019 19:27
different ways to slice a string in Puppet
#
# All of these examples should return 'bar'.
#
$string = 'foo@bar'
notice($string.split('@')[-1])
notice($string.regsubst(/\A.+@(.+)\Z/, '\1'))
with() || {
$string =~ /\A.+@(.+)\Z/
@natemccurdy
natemccurdy / pkg_version_from_puppet.pp
Created March 14, 2019 22:20
Getting a package version from PE's package inventory feature
# PuppetDB Query method
$query = "package_inventory[package_name,version,provider] {certname = \"${facts['fqdn']}\"}"
$pkgs_from_puppetdb = puppetdb_query($query)
$bash_version_from_puppetdb = $pkgs_from_puppetdb.filter |$pkg| {$pkg['package_name'] == 'bash'}[0]['version']
notice($bash_version_from_puppetdb)
# PE Inventory Fact method
$pkgs_from_inventory_fact = $facts['_puppet_inventory_1']['packages']
$bash_version_from_inventory = $pkgs_from_inventory_fact.filter |$pkg| {$pkg[0] == 'bash'}[0][1]
@natemccurdy
natemccurdy / postgres.yaml
Created September 20, 2018 05:55
Puppet Stack: k8s (from pupperware)
---
# Postgres: Service
apiVersion: v1
kind: Service
metadata:
labels:
app: puppet
service: postgres
name: postgres
spec: