Skip to content

Instantly share code, notes, and snippets.

View svetlio's full-sized avatar

Svetoslav Stoyanov svetlio

View GitHub Profile
@svetlio
svetlio / SA-CORE-2013-003.nginx
Last active August 12, 2018 09:35
SA-CORE-2013-003 for nginx
# add on active server block
location ~* /(files|files-private|tmp)/.*\.php$ {
deny all;
}
@svetlio
svetlio / SerializerCount.php
Last active February 12, 2020 22:13
Drupal 8 views rest with pager data
<?php
// thanks Dan - http://www.mediacurrent.com/blog/eight-insights-and-useful-snippets-d8-rest-module
/** @file
* Contains \Drupal\views_ext\Plugin\views\style\SerializerCount.
*/
namespace Drupal\views_ext\Plugin\views\style;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableDependencyInterface;
@svetlio
svetlio / no-dbl-click-mat.directive.ts
Last active April 7, 2023 09:48
Angular 5 directive - Prevent double click for html button (no-dbl-click.directive.ts), and material mat-button (no-dbl-click-mat.directive.ts)
import { Directive, HostListener } from '@angular/core';
@Directive({
selector: '[appNoDblClickMat]'
})
export class NoDblClickDirectiveMat {
constructor() { }
@HostListener('click', ['$event'])
@svetlio
svetlio / ngx-datatable-html-select-update-value.ts
Created March 13, 2018 15:21
ngx-datatable html select update value
/**
* Update select list (html select)
*/
updateValueList(event, cell, rowIndex, row) {
var data = {
//"nid": [{"value": row.nid}],
"type":[{"target_id":"request_material"}],
"field_req_material_state": [{"value": event.target.value}]
};
@svetlio
svetlio / 50-cloud-init.yaml
Last active January 3, 2021 01:42
Netplan config bridge - ubuntu-server-18.04, and ex. default lxd profile
# located at /etc/netplan/
# $ sudo netplan apply
network:
version: 2
renderer: networkd
ethernets:
enp5s0f0:
dhcp4: false
bridges:
br0:
@svetlio
svetlio / post-receive
Created August 9, 2018 15:33
git push to prepopulate code in webdir
#!/bin/bash
while read oldrev newrev ref
do
branch=`echo $ref | cut -d/ -f3`
if [[ "master" == "$branch" ]]; then
git --work-tree=/var/www/vhosts/bms2/ checkout -f $branch
echo 'Changes pushed master to bms2'
@svetlio
svetlio / FileIdFieldFormatter.php
Created September 8, 2018 07:27
Drupal 8 FieldFormatter for file and image. Output file/image ID. Usable for rest in views. ($ drupal generate:plugin:fieldformatter)
<?php
/**
* @file FileIdFieldFormatter.php
*
* field formatter id for file and image
*
*/
namespace Drupal\custom_fs\Plugin\Field\FieldFormatter;
@svetlio
svetlio / CustomLoginResource.php
Last active November 9, 2018 09:07
Drupal 8 rest custom login resource, return session data to build cookie in frontend, missing csrf (can be obtained at /rest/session/token). !!! This is a POST resource, so '$ drush cr', enable resource, and add a permission for anonymous role.
<?php
namespace Drupal\exp_fs\Plugin\rest\resource;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\rest\ModifiedResourceResponse;
use Drupal\rest\Plugin\ResourceBase;
use Drupal\rest\ResourceResponse;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
$view = new view();
$view->name = 'files';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'file_managed';
$view->human_name = 'Files';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
@svetlio
svetlio / ManageVocabulariesController.php
Created January 16, 2019 13:16
Manage vocabularies page to show vocabularies translation in other languages too.
<?php
namespace Drupal\tools_ext\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\language\ConfigurableLanguageManagerInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;