Skip to content

Instantly share code, notes, and snippets.

View DavidHernandez's full-sized avatar
📎

David Hernández DavidHernandez

📎
View GitHub Profile
@DavidHernandez
DavidHernandez / Sci-fi books
Last active January 25, 2016 15:12
David's Sci-Fi book collection
The moon is a harsh mistress - Robert A. Heinlein - 5*
A canticle for Leibowitz - Walter M. Miller 4*
Flowers for Algernon - Daniel Keyes 5*
The Forever War - Joe Haldeman - 4*
The Stars my destination (also known as Tiger! Tiger!) - Alfred Bester - 5*
The Road - Cormac Mc Carthy - 4*
God is Dead - Ron Currie Jr. - 4*
The world without us - Alan Weisman (not really sci fi, but interesting, anyways) - 4*
Animal Farm - George Orwell - 5*
1984 - George Orwell - 5*
@DavidHernandez
DavidHernandez / script
Created September 22, 2014 10:40
A little script to install some Drupal tables. It could be a drush command, but I'm feeling lazy...
<?php
// Module name
$module = '';
// List of tables to install
$tables = array('');
$schemas = drupal_get_schema_unprocessed($module);
foreach ($schemas as $key => $schema) {
@DavidHernandez
DavidHernandez / d7-autologin.php
Created October 16, 2014 17:19
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.
<?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
*
@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
@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 / 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 / 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 / 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 / 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 / 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);