Skip to content

Instantly share code, notes, and snippets.

View BlackthornYugen's full-sized avatar

John Steel BlackthornYugen

View GitHub Profile
#include <cstdio>
#include <iostream>
#include <vector>
static const int BUFFER_READ_SIZE = 8;
static const int MAX_READ_SIZE = 4 * 1024 * 1024; // 4MiB
int main() {
std::vector<char> echoData;
char stdinBuffer[BUFFER_READ_SIZE];
@BlackthornYugen
BlackthornYugen / create_ca_and_ee.sh
Last active April 3, 2021 14:04
Certificate Chain Generator
#!/usr/bin/env bash
set -e
DEFAULT_SUBJECT_PREFIX=${DEFAULT_SUBJECT_PREFIX:-"/C=CA/ST=Ontario/L=Kitchener/O=jskw"}
DEFAULT_KEY_TYPE="${DEFAULT_KEY_TYPE:-ec:prime256v1.pem}"
openssl ecparam -name prime256v1 > prime256v1.pem
log() {
# cowsay if available
if which cowsay > /dev/null ; then
echo ""
#!/usr/bin/env bash
#
# Create container with the following command:
docker run \
-d \
-e TZ=America/Toronto \
-v $PWD/data:/home/node/.webthings \
--log-opt max-size=1m \
--log-opt max-file=10 \
@BlackthornYugen
BlackthornYugen / check_certs.sh
Created January 24, 2021 02:51
Send email if a server isn't using the latest certificate.
#!/usr/bin/env bash
set -e
DAYS_BEFORE_EMAIL=21
TO_ADDR="Joe <joe@example.com>"
BCC_ADDR="Demo <demo@example.com>"
find ~/.acme.sh -name '*cer' | tee certs_to_check.txt
# usage $0 {NEW_CERT} {OLD_CERT}
@BlackthornYugen
BlackthornYugen / aoc2-2.jq
Last active December 3, 2020 14:44
Advent of Code 2020
# https://adventofcode.com/2020/day/2 part 2 in jq
# Invoked with jq --raw-input --slurp --from-file aoc2.jq input.2.txt
# x ^ y
def xor($x;$y):
($x or $y) # Either $x or $y
and # but
($x and $y | not) # not both
;
@BlackthornYugen
BlackthornYugen / can_you_dig_it.log
Created June 17, 2020 01:28
Use yq, jq, and dig +yaml to resolve a bunch of domains with nice output.
# Make a neato jq filter that just gives us question and answer sections.
JQ_FILTER='.[].message.response_message_data | [.QUESTION_SECTION[], ( .ANSWER_SECTION[]? | split(" ")[-1])]'
# What are my name servers for each of these?
for domain in jskw jsteel jsteelkw ; do for tld in ca dev ; do dig ${domain}.${tld} +yaml -tns | yq $JQ_FILTER ; done ; done # SHOW NS
[
"jskw.ca. IN NS",
"ns-cloud-c4.googledomains.com.",
"ns-cloud-c3.googledomains.com.",
"ns-cloud-c2.googledomains.com.",
@BlackthornYugen
BlackthornYugen / gen_random_haproxy_passwords.sh
Created June 16, 2020 13:12
Generate a few passwords for haproxy (or other things that use unix style passwords)
#!/usr/bin/env bash
# Need a recent openssl to use -6 option (sha512). Either update openssl or change to -1 or similar if it doesn't work
shuf -n30 /usr/share/dict/words | tr '\n' ' ' | fold -s -w 48 | tr ' ' ';' | openssl passwd -6 -noverify -table -stdin
# Example Output:
#carrotwood;sacerdotalist;unfallible;homeliness; $6$xGj40hGX9L0NyToC$hqPn25jIFzS2vzfEVpsmzbDe3XeXtUkTJPHKBO7SI6FTkub4gqUWq5dpB8wfqkEoQClTmWkuiuN8K8eYIcfXL1
#schoolteaching;moule;malesherbiaceous; $6$//mFpIknpKEToVt1$cyNLuPOsvPCW5KzJiS86rKKfonl8PBG0B/Xf5bLwiEvdcm64OX0jqwbhIxjOjrTejxUcB0ys.B0kdBLasb8l/.
#hypsophonous;ungroundedness;did;sapek; $6$NA29jYnRwQ1Tstlh$AW0NoJSKXCIiBo86FB9TKmD0aS67fcdtc.x8.VjeGgj287EuREkDWRmh/cxArFs8rGSM5eDPVC0kYyn52DlpX0
#strepsinema;Thackerayana;camelman; $6$tze4YcdZgPo6e18o$PtsCCwvbkEuvfQoOnPH8ZErQeoGE8/PQvOhdkYioP687ZAujRbtK.IpKLSfVPM6tvsTkN9Z1qjrbssioezG1S.
#amyelencephalia;creeded;city;Triodon;oosporic; $6$Jh/vWDP3BM5Wah/X$CVfCUvFVVXQRBdGPo0x8YiIlLm0mm/4uadaHP39tCITxij8T98HMtVD9khCrVce0D.7AaC1cetiOlX/BF3IG..
@BlackthornYugen
BlackthornYugen / App.kt
Last active January 4, 2024 07:14
Sending an email using kotlin and javax.mail
/*
* Sending an email using kotlin and javax.mail
*
* Usage: java -jar app.jar <user> <password> <from> <to> <cc>
*/
package main.kotlin.sendmail
import java.util.*
import javax.mail.*
import javax.mail.internet.*
#!/usr/bin/env bash
FILTER_YUBIKEY='/Yubikey/{print;getline;getline;print;getline;print}'
EXPECTED_YUBI_MD5="1a067fac7f6915a0acd5a235876fd33e" # Hash of USB Device
LONG_POLL_TIME=3 # Poll time after locking
SHORT_POLL_TIME=1 # Poll time while waiting for yubikey to disconnect
ARMED=0
DATESTRING=%Y-%m-%d\ %H:%M:%S.000
do_screen_saver() {
echo "`date \"+${DATESTRING}\"` locking screen"
@BlackthornYugen
BlackthornYugen / duck.sh
Last active March 28, 2024 15:56
Duckdns cron script
#!/usr/bin/env bash
DUCKPATH=~/duckdns
TOKEN=changeme
DOMAINS=steelcomputers
curl -sSv "https://www.duckdns.org/update?domains=${DOMAINS}&token=${TOKEN}&ip=" \
2>> ${DUCKPATH}/stderr.log \
>> ${DUCKPATH}/stdout.log
printf ' - ' >> ${DUCKPATH}/stdout.log
date >> ${DUCKPATH}/stdout.log