Skip to content

Instantly share code, notes, and snippets.

View toriaezunama's full-sized avatar

Paul Wadsworth toriaezunama

  • Bluescape
  • Vancouver BC Canada
View GitHub Profile
@toriaezunama
toriaezunama / top-10-slow-queries-by-avg-execution-time.sql
Created October 4, 2022 18:56
10 slow queries by average time taken to execute the query
select SCHEMA_NAME,
DIGEST,
DIGEST_TEXT,
FORMAT(COUNT_STAR, 0) as COUNT_STAR,
CONCAT(ROUND(SUM_TIMER_WAIT * 0.000000000001, 2), 's') as SUM_TIMER_WAIT_S,
CONCAT(ROUND(MIN_TIMER_WAIT * 0.000000001, 2), 'ms') as MIN_TIMER_WAIT_MS,
CONCAT(ROUND(AVG_TIMER_WAIT * 0.000000000001, 2), 's') as AVG_TIMER_WAIT_S,
CONCAT(ROUND(MAX_TIMER_WAIT * 0.000000001, 2), 'ms') as MAX_TIMER_WAIT_MS,
CONCAT(ROUND(SUM_LOCK_TIME * 0.000000000001, 2), 's') as SUM_LOCK_TIME_S
from events_statements_summary_by_digest
@toriaezunama
toriaezunama / promise-test-01.js
Last active August 15, 2019 22:37
Promise and async Qs
// Question: What is the result of running the following?
function job() {
return new Promise(function(resolve, reject) {
reject();
});
}
let promise = job();
@toriaezunama
toriaezunama / self-destruct-server.js
Last active April 23, 2018 00:50
node js example to demonstrate socket lifecycle events
const net = require('net');
const { spawn } = require('child_process');
const HOST = '127.0.0.1';
const PORT = 6969;
// Server /////
const _logServer = (p) => (s) => console.log(`[Server:${p}]`, s);
const logServer = _logServer('main');
@toriaezunama
toriaezunama / sset.js
Last active April 16, 2018 18:25
Extension of javascript Set adding union, intersection & difference member functions
class SSet extends Set {
union(a) {
return new SSet([...this, ...a]);
}
intersection(a) {
return new SSet([...this].filter(x => a.has(x)));
}
difference(a) {
return new SSet([...this].filter(x => !a.has(x)));
}
@toriaezunama
toriaezunama / gist:f4df1d9e8e7c98b7422655d8404e3d78
Created April 5, 2018 19:27
How to debug node js with nodemon and chromedev tools
# Chrome
chrome://inspect/
Click: "Open dedicated DevTools for Node" link
# index.js
...
debugger; // stop here
...
# node
@toriaezunama
toriaezunama / proxy.sh
Created April 5, 2018 17:49
Use netcat to proxy requests
#!/bin/bash
# From: https://notes.tweakblogs.net/blog/7955/using-netcat-to-build-a-simple-tcp-proxy-in-linux.html
LOCAL_PORT=$1
REMOTE_HOST=$2
REMOTE_PORT=$3
mkfifo fifo
nc -k -l -p $LOCAL_PORT <fifo | nc $REMOTE_HOST $REMOTE_PORT >fifo
rm fifo
@toriaezunama
toriaezunama / TLS.md
Last active January 29, 2019 21:01
OpenSSL, TLS, SSH, Certificates etc
@toriaezunama
toriaezunama / bash-prompt.sh
Last active March 29, 2018 21:50
Shell prompt
# Special
\e # an ASCII escape character (033)
\h # the hostname up to the first `.'
\H # the hostname
\j # the number of jobs currently managed by the shell
\l # the basename of the shell's terminal device name
\n # newline
\r # carriage return
\t # the current time in 24-hour HH:MM:SS format
@toriaezunama
toriaezunama / docker-prod-checklist.md
Last active March 29, 2018 18:39
Docker production checklist

Docker compose

Logs

Restart

Resource limits

docker-compose-prod.yml

Write a production version of your docker compose file that overrides dev only features in the base (dev) version of the docker file. Run with docker-compose -f docker-compose.yml -f docker-compose-prod.yml up -d.

ssh-keygen -t rsa -b 2048