Skip to content

Instantly share code, notes, and snippets.

View Unifex's full-sized avatar

Gold Unifex

  • Ackama
  • Wellington, New Zealand
View GitHub Profile
@Unifex
Unifex / index.php
Created March 18, 2019 21:40
This file provides a practical test of using Chrome PHP and PHPUnite to create a PDF of multiple pages from the web.
<?php
/**
* @file
* A test of using Headless Chrome and the Linux CLI tool phpunite.
*
* Save this file to a directory.
* Run `composer require chrome-php/chrome` in the same directory
* If you are using Chromium run `export CHROME_PATH=chromium-browser`
* Run `php -S localhost:8080` to start a local server.
@Unifex
Unifex / NoOp.php
Created July 16, 2018 02:37
A Drupal 8 Migrate destination plugin that does nothing.
<?php
namespace Drupal\migrate_nbr\Plugin\migrate\destination;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Plugin\migrate\destination\DestinationBase;
use Drupal\migrate\Row;
/**
* Provides noop destination plugin.
@Unifex
Unifex / ValueFromCsv.php
Created June 18, 2018 21:23
A Drupal 8 migration process plugin to to allow for fetching data from a CSV.
<?php
namespace Drupal\migrate_custom\Plugin\migrate\process;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
/**
* Load a CSV and return a col for a specific row.
@Unifex
Unifex / SkipOn404.php
Last active June 18, 2018 22:39
For... reasons I was working with bad data and a migration into Drupal 8 had me in a situation where I couldn't trust that the source file URL was actually present. The following is a migration process plugin that will check the URL and skip the row if it is a 404.
<?php
namespace Drupal\migrate_custom\Plugin\migrate\process;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate\Row;
use Drupal\Component\Utility\UrlHelper;

Keybase proof

I hereby claim:

  • I am unifex on github.
  • I am unifex (https://keybase.io/unifex) on keybase.
  • I have a public key ASAT2XEazm64eApeq4pw3XtJTPu3s1ntfw-KrBT1P7YIugo

To claim this, I am signing this object:

@Unifex
Unifex / template.php
Created August 17, 2016 00:55
Drupal 7: Find when a node is first published. This uses workbench moderation.
<?php
/**
* Implements hook_preprocess_node().
*/
function my_module_preprocess_node(&$variables) {
$node = $variables['node'];
// First published.
// This query uses workbench moderation to determine the first moderation
// transition that resulted in a published node and takes the timestamp
// from that record.
@Unifex
Unifex / gist:bd5f650b604d3695e94746be62b6e3aa
Created June 1, 2016 22:08
I do a lot of prototyping on the command line with drush. This allowed me to test switching content types. It's very bare bones but it's a good place to start.
drush ev '
$query = new EntityFieldQuery;
print_r($query);
$result = $query->entityCondition("entity_type", "node")
->propertyCondition("type", "morning_message")
->execute();
print_r($result);
foreach ($result['node'] as $row) {
print_r($row);
$node = node_load($row->nid);
@Unifex
Unifex / gist:7db225da0cb406b3d9b00c70b44b5103
Last active May 31, 2016 22:38
Drupal 7 has a reasonably messed up way of handling menus and I was unable to find a simple way of saying "starting here give me 2 levels of menu." This does that for you. It returns an array of menu items. If you've set depth to anything greater than 0 it will append these and an array to the `children` key. No authentication or validation is p…
/**
* Helper funtion to get an array of menu items and children.
*
* This returns an array of menu items with child menu items added to the
* 'children' key.
*
* @param int $mlid
* The menu link ID we are looking at.
* @param int $depth
* How deep do you want to go?
@Unifex
Unifex / Homoeopathy for induction of labour.md
Created October 14, 2015 22:45
A response to @homeopathynatho about checking Cochrane for support for homeopathy
@Unifex
Unifex / Homeopathic medicines for adverse effects of cancer treatments.md
Created October 14, 2015 22:43
A response to @homeopathynatho about checking Cochrane for support for homeopathy

Response to homeopathynatho

This review looked at whether these [homeopathic] medicines could help patients with problems caused by cancer treatments […] Two studies with low risk of bias demonstrated benefit: one with 254 participants demonstrated benefits from calendula ointment in the prevention of radiotherapy-induced dermatitis, and another with 32 participants demonstrated benefits from Traumeel S (a complex homeopathic medicine) […] These trials need replicating. Two other studies reported positive results, although the risk of bias was unclear, and four further studies reported negative results. […].