Skip to content

Instantly share code, notes, and snippets.

View delphian's full-sized avatar

Bryan Hazelbaker delphian

  • Hesperia, CA
View GitHub Profile
@delphian
delphian / touch-all-fids.php
Last active December 29, 2015 02:48
When working on a drupal site on localhost instead of production often there are no files in the localhost files directory. This script will create (touch) empty filenames that match all files managed by the drupal database.
<?php
/**
* @file
* When working on a drupal site on localhost instead of production often
* there are no files in the localhost files directory. This script will
* create (touch) empty filenames that match all files managed by the
* drupal database. In a multi-site environment this script should be
* located in the drupal root.
*
@delphian
delphian / drush-flush-memcache.sh
Created September 16, 2013 17:12
Manually flush memcache from the drush command prompt
# Copy this into your command prompt to manually flush memcache.
# Replace localhost.com with the domain name of the drupal site.
drush ev "dmemcache_flush()" --uri="localhost.com"
@delphian
delphian / intellij-xdebug-virtual-machine.txt
Created September 7, 2013 01:52
Configure Intellij to debug php scripts running on a virtual machine using xdebug
# Configure intellij by adding new PHP Server
IntelliJ IDEA -> Preferences -> PHP -> Servers
# Configure Intellij by adding new Run/Debug Configuration
Add new 'PHP Web Application' and select the server name created above.
# Run from host to forward 9000 out of virtual machine back to host listener.
ssh -p 2222 vagrant@127.0.0.1 -R 9000:localhost:9000
# Edit xdebug configuration in virtual machine
@delphian
delphian / drupal-xdebug-exception-stack-trace.patch
Created September 6, 2013 20:07
Override Drupal's default exception handler so XDebug can provide us the stack trace.
// Comment out this following line in bootstrap.inc
set_exception_handler('_drupal_exception_handler');
@delphian
delphian / bootstrap-drupal.php
Created September 5, 2013 23:47
Bootstrap Drupal multi-site for custom php script
<?php
// Needed for multisite bootstrap.
$_SERVER['HTTP_HOST'] = 'domainname.org';
// Name of this script. Include forward slash.
$_SERVER['SCRIPT_NAME'] = '/' . 'bootstrap-drupal.php';
// Set this to avoid php warnings.
$_SERVER['REMOTE_ADDR'] = '';
define('DRUPAL_ROOT', '/Absolute/path/domainname.org');
@delphian
delphian / drupal-remove-duplicate.sh
Last active April 29, 2016 23:12
Remove all duplicate files in the current directory that are not managed by drupal.
#!/bin/bash
#
# Remove all duplicate files in current directory that are not present
# in Drupal's managed file table. If a backup directory exists then the
# files will be moved into that directory instead of being deleted.
#
#
# Determine if a file is manged by drupal. Drush is required.
@delphian
delphian / mink-step-helper-elementhascssvalue.php
Created August 17, 2013 05:01
Determine if a Mink NodeElement contains a specific css rule attribute value.
/**
* Determine if a Mink NodeElement contains a specific css rule attribute value.
*
* @param NodeElement $element
* NodeElement previously selected with $this->getSession()->getPage()->find().
* @param string $rule
* Name of the CSS rule, such as "visibility".
* @param string $value
* Value of the specified rule, such as "hidden".
*
@delphian
delphian / mink-step-helper-elementselectfirst.php
Created August 17, 2013 04:55
Returns the first element found from Mink's NodeElement::findAll() request.
/**
* Select the first CSS element returned by findAll query.
*
* @param string $selector.
* CSS selector.
*
* @return NodeElement
* Or throws error if unable to locate.
*/
protected function elementSelectFirst($selector)
@delphian
delphian / mink-nodeelement-mouseover-replacement.php
Created August 17, 2013 04:15
A replacement for mink's NodeElement mouseOver method. Occationally the mouseOver method will not cause the desired effect (such as when custom javascript is watching for a change of rate in the mouse location before popping up a menu item).
/**
* More reliable way to hover over an element. Talk to selenium directly.
*
* @param string $selector
* CSS selector.
* @param int $sleep
* Number of seconds to sleep after hover is initiated. Allows some
* slower third party javascript to do its thing before moving on
* with more test steps.
*
@delphian
delphian / drupal-7-example-local-settings.php
Created August 15, 2013 17:12
Example of drupal 7 local settings.php file.
<?php
// To set up a local environment, make a duplicate of this file and name it
// local-settings.inc in the site directory that contains the settings.php file.
// Ignore sites/*/local-settings.php in the .gitignore file. Change the settings.php
// file to include local-settings.php if the file exists.
// Point database to local service.
$databases['default']['default'] = array(
'database' => 'local_db_name',