Skip to content

Instantly share code, notes, and snippets.

@broskees
broskees / streambian
Created August 17, 2024 18:30
Streambian boot command
#!/usr/bin/bash
# Check if gum is installed, if not, install it
if ! command -v gum &> /dev/null; then
echo "gum could not be found, installing..."
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg
echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list
sudo apt update && sudo apt install gum
fi
@broskees
broskees / hackylogger.js
Last active August 16, 2024 15:45
log all the functions attached to an object
function logFunctions(item, path = '', seen = new WeakMap(), depth = 0) {
const MAX_DEPTH = 10;
if (depth > MAX_DEPTH) {
return item;
}
if (item === null || (
typeof item !== "object"
&& typeof item !== "function"
@broskees
broskees / robots-txt-additions.php
Created August 8, 2024 14:43
Really Simple Robots.txt editor for WordPress (doesn't require DISALLOW_FILE_EDIT or DISALLOW_FILE_MODS to be false)
<?php
/**
* Plugin Name: Robots.txt Additions
* Description: Add custom rules to robots.txt
* Version: 1.0
* Author: Joseph Roberts
* Author URI: https://github.com/broskees
* License: MIT
* License URI: https://opensource.org/licenses/MIT
**/
@broskees
broskees / wp_usermeta.md
Created July 19, 2024 21:02 — forked from magnific0/wp_usermeta.md
Show and Edit User Meta in Wordpress

Show and Edit User Meta in Wordpress

Description

This simple procedure will allow you to:

  1. Display user meta fields under in the user list as additional columns (Users > All Users).
  2. Display these fields on user profiles.
  3. Edit these fields under user edit.

This method works completely without plugins and involves just some functions and hooks in functions.php. Plugins like "User Meta Display" achieve this to some level, but treat custom meta fields completely different from the regular fields. They are shown and edited in seperate environment and fail to show the meta data is a table list. This method integrates custom user meta along with regular user (meta).

@broskees
broskees / Singleton.php
Last active August 8, 2024 18:13
Trait for Singleton Pattern for PHP
<?php
trait Singleton
{
/**
* Stores the instance, implementing a Singleton pattern.
*
* @var self
*/
private static self $instance;
@broskees
broskees / GoogleTagManager.php
Created May 8, 2024 21:20
The most straightforward way to install a Google Tag Manager Tag onto a WordPress install.
<?php
add_action('wp_head', fn () => print <<<HTML
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','YOUR-GOOGLE-TAG-ID-HERE');</script>
<!-- End Google Tag Manager -->
@broskees
broskees / CleanWordBreaks.php
Last active November 1, 2023 21:37
PHP function to break words on special characters
<?php
if (! function_exists('cleanWordBreaks')) {
function cleanWordBreaks(string $text): string
{
$cleanText = $text;
$cleanup = [];
$makeReplacement = function ($regex, $replacement = '') use (&$cleanup, &$cleanText) {
@broskees
broskees / acf-required.php
Last active September 3, 2024 14:58
Force Site to use ACF to Function (MU-Plugin)
<?php
! defined('ABSPATH') && exit;
add_action('plugins_loaded', function () {
if (// is network install and main site is not set up
(is_multisite() && ! get_blog_option(1, 'siteurl'))
// is single site install and site is not set up
|| (! is_multisite() && ! is_blog_installed())
// ACF is already installed
@broskees
broskees / anonymous-singleton.php
Last active July 20, 2023 16:09
PHP — Anonymous Singleton Class
<?php
$singleton = get_class(
new class
{
protected static $instance;
public static function getInstance()
{
if (! isset(self::$instance)) {
@broskees
broskees / get-private.php
Last active June 13, 2023 15:58
A function for getting a private property from an object — for use in Roots Acorn & Laravel (SHOULD BE USED FOR DEBUGGING ONLY)
<?php
/**
* Get a private property from an object.
*
* @param object $that
* @param string $var
* @return mixed
*/
function &getPrivateProp(&$that, $var): mixed