Skip to content

Instantly share code, notes, and snippets.

@xandeadx
xandeadx / gist:5c9c0808c723fe9d2d78bd98fe322dd1
Last active November 14, 2021 08:20
Tampermonkey xDebug helper
// ==UserScript==
// @name xDebug helper
// @namespace http://xandeadx.ru/
// @version 0.1
// @author xandeadx
// @match http://*.local/*
// @grant none
// @require https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.2.0/js.cookie.js
// ==/UserScript==
$queue = \Drupal::queue('my_custom_queue');
$queue->deleteQueue();
$queue->createQueue();
timer_start();
for ($i = 0; $i < 10000; $i++) {
$queue->createItem([
'key' => 'value',
'nested' => [
'key' => 'value'
]
@xandeadx
xandeadx / README.md
Created February 16, 2021 00:51
Associate .sh files to Cygwin Bash
assoc .sh=ShellScript
ftype ShellScript="D:\Programs\Coding\Cygwin\bin\bash.exe" "%1" %*
@xandeadx
xandeadx / README.md
Last active February 16, 2021 04:21
Associate .sh files to Cygwin Bash in Windows Terminal
assoc .sh=ShellScript
ftype ShellScript=wt -p "Cygwin BASH" "D:\Programs\Coding\Cygwin\bin\bash.exe" "%1" %*

Cygwin BASH it's Windows Terminal profile name.

@xandeadx
xandeadx / gist:20e458dfe870fc850040d5a9fd6b6a33
Created September 10, 2020 13:19
Drupal Commerce 1 - copy fields values from product display to product
$products_displays = node_load_multiple([], ['type' => 'product_display']);
foreach ($products_displays as $product_display) {
$product_id = $product_display->field_product['und'][0]['product_id'];
$product = commerce_product_load($product_id);
foreach ($product_display as $product_display_field_name => $product_display_field_value) {
if (strpos($product_display_field_name, 'field_product_') === 0 && $product_display_field_value && isset($product->{$product_display_field_name})) {
$product->{$product_display_field_name} = $product_display_field_value;
}
}
@xandeadx
xandeadx / gist:6ca1b50235b93b4f9bbdfbbeaa7ccb33
Last active March 9, 2019 15:18
Total Commander open siblings directory
<?php
$directory = $argv[1] ?? '';
$direction = $argv[2] ?? '';
if (!$directory || !in_array($direction, ['prev', 'next'])) {
exit('Invalid parameters');
}
$directory = rtrim($directory, DIRECTORY_SEPARATOR);
@xandeadx
xandeadx / test.js
Created September 30, 2018 20:50
Drupal 7 autocomplete extra data
(function ($) {
Drupal.behaviors.test = {
attach: function (context, settings) {
$('input[data-autocomplete-extra-data-selector]', context).bind('autocompleteSelect', function (event) {
var $input = $(this);
var $targetElement = $($input.data('autocomplete-extra-data-selector'));
if ($targetElement.length) {
var matches = $input.val().match(/(.+) \[(.+)\]/);
$input.val(matches[1]);
$targetElement.val(matches[2]);
composer create-project drupal/drupal . --no-dev
composer require drupal/core --update-no-dev
class helper_handler_sort_mysort extends views_handler_sort {
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$relationships = $this->view->display_handler->get_option('relationships');
$relationship_options = array('none' => t('Do not use a relationship'));
foreach ($relationships as $relationship) {
$relationship_handler = views_get_handler($relationship['table'], $relationship['field'], 'relationship');
$relationship_handler->init($this->view, $relationship);