Skip to content

Instantly share code, notes, and snippets.

View leymannx's full-sized avatar
✍️
git reset --soft HEAD~1

Norman Kämper-Leymann leymannx

✍️
git reset --soft HEAD~1
View GitHub Profile
version: '2'
services:
web:
image: php:7.0-apache
volumes:
- /var/www/myapp
restart: always
bg-sync:
@leymannx
leymannx / 000-default.conf
Created January 22, 2018 13:27
apache2.4 default conf
# cat /etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
@leymannx
leymannx / Dockerfile
Last active August 8, 2018 00:59 — forked from Majkl578/Dockerfile
[Updated PHP7.0 to PHP 7.1 ] Dockerized example for article at Pehapkari.cz about running multiple PHP versions on NGINX: https://pehapkari.cz/blog/2017/03/27/multiple-php-versions-the-easy-way/
FROM debian:stretch
ENV DEBIAN_FRONTEND noninteractive
# install NGINX
RUN apt-get update && \
apt-get install -y nginx --no-install-recommends && \
rm -rf /var/lib/apt/lists/*
@leymannx
leymannx / docker.sh
Created January 12, 2018 13:13
Docker beginner commands
# List containers
docker ps
# List images
docker images
# Stop and delete all containers
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
@leymannx
leymannx / functions.php
Last active December 19, 2017 15:45
Wordpress require image alt and title workaround found on https://wpkraken.io/blog/wordpress-images/
<?php
/* Automatically set the image Title, Alt-Text, Caption & Description upon upload
-----------------------------------------------------------------------*/
add_action('add_attachment', 'my_set_image_meta_upon_image_upload');
function my_set_image_meta_upon_image_upload($post_ID) {
// Check if uploaded file is an image, else do nothing
@leymannx
leymannx / mytheme.php
Last active November 29, 2017 12:08
Drupal 8 add external link field class
<?php
use Drupal\Core\Render\Element;
/**
* Implements template_preprocess_field().
*
* @param array $variables
*/
function MYTHEME_preprocess_field(&$variables) {
@leymannx
leymannx / toTitleCase.js
Last active November 17, 2017 17:09
jQuery title case headings
(function ($) {
'use strict';
/**
* To Title Case 2.1 – http://individed.com/code/to-title-case/
* Copyright © 2008–2013 David Gouch. Licensed under the MIT License.
*
* @returns {string}
*/
String.prototype.toTitleCase = function () {
@leymannx
leymannx / HeroImageBlock.php
Created October 17, 2017 13:59
Drupal 8 load and render responsive image field inside a block programmatically
<?php
namespace Drupal\abc_header\Plugin\Block;
use Drupal\Core\Block\BlockBase;
/**
* Provides a 'ABC Hero Image' Block.
*
* @Block(
@leymannx
leymannx / webhook.php
Last active November 6, 2018 14:43 — forked from cowboy/github_post_recieve.php
PHP webhook to pull and Gulp build automatically after push
<?php
if ( isset($_POST['payload']) && $_POST['payload'] ) {
echo shell_exec('cd /var/www/mydrupal/ && sudo -u myuser git pull');
echo shell_exec('cd /var/www/mydrupal/sites/all/themes/mytheme/ && sudo -u myuser node ./node_modules/gulp/bin/gulp.js mygulptask');
// Adding the drush will cause the delivery being displayed as unsuccessful. Means GitHub doesn't wait so long. The command will run nevertheless.
echo shell_exec('cd /var/www/mydrupal/ && sudo -u myuser drush @sites cc all -y');
}
// Should return www-data
@leymannx
leymannx / mymodule.php
Created January 7, 2017 21:54
Drupal 8 user login redirect to front page
<?php
/**
* Implements hook_user_login().
*/
function MYMODULE_user_login($account) {
\Drupal::service('request_stack')->getCurrentRequest()->query->set('destination', '/');
}