Skip to content

Instantly share code, notes, and snippets.

@jonshipman
jonshipman / Worker.js
Created October 25, 2022 13:28
NodeJS Worker Forking - Allows workers to execute a command once regardless of process. Primary process keeps track of open "slots" and broadcasts an open PID when getting execution request (through runonce). If the PID matches that process, the callback executes.
import EventEmitter from 'node:events';
import cluster from 'cluster';
import { v4 as uuidv4 } from 'uuid';
import CONFIG, { isDevelopment } from '../configuration.js';
class Worker extends EventEmitter {
variables = {};
workers = {};
@jonshipman
jonshipman / search-keywords.js
Created August 17, 2022 21:54
Example of MongoDB Change Stream updating the same document.
/**
* I wanted to create an example of a change stream that updates itself.
* I couldn't find any examples online that weren't a simple "console.log" in the change stream.
* The secret sauce is in the $update.$match.
* We are only watching for changes that do not update the searchKeywords (in this example).
*
* In execution this collection has a text index on "searchKeywords" and createEdgeNGrams is a standard algorithm for splitting up words.
* If you ran LeadModel.updateOne({_id: anyId}, {name:'Hello World'}), the on('change') will be triggered and update the searchKeywords.
* Since this followup update changes searchKeywords, the filter will prevent an infinite loop.
*/
@jonshipman
jonshipman / Hooks.js
Created May 27, 2022 22:02
Gets all the styling hooks in use on SLDS
export default class Hooks {
constructor() {
console.log(this.styleHooks);
}
get stylesheets() {
return [...document.styleSheets, ...document.adoptedStyleSheets];
}
get rules() {
@jonshipman
jonshipman / desc.log
Created March 18, 2022 00:44
Error building on Linux ARM64 Yarn 3.2.0
➤ YN0000: ┌ Resolution step
➤ YN0032: │ fsevents@npm:2.3.2: Implicit dependencies on node-gyp are discouraged
➤ YN0061: │ rollup-plugin-inject@npm:3.0.2 is deprecated: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-inject.
➤ YN0013: │ vscode-textmate@https://github.com/octref/vscode-textmate.git#commit=e65aabe2227febd
➤ YN0032: │ fsevents@npm:2.1.3: Implicit dependencies on node-gyp are discouraged
➤ YN0061: │ fsevents@npm:2.1.3 is deprecated: "Please update to latest v2.3 or v2.2"
➤ YN0013: │ vscode-textmate@https://github.com/octref/vscode-textmate.git#commit=e65aabe2227febd
➤ YN0058: │ vscode-textmate@https://github.com/octref/vscode-textmate.git#commit=e65aabe2227febda7beaad31dd0fca1228c5ddf3: Packing the package failed (exit code 1, logs can be found here: /tmp/xfs-bda6b316/pack.log)
➤ YN0000: └ Completed in 2m 7s
➤ YN0000: Failed with errors in 2m 7s
@jonshipman
jonshipman / Set-ScreenResolution.ps1
Created February 7, 2022 13:59
Change Screen resolution with powershell.exe (not pwsh.exe core!)
# REF: https://kindleit.blogspot.com/2012/09/changing-screen-resolution-with.html
# Execute via ``powershell.exe -File .\path-to-script.ps1 1920 1080``
param (
[Parameter(Mandatory=$true, Position = 0)]
[int]
$Width,
[Parameter(Mandatory=$true, Position = 1)]
[int]
$Height
@jonshipman
jonshipman / .gitalb-ci.yml
Created November 16, 2021 17:23
Add cwebp to a gitlab runner ci yaml (docker image)
before_script:
- apt-get update -y
- apt-get install curl -y
- curl https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-0.4.1-linux-x86-64.tar.gz -o cwebp.tar.gz
- tar -zxvf cwebp.tar.gz
- export PATH="$PATH:$(realpath libwebp-0.4.1-linux-x86-64/bin)"
# Set these as "RUN" commands and you can use these in any dockerfile.
@jonshipman
jonshipman / screenfetch.txt
Created November 6, 2021 18:15
Gateway Screenfetch
./+o+- jon@Gateway
yyyyy- -yyyyyy+ OS: Ubuntu 21.04 hirsute
://+//////-yyyyyyo Kernel: x86_64 Linux 5.11.0-37-generic
.++ .:/++++++/-.+sss/` Uptime: 2h 4m
.:++o: /++++++++/:--:/- Packages: 1656
o:+o+:++.`..```.-/oo+++++/ Shell: bash 5.1.4
.:+o:+o/. `+sssoo+/ Resolution: 1280x800
.++/+:+oo+o:` /sssooo. DE: Xfce
/+++//+:`oo+o /::--:. WM: Xfwm4
\+/+o+++`o++o ++////. WM Theme: Greybird
@jonshipman
jonshipman / Disconnect RDP and Restart Gamestream.BAT
Created May 18, 2021 14:59
Restart NVIDIA Gamestream after RDP session
@echo off
REM kill the RDP clipboard to prevent errors...
taskkill /f /t /im rdpclip.exe
REM disconnects all active RDP sessions...
for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (
%windir%\System32\tscon.exe %%s /dest:console
)
@jonshipman
jonshipman / wc-product-attributes-dedupe.php
Created April 7, 2021 18:32
Woocommerce Product Attribute Dedupe
<?php
/**
* Product Attribute DeDupe
*
* @package Divide
*/
/**
* Product Attributes in Woocommerce are only checked in this tables for "register_taxonomy" loop.
* Deleting duplicates in this table does not require reassigning IDs. Terms are related to taxonomies by name only.