Skip to content

Instantly share code, notes, and snippets.

View dkesberg's full-sized avatar

Daniel Kesberg dkesberg

View GitHub Profile
@dkesberg
dkesberg / bootstrap-fileinput.css
Created April 17, 2014 13:22
file input styling for bootstrap 3
.btn-file {
position: relative;
overflow: hidden;
}
.btn-file input[type=file] {
position: absolute;
top: 0;
right: 0;
min-width: 100%;
min-height: 100%;
@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/"
$imagine = new Imagine\Gd\Imagine();
$pathPhoto = 'photo.jpg';
$pathThumbnail = 'thumb.jpg';
$watermarkText = 'My watermark text';
// thumb config
$thumbQuality = 75;
$thumbSize = new \Imagine\Image\Box(800, 600);
@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 / 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 / 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 / jQuery.validator.filesize.js
Created November 15, 2013 08:32
jQuery Validator method for maximum filesize
jQuery.validator.addMethod("filesize_max", function(value, element, param) {
var isOptional = this.optional(element),
file;
if(isOptional) {
return isOptional;
}
if ($(element).attr("type") === "file") {