Skip to content

Instantly share code, notes, and snippets.

@petebarnett
petebarnett / sam.js
Created September 6, 2021 16:04
Implementation of State-Action-Model pattern
class Machine {
constructor(spec) {
this.acceptors = spec.acceptors;
this.actions = spec.actions;
this.sr = spec.state;
this.model = spec.model;
}
@petebarnett
petebarnett / keybase.md
Created October 27, 2020 16:20
Keybase Proof

Keybase proof

I hereby claim:

  • I am petebarnett on github.
  • I am petebarnett (https://keybase.io/petebarnett) on keybase.
  • I have a public key whose fingerprint is D838 25D0 BB56 0E4C B7E9 DEB2 F5AA 5CD6 E467 8BC2

To claim this, I am signing this object:

@petebarnett
petebarnett / FieldTypePluginExample.php
Created September 27, 2016 14:54
DrupalCon Dumb Storage of Typed Data
<?php
namespace Drupal\yourmodule\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\zuora\Plugin\DataType\Account;
use Drupal\zuora\TypedData\Definition\AccountDefinition;
<?php
$referenced_files = $node->get('your_field')->referencedEntities();
$vars['download_article'] = file_create_url($referenced_files[0]->uri->value);
<?php
try {
new RecursiveArrayIterator(NULL);
}
catch(Exception $e) {
print $e->getMessage();
}
// prints "Passed variable is not an array or object, using empty array instead"
id: the_content
label: Your Content Migration
migration_group: whatever_you_call_this_group
source:
plugin: your_content_source
destination:
plugin: entity:your_content_type
process:
destination:
plugin: entity:your_custom_entity_type
process:
type:
plugin: default_value
default_value: your_bundle
(function($) {
var beforeSend = Drupal.ajax.prototype.beforeSend;
Drupal.ajax.prototype.beforeSend = function(xmlhttprequest, options) {
// Do your thing here...
// And call the original
beforeSend.call(this, xmlhttprequest, options);
}
class Test {
function getSomething($something) {
return $something;
}
}
$blah = new Test();
<?php
/**
* Implements hook_theme().
*/
function ds_extras_tokens_theme() {
// Declare our own theme hook, to add to the
// theme_hook_suggestions for 'field'
return array(