Skip to content

Instantly share code, notes, and snippets.

View MGHollander's full-sized avatar
👋

Marc Hollander MGHollander

👋
View GitHub Profile
@MGHollander
MGHollander / ClientScriptView.php
Last active June 12, 2020 08:14
Yii2 View extension to highlight JavaScript code block and capture them with the registerJs function. (Yii 1.1. version: https://gist.github.com/MGHollander/c3f677260f742e6cacce)
<?php
namespace common\components;
/**
* ClientScriptView class file.
*
* @author Tsunu {@link http://www.yiiframework.com/forum/index.php/topic/24429-the-best-way-to-write-javascript/page__p__118436#entry118436}
* @author MGHollander {@link https://github.com/MGHollander}
* @version 1.1
*/
@MGHollander
MGHollander / mysql.sql
Created June 12, 2020 07:21
MySQL commands
# Calculate the size of each database
## Order by name
SELECT
table_schema AS `Database`,
ROUND((SUM(data_length + index_length) / 1024 / 1024), 2) AS `Size in MB`
FROM
information_schema.tables
GROUP BY
table_schema
@MGHollander
MGHollander / commands.sh
Last active June 13, 2022 09:59
Terminal commands (Tar, MySQL, Drush)
# Compress a folder with an exclude
tar --exclude='folder/exclude' -czvf filename.tar.gz folder/
# Compress a folder with progress bar (https://superuser.com/a/665181)
tar cf - /folder/to/compress -P | pv -s $(($(du -sk /folder/to/compress | awk '{print $1}') * 1024)) | gzip > filename.tar.gz
# Display disk usage in a summarized and human readable output
du -h -d1 /path
# Find files older than 7 days
@MGHollander
MGHollander / node.twig
Last active July 1, 2020 10:23
Common ways to get field values in twig templates in Drupal 8
{# Get field_text #}
{{ content.field_text }}
{# Get content of field_text #}
{{ content.field_text.0 }}
{# Get the path of an image / file #}
{{ file_url(content.field_image[0]['#media'].field_media_image.entity.uri.value) }}
{# Get the alt value of an image #}
@MGHollander
MGHollander / .lando.local.yml
Last active June 22, 2020 08:40
Local Lando config to speed up Lando for Drupal projects
excludes:
# General
- vendor
# Drupal 8
- web
- '!web/sites'
- '!web/modules/custom'
- '!web/themes/custom'
@MGHollander
MGHollander / MY_D8_THEME.theme.php
Last active April 23, 2020 08:31 — forked from mogtofu33/MY_D8_THEME.theme
Common Drupal 8 preprocess and theme suggestion applications.
<?php
/**
* @file
* Preprocess and suggestions for a Drupal sub-theme.
*
*/
use Drupal\block\Entity\Block;
@MGHollander
MGHollander / MY_MODULE.drush.inc
Created October 30, 2019 13:52
Drupal 7 custom drush sanitization hook
<?php
/**
* Implements hook_drush_sql_sync_sanitize.
*/
function MY_MODULE_drush_sql_sync_sanitize($source) {
// Sanitize username
$users_query = "UPDATE users SET name = CONCAT('name', uid) WHERE uid > 1;";
drush_sql_register_post_sync_op('sanitise_users_name', dt('Sanitise users name field'), $users_query);
@MGHollander
MGHollander / maps.js
Created January 6, 2016 13:27
Where I Was, Where I Will Be fix
/*
Topic: https://wordpress.org/support/topic/problem-on-adding-local-and-shortcode?replies=4#post-7851880
*/
//Show Map by Address
function show_map(id, div, lat, lng) {
var geocoder;
var map;
geocoder = new google.maps.Geocoder();
@MGHollander
MGHollander / ClientScript.php
Last active June 12, 2020 08:14
Yii1.1 CClientScript extension to highlight JavaScript code block and capture them with the registerScript function (Yii2 version: https://gist.github.com/MGHollander/fe913a62efadc3bc5d9d123f7a7f870d)
<?php
/**
* ClientScript class file.
*
* @author Tsunu {@link http://www.yiiframework.com/forum/index.php/topic/24429-the-best-way-to-write-javascript/page__p__118436#entry118436}
* @author MGHollander {@link https://github.com/MGHollander}
*/
/**
* ClientScript class is an extension on Yii's CClientScript to register scripts inside a view.