Skip to content

Instantly share code, notes, and snippets.

Avatar
📎

David Hernández DavidHernandez

📎
View GitHub Profile
@DavidHernandez
DavidHernandez / ServiceContainer.php
Last active Oct 7, 2015
20 lines service container
View ServiceContainer.php
<?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 Jul 14, 2015
Save a remote file into local storage and add it to a file field
View import-files.php
<?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 Aug 29, 2015
Drupal Commerce instant buy link
View instant_buy.module
<?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 Jan 16, 2015
Maybe another singleton implementation
View singleton.php
<?php
/**
* @file
* Contains Singleton.
*/
/**
* Singleton that gets saved into a global variable.
*/
@DavidHernandez
DavidHernandez / color-progress.php
Created Jan 5, 2015
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.
View color-progress.php
#!/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 Dec 19, 2014
Start the my drupal dev environment
View tmux-project.sh
#!/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 Nov 28, 2014
render a node with comments when the $node item is not available in the path
View gist:859cbacdce8f2e892b67
<?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);
View fix_permissions.sh
// 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
@DavidHernandez
DavidHernandez / d7-autologin.php
Created Oct 16, 2014
This is another PoC for the SA-CORE-2014-005 vulnerability. Instead of updating the users table, activates an anonymous session to change your session into admin.
View d7-autologin.php
<?php
/**
* D7 autologin.
* Exploits SA-CORE-2014-005 to change your anonymous session into an uid 1 session.
* In order to work, first you need to have an anonymous session in the sessions table.
* One way to achieve this is to go to the update.php page.
*
* Usage: php d7-autologin.php http://example.com 127.0.0.1
*
You can’t perform that action at this time.