Skip to content

Instantly share code, notes, and snippets.

View bdlangton's full-sized avatar

Barrett Langton bdlangton

View GitHub Profile
@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 / README.md
Last active June 1, 2022 19:13
Git hooks

Install required packages

Install the packages that you'll need. Drupal/coder includes phpcs. If you're not wanting to use a specific hook, then you don't need to install the associated packages.

composer global require drupal/coder phpmd/phpmd sebastian/phpcpd

Set path

Set the path in your shell startup script (ex: .zshrc or .bashrc).

@bdlangton
bdlangton / phpcs.txt
Last active May 27, 2022 00:49
phpcs config-set for Drupal using Coder module
# Basic default configs.
phpcs --config-set installed_paths ~/.composer/vendor/drupal/coder/coder_sniffer
phpcs --config-set default_standard Drupal
phpcs --config-set colors 1
# Show all errors.
phpcs --config-set error-severity 1
# Shows warnings, but doesn't return a non-zero return.
phpcs --config-set ignore_warnings_on_exit 1

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