Skip to content

Instantly share code, notes, and snippets.

function array_merge_recursive_ex(array & $array1, array & $array2)
{
$merged = $array1;
foreach ($array2 as $key => & $value)
{
if (is_array($value) && isset($merged[$key]) && is_array($merged[$key]))
{
$merged[$key] = array_merge_recursive_ex($merged[$key], $value);
} else if (is_numeric($key))
@DavMorr
DavMorr / gen-d8-salt.sh
Created July 25, 2017 22:44 — forked from pfaocle/gen-d8-salt.sh
Generate Drupal 8 hash salt
drush eval "var_dump(Drupal\Component\Utility\Crypt::randomBytesBase64(55))"
@DavMorr
DavMorr / gist:5b435050faea108f76b7e1ac845c27e0
Last active September 8, 2017 11:51
Set all directories to 755, and all files to 644
If you need a quick way to reset your public_html data to 755 for directories and 644 for files, then you can use something like this:
cd /path/to/sites/site/docroot
find . -type d -exec chmod 0755 {} \;
find . -type f -exec chmod 0644 {} \;
additionally, if you know php runs as the user and not as "apache", then you can set php files to 600, for an extra level of security, eg:
find . -type f -name '*.php' -exec chmod 600 {} \;
@DavMorr
DavMorr / gist:53e3ad5c26d16f4f6be3220b078b19c9
Last active March 9, 2024 11:43
Include hidden files in tar archive
When you create a tar archive of a directory tree the hidden files are normally not included. Here’s how to include the hidden files.
Say you have a web directory called “/var/www/html/mysite/” that contains the following tree:
.htaccess
index.php
logo.jpg
style.css
admin_dir/.htaccess
admin_dir/includes.php
@DavMorr
DavMorr / git_branch_and_track__notes.md
Last active March 10, 2018 17:20
git checkout --track [remotename]/[branch] // shorthand for 'git checkout -b [branch] [remotename]/[branch]'

You need to create a local branch that tracks a remote branch. The following command will create a local branch named daves_branch, tracking the remote branch origin/daves_branch. When you push your changes the remote branch will be updated.

For most versions of git:

git checkout --track origin/daves_branch --track is shorthand for git checkout -b [branch] [remotename]/[branch] where [remotename] is origin in this case and [branch] is twice the same, daves_branch in this case.

For git 1.5.6.5 you needed this:

git checkout --track -b daves_branch origin/daves_branch

Compiled from gist thread: https://gist.github.com/evanscottgray/8571828
##CONTAINERS
stop all containers:
docker stop $(docker ps -a -q)
--prefereable
docker kill $(docker ps -q)
--brute force
remove all containers
@DavMorr
DavMorr / Linux - display version of OS running.md
Last active February 18, 2018 22:05
Displays the current version of Linux OS running on machine, useful for quickly checking VM or Docker image.

Get Linux make, version and other info (same as cat /etc/os-release but with broader scope):

$ cat /etc/*release*
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
@DavMorr
DavMorr / PHP Code Tools - Install on OS X.md
Last active February 23, 2018 20:40
Installation instructions for some command line code review tools on Mac

CodeSniffer

via Composer (Drupal specific):

composer global require drupal/coder
composer global show -P  # should be equivalent to ~/.composer/vendor/drupal/coder
# Register Coder Standards: Drupal and DrupalPractice
composer global require drupal/coder:^8.2.12
composer global require dealerdirect/phpcodesniffer-composer-installer
# Review standards
@DavMorr
DavMorr / sed-to-strip-uuid-from-yaml-config-files--osx.md
Last active March 5, 2024 13:23
Drupal 8 - use sed to strip uuid line from exported config files

[Drupal 8] use sed (on OSX) to strip the uuid line from exported config files being used for module default configuration; i.e. [module_name]/config/optional|install

NOTE: this can also by bypassed in the export by using Drupal Cnnsole and including the --remove-uuid flag. Also using the --remove-config-hash flag can help prevent additional headaches.

Ex: drupal config:export --directory=”[full-path-to-location]” --tar --remove-uuid --remove-config-hash

The UUID should never be included when using when using these exported config yaml files as the default configuration pagaged with a custom module. This is suppoedly not to be a thing in the exported yaml files at some point, but until then stripping the uuid line out is a manual process which can be a pain as there can be a lot of files.

To automate this, run the following sed command in the directory containing the yaml files:

@DavMorr
DavMorr / behat.yml
Created March 7, 2018 18:58
Composer does not create the top level behat.yml file when installing behat on OS X. This is out of the box for behat ~3.0 for drupal 8.
default:
suites:
default:
contexts:
- FeatureContext
- Drupal\DrupalExtension\Context\DrupalContext
- Drupal\DrupalExtension\Context\MinkContext
- Drupal\DrupalExtension\Context\MessageContext
- Drupal\DrupalExtension\Context\DrushContext
extensions: