Skip to content

Instantly share code, notes, and snippets.

View chriscalip's full-sized avatar

Christopher Calip chriscalip

  • Chicago, IL
  • 06:08 (UTC -05:00)
View GitHub Profile
<?php
<?php
namespace Drupal\rl_migrates\Plugin\migrate\source;
use Drupal\migrate_drupal\Plugin\migrate\source\ContentEntity;
/**
* ContentEntity migration source that accepts multiple bundles.
<?php
namespace Drupal\rl_migrates\Plugin\migrate\source;
use Drupal\migrate_drupal\Plugin\migrate\source\ContentEntity;
/**
* ContentEntity migration source that accepts multiple bundles.
*
* This is a stop gap measure for:
<?php
namespace Drupal\xxx\Authentication\Provider;
use Drupal\Core\Authentication\AuthenticationProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Session\AccountProxyInterface;
/**
* Allow all authentication provider.
<?php
namespace Drupal\rl_migrates\Plugin\migrate\process;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Drupal\migrate\MigrateSkipRowException;
/**
@chriscalip
chriscalip / addressor-draft.php
Last active September 18, 2019 21:43
Proposed draft for an address parser through a conyever belt.
<?php
/**
* Description:
*
* Draft process of gaining stuctured address components (street,street2,city,state,zipcode,building) from a unstructured address string.
*
* Legend:
*
* Address String - unstructured address string. eg. "123 Main St, Chicago, IL, 60140", "123 Main Street Chicago Illinois 60640-1242", etc..
@chriscalip
chriscalip / gist:937531771c14434d41fed4f13d9facd8
Created August 21, 2019 20:26
utility for updating a node or entity's field value. useful for bulk operations
<?php
/**
* Utility function either updates/inserts an entity field values; useful for bulk update situations to avoid node-save.
*
* @param string $entity_type eg. node, taxonomy_term, etc..
* @param string $bundle eg. asset, etc..
* @param string $entity_id
* @param string $field field name
* @param array $field_values indexed by delta, then an array of components. [0 => ['value' => 'County Name']]
@chriscalip
chriscalip / cduxx_get_bulk_field_values.php
Created August 16, 2019 03:20
bulk data retrieval for drupal 8.
<?php
/**
* Utility get all field values
* @param string $entity_type Entity Type eg. (node,taxonomy)
* @param string $bundle Bundle (asset)
* @param string $field_name Field Name machine_name (field_asset_address)
* @param string $column_key $records keyed by column eg. (entity_id)
* @param array $columns Field columns eg. (value,uri,address_line1,locality)
@chriscalip
chriscalip / execute-migrate-via-repl.php
Created March 29, 2019 20:53
Execute a drupal 8 migration via REPL
$m = \Drupal::service('plugin.manager.migration');
$mi = $m->createInstance('migration_id');
$source = $mi->getSourceConfiguration();
$source['urls'][0] = 'temporary://file.json'
$source['data_fetcher_plugin'] = 'file';
$mi->set('source', $source);
$exe = new \Drupal\migrate\MigrateExecutable($mi);
$mi->setStatus(\Drupal\migrate\Plugin\MigrationInterface::STATUS_IDLE);
$result = $exe->import();
@chriscalip
chriscalip / example.php
Created March 15, 2019 20:58
PHP: how to get a list of classes that implement certain interface?
<?php
$targetMiners = array_values(array_filter(get_declared_classes(), function ($className) {
return in_array('App\Contracts\MinerInterface', class_implements($className));
}));
@chriscalip
chriscalip / test.py
Created December 6, 2018 03:55
initial try swagger-api/swagger-client python
import swagger_client as looker
# replace with your custom Looker API Host domain and port, if applicable.
base_url = 'https://your.looker.instance:19999/api/3.0/'
client_id = 'your-API3-client-id'
client_secret = 'your-API3-client-secret'
unauthenticated_client = looker.ApiClient(configuration=None)
unauthenticated_authApi = looker.ApiAuthApi(unauthenticated_client)
token = unauthenticated_authApi.login(client_id=client_id, client_secret=client_secret)
client = looker.ApiClient(base_url, 'Authorization', 'token ' + token.access_token)