Skip to content

Instantly share code, notes, and snippets.

Avatar

Jason Riddle jason-riddle

View GitHub Profile
@jason-riddle
jason-riddle / custom-error.js
Created Jul 11, 2020 — forked from justmoon/custom-error.js
Creating custom Error classes in Node.js
View custom-error.js
'use strict';
module.exports = function CustomError(message, extra) {
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name;
this.message = message;
this.extra = extra;
};
require('util').inherits(module.exports, Error);
@jason-riddle
jason-riddle / keytool_guide.sh
Last active Oct 22, 2019
Examples using keytool #keytool
View keytool_guide.sh
# List certs in keystore
keytool -list -v -keystore /etc/ssl/certs/java/cacerts
# Grep for a specific certificate
echo -n 'changeit' | keytool -list -keystore /etc/ssl/certs/java/cacerts 2>/dev/null | grep -B1 -i 01:18
@jason-riddle
jason-riddle / dmesg_to_utc.sh
Last active Oct 21, 2019
Convert dmesg timestamps to UTC format
View dmesg_to_utc.sh
#!/bin/bash
# Translate dmesg timestamps to human readable format
# desired date format
date_format="%Y-%m-%dT%H:%M:%SZ"
# [ 3.469072] EXT4-fs (xvda1): mounted filesystem with ordered data mode. Opts: (null)
# [ 3.483769] dracut: Remounting /dev/disk/by-label/\x2f with -o noatime,ro
# [ 3.495019] EXT4-fs (xvda1): mounted filesystem with ordered data mode. Opts: (null)
# [ 3.506417] dracut: Mounted root filesystem /dev/xvda1
@jason-riddle
jason-riddle / curl_examples.sh
Created Oct 21, 2019
Examples for Curl #snippet #complete
View curl_examples.sh
# Robust curl command to retry, timeout, and save the output to a file
curl --silent --show-error \
--location --max-redirs 3 \
--retry 3 --retry-connrefused --retry-delay 2 \
--max-time 30 \
"$url"
@jason-riddle
jason-riddle / gist:d2bf6de8b25a70c05a6570232da9d0c9
Last active Oct 21, 2019
Snippet using tcpdump to listen on an http port #snippet #complete
View gist:d2bf6de8b25a70c05a6570232da9d0c9
# Ref: https://github.com/SergK/cheatsheat-tcpdump/blob/master/tcpdump_advanced_filters.txt
# Ref: http://edoceo.com/cli/tcpdump
HTTP_PORT="8444"
HTTP_FILTER="(((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)"
tcpdump -i any -s 0 -A "tcp port $HTTP_PORT and $HTTP_FILTER"
@jason-riddle
jason-riddle / idle_busy_command.sh
Last active Oct 21, 2019
Snippet to keep idle ssh connection busy to avoid disconnecting #snippet #complete
View idle_busy_command.sh
# !/usr/bin/env bash
while :; do sleep 59; echo -n ' ' >&2; done &
@jason-riddle
jason-riddle / maxProfit.py
Last active Oct 21, 2019
Interview Practice #interviewing #complete
View maxProfit.py
#!/usr/bin/env python3
"""
I have an ordered historical list of daily prices of quizlet coin - the hot new cryptocurrency.
[100, 50, 120, 100, 300, 250, 1]
What is the best profit I could have made from 1 purchase and 1 sale of Quizlet Coin?
View recover.sh
cryptsetup luksOpen /dev/nvme0n1p2 cryptkey
cryptsetup luksOpen --key-file=/dev/mapper/cryptkey /dev/nvme0n1p3 cryptswap
cryptsetup luksOpen --key-file=/dev/mapper/cryptkey /dev/nvme0n1p4 cryptroot
#+END_SRC
Then for a not fun bit, matching entries in =/dev/disk/by-uuid/= to
the partitions we want to mount where. Running ~ls -l
/dev/disk/by-uuid/~ shows which devices have which UUIDs. To determine
what =dm-1= and =dm2=, I ran ~ls -la /dev/mapper~:
@jason-riddle
jason-riddle / jshell_docker_snippets.sh
Last active Oct 21, 2019
Guide using Jshell to query CPU and memory information within a docker container #jvm #guide #complete
View jshell_docker_snippets.sh
#!/usr/bin/env bash
# Ref: https://jaxenter.com/better-containerized-jvms-jdk-10-140593.html
set -eu
OPENJDK_IMAGE='openjdk:10-ea-jdk-slim'
JSHELL_CMD=(/bin/sh -c 'jshell -q')
You can’t perform that action at this time.