Skip to content

Instantly share code, notes, and snippets.

View dkesberg's full-sized avatar

Daniel Kesberg dkesberg

View GitHub Profile
@dkesberg
dkesberg / functions.php
Created June 27, 2023 10:03
WP Sanitize SVG markup
/**
* Sanitize SVG markup for front-end display.
*
* @link https://developer.wordpress.org/reference/functions/wp_kses/#comment-6185
*
* @param string $svg SVG markup to sanitize.
* @return string Sanitized markup.
*/
function sanitize_svg( $svg = '' ) {
$allowed_html = array(
@dkesberg
dkesberg / Readme.md
Last active March 21, 2023 16:00
set www-data user to handle file permissions in nginx / php-fpm

Project structure

  • ./docker-compose.yml
  • ./php/Dockerfile
  • ./php/php.ini
  • ./nginx/Dockerfile
  • ./nginx/default.conf
  • ./nginx/certs (Directory for generated certificates)

Make mkcert work in WSL2

@dkesberg
dkesberg / .env.production
Created February 22, 2023 08:58
Vue JS subdirectory setup for /directory
VITE_BASE="/directory/"
@dkesberg
dkesberg / boilerplate.html
Last active September 13, 2022 10:53
Html boilerplate with normalize
<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<!-- Supports modern JS? -->
@dkesberg
dkesberg / Controller.php
Created February 23, 2022 10:16
Laravel request validation: Missing array values after POST request from input[type="checkbox"] fields
function post(Request $request)
{
$rules = [
'items' => 'nullable|array'
];
// set default value for optional array fields
$request->merge(['items' => $request->input('items', [])]);
// validate as usual
@dkesberg
dkesberg / schedule.sh
Created November 4, 2021 15:19
laravel schedule sh
#!/usr/bin/env bash
directory="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
/usr/local/bin/php "$directory/artisan" schedule:run >> /dev/null 2>&1
@dkesberg
dkesberg / db-specific-migration.md
Created February 23, 2021 09:24
Running migration on a specific db

Running migration on a specific db

To run a migration on a specific db the db has to be set in the artisan command, setting it in the migration file doesnt seem to work

php artisan migrate --path=/database/migrations/my_migration.php --database=my_database

@dkesberg
dkesberg / eager-load-specific-cloumns-in-eloquent.md
Last active August 11, 2022 19:22
Eager loading specific columns in a nested relationship

Eager loading specific columns in a nested relationship

For eager loading a nested relationship you always have to include the primary key or the foreign key to the field list.

Wrong

$posts = Posts::with(['comments:id,title', 'comments.author:id,email']);

Right

@dkesberg
dkesberg / superscript.js
Created October 20, 2020 15:29
Superscript ®and &reg;
// superscript &reg;
$(function() {
$('body :not(script,sup)').contents().filter(function() {
return this.nodeType === 3
}).replaceWith(function() {
return this.nodeValue
.replace(/&reg;/gi, '<sup>&reg;</sup>')
.replace(/®/gi, '<sup>&reg;</sup>');
});
});
@dkesberg
dkesberg / import-csv.md
Last active March 4, 2020 12:29
import csv data into xls

Excel 2010:

Create new workbook Data > From Text > Select your CSV file In the popup, choose "Delimited" radio button, then click "Next >" Delimiters checkboxes: tick only "Comma" and uncheck the other options, then click "Next >" In the "Data preview", scroll to the far right, then hold shift and click on the last column (this will select all columns). Now in the "Column data format" select the radio button "Text", then click "Finish".

Excel office365: (client version)