Skip to content

Instantly share code, notes, and snippets.

@jleehr
jleehr / delete.php
Created October 9, 2022 10:26
Delete directory and files recursive
<?php
$dir = __DIR__ . '/data/folder-to-delete';
$it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS);
$files = new RecursiveIteratorIterator($it,
RecursiveIteratorIterator::CHILD_FIRST);
foreach($files as $file) {
if ($file->isDir()){
rmdir($file->getRealPath());
@jleehr
jleehr / psdConverter.php
Created February 25, 2021 07:51
Converter script to generate PDF files.
<?php
/**
* Image to PSD converter
*
* Converts an base64 encoded image (PNG) to PSD via ImageMagick.
*
* The receiving data must be an array with
* - id = Unique dataset id.
* - name = Image name.
* - images = Array with the image data.
@jleehr
jleehr / JSON.py
Created November 18, 2020 15:06
BBEdit Text actions
#!/usr/bin/python
import fileinput
import json
print json.dumps( json.loads(''.join([line.strip() for line in fileinput.input()])), sort_keys=True, indent=2)
@jleehr
jleehr / .blackfire.env
Last active June 8, 2021 13:43
Blackfire.io & Lando
####
## Blackfire config - `lando rebuild` required
####
BLACKFIRE_CLIENT_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx
BLACKFIRE_CLIENT_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
BLACKFIRE_SERVER_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx
BLACKFIRE_SERVER_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
@jleehr
jleehr / gist:7ac2a5de785881dfce99f7034547f07b
Last active May 25, 2023 11:02
Drupal 8 - Migrate from public to private files
# Enable maintanance mode
drush state-set system.maintenance_mode 1
# Backup file field data
drush sql-query "CREATE TABLE media__field_file_bak AS SELECT * FROM media__field_file;"
drush sql-query "CREATE TABLE media_revision__field_file_bak AS SELECT * FROM media_revision__field_file;"
# Truncate file field tables (need to change storage settings)
drush sql-query "TRUNCATE media__field_file;"
drush sql-query "TRUNCATE media_revision__field_file;"
@jleehr
jleehr / gist:9aaebcc54e683b96536689b30510efac
Last active February 9, 2018 11:20
Php Code Sniffer + Drupal
Global Coder Install
$ composer global require drupal/coder
PHPCS zur Pfadvariable hinzufügen in ~/.profile, ~/.bash_profile oder ~/.bashrc
export PATH="$HOME/AppData/Roaming/Composer/vendor/bin:$PATH"
Standards registrieren
$ phpcs --config-set installed_paths C:\Users\[USER]\AppData/Roaming/Composer/vendor/drupal/coder/coder_sniffer
Prüfung durchführen mit
@jleehr
jleehr / README.md
Last active August 13, 2020 13:59
[Drupal 8] Alter route (permissions) for taxonomy vocabulary page

[Drupal 8] Alter route (permissions) for taxonomy vocabulary page

Needs the patch: https://www.drupal.org/node/1848686

Split "Administer vocabularies and terms" permission: Access the taxonomy overview page and Add terms in vocabulary name

File structure:

mymodule
|- src
@jleehr
jleehr / Readme.md
Last active June 30, 2017 07:49
Configuring Git over SSH to login once

MsysGit or Cygwin

Add a file called .bashrc to your home folder. Open the file and paste in:

#!/bin/bash
eval `ssh-agent -s`
ssh-add

# Stop ssh-agent if session is closed.
@jleehr
jleehr / domcheck.js
Last active August 15, 2024 20:05
Detection if an element is added to DOM
// Detection if an element is added to DOM
function onElementInserted(containerSelector, elementSelector, callback) {
var onMutationsObserved = function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.addedNodes.length) {
var elements = $(mutation.addedNodes).find(elementSelector);
for (var i = 0, len = elements.length; i < len; i++) {
callback(elements[i]);
}
}
@jleehr
jleehr / restore.php
Last active September 15, 2016 14:06
Restore lost files in git
#!/bin/bash
# 1. git fsck --lost-found
# 2. run this script via bash restore.php
cd PATH_TO/.git/lost-found/other
FILES=*
COUNTER=0
for f in $FILES; do
echo "Processing $f file..."
git show $f > "PATH_TO/recover/$COUNTER.txt"