Skip to content

Instantly share code, notes, and snippets.

@dstorozhuk
dstorozhuk / TermReferenceBoost.php
Created Oct 1, 2020 — forked from schnippy/TermReferenceBoost.php
Drupal 8.x Search API processor plugin for boosting search items by term reference field
View TermReferenceBoost.php
<?php
// This plugin allows the administrator to boost items in an index based on a taxonomy term.
//
// Drop into an existing plugin module or create a new one, ex. create an info.yml file as
// modules/custom/search_api_boost_term_reference/search_api_boost_term_reference.info.yml
//
// name: 'Search API Boost by Term Reference'
// description: 'Define custom boost priority in Search API index by term reference field'
// core: 8.x
View smooth-scrolling-polyfill.md

The Scroll Behavior specification has been introduced as an extension of the Window interface to allow for the developer to opt in to native smooth scrolling. To date this has only been implemented in Chrome, Firefox and Opera.

There's a complete polyfill here (3.3KB minified). But most of the times, the following is enough for me (641 bytes minified):

smooth-scrolling-poyfill.js

Use as: scrollToElem('#elem-selector');

@dstorozhuk
dstorozhuk / import.php
Last active May 8, 2020 — forked from mikecrittenden/import.php
Importing Drupal 8 config programmatically
View import.php
<?php
// Import arbitrary config from a variable.
// Assumes $data has the data you want to import for this config.
$config = \Drupal::service('config.factory')->getEditable('filter.format.basic_html');
$config->setData($data)->save();
// Or, re-import the default config for a module or profile, etc.
\Drupal::service('config.installer')->installDefaultConfig('module', 'my_custom_module');
@dstorozhuk
dstorozhuk / IdentificationNumber.php
Created Jun 27, 2017
Расшифровка идентификационного номера (Украина) в PHP получение даты рождения и пола
View IdentificationNumber.php
function IdentificationNumber($number)
{
$result = array();
$result['number'] = $number;
$result['sex'] = (substr($number,8,1)%2) ? 'Мужчина' : 'Женщина';
$split = str_split($number);
$execute = $split[0]*(-1)+$split[1]*5+$split[2]*7+$split[3]*9+$split[4]*4+$split[5]*6+$split[6]*10+$split[7]*5+$split[8]*7;
$number = substr($number,0,5);
$date = date('d.m.Y',strtotime('01.01.1900 + '.$number.' days - 1 days'));
list($result['day'],$result['month'],$result['year']) = explode('.',$date);
View Install image magic
Installing PHP PECL IMagick on Ubuntu:
--------------------------------------
1. $ sudo aptitude install php-pear imagemagick php5-dev libmagick9-dev
2. $ sudo apt-get install libmagickwand-dev
3. $ sudo pecl install Imagick
4. $ sudo nano /etc/php5/apache2/php.ini
4. enter extension=imagick.so -> save (ctrl+x / Y)
6. $ sudo apache2ctl configtest
@dstorozhuk
dstorozhuk / CssServer.php
Created Feb 28, 2017
Extends the Leafo\ScssPhp\Server. Add source map. Part of Drupal 8 module.
View CssServer.php
<?php
/**
* Created by PhpStorm.
* User: dima
* Date: 11/12/16
* Time: 11:58 AM
*/
namespace Drupal\bootstrap_sass_helper;
View .bash_aliases
# Put this in ~/.bash_aliases
# `source ~/.bash_aliases` to activate
alias dcr='drush cr'
alias ddis='drush dis -y '
alias ddl='drush dl -y '
alias den='drush en -y '
alias dcex='drush csex -y'
alias dcim='drush csim -y'
alias ga='git add '
alias gb='git branch '