Skip to content

Instantly share code, notes, and snippets.

View keopx's full-sized avatar

Ruben Egiguren keopx

View GitHub Profile
@keopx
keopx / ImageStyleGenerator.php
Created September 1, 2017 11:31
Drupal 8 generate image style
<?php
/**
* Create images with timeline ImageStyle.
*/
protected function createImages() {
$style = ImageStyle::load('timeline');
$style_extra = ImageStyle::load('timeline_extra');
$nodes = $this->getNodes();
foreach ($nodes as $node) {
docker run -it -p 127.0.0.1:8983:8983 -t 36_web:latest bash
<?php
/*
+----------------------------------------------------------------------+
| APC |
+----------------------------------------------------------------------+
| Copyright (c) 2006-2011 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
{% block version -%}
vcl 4.0;
{% endblock %}
# This Varnish VCL has been adapted from the Four Kitchens VCL for Varnish 3.
# Default backend definition. Points to Apache, normally.
backend default {
{% block backend -%}
.host = "{{ varnish_default_backend_host }}";
@keopx
keopx / Concurrent_apache.sh
Last active July 7, 2017 08:44
Concurrent connections Apache
#!/bin/bash
# RAM consumed in MB per connection
ps -ylC apache2 --sort:rss | awk '{SUM += $8; I += 1} END {print SUM/I/1024}'
# System consumed in MB.
ps -N -ylC apache2 --sort:rss | awk '{SUM += $8} END {print SUM/1024}'
(RAMTOTAL – RAM_RESTOPROCESOS) / RAM_POR_CONEXIÓN
aptitude install optipng jpegoptim
optipng *.png
jpegoptim *.jpg
@keopx
keopx / drupal8_reinstall.sh
Last active April 25, 2017 17:18
Drupal 8 reinstall site script
#!/bin/bash
cd drupal
sudo rm -fr vendor
composer install
sudo chmod 777 sites/default
cd sites/default
rm -fr settings.php services.yml
# for developers only (sets up some dev mode settings, do this before install!)
cp ../example.settings.local.php ./settings.local.php
# for everyone
<?php
namespace Drupal\view_mode_page\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Routing\AccessAwareRouterInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\HttpKernelInterface;
@keopx
keopx / ReferencedEntityLoad.php
Created April 18, 2017 13:18
How to get instance of referenced entity - The path to referenced entity is very long
<?php
// $id = some node ID
// $field = field name for entity reference field
$node = Node::load($id);
/** @var \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem $referenceItem */
$referenceItem = $node->get($field)->first();
/** @var \Drupal\Core\Entity\Plugin\DataType\EntityReference $entityReference */
$entityReference = $referenceItem->get('entity');
@keopx
keopx / settings.cache.php
Created April 2, 2017 08:24
Drupal backend cache memcache OR redis.
<?php
# KO memcache: http://cgit.drupalcode.org/memcache/tree/README.txt?h=8.x-2.x
//$settings['memcache']['servers'] = ['memcached:11211' => 'default'];
//$settings['memcache']['bins'] = ['default' => 'default'];
//$settings['memcache']['key_prefix'] = '';
/**
* Memcache Configuration.
*/
/*