Skip to content

Instantly share code, notes, and snippets.

View jnous's full-sized avatar

Jari Nousiainen jnous

  • Siili Solutions Oyj
  • Helsinki, Finland
  • X @jnous
View GitHub Profile
@jnous
jnous / trim-regex.md
Last active May 26, 2016 13:53
Regular expression to trim text to either period or 120 characters (cut at word boundary), whichever comes first.

search: /[\W]*^([^.]{0,120}[.\s]{1})[\w\W]*/

Use just $1 as replacement to print only the match.

#!/usr/bin/env bash
# For Drupal 8 configuration management.
# Strips UUIDs out of configuration YAMLs so that they can be used on any site.
# First parameter should be the directory in which to look for the files.
for f in $(find "${1}" -type f)
do
if [[ $(basename "${f}") != "system.site.yml" ]]
then
perl -pi -e '$_ = "" if ( $. == 1 && $_ =~ /^uuid.*$/ );' "${f}"
@jnous
jnous / policy.drush.inc
Created August 30, 2017 13:57
Prevents running harmful Drush commands when managing site installation with Composer
<?php
/*
* Customize this file as desired. See https://github.com/drush-ops/drush/blob/8.x/examples/policy.drush.inc for documentation.
*/
/**
* Implements drush_hook_COMMAND_validate().
*
* Encourage folks to use `composer` instead of Drush pm commands
@jnous
jnous / reset-schema.php
Created December 10, 2018 20:40
D8 reset module database schema version
<?php
\Drupal::keyValue('system.schema')->set('moduleName', (int) 8000);
@jnous
jnous / install-phpcs-hook.sh
Created March 16, 2021 07:36
A Git hook for running PHPCS on pre-commit, and a script for installing it. Place them in the same directory inside your project.
#!/usr/bin/env bash
set -e
set -o nounset
set -o pipefail
project_root=$(git rev-parse --show-toplevel)
scripts_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
hooksdir="${project_root}/.git/hooks"