Skip to content

Instantly share code, notes, and snippets.

View DavidHernandez's full-sized avatar
📎

David Hernández DavidHernandez

📎
View GitHub Profile
@DavidHernandez
DavidHernandez / ServiceContainer.php
Last active October 7, 2015 09:27
20 lines service container
<?php
Class ServiceContainer {
public $services;
private $container;
public static function get($service) {
$container = ServiceContainer::getContainer();
return $container->services[$service];
@DavidHernandez
DavidHernandez / import-files.php
Created July 14, 2015 11:27
Save a remote file into local storage and add it to a file field
<?php
$file = system_retrieve_file($remote_file_url);
$node->field_image[$node->language][] = (array) $file;
node_save($node);
@DavidHernandez
DavidHernandez / instant_buy.module
Last active August 29, 2015 14:19
Drupal Commerce instant buy link
<?php
/**
* @file
*
* This super small module adds a page that creates an order with a product
* and redirects to the payment platform.
*
* It can be used as sample or base for simple commerce workflows. It
* doesn't need to be a menu item, can be done in a form submit callback.
@DavidHernandez
DavidHernandez / singleton.php
Created January 16, 2015 10:15
Maybe another singleton implementation
<?php
/**
* @file
* Contains Singleton.
*/
/**
* Singleton that gets saved into a global variable.
*/
@DavidHernandez
DavidHernandez / color-progress.php
Created January 5, 2015 13:38
This little PHP script helps you when you need to get all the colors between two specific colors. It's usefull if you need to create a progress bar, that changes its color.
#!/usr/bin/php
<?php
/**
* This script receives two colors and the number of steps
* of the progress and returns the different color for each
* step.
*/
@DavidHernandez
DavidHernandez / tmux-project.sh
Created December 19, 2014 10:40
Start the my drupal dev environment
#!/bin/sh
PROJECT = $1
tmux new-session -d -s $PROJECT
tmux new-window -t $PROJECT:1 -n 'Logs' ;
tmux split-window -h ;
tmux select-pane -L
tmux send-keys -t $PROJECT:1 'sudo tail -f /var/log/apache2/error.log' C-m
@DavidHernandez
DavidHernandez / gist:859cbacdce8f2e892b67
Created November 28, 2014 12:45
render a node with comments when the $node item is not available in the path
<?php
/**
* If you want to emulate the node/%node page in a page without the $node in the path
* you can just call the same page callback as that url: node_page_view($node);
*/
$node = node_load($nid);
return node_page_view($node);
@DavidHernandez
DavidHernandez / fix_permissions.sh
Created November 13, 2014 13:14
Fix Drupal permissions
// Replace [data] with correct data.
sudo chown [user]:www-data [buildpath] -R
sudo chmod u-x,g-x [buildpath] -R
sudo chmod u=rwX,g=rX,o= [buildpath] -R
sudo chmod 2770 [files]
sudo chown www-data:www-data [files] -R
sudo chmod u=rwX,g=rwX,o= [files] -R