Skip to content

Instantly share code, notes, and snippets.

View bdlangton's full-sized avatar

Barrett Langton bdlangton

View GitHub Profile
@bdlangton
bdlangton / sudoers
Created March 4, 2020 22:10
Don't require password for vagrant commands
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 September 4, 2019 23:02
Sitemap of sitemaps
<?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 May 1, 2024 12:09
Tmux Commands

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 October 12, 2023 08:40
Drupal 8 programmatic solutions

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 November 28, 2017 02:58
Sample gitconfig
[user]
name = Barrett Langton
email = [email protected]
[core]
editor = vim
filemode = false
[merge]
tool = vimdiff
[alias]
br = branch

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 19:38
Development settings for Drupal 7
// 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 March 4, 2020 22:46
Drupal: dpm backtrace any errors
// 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 September 22, 2016 21:45
Clears out current git hooks and runs 'git init' to apply hooks that are in .git-templates/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 December 12, 2016 22:34
Print out db_select/views final query for debugging
// 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());