Skip to content

Instantly share code, notes, and snippets.

View GuyPaddock's full-sized avatar

Guy Elsmore-Paddock GuyPaddock

View GitHub Profile
@GuyPaddock
GuyPaddock / NestedEntityReference.php
Created November 3, 2020 21:28
NestedEntityReference utility class for safely getting access to ER fields
<?php
namespace Drupal\my_utiilities\Utility;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Plugin\DataType\EntityAdapter;
use Drupal\Core\Field\EntityReferenceFieldItemListInterface;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\TypedData\DataReferenceInterface;
@GuyPaddock
GuyPaddock / console.js
Created October 27, 2020 13:18
Extract Titles of Confluence Spaces from the Spaces Page
$('.space-name').each(function () { console.log($(this).text()); });
@GuyPaddock
GuyPaddock / modulename.install.php
Created October 19, 2020 15:19 — forked from crittermike/modulename.install.php
Uninstall Multiversion and Workspace from Drupal 8. This is an update hook which successfully uninstalled the module from our fairly complicated site.
<?php
/**
* Uninstall Multiversion and related modules.
*/
function modulename_update_8000() {
// !!! IMPORTANT !!!
// First, make sure to check and see if any of the below entities have a
// value of NULL in "_deleted" or "workspace" columns, because if so,
// you'll want to update that. See this issue for more information:
@GuyPaddock
GuyPaddock / calc_similarity.sh
Created August 5, 2020 20:27
Convert images to PNG, resize them, and then compute dissimilarity
#!/usr/bin/env bash
mogrify -format png *.jpg
mogrify \
-resize 4096x4096 \
-background black \
-gravity center \
-extent 4096x4096 \
-format png \
@GuyPaddock
GuyPaddock / update_aks_node_key.sh
Created July 28, 2020 16:05
Azure Kubernetes Service (AKS) reset SSH key of azureuser account on nodes
#!/usr/bin/env bash
##
# Update the SSH key for the azureuser account on the specified AKS node.
#
cluster_resource_group="${1:-}"
node="${2:-}"
public_key_path="${3:-}"
AZURE_USER="azureuser"
@GuyPaddock
GuyPaddock / kubectl_timeout_evade_trick.sh
Created June 17, 2020 12:41
Keeping a long-running command going without interruption through kubectl exec through timeouts
# This trick keeps the kubectl session active by printing the current time every 10 seconds
#
# Run commands like this
(while true; do sleep 10; date; done) & <YOUR LONG RUNNING COMMAND GOES HERE>
# For example:
(while true; do sleep 10; date; done) & sha512sum my_super_large_file.dat | tee checksum.sha512
# When done, to get control back, run this command:
fg
@GuyPaddock
GuyPaddock / password.txt
Created May 16, 2020 20:23
Technicolor CGA4234 VGW Default Password
The default username and password for a Technicolor CGA4234 VGW from AtlanticBBInc is "user" with no password.
@GuyPaddock
GuyPaddock / 01-test-failing.php
Last active May 1, 2020 03:45
Why does this script lose CSV rows when three concurrent processes are run? Test.csv has an additional column added in Excel. It's TRUE when two rows are sequential.
<?php
// Run this command in three separate consoles, concurrently.
// - Run the first with php -f ./test.php 1
// - Run the second with php -f ./test.php 2
// - Run the second with php -f ./test.php 3
$prefix = $argv[1];
for ($value = 0; $value < 1000; ++$value) {
$sleep_amount = rand(50000, 250000);
@GuyPaddock
GuyPaddock / sample.js
Last active February 29, 2020 02:00
Converting an Array or jQuery Object to NodeList (from https://stackoverflow.com/a/13363526/4342230)
var tagAttribute = 'data-tag-for-query';
$(elements).each(function() {
$(this).attr(tagAttribute, 'true');
});
var nodes = document.querySelectorAll('[' + tagAttribute + '="true"]');
Array.prototype.forEach.call(nodes, function(node) {
$(node).removeAttr(tagAttribute);
@GuyPaddock
GuyPaddock / more_advanced_js.html
Last active January 18, 2020 19:52
Simple HTML + JS Examples
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My Slightly More Advanced Page</title>
</head>
<body>
<h1>A Slightly More Advanced Simple Page</h1>
<p id="my_paragraph"></p>