Skip to content

Instantly share code, notes, and snippets.

View GuyPaddock's full-sized avatar

Guy Elsmore-Paddock GuyPaddock

View GitHub Profile
@GuyPaddock
GuyPaddock / array_contains.sh
Created July 2, 2019 03:38
Check if a value is in an array in Bash
##
# Determine if a given element exists in an array.
#
# Based on:
# https://stackoverflow.com/a/11525897/4342230
#
# @param string $1
# The value to look for (the "needle").
# @param string... $2...
# The array of values to search (the "haystack").
@GuyPaddock
GuyPaddock / resurrect.php
Last active September 18, 2019 14:45
Resurrecting an Unsaved Drupal 8 Node from the Database using Devel
<?php
// NOTE: Node previews expire after 7 days. Be sure to use this method to extract the desired data before then.
// IMPORTANT: Set this to the user ID of the person who was creating/lost the node.
$user_id = 1;
// IMPORTANT: Set this to the UUID that appeared in the node preview URL.
// This value is from a URL that looked like this:
// https://my-site/node/preview/ed4eaac0-3c32-427e-860f-6ce8fc79c3b2/full
$preview_id = 'ed4eaac0-3c32-427e-860f-6ce8fc79c3b2';
@GuyPaddock
GuyPaddock / results.txt
Last active December 18, 2019 14:55
How Static Variables Work with Inheritance in PHP
On PHP 7.2.24-0ubuntu0.18.04.1 (cli) (built: Oct 28 2019 12:07:07) ( NTS ):
ClassA = 1576680836
ClassA = 1576680836
ClassA = 1576680838
ClassA = 1576680838
ClassA = 1576680840
ClassA = 1576680840
ClassX = 1576680842
@GuyPaddock
GuyPaddock / results.txt
Last active December 18, 2019 14:57
How array_reduce() and array_map() Behave with Associative Arrays in PHP
On PHP 7.2.24-0ubuntu0.18.04.1 (cli) (built: Oct 28 2019 12:07:07) ( NTS ):
Array
(
[a] => ABC: 1
[b] => ABC: 2
)
,1,2
@GuyPaddock
GuyPaddock / results.txt
Created December 30, 2019 22:02
How array_merge() compares to the + operator when working with different array types
On PHP 7.2.24-0ubuntu0.18.04.1 (cli) (built: Oct 28 2019 12:07:07) ( NTS ):
Result of combining:
Array
(
[0] => 1
[1] => 2
[2] => 3
)
...with:
@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>
@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 / 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 / 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 / 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