Skip to content

Instantly share code, notes, and snippets.

View peterwwillis's full-sized avatar

Peter W peterwwillis

View GitHub Profile
@peterwwillis
peterwwillis / Makefile
Created February 1, 2021 20:18
Makefile samples that I have found useful
# This Makefile allows you to pass arguments to 'make', and have those get passed into commands for a target.
# This also shows how to automatically generate a help menu using specially annotated comments on targets.
#
# Usage:
# - make help
# List of available targets:
#
# help List all available targets (default)
# jenkins-cluster Run terraformctl on the aws-jenkins-cluster root module
# cognito-userpool Run terraformctl for the cognito user pool

Package Management is Inherently Dumb

All packaged software is just a random person trying to guess at how to install and run some random software. The package has to declare what packages it depends on, and what it conflicts with.

The only way for a package to have the correct 'depends' and 'conflicts' is for the original software to ship with an explicit map of all its dependencies and conflicts. No software does this, in part because every Linux distribution ships different packages, and thus has different dependencies and conflicts. And so, we have to build packages by hand. A human (who isn't the software developer) has to determine the correct dependencies and conflicts (based on other packages that this human also did not create). Then they need to build the package and test it.

A package manager (dpkg) is a dumb program that does whatever you tell it to do. A package encodes its own dependencies, and the package manager fulfills the requirements as stated, or fails if it's impossible. There's n

@peterwwillis
peterwwillis / Unix_Tips_n_Tricks.md
Created October 28, 2020 01:57
Unix Tips And Tricks

Awk

Print only the first part of a file separated by two newlines

Note that this uses tr to remove any carriage-returns (as in "\r\n" from Windows or network programs)

# Print only the block of lines before the first double-newline
cat file.txt | tr -d '\r' | \
  awk 'BEGIN {RS="\n\n"} NR==1'
 
@peterwwillis
peterwwillis / cp_src_dir_symlink_weirdness.md
Created July 21, 2020 14:27
Copying a source directory into a symlinked target directory
@peterwwillis
peterwwillis / LINUX_ACTIVE_DIRECTORY_SSSD_HOWTO.md
Created July 13, 2020 12:09
How to set up an Ubuntu 18.04 Linux system to use sssd to authenticate users using Active Directory without joining a domain

Set up Ubuntu Linux to use Active Directory for user authentication + authorization

This guide will step you through setting up an Ubuntu 18.04 Linux system so that you can login to it using an Active Directory server for authentication and authorization. NOTE: You do not need to join a domain to use this method!!

The net effect of this guide is that you do not need to ever set up a user on your Linux host. Its home directory will be automatically created at log-in time, and its password is checked (along with account expiration) against the Active Directory server.

@peterwwillis
peterwwillis / C_Tips_Best_Practices.md
Last active September 13, 2020 12:58
C Tips and Best Practices

Tips and Best Practices for programming in C

Syntax

Tips

  • You can explain a complicated declaration in English using cdelc.

Data Structures / Types

@peterwwillis
peterwwillis / Docker cheat sheet.md
Last active February 14, 2020 05:02
Docker cheat sheet

Run commands

Use Docker to build a Jenkins plugin

  1. Check out a Jenkins plugin from GitHub
    $ git clone [email protected]:jenkinsci/configuration-as-code-secret-ssm-plugin.git
    $ cd configuration-as-code-secret-ssm-plugin
  2. Build the plugin. Change the maven tag to something like 3-jdk-8 or 3-jdk-11 if you run into errors, as some plugins only build with one JDK version.
    • Run as a non-root user
// from https://stackoverflow.com/questions/9815273/how-to-get-a-list-of-installed-jenkins-plugins-with-name-and-version-pair#12730830
// the sort version doesn't seem to work on my jenkins install
Jenkins.instance.pluginManager.plugins.each{
plugin ->
println ("${plugin.getDisplayName()} (${plugin.getShortName()}): ${plugin.getVersion()}")
}
@peterwwillis
peterwwillis / using-unix-pass.md
Created December 3, 2019 21:59
Using the Unix tool `pass` to manage passwords

About

This document explains how to use the Unix tool pass to manage passwords.

Using pass

Initial set-up

  1. Install software
@peterwwillis
peterwwillis / extract_jenkins_credentials.groovy
Last active May 24, 2024 14:53
If you can't find a Jenkins credential's value any other way, use the Script Console to extract the values
// To support more types of credentials, look up the credentials plugin code and write
// additional groovy to parse those credential types.
//
// From Mohamed Saeed: https://medium.com/@eng.mohamed.m.saeed/show-all-credentials-value-in-jenkins-using-script-console-83784e95b857
def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(
com.cloudbees.plugins.credentials.common.StandardUsernameCredentials.class,
Jenkins.instance,
null,
null