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 / 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"
@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 / 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
#!/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 / 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.

@jnous
jnous / prepare-commit-msg
Created April 18, 2016 10:37
Version 2 of commit message prepending hook.
#!/bin/bash
# Save as .git/hooks/prepare-commit-msg (or if one exists, append to it)
# and execute `chmod a+x .git/hooks/prepare-commit-msg`
# This way you can customize which branches should be skipped when
# prepending commit message.
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=( master )
fi
<?php
/**
* @file
* Local development override configuration feature.
*
* To activate this feature, copy and rename it such that its path plus
* filename is 'sites/example.com/settings.local.php', where example.com
* is the name of your site. Then, go to the bottom of
* 'sites/example.com/settings.php' and uncomment the commented lines that
@jnous
jnous / README.md
Last active February 9, 2016 08:06
Responsive SVG (for D3 charts)
@jnous
jnous / SassMeister-input-HTML.html
Created January 11, 2016 14:46
Generated by SassMeister.com.
<div class="supercontainer">
<div class="container">
</div>
</div>
<div class="hidden">
<div id="bg-element" class="element">
Lorem ipsum dolor sit amet
</div>
</div>
@jnous
jnous / d8-language-switcher-to-front.php
Last active December 2, 2015 08:16
Drupal 8 implementation of hook_language_switch_links_alter that replaces links in language switcher block with links to front page.
<?php
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Url;
/**
* Implements hook_language_switch_links_alter().
*
* Replaces links in language switcher block with links to front page.
*/