Skip to content

Instantly share code, notes, and snippets.

@gonssal
gonssal / MODULE.module
Last active March 4, 2020 20:44
Drupal 8 code to mark as active all the menu links poiting to /user when viewing an user's own profile.
/**
* Implements hook_preprocess_HOOK().
*
* @note: This can be removed if https://www.drupal.org/project/drupal/issues/2870054 is fixed.
*/
function MODULE_preprocess_menu(&$variables) {
/** @var Drupal\Core\Routing\CurrentRouteMatch */
$routeMatcher = \Drupal::routeMatch();
/** @var Drupal\Core\Routing\RouteMatch */
@gonssal
gonssal / deploy.php
Last active March 31, 2022 17:10
Deployer script for locally-built composer-based Drupal 8 deployment. Drush heavily used, including sql-dump for backup.
<?php
/**
* @file
* Deployment script for composer-based Drupal 8 installations using Deployer.
*/
namespace Deployer;
use Deployer\Support\Unix;
@gonssal
gonssal / functions.php
Created September 22, 2019 23:26
WordPress theme debug template name
<?php
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
/**
* Adds the current template info for debugging.
*
* @param string $t The template.
*/
function var_template_include( $t ) {
@gonssal
gonssal / ArrayRecursiveIterator.php
Last active September 21, 2019 01:38
Using PHP's ArrayRecursiveIterator to find a key and its value in any multidimensional array.
<?php
$iterator = new RecursiveIteratorIterator(
new RecursiveArrayIterator($multidimensional_array, RecursiveArrayIterator::CHILD_ARRAYS_ONLY),
RecursiveIteratorIterator::SELF_FIRST
);
foreach ($iterator as $key => $value) {
if ($key === $search) {
$your_data = $value;
break;
@gonssal
gonssal / .lando.yml
Last active March 4, 2020 20:36
Drupal 8 + PHPMyAdmin Lando config file
name: example
recipe: drupal8
config:
webroot: web
xdebug: true
tooling:
drush:
service: appserver
cmd:
- "drush"
@gonssal
gonssal / Dockerfile
Last active September 21, 2019 01:36
Ruby's Bundler Dockerfile
# This Dockerfile is aimed at building it from a directory containing a Gemfile.
# It installs the Gemfile packages and then gives you the "bundle exec" entry point.
#
# Usage:
# * docker build --tag=bundle-exec .
# * docker run -it --rm --user $(id -u):$(id -g) -v $(pwd):/src bundle-exec
# Example: docker run -it --rm --user $(id -u):$(id -g) -v $(pwd):/src bundle-exec compass compile -e production
FROM ubuntu:16.04
@gonssal
gonssal / https-and-canonical-url-force.php
Created January 5, 2019 19:18
PHP force HTTPS and canonical host URL
/**
* Force HTTPS and canonical host.
*/
if (php_sapi_name() != 'cli') {
$primary_domain = 'www.example.com';
if ($_SERVER['HTTP_HOST'] != $primary_domain || !array_key_exists('HTTPS', $_SERVER)) {
header('HTTP/1.0 301 Moved Permanently');
header('Location: https://'. $primary_domain . $_SERVER['REQUEST_URI']);
exit();
}
@gonssal
gonssal / acme-cpanel.sh
Last active January 5, 2019 04:25
Shell script for quick creation of Let's Encrypt certificates in cPanel-based hosts
#!/usr/bin/env sh
# Basically packs all the instructions in https://github.com/Neilpang/acme.sh/wiki/Simple-guide-to-add-TLS-cert-to-cpanel
# into a single command, while adding all the default cPanel subdomains. If this is useful to you, consider donating to
# the acme.sh creator here: https://donate.acme.sh/.
### Change the following variables with your info.
EMAIL="[email protected]"
DOMAIN="example.com"
WEBROOT="${HOME}/public_html/" # Trailing slash required!