Skip to content

Instantly share code, notes, and snippets.

@NeilMasters
NeilMasters / mysql-long-running-transactions.sql
Created April 4, 2024 17:33
List all long running transactions on a mysql database server
SELECT
a.trx_id, a.trx_state, a.trx_started,
TIMESTAMPDIFF(SECOND,a.trx_started, now()) as "Seconds Transaction Has Been Open",
a.trx_rows_modified,
b.USER, b.host, b.db, b.command, b.time, b.state
FROM
information_schema.innodb_trx a
INNER JOIN
information_schema.processlist b ON b.id = a.trx_mysql_thread_id
ORDER BY
@NeilMasters
NeilMasters / delete-aws-queues.sh
Created December 12, 2023 20:12
Delete AWS queues using a prefix and optional dry-run
#!/bin/bash
PREFIX=$1
DRY_RUN=$2
echo "Starting the purge of queues that have the prefix of ${PREFIX}"
# Get the list of queues with the $ PREFIX and store as a block of json
QUEUES=$(aws-vault exec $AWS_PROFILE -- aws sqs list-queues --queue-name-prefix=${PREFIX} | jq '.QueueUrls')
echo $QUEUES > /tmp/queues.json
@NeilMasters
NeilMasters / monitor-node-service.sh
Created November 1, 2023 14:07
monitor node service and restart if required
#!/bin/bash
# This small script will check the running processes for the
# node service running the application. If it is not found it
# will start another instance of the service.
SOCKET_SERVICES_RUNNING=$(ps -aux | grep "[n]ode index.js")
if [ "${SOCKET_SERVICES_RUNNING}" == ""]; then
cd /srv/app && (npm run serve&)
@NeilMasters
NeilMasters / serialize-trait.php
Last active March 31, 2023 07:59
example trait doing heavy lifting in 8.2
<?php
trait Serialize {
public function jsonSerialize(): array
{
$array = [];
foreach (get_object_vars($this) as $var => $value) {
if ($value instanceof \JsonSerializable) {
$array[$var] = $this->$var->jsonSerializeToArray();
} else {
@NeilMasters
NeilMasters / get-group-of-url-statuses.sh
Created March 20, 2023 10:15
Get http statuses for a grouped list of urls
#!/bin/bash
###############################################################################
#
# Script accepts a csv of sites by named key.
#
# Usage
#
# ./benchmark-curl.sh 'group1,https://whatever,https://that,https://this
# group2,https://whatever,https://that,https://this'
@NeilMasters
NeilMasters / benchmark-curl.sh
Created March 20, 2023 08:52
Benchmarking curl speed
!#/bin/bash
I=1
while [ $I -le 500 ]
do
echo $I
curl -I -S https://www.google.com
I=$(( $I + 1 ))
done
@NeilMasters
NeilMasters / install-datadog.sh
Created February 10, 2023 16:29
Install datadog.sh
# Install datadog apm
curl -LO https://github.com/DataDog/dd-trace-php/releases/latest/download/datadog-setup.php
php datadog-setup.php --php-bin=all
@NeilMasters
NeilMasters / delete-all-facebook-photos.js
Created December 6, 2022 11:45
Javascript to delete all of your facebook photos without having to do it manually.
/**
* Run this in your browser console and it will delete all of your facebook photos
* one after another.
*
* You will most likely need to fiddle with the css selectors but its basically:
* 1. Click edit of first photo
* 2. Click delete in dropdown menu
* 3. Click confirm in dialog
*/
setInterval(() => {
<?php
if(isset($argv[1])) {
class Xml {
public $url;
}
class Url {
public $loc;
}
@NeilMasters
NeilMasters / list-certificates.sh
Created June 27, 2016 14:05
List all support certificates
# Certificates commands
# 1) List all valid certificates
# 2) List all G5 certificates
#
# RedHat(because they want to be different): ca-bundle.crt
# Everyone else: ca-certificates.crt
awk -v cmd='openssl x509 -noout -subject' '/BEGIN/{close(cmd)};{print | cmd}' < /etc/ssl/certs/ca-bundle.crt
awk -v cmd='openssl x509 -noout -subject' '/BEGIN/{close(cmd)};{print | cmd}' < /etc/ssl/certs/ca-bundle.crt | grep "G5"