Skip to content

Instantly share code, notes, and snippets.

Julian Pustkuchen JPustkuchen

Block or report user

Report or block JPustkuchen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@JPustkuchen
JPustkuchen / scrollToMiddle.js
Created Aug 14, 2019
jQuery: Scroll element to the middle of the viewport
View scrollToMiddle.js
(function($) {
/**
* jQuery function to scroll the viewport middle to the element.
*/
$.fn.scrollToMiddle = function(options) {
var settings = $.extend({
duration: 1000
}, options );
return this.each(function() {
@JPustkuchen
JPustkuchen / CustomBreadcrumbBlock.php
Last active Aug 8, 2019
Drupal 8 Custom Breadcrumb block printing the 2 top level breadcrumbs including page title
View CustomBreadcrumbBlock.php
<?php
namespace Drupal\custom_breadcrumb_block\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Controller\TitleResolverInterface;
@JPustkuchen
JPustkuchen / d8-remove-wrong-equal-translations-l10n.md
Last active Jul 16, 2019
Drupal 8 CMS: Delete equal customized translation (source language string = target language string)
View d8-remove-wrong-equal-translations-l10n.md

Drupal 8 CMS: Delete equal customized translation (source language string = target language string)

If you should encounter the problem that some translations are wrongly translated with the equal source language string (for example in our case there were German translations for "Author" translated with "Author" or "Published" with "Published"), you may use the following snippet to delete them.

SELECT s.lid FROM `locales_source` s
INNER JOIN locales_target t
WHERE s.lid=t.lid AND CONVERT(s.source USING utf8) = CONVERT(t.translation USING utf8) 
AND t.customized=1
@JPustkuchen
JPustkuchen / drupal8-settings-devel-kint-maxLevels-override.md
Last active Jun 24, 2019
Drupal 8 kint set maxLevels in settings.php to prevent out of memory
View drupal8-settings-devel-kint-maxLevels-override.md

Currently devel doesn't allow to override KINT configuration in a clean way. Hopefully this will be possible some day via setting in UI or drupal setting override in settings.php Until this happens you may use this dirty trick in settings.php to override the setting.

See issues:

Simply copy this into your settings.php and change the value accordingly (Kint default: 7)

@JPustkuchen
JPustkuchen / field_type_schema_change_helper.md
Last active Sep 12, 2019
Drupal 8 Field type schema column change helpers.
@JPustkuchen
JPustkuchen / getMinMaxFromMediaQuery.php
Last active Feb 12, 2018
PHP regex extraxt min-width / max-width from CSS MediaQuery
View getMinMaxFromMediaQuery.php
<?php
function getMinMaxFromMediaQuery($mediaQuery) {
$re = '/\d*(min-width|max-width):\s*(\d+\s?)(px|em|rem)/';
preg_match_all($re, $mediaQuery, $matches, PREG_SET_ORDER, 0);
$result = array();
if (!empty($matches)) {
if (count($matches) <= 2) {
foreach ($matches as $match) {
if (count($match) == 4) {
$result[] = [
View xmlsitemap-multipage-cache-warmer.sh
#!/bin/bash
# CACHE WARMER script for XML Sitemaps with MULTIPLE SUB-SITEMAPS:
DOMAIN='https://www.xyz.com'
wget -q $DOMAIN/sitemap.xml --no-cache -O - | egrep -o "$DOMAIN[^<]+" | while read subsite;
do
echo --- Reading sub-sitemap: $subsite: ---
wget -q $subsite --no-cache -O - | egrep -o "$DOMAIN[^<]+" | while read line;
do
echo $line:
time curl -A 'Cache Warmer' -s -L $line > /dev/null 2>&1
@JPustkuchen
JPustkuchen / README.md
Last active Jan 9, 2018
[Docker set default binding IP e.g. for links in portainer] #docker
View README.md

cd /etc/default/docker (if not existing, create the file)

Add the following line (or the --ip=... part if already existing):

DOCKER_OPTS="--ip=192.168.123.123" (Your docker host IP)

Restart docker: systemctl stop docker

You can’t perform that action at this time.