Skip to content

Instantly share code, notes, and snippets.

Avatar

Barrett Langton bdlangton

View GitHub Profile
@bdlangton
bdlangton / sudoers
Created Mar 4, 2020
Don't require password for vagrant commands
View sudoers
Type: sudo visudo
Add the following to the end of the file:
# Set these vagrant commands so that they don't require entering a password.
Cmnd_Alias VAGRANT_HOSTS_ADD = /bin/sh -c echo "*" >> /etc/hosts
Cmnd_Alias VAGRANT_HOSTS_REMOVE = /usr/bin/sed -i -e /*/ d /etc/hosts
Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/tee -a /etc/exports
Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /usr/bin/sed -E -e /*/ d -ibak /etc/exports
Cmnd_Alias VAGRANT_NFSD = /sbin/nfsd restart
@bdlangton
bdlangton / Sitemap.php
Created Sep 4, 2019
Sitemap of sitemaps
View Sitemap.php
<?php
namespace Drupal\mymodule\Plugin\simple_sitemap\SitemapGenerator;
use Drupal\simple_sitemap\Plugin\simple_sitemap\SitemapGenerator\SitemapGeneratorBase;
/**
* Class Sitemap.
*
* @package Drupal\mymodule\Plugin\simple_sitemap\SitemapGenerator
@bdlangton
bdlangton / tmux.md
Last active Jun 2, 2020
Tmux Commands
View tmux.md

NOTE: All commands that start with tmux can be executed within a tmux session by typing prefix, followed by :, then type the rest of the command (after tmux).

There is a binary script called tat that can be run and it will create a new session named after the directory that you are currently in. If a session with that name already exists, it will just open that session.

Sessions

Command Description
tmux new -s [session name] Start new named session
prefix s Choose a different session using fzf (custom mapping)
@bdlangton
bdlangton / Blocks.md
Last active Mar 1, 2021
Drupal 8 programmatic solutions
View Blocks.md

Render custom blocks

$bid = 'myblock';
$block = \Drupal\block_content\Entity\BlockContent::load($bid);
$render = \Drupal::entityTypeManager()->getViewBuilder('block_content')->view($block);

Render plugin blocks

$block_manager = \Drupal::service('plugin.manager.block');
@bdlangton
bdlangton / .gitconfig
Created Nov 28, 2017
Sample gitconfig
View .gitconfig
[user]
name = Barrett Langton
email = barrett@example.com
[core]
editor = vim
filemode = false
[merge]
tool = vimdiff
[alias]
br = branch
View Some Custom git commands.md

Show number of commits per author.

git shortlog -sn --all

Use --no-merges if you want to exclude merge commits Use -e if you want to see the users' email addresses

Get list of contributors for the repo.

git log --format='%aN' | sort -u

@bdlangton
bdlangton / custom.settings.php
Last active May 16, 2017
Development settings for Drupal 7
View custom.settings.php
// My custom settings.
// Show all errors.
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
// Show Views SQL query and performance stats in preview. Requires: views_ui.
$conf['views_ui_show_sql_query'] = 1;
$conf['views_ui_show_performance_statistics'] = 1;
@bdlangton
bdlangton / bootstrap.inc
Last active Mar 4, 2020
Drupal: dpm backtrace any errors
View bootstrap.inc
// This function exists in includes/bootstrap.inc.
// Just need to add lines 6-7 to it.
function _drupal_error_handler($error_level, $message, $filename, $line, $context) {
require_once DRUPAL_ROOT . '/includes/errors.inc';
$d = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
dpm($d, $message);
_drupal_error_handler_real($error_level, $message, $filename, $line, $context);
}
@bdlangton
bdlangton / update-hooks
Created Sep 22, 2016
Clears out current git hooks and runs 'git init' to apply hooks that are in .git-templates/hooks
View update-hooks
#!/usr/bin/env bash
# Check that the git directory exists.
GIT_DIR=$(git rev-parse --git-dir 2>/dev/null)
if [ -z "$GIT_DIR" ]; then
echo >&2 "Fatal: GIT_DIR not set"
exit 1
fi
# Remove existing hooks and re-init to copy new hooks.
@bdlangton
bdlangton / gist:f2ad5b4c06755a7f025ebfafdb6d0cae
Last active Dec 12, 2016
Print out db_select/views final query for debugging
View gist:f2ad5b4c06755a7f025ebfafdb6d0cae
// Print out query built by views:
// Can use pre_execute or post_render (probably more also).
function hook_views_pre_execute(&$view) {
dpq($view->build_info['query']);
}
// Print out query build by db_select:
dpm((string) $query);
dpm($query->arguments());