Skip to content

Instantly share code, notes, and snippets.

View lolandese's full-sized avatar
💭
My public code is on Drupal.org and Backdrop CMS

Martin Postma lolandese

💭
My public code is on Drupal.org and Backdrop CMS
View GitHub Profile
@lolandese
lolandese / unindent.php
Last active October 1, 2019 15:14
Removes excessive indenting that consist of spaces or tabs
<?php
$str = " This is a test
string spanning
multiple lines.
It contains three
sentences, each are
split on three lines.
The indentation decides
which lines belongs
to which sentence.";
@lolandese
lolandese / YamlSnippet2Array.php
Last active September 19, 2019 08:14
Convert a Drupal YAML snippet to an array as a working PHP code snippet to write its values to the database. This is code to generate code. Short URL: https://git.io/Jem8t
<?php
/**
* @file
* Convert YAML snippet to PHP code snippet to write its values to database.
*/
use Drupal\Component\Serialization\Yaml;
// Replace the input below with any part of a valid YAML snippet.
@lolandese
lolandese / Yaml2Array.php
Last active January 14, 2022 13:36
Convert a Drupal YAML configuration file to an array as a working PHP code snippet to write its values to the database. This is code to generate code. Short URL: https://git.io/fjjDu
<?php
/**
* @file
* Convert a YAML file to PHP code to write its values to the database.
*/
use Drupal\Component\Serialization\Yaml;
// Replace 'filter.format.full_html' with any other existing configuration
@lolandese
lolandese / languages-drupal.json
Last active September 6, 2019 18:04
Drupal languages
{"af":["Afrikaans","Afrikaans"],"am":["Amharic","\u12a0\u121b\u122d\u129b"],"ar":["Arabic","\u0627\u0644\u0639\u0631\u0628\u064a\u0629","rtl"],"ast":["Asturian","Asturianu"],"az":["Azerbaijani","Az\u0259rbaycanca"],"be":["Belarusian","\u0411\u0435\u043b\u0430\u0440\u0443\u0441\u043a\u0430\u044f"],"bg":["Bulgarian","\u0411\u044a\u043b\u0433\u0430\u0440\u0441\u043a\u0438"],"bn":["Bengali","\u09ac\u09be\u0982\u09b2\u09be"],"bo":["Tibetan","\u0f56\u0f7c\u0f51\u0f0b\u0f66\u0f90\u0f51\u0f0b"],"bs":["Bosnian","Bosanski"],"ca":["Catalan","Catal\u00e0"],"cs":["Czech","\u010ce\u0161tina"],"cy":["Welsh","Cymraeg"],"da":["Danish","Dansk"],"de":["German","Deutsch"],"dz":["Dzongkha","\u0f62\u0fab\u0f7c\u0f44\u0f0b\u0f41"],"el":["Greek","\u0395\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac"],"en":["English","English"],"en-x-simple":["Simple English","Simple English"],"eo":["Esperanto","Esperanto"],"es":["Spanish","Espa\u00f1ol"],"et":["Estonian","Eesti"],"eu":["Basque","Euskera"],"fa":["Persian, Farsi","\u0641\u0627\u0631\u0633
@lolandese
lolandese / Drupal git pre-commit hook.md
Last active October 16, 2019 09:00 — forked from skwashd/README.md
Drupal git pre-commit hook

Referrer: https://www.drupal.org/docs/develop/local-server-setup/linux-development-environments/set-up-a-local-development-drupal#githooks

This pre-commit hook is designed to be used for Drupal 7 and 8 sites.

Download the pre-commit file. Save it as .git/hook/pre-commit in your git repo. You need to ensure that the file is executable.

If you want this to be added to all new projects automatically, add it to your git init templates.

To install and PHP CodeSniffer for Drupal, please read the official documentation.

@lolandese
lolandese / GS_sort_in_menu.js
Last active May 24, 2018 13:36
Google Sheets script to sort on two columns as a menu option.
// Merge related issues: Try selecting all cells, then click Format > Merge cells > Unmerge
function onOpen(e) {
var menu = SpreadsheetApp.getUi().createMenu('Sort');
if (e && e.authMode == ScriptApp.AuthMode.NONE) {
// Add a normal menu item (works in all authorization modes).
menu.addItem('Sort Sheet', 'sort');
} else {
// Add a menu item based on properties (doesn't work in AuthMode.NONE).
var properties = PropertiesService.getDocumentProperties();
var workflowStarted = properties.getProperty('workflowStarted');
@lolandese
lolandese / GS-timestamp-counter.js
Last active May 24, 2018 13:36
Google Sheets script to keep a 'Modified' timestamp and a counter (serial) column.
function onEdit() {
// Set some 'global' variables.
var sheet = SpreadsheetApp.getActiveSheet();
var cell = sheet.getActiveCell();
var row = cell.getRow();
// Create a timestamp in column 'C' with user ID (first 6 characters of mail address) when a row gets modified.
if( cell.getRow() != 1 ) { // Don't process the header row.
var user = Session.getActiveUser().getEmail();
var date = Utilities.formatDate(new Date(), "GMT+2", "yyyy.MM.dd");