Skip to content

Instantly share code, notes, and snippets.


Marlon (Esolitos) Saglia esolitos

View GitHub Profile
esolitos / MigrationClass.php
Created December 4, 2014 13:47
Migrate Add Field Collection
View MigrationClass.php
* Attaches a (group) of field collections to an node entity
* @param stdClass $node_entity The loaded node object.
* @param array $field_collections the array of structures describing the entity collections
* keyed by the entity collection field name.
* @return void
public function attachFieldCollections(&$node_entity, $field_collections)
esolitos / index.php
Created December 4, 2014 23:17
Language redirect in php with javascript fallback.
View index.php
$allowLang = array('en', 'it', 'de', 'fr');
$base_url = $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
if ( !in_array($lang, $allowLang) ) {
$lang = 'en';
View gist:6d10d8532ad6678fa29d
# While inside a drupal site directory creates a SQL backup with the name of the site's directory and the current date.
drush sql-dump | gzip > ~/SQL-Backup/${PWD##*/}.$(date +%y%m%d).gz
# More advanced example:
# From the `drupal/sites` directory do a SQL backup of all the sites available
for dir in $(ls | egrep -v 'all|default'); do
if [ -d $dir ]; then
cd $dir
echo "Backup of site: $dir"
drush sql-dump | gzip > ~/SQL/${pwd##/}.$(date +%Y-%m-%d).gz
esolitos /
Last active August 29, 2015 14:17
Create SSL Certificate Authority and Device Certificates

Note: Since I believe that sudo it's evil (contact me fore more info about it) I'm not going to assume that all the commands are run as root, ese at your own risk. Remember, with great powers...

Generate CA Certificate

In this part we will egnerate the key and the certificate for the CA, that are going to be used asto issue the device certificates.

Step 0. Move in a secure location: #: mkdir /root/certs/CA && cd /root/certs/CA

Step 1. Gen. CA Key: #: openssl genrsa -des3 -out rootCA.key 2048

esolitos / Full Version
Created June 15, 2015 19:39
HDAccess Expand Poster Script
View Full Version
function findPosterLink(baseElement) {
if ( !baseElement ) {
return false;
// console.warn('findPosterLink');
var linkCells = baseElement.getElementsByClassName('torrents');
if ( linkCells.length ) {
var linkElem = linkCells[0].getElementsByTagName('a');
esolitos /
Last active August 29, 2015 14:26
Restore database from mysql ibdata1 file.

First run ./stream_parser as described in this article and the use the following script. Good luck, you need it.

esolitos / gist:4b7a9919454c7eccab2e
Created April 29, 2015 13:39
Enable XDebug on OS.X
View gist:4b7a9919454c7eccab2e

Each machine that has Apple's XCode installed has also XDebug, so we don't need to add it with pecl, brew, macports, or any similar package manager, simply add it to your php.ini file!

To simply do it, I give you this one-liner solution:

  sudo sh -c 'echo zend_extension=$(find /usr/lib/php/extensions -name "") >> $(php -qr "echo php_ini_loaded_file();") && apachectl restart'

If you're familiar with bash you probably have already understood, but if you need extra info about what's happening (and you should) there's the explaination:

esolitos / drush
Last active February 9, 2016 14:53
Drush Base Modules
View drush
# Disable default core modules that probably are not required (I suggest running also `drush pm-uninstall -y` on the same module list)
drush dis -y toolbar overlay color comment dashboard dblog help rdf
# Enable most used modules
drush en -y absolute_messages admin_views backup_migrate chosen ckeditor ckeditor_link save_edit module_filter page_manager field_ui image link field_collection entityreference email ds_ui date_views date_popup path pathauto globalredirect node navbar list options taxonomy features field_group media l10n_update date focal_point menu rules_admin strongarm views_ui jquery_update redirect transliteration ultimate_cron variable
# In case you are developing the site you can also enable those modules
drush en -y devel devel_contrib ds_devel metatag_devel performance
esolitos / local.aliases.drushrc.php
Last active April 6, 2016 11:58
Drush Alias File for Folder Names within multisites
View local.aliases.drushrc.php
$all = $platforms = array();
// Use standard linux 'PATH' style, so if you need more entries separate them using a column ':' char
// For example: '/path/to/platforms/container' OR '/path/to/platforms/container:/path/to/another/location'
// This dorectory will contain one or more drupal roots directories
$platforms_path = '/var/www/platforms';
$paths = explode(':', $platforms_path);
foreach($paths as $path) {
esolitos /
Last active June 26, 2016 10:17
Auto restart Mc server with mscs
# Checks if a server is running, otherwise it restarts it
if [ -z "$SERVER" ]; then
echo "Server name not provided!" 1>&2
exit 1