Skip to content

Instantly share code, notes, and snippets.

View svandragt's full-sized avatar
🤞

Sander van Dragt svandragt

🤞
View GitHub Profile
@svandragt
svandragt / favicon.php
Last active January 23, 2024 10:52
Dynamic icon based on HTTP_HOST
<?php
/**
* `favicon.php` - Dynamically generate a favicon image with background color and text overlay
*/
$fallback = 'favicon.ico';
if ( file_exists( $fallback ) ) {
// use a favicon.ico if available
header( "Location: $fallback" );
die( "Redirecting to $fallback" );
<?php
register_shutdown_function('handleShutdown');
function handleShutdown() {
$lastError = error_get_last();
if (null !== $lastError) {
switch ($lastError['type']) {
case E_ERROR:
case E_PARSE:
@svandragt
svandragt / cascade.sh
Last active January 16, 2024 15:03
Cascade the windows on the current workspace and display
#!/bin/bash
# Variables to set the starting position and increment.
xPos=60
yPos=60
increment=30
# Save the active window id for later.
active_window_id=$(xdotool getactivewindow)
active_window_id_hex=$(printf "0x%08x" "$active_window_id")
@svandragt
svandragt / shorthand.js
Last active January 3, 2024 14:53
shorthand.js prototype
/**
* Returns the first element that matches the specified CSS selector within the document.
*
* @function $
* @param {string} selector - The CSS selector used to select the element.
* @returns {Element|null} The first element that matches the selector, or null if no elements are found.
*/
let $ = document.querySelector.bind(document);
/**
@svandragt
svandragt / wp-proxy.sh
Last active March 13, 2024 16:56
WordPress reverse proxy
#!/usr/bin/env bash
# Requirements
if ! command -v docker &> /dev/null; then
echo 'Please install docker: https://docs.docker.com/engine/install/'
exit 1
fi
if ! command -v ngrok &> /dev/null; then
echo 'Please install ngrok: https://ngrok.com/download'
@svandragt
svandragt / user-stylesheet.css
Last active September 5, 2023 11:14
BookStack Elementary User Stylesheet
.tri-layout-container .tri-layout-middle {
padding-top: 0 !important;
}
.content-wrap.card {
padding: 4px 16px !important;
}
.content-wrap.card h2 {
font-size: 1.25rem !important;
}
.tri-layout-left-contents, .tri-layout-right-contents {
@svandragt
svandragt / stamped-data.php
Created August 13, 2023 10:49
Timestamp data
<?php
// mock get_option / update_option using global state
require_once( 'mock.php' );
/**
* Timestamp a value.
* update_option( $name, stamp( $value ) );
*
* @param int|null $timestamp now, or provided time() compatible timestamp.
*
@svandragt
svandragt / git-sw.sh
Created June 13, 2023 09:34
Fuzzy switcher, handles checking out origin branches.
#!/usr/bin/env bash
# filename: ~/bin/git-sw
# example: git sw 930
# example: git sw origin/JIRA-2
#
# Fuzzy switch
# TODO: Does not handle remotes other than origin.
# Check branch locally
BRANCH=$(git branch | grep $1 | head -n1 | xargs)
@svandragt
svandragt / clone-gists.py
Last active May 26, 2023 13:17
Clones all gists for a user. NOTE: change the user to you
#!/usr/bin/env python3
import json
import os
import re
import requests
import subprocess
import unicodedata
@svandragt
svandragt / system-update.sh
Last active January 10, 2024 09:05
One stop "system and various dev software" updates shop
#!/usr/bin/env bash
update_apt() {
if ! command -v apt-get &> /dev/null
then
return
fi
echo;
echo ">>> Updating apt-get packages..."
sudo apt-get update -qq