Skip to content

Instantly share code, notes, and snippets.

View codebymikey's full-sized avatar

codebymikey codebymikey

View GitHub Profile
<?php
/**
* Checks where a serialize call would've failed.
*/
public static function check($checking_key, $data, $path = [], $processed = []) {
try {
// Attempt to serialize the data to check for serializability.
serialize($data);
} catch (\Throwable $e) {
@codebymikey
codebymikey / parse-command.sh
Created March 8, 2023 14:23
Provide a script that parses a command and prints out its options and positional arguments.
#!/bin/bash
# Define variables for holding positional arguments and options
POSITIONAL=()
OPTIONS=()
# Loop through all arguments passed to the script
while [[ $# -gt 0 ]]
do
key="$1"
@codebymikey
codebymikey / inquirer-input-multiple.js
Created August 11, 2021 11:28
Plop.js Inquirer.js multiple inputs e.g. for input tags or taxonomies.
const BaseInput = require('inquirer/lib/prompts/input');
/**
* A custom inquirer input plugin that keeps requesting the same input until
* nothing is specified.
* Useful for taking in the same input multiple times e.g. tags.
*/
class InputMultiplePrompt extends BaseInput {
constructor(...args) {
@codebymikey
codebymikey / find-invalid-yaml-files.sh
Created May 19, 2021 10:58
Find invalid YAML files
#!/usr/bin/env bash
# Script for finding invalid yaml files in the current directory.
# Requires the yq script.
for program in find yq; do
which "$program" > /dev/null || { echo "ERROR: '$program' program could not be found."; exit 1; }
done
if yq --version 2>/dev/null | grep -E "yq version [4-9]" > /dev/null; then
#!/usr/bin/env bash
#: Your comments here.
set -o errexit
set -o nounset
set -o pipefail
work_dir=$(dirname "$(readlink -f "${0}" 2> /dev/null)")
readonly conf_file="${work_dir}/script.conf"
readonly error_reading_conf_file=80
readonly error_parsing_options=81
readonly script_name="${0##*/}"
@codebymikey
codebymikey / simplesaml-custom-install-autoload.patch
Last active February 15, 2023 13:10
SimpleSAMLPHP custom install autoloader support.
diff --git a/lib/_autoload.php b/lib/_autoload.php
index e44c70f97..75945f742 100644
--- a/lib/_autoload.php
+++ b/lib/_autoload.php
@@ -8,14 +8,21 @@
* @package SimpleSAMLphp
*/
-// SSP is loaded as a separate project
-if (file_exists(dirname(dirname(__FILE__)) . '/vendor/autoload.php')) {
@codebymikey
codebymikey / civicrm-core.patch
Created October 23, 2020 10:23
CiviCRM temporary patch
From 10e59978672d9b779ae7ada18130837717397b29 Mon Sep 17 00:00:00 2001
From: demeritcowboy <[email protected]>
Date: Sat, 26 Sep 2020 10:25:12 -0400
Subject: [PATCH] avoid crash from recursion on exceptions
Source: https://github.com/civicrm/civicrm-core/pull/18610
---
CRM/Core/Error.php | 13 ++++---
diff --git a/CRM/Core/Error.php b/CRM/Core/Error.php
wget -nv -q https://github.com/mglaman/drupalorg-cli/releases/latest/download/drupalorg.phar && \
chmod +x drupalorg.phar && sudo mv drupalorg.phar /usr/local/bin/drupalorg
@codebymikey
codebymikey / wsl-notify.sh
Created May 13, 2020 19:01
(wsl-notify) WSL notify-send shim.
#!/usr/bin/env bash
# Inspiration: https://codelearn.me/2019/01/13/wsl-windows-toast.html
# Shim https://ss64.com/bash/notify-send.html for WSL.
# Just add an alias for it:
# alias notify-send='wsl-notify'
POSITIONAL=()
urgency='terminal'
@codebymikey
codebymikey / rotate-secrets.yml
Created September 25, 2019 10:25 — forked from tomwassenberg/rotate-secrets.yml
A hacky Ansible playbook that can be adapted to rotate Ansible Vault-encrypted secrets in-place.
---
# This playbook rotates Ansible Vault-encrypted secrets that are defined
# as dictionaries in the group_vars of an Ansible repository.
#
# The changes are split over multiple tasks, because the dictionary logic
# doesn't handle looping over secrets on differing levels within a
# dictionary.
- hosts: "all"
user: "ansible"