Skip to content

Instantly share code, notes, and snippets.

View twfahey1's full-sized avatar

Tyler Fahey twfahey1

View GitHub Profile
@twfahey1
twfahey1 / settings.local.php
Created November 9, 2018 16:13
Lando local settings
<?php
/**
* @file
* Local settings.
*/
$lando_info = json_decode(getenv('LANDO_INFO'), TRUE);
$databases['default']['default'] = array(
@twfahey1
twfahey1 / convert-drupal-modules-to-composer.sh
Created September 26, 2019 14:49
Convert Drupal pre-composer project to Composer based
#!/bin/bash
### Convert a pre-Composer Drupal project to use Composer for contrib modules. ###
# This script can automate the process of taking a codebase previously managed via
# drush or otherwise non-composer, and add all the modules to the composer.json
# in the docroot, with the current version number. The script will get
# all modules and version numbers, and pass to composer for an update.
# This statement will be appended on as each module is found. We can add as
# many modules as are found to the statement, so that composer can fire
@twfahey1
twfahey1 / .htaccess
Created October 11, 2019 00:32
A .htaccess file for Apache based server to run Drupal in web docroot
# Assuming the Drupal site is installed in /public_html/web, place this in the /public_html folder.
RewriteEngine on
# <!-- Force HTTPS START -->
# If we receive a forwarded http request from a proxy...
RewriteCond %{HTTP:X-Forwarded-Proto} =http [OR]
# ...or just a plain old http request directly from the client
RewriteCond %{HTTP:X-Forwarded-Proto} =""
@twfahey1
twfahey1 / phpunit.xml
Created October 11, 2019 00:34
Docksal PHPUnit file for web docroot Drupal 8
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="/var/www/web/core/tests/bootstrap.php" colors="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutChangesToGlobalState="true"
printerClass="\Drupal\Tests\Listeners\HtmlOutputPrinter">
<php>
<!-- Set error reporting to E_ALL. -->
<ini name="error_reporting" value="32767"/>
<!-- Do not limit the amount of memory tests take to run. -->
@twfahey1
twfahey1 / run-testbot.sh
Created October 11, 2019 00:40
Run a Drupal 8 PHPUnit test via TestBot method
php core/scripts/run-tests.sh PHPUnit --dburl mysql://root:pass@127.0.0.1:3306/mysitedatabase --url https://mysite.local/ --module mymodule
@twfahey1
twfahey1 / function.php
Last active November 18, 2019 16:03
Wordpress - Manipulate headers programmatically in plugin / theme
function add_header_auth( $headers ) {
if ( ! is_admin() ) {
$headers['X-Frame-Options'] = 'SAMEORIGIN';
}
return $headers;
}
add_filter( 'wp_headers', 'add_header_auth' );
@twfahey1
twfahey1 / README.md
Last active December 17, 2019 18:41
Check table size in mb
In this example using the bookstore database, 
we’re combining the DATA_LENGTH and INDEX_LENGTH as bytes, 
then dividing it by 1024 twice to convert into kilobytes and then megabytes.
@twfahey1
twfahey1 / puppeteer-script.js
Created January 9, 2020 02:04
Dump contents of page in puppeteer - node JS
let bodyHTML = await page.evaluate(() => document.body.innerHTML);
console.log(bodyHTML);
@twfahey1
twfahey1 / wp-config.php
Created January 17, 2020 15:53
Enforce https only for certain URLs in Wordpress wp-config
$urls_that_should_be_http = [
'/zonedata/manifest.txt',
'/zonedata/tzone_npanxx.unl',
'/zonedata/new_tzones.full.unl',
'/zonedata/tzone_tollfree.unl',
'/zonedata/tzrules.unl',
'/hello-world/',
];
@twfahey1
twfahey1 / some_module.install
Created February 5, 2020 18:53
Install hook to update database with entity definitions - Drupal 8
<?php
/**
* Update 8001 - Create foobar entity.
*/
function aws_bucket_fs_update_8001() {
//check if the table exists first. If not, then create the entity.
if(!db_table_exists('foobar')) {
\Drupal::entityTypeManager()->clearCachedDefinitions();
\Drupal::entityDefinitionUpdateManager()