Skip to content

Instantly share code, notes, and snippets.

View thommyhh's full-sized avatar

Thorben Nissen thommyhh

View GitHub Profile
@thommyhh
thommyhh / StatisticHook.php
Created September 1, 2021 17:00
TYPO3 EXT:form afterSubmit hook per form definition
<?php
declare(strict_types=1);
namespace YourVendor\YourPackage\Form;
use TYPO3\CMS\Form\Domain\Model\Renderable\AbstractRenderable;
use TYPO3\CMS\Form\Domain\Model\Renderable\RenderableInterface;
use TYPO3\CMS\Form\Domain\Runtime\FormRuntime;
@thommyhh
thommyhh / typo3_page_layouts_recursive.sql
Created February 15, 2021 15:38
TYPO3 CMS: Find used page layouts in database
###################################################################################
### WARNING: This query uses recursion. This requires MySQL 8+ or MariaDB 10.2+ ###
###################################################################################
# Find the used backend layout for each page, including next level layout from parent pages
WITH RECURSIVE Layout AS (
SELECT
uid,
pid,
slug,
@thommyhh
thommyhh / ssh_key_pair.yaml
Created November 17, 2020 11:21
Ansible + passwordstore: Create and save SSH key pair
# Copy this file into to playbook or your role's tasks directory
# and include it with
# - name: Generate SSH key pair for root {your-user-name-here}
# include_tasks: ./ssh_key_pair.yaml
# vars:
# user: {your-user-name-here}
# type: {ssh-key-type} # defaults to `rsa`
#
# Arguments:
# - user: The user name you want to generate a key pair for (required)
@thommyhh
thommyhh / php_my_cnf.php
Last active September 17, 2020 13:58
PHP: Reading DB credentials from `.my.cnf`
<?php
$dbConfig = [
'host' => 'localhost',
'database' => '',
'user' => '',
'password' => ''
];
if (file_exists($_SERVER['HOME'] . '/.my.cnf')) {
// If `.my.cnf` exists in PHP home directory, parse it with sections
@thommyhh
thommyhh / log.sh
Last active July 31, 2022 01:19
Nice logging for bash scripts
#!/usr/bin/env bash
# Takes stdin as message and prepends timestamp and severity and writes it into the given log file
function log() {
file=$1
severity=$2
while read text
do
LOGTIME=$(date "+%Y-%m-%d %H:%M:%S")
touch $file
@thommyhh
thommyhh / mysqldump_mysqlimport_csv.md
Last active September 30, 2019 08:13
MySQL Dump to/Import from CSV

Export the table structure

mysqldump -d --skip-triggers --skip-events --skip-routines {database} > structure.sql

Export tables as CSV

mysqldump -t --fields-enclosed-by='"' --fields-escaped-by='\' --fields-terminated-by='\n' --lines-terminated-by='\n' --tab {absoluteTargetDir} {database}
@thommyhh
thommyhh / composer.sh
Last active March 24, 2022 16:00
A script to easily run composer through docker to provide a defined environment
#!/bin/sh
# This script is meant to be user with docker images from https://hub.docker.com/r/webcoastdk/composer/tags
#
# It mounts the current working directory into /build in the container and calls the given command.
# Additionally the current users `.ssh` and `.composer` directory are also mounted to give access to composer cache
# and SSH known hosts
#
# On hosts with MacOS the SSH agent is started inside the container, as it is currently not possible to mount the SSH
# authentication agent socket into the container.
# On other hosts (mainly Linux) the current `$SSH_AUTH_SOCK` is mounted to `/ssh-agent` and the environment variable
@thommyhh
thommyhh / delay-promise.js
Last active July 21, 2023 21:43
JavaScript delayed promise
// Sometimes it is helpful/necessary to create a promise, that delays the execution.
// This snippet returns a promise, that is resolved after a given timeout.
// The `min` and `max` arguments are used to calcuate a random delay in the range between `min` and `max`
let delay = (min, max) => {
return new Promise(resolve => {
setTimeout(resolve, Math.random() * (max - min) + min)
})
}
// In your actual code you use it as follows:
@thommyhh
thommyhh / less-more-pagination.njk
Last active June 21, 2022 11:48
Nunjucks pagination with less and more
{#
Pagination template code to create a pagination with a maximum number of links
plus first and last link and more and less indicators.
Adjust the page link/button markup to fit your needs. This would create a paginations like the following:
_1_ 2 3
1 2 _3_ 4 5 6
1 2 _3_ 5 6 ... 7
1 ... 5 6 _7_ 8 9 ... 13