Skip to content

Instantly share code, notes, and snippets.

View dkesberg's full-sized avatar

Daniel Kesberg dkesberg

View GitHub Profile
@dkesberg
dkesberg / preview.sh
Created July 26, 2024 14:42
Generate peview images for all pdf in current directory.
#! /bin/bash
for file in *.pdf
do
convert "$file[0]" -quality 100 -flatten "$file.jpg"
done
rename 's/\.pdf\.jpg/\.jpg/g' *.jpg
@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>');
});
});