Skip to content

Instantly share code, notes, and snippets.

View ValeriiVasyliev's full-sized avatar
🏄
Focusing

Valerii Vasyliev ValeriiVasyliev

🏄
Focusing
View GitHub Profile
@ValeriiVasyliev
ValeriiVasyliev / max-difference-array-elements.php
Last active February 22, 2018 03:00
Highest/Maximum difference between two values in an array (HackerRank Task)
<?php
$a = [5, 10, 8, 7, 6, 5];
$size = sizeof($a)/sizeof($a[0]);
$max_diff = -1;
$min_element = $a[0];
for ($i=1; $i<$size; $i++) {
@ValeriiVasyliev
ValeriiVasyliev / array-remaining-sticks.php
Last active May 26, 2017 07:32
Remaining sticks element (HackerRank Task)
<?php
$lengths = [6, 5, 4, 4, 2, 2, 8];
$result = [];
while (true) {
$lengths = array_filter($lengths, function($a) { return ($a !== 0); });
@ValeriiVasyliev
ValeriiVasyliev / merge-arrays-sort.php
Last active May 26, 2017 07:31
Merge two arrays and sort (HackerRank Task)
<?php
$a = [4, 1, 5, 7, 7, 4, 0, 1, 2, 3];
$b = [5, 2, 4, 5, 9, 9, 5, 0, 1, 2, 3, 4];
$result = $a;
foreach ($b as $el) {
@ValeriiVasyliev
ValeriiVasyliev / drupal8-get-multisites-list.php
Last active May 26, 2017 07:31
Drupal 8. Get all multisites names
<?php
$multisites = [];
if (is_file(DRUPAL_ROOT . '/sites/sites.php')) {
include DRUPAL_ROOT . '/sites/sites.php';
$multisites = array_keys($sites);
$multisites[] = 'default';
@ValeriiVasyliev
ValeriiVasyliev / drupal-drush-commands.md
Last active May 18, 2021 08:11
Drupal. Drush commands

Uninstall module

drush pm-uninstall MODULE -y

Install module

drush pm-enable MODULE -y
@ValeriiVasyliev
ValeriiVasyliev / drupal8-get-list-installed-themes.php
Created May 26, 2017 09:47
Drupal 8. Get list installed themes
<?php
$themesList = array_keys( \Drupal::service('theme_handler')->listInfo() );
@ValeriiVasyliev
ValeriiVasyliev / drupal8-upload-file-permanent.php
Created May 26, 2017 16:05
Drupal 8. Upload file and set statuds permanent
<?php
$fid = $form_state->getValue('file');
if (isset($fid[0]) && $fid[0] > 0) {
$file = \Drupal\file\Entity\File::load($fid[0]);
$file->setPermanent();
$file->save();
@ValeriiVasyliev
ValeriiVasyliev / drupal8-set-programmatically-theme-default.php
Created May 28, 2017 12:08
Drupal 8. Set programmatically theme default
<?php
\Drupal::service('theme_installer')->install('my_custom_theme');
\Drupal::configFactory()
->getEditable('system.theme')
->set('default', 'my_custom_theme')
->save();
@ValeriiVasyliev
ValeriiVasyliev / drupal8-debug.md
Last active May 18, 2021 08:10
Drupal 8. Debug errors

Copy File

cp sites/example.settings.local.php sites/default/settings.local.php

Change settings

$config['system.logging']['error_level'] = 'verbose'; // hide|some|all|verbose

Print variable

@ValeriiVasyliev
ValeriiVasyliev / settings.local.php
Created May 29, 2017 16:24 — forked from scor/settings.local.php
Drupal 8. Settings local - development mode
<?php
/**
* @file
* Local development override configuration feature.
*
* To activate this feature, copy and rename it such that its path plus
* filename is 'sites/yoursite.com/settings.local.php'. Then, go to the bottom
* of 'sites/yoursite.com/settings.php' and uncomment the commented lines that
* mention 'settings.local.php'.