Skip to content

Instantly share code, notes, and snippets.

View svandragt's full-sized avatar
🤞

Sander van Dragt svandragt

🤞
View GitHub Profile
@svandragt
svandragt / car-sale-sim-ai.txt
Last active June 26, 2024 08:58
generative ai car salesman simulator prompt
this is a haggling simulator where I am trying to buy any secondhand car and you have the role of the car salesman. the car is values at a certain price which is stated up front. Your aim is to try and get as close to the target price, you get paid by commision which is the typical percentage of the agreed price, which is your score. my goal is to pay as little as possible, anything less than the target price is my score. Every time we play the car is generated again, with a new target price, and new characteristics. There are additional characteristcs of the car and its condition that are not mentioned that can be uncovered by an inspection, that you are aware of. All characteristics are revealed at the end of the game. You, the salesman, use typical car sales techniques to convince me to buy the car at your desired price. I try and use typical car buyer techniques to bring the price down. We take turns making arguments pro and con. Are you ready? When you are ready, generate a car with visible characteristi
@svandragt
svandragt / error.php
Last active June 5, 2024 15:39
Top PHP log errors
<?php
// Read the contents of the log file into an array
$log_file = 'web1_php_errors.log';
$log_entries = file($log_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
// Filter log entries for the last 14 days
$current_date = new DateTime();
$filtered_entries = array_filter($log_entries, function($entry) use ($current_date) {
// Extract the date part and convert it to a DateTime object
$entry_date_str = substr($entry, 1, 20); // Extracting the date part
@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)