Skip to content

Instantly share code, notes, and snippets.

View blizzardengle's full-sized avatar

Christopher Keers blizzardengle

View GitHub Profile
@blizzardengle
blizzardengle / deep-merge.js
Created March 29, 2024 15:32
Deep merge two object together. Built this with AI and have no use for it anymore keeping around just in case.
/**
* Deep merge two objects together keeping unique keys from each object.
*
* @param {object} mergeIntoObj - The object to merge another object into.
* @param {object} mergeAndPrioritizeObj - The object to merge into mergeIntoObj. This object
* has priority when collisions occur.
* @returns
*/
const deepMerge(mergeIntoObj, mergeAndPrioritizeObj) => {
@blizzardengle
blizzardengle / print.js
Last active June 28, 2024 18:18
A simple logger class that allows printing console messages in color. Designed for node.js applications but usable in supported browsers as well.
/**
* Author: Christopher Keers | Caboodle Tech
* License: MIT
* Source: https://gist.github.com/blizzardengle/8147b6e7d8ffab2709ae2f79b7006b02
*/
class Print {
#enabled = true;
disable() {
@blizzardengle
blizzardengle / function.php
Last active January 11, 2024 07:56
Allows you to enqueue scripts as modules or import maps in WordPress using the built-in wp_enqueue_script function. You should add this code somewhere in your plugin or theme, most likely your functions.php file.
<?php
// If your PHP version is < 8
if ( ! function_exists( 'str_contains' ) ) {
/**
* Based on original work from the PHP Laravel framework.
*
* @author scm6079
* @link https://www.php.net/manual/en/function.str-contains.php#125977 Original Source
*
@blizzardengle
blizzardengle / classes.js
Last active March 26, 2022 00:23
Adds a global constant class that ES6 classes can register themselves with; useful for referencing dynamically named classes and so on.
/**
* Adds a global constant class that ES6 classes can register themselves with.
* This is useful for referencing dynamically named classes and instances
* where you may need to instantiate different extended classes.
*
* NOTE: This script should be called as soon as possible, preferably before all
* other scripts on a page.
*
* @class Classes
*/
@blizzardengle
blizzardengle / openwrt-resize-ext4.sh
Created February 8, 2022 22:37
Resize the ext4 filesystem on OpenWrt after having resized the partition table.
opkg update
opkg install losetup resize2fs
BOOT="$(sed -n -e "/\s\/boot\s.*$/{s///p;q}" /etc/mtab)"
DISK="${BOOT%%[0-9]*}"
PART="$((${BOOT##*[^0-9]}+1))"
ROOT="${DISK}${PART}"
LOOP="$(losetup -f)"
losetup ${LOOP} ${ROOT}
fsck.ext4 -y ${LOOP}
resize2fs ${LOOP}
@blizzardengle
blizzardengle / openwrt-uuid.sh
Last active February 8, 2022 22:36
Update the GPT partition UUID in the GRUB configuration when using EFI images of OpenWrt.
opkg update
opkg install lsblk
BOOT="$(sed -n -e "/\s\/boot\s.*$/{s///p;q}" /etc/mtab)"
DISK="${BOOT%%[0-9]*}"
PART="$((${BOOT##*[^0-9]}+1))"
ROOT="${DISK}${PART}"
UUID="$(lsblk -n -o PARTUUID ${ROOT})"
sed -i -r -e "s|(PARTUUID=)\S+|\1${UUID}|g" /boot/grub/grub.cfg
@blizzardengle
blizzardengle / openwrt-partion.sh
Last active February 8, 2022 22:36
Auto expand OpenWrt to take up the entire disk on x86 systems.
opkg update
opkg install fdisk
BOOT="$(sed -n -e "/\s\/boot\s.*$/{s///p;q}" /etc/mtab)"
DISK="${BOOT%%[0-9]*}"
PART="$((${BOOT##*[^0-9]}+1))"
ROOT="${DISK}${PART}"
OFFS="$(fdisk ${DISK} -l -o device,start | sed -n -e "\|^${ROOT}\s*|s///p")"
echo -e "p\nd\n${PART}\nn\np\n${PART}\n${OFFS}\n\nn\np\nw" | fdisk ${DISK}
@blizzardengle
blizzardengle / dockcmd.sh
Last active May 12, 2020 16:57
Run common docker-compose commands from any sub-directory of a docker project.
#!/bin/bash
# Run common docker-compose commands from any sub-directory of a docker project
dockcmd(){
# Versions
local dockcmd_version="1.5.0"
local docker_version=$(docker --version | egrep -o "([0-9]{1,}\.)+[0-9]{1,}")
local dcompose_version=$(docker-compose --version | egrep -o "([0-9]{1,}\.)+[0-9]{1,}")
# Assign arguments
// Attempt to find the message list on this page.
var msgList = document.querySelector('#content .message-list .messages');
var scroller = document.querySelector('#content .message-list-scroller');
// If the list was found continue.
if( msgList && scroller ){
console.log('Active.')
var li = document.createElement('LI');
li.id = 'controls'
var html = '<label>Ignore last <input type="text" id="days" style="display:inline-block;"> days.</label><br>'
@blizzardengle
blizzardengle / capture-table.js
Last active February 18, 2023 17:43
Capture Table
/**
* Loop through a table and pull out certain cells of data.
*
* This loops through a the rows of a table and grabs the requested cell(s) from each row.
* Cell data is seperated with tabs when multiple cells of data are requested OR with the
* combine flag set to true the data will be combined into a single string per row.
*
* Version: Alpha
*
* @param {int} id The value of the tables HTML id attribute.