Skip to content

Instantly share code, notes, and snippets.

View esolitos's full-sized avatar

Marlon (Esolitos) Saglia esolitos

View GitHub Profile
@esolitos
esolitos / MigrationClass.php
Created December 4, 2014 13:47
Migrate Add Field Collection
<?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
esolitos / index.php
Created December 4, 2014 23:17
Language redirect in php with javascript fallback.
<?php
if ( isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && strlen($_SERVER['HTTP_ACCEPT_LANGUAGE']) >= 2 )
{
$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';
}
# 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
esolitos / instructions.md
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
esolitos / Full Version
Created June 15, 2015 19:39
HDAccess Expand Poster Script
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
esolitos / Readme.md
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
esolitos / gist:4b7a9919454c7eccab2e
Created April 29, 2015 13:39
Enable XDebug on OS.X

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 "xdebug.so") >> $(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
esolitos / drush
Last active February 9, 2016 14:53
Drush Base Modules
# 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
esolitos / local.aliases.drushrc.php
Last active April 6, 2016 11:58
Drush Alias File for PROJECT.dev Folder Names within multisites
<?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
esolitos / check-server.sh
Last active June 26, 2016 10:17
Auto restart Mc server with mscs
#!/bin/sh
#
# Checks if a server is running, otherwise it restarts it
SERVER=$1
if [ -z "$SERVER" ]; then
echo "Server name not provided!" 1>&2
exit 1
fi