Skip to content

Instantly share code, notes, and snippets.

View benjbmc's full-sized avatar

Benjamin R. benjbmc

View GitHub Profile
@benjbmc
benjbmc / .gitconfig
Created November 30, 2018 09:35
Git global aliases in ~/.gitconfig
[alias]
last = log -1 HEAD
lst = log --oneline --name-status
ldf = log --oneline --name-status --diff-filter=$1
lf = log --oneline -- $1
ls = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate
ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat
@benjbmc
benjbmc / d8-empty-cache-mysql-snippet
Created February 12, 2018 11:40
Truncate cache tables in D8
# Taken from https://www.drupal.org/docs/7/administering-drupal-7-site/clearing-or-rebuilding-drupals-cache
TRUNCATE cache_config;
TRUNCATE cache_container;
TRUNCATE cache_data;
TRUNCATE cache_default;
TRUNCATE cache_discovery;
TRUNCATE cache_dynamic_page_cache;
TRUNCATE cache_entity;
TRUNCATE cache_menu;
@benjbmc
benjbmc / working-days-between-dates.php
Created January 26, 2018 14:50
MySQL function to find the number of working days between two dates
<?php
// original expression: 5 * (DATEDIFF(@E, @S) DIV 7) + MID('0123444401233334012222340111123400012345001234550', 7 * WEEKDAY(@S) + WEEKDAY(@E) + 1, 1)
// see: https://stackoverflow.com/a/6762805
// Example
$sql_diff = "SELECT (5 * (DATEDIFF(date_expedie, date_enattentedimpression) DIV 7) + MID('0123444401233334012222340111123400012345001234550', 7 * WEEKDAY(date_enattentedimpression) + WEEKDAY(date_expedie) + 1, 1)) FROM `" . _DB_PREFIX_ . "orders` WHERE `id_order` = " . (int) $order->id . " AND `date_enattentedimpression` IS NOT NULL AND `date_enattentedimpression` IS NOT NULL";
echo 'alias drush="~/public_html/vendor/bin/drush"' >> ~/.bashrc
source ~/.bashrc
@benjbmc
benjbmc / themename.theme
Created January 22, 2018 22:40
[ D8 ] To add body class - themename.theme
<?php
/**
* Implements hook_preprocess_html().
*
* @param type $variables
*/
function THEMENAME_preprocess_html(&$variables) {
if (isset($variables['root_path'])) {
switch ($variables['root_path']) {
<?php
$nid = \Drupal::routeMatch()->getRawParameter($node_id); // To get node id from url
$node = \Drupal::entityTypeManager()->getStorage('node')->load($nid); // To load node data using nid via entity manager
$node = Node::load($nid); // To load node data using nid via static call
$title = $node->getTitle(); // To get node title. Returns $node->get('title')->value;
if (!empty($node->field_name))
echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bashrc
# or: sed -i '1i export PATH="$HOME/.composer/vendor/bin:$PATH"' $HOME/.bashrc
source $HOME/.bashrc
composer show | grep drupal/console
composer update drupal/core --with-dependencies