Skip to content

Instantly share code, notes, and snippets.

@achesco
achesco / local-ssl-authority.md
Last active May 6, 2019 10:13
Self-signed SSL certificates signed with authority for multiple (sub)domains

Create CA key (keep it a secret)

openssl genrsa -out rootCA.key 4096

Create CA cert

openssl req -new -x509 -days 1826 -key rootCA.key -out rootCA.crt
@achesco
achesco / curls.sh
Last active December 6, 2019 15:22
Curl requests
# POST request with cookies
curl \
--cookie "authId=12345" \
-X POST \
-d '{"payload":"DATA"}' \
-H "Content-Type: application/json" \
-k https://localhost:8080/
# Call senecajs action with POST request
curl \
@achesco
achesco / p12-keys-convertion.md
Created April 20, 2018 16:06
p12/pfx <==> key+cert+ca

Assemble

openssl pkcs12 -export -out bundle.p12 -inkey user.key -in user.crt -certfile authority.crt

Disassemble

openssl pkcs12 -in bundle.p12 -nocerts -out user.encrypted.key &amp;&amp; openssl rsa -in user.encrypted.key -out user.key
@achesco
achesco / server-client-ssl.md
Last active February 20, 2019 15:35
Server and client SSL certificates

CNs are important!!! -days 3650

Create server key and cert (server_key.pem, server_cert.pem)

openssl req -x509 -newkey rsa:4096 -keyout server_key.pem -out server_cert.pem -nodes -days 3650 -subj "/CN=localhost"

Create client key and cert signing request (admin_key.pem, admin_csr.pem)

openssl req -newkey rsa:4096 -keyout admin_key.pem -out admin_csr.pem -nodes -days 3650 -subj "/CN=admin"
@achesco
achesco / generate-mongo-ssl.md
Last active July 18, 2024 07:10
Generate self-signed SSL certificates for MongoDb server and client

CNs are important!!! -days 3650

Make PEM containig a public key certificate and its associated private key

openssl req -newkey rsa:2048 -new -x509 -days 3650 -nodes -subj '/C=US/ST=Massachusetts/L=Bedford/O=Personal/OU=Personal/emailAddress=example@example.com/CN=localhost' -out mongodb-cert.crt -keyout mongodb-cert.key
cat mongodb-cert.key mongodb-cert.crt > mongodb.pem
@achesco
achesco / generate-pg-ssl.md
Last active August 16, 2024 22:09
Generate self-signed SSL certificates for PostgreSQL server and client

CNs are important!!! -days 3650

Create a Certificate Signing Request (CN=localhost)

umask u=rw,go= && openssl req -days 3650 -new -text -nodes -subj '/C=US/ST=Massachusetts/L=Bedford/O=Personal/OU=Personal/emailAddress=example@example.com/CN=localhost' -keyout server.key -out server.csr

Generate self-signed certificate

umask u=rw,go= &amp;&amp; openssl req -days 3650 -x509 -text -in server.csr -key server.key -out server.crt
@achesco
achesco / Git, GitFlow code snippets
Last active November 6, 2017 09:59
git-snippets.sh
# GitFlow
git checkout develop && git checkout -b _feature-branch_
git reset --soft _commit-id_
git commit [-a] [-—amend] [--no-edit]
git fetch origin
git pull --rebase origin develop
git push origin _branch-name_ [-f]
# Reset one commit back
@achesco
achesco / node-uninstall.sh
Last active August 20, 2017 12:16
Uninstall node installed from source or from a binary distribution
#bin/bash
# WARNING!!!
# Check out following lines before run!
# npm settings file
# rm ~/.npmrc
rm -r /usr/local/lib/{node,node_modules}
rm -r /usr/local/include/{node,node_modules}
@achesco
achesco / split-to-scenes.sh
Last active January 14, 2024 19:40
Detect and split video to scenes with ffmpeg
# Splits video to separate scenes files
# Inspired by https://stackoverflow.com/a/38205105
#!/bin/bash
file=""
out="./"
diff=0.4
bitrate="512k"
trim=0
@achesco
achesco / shell-snippets.sh
Last active May 7, 2024 11:36
Linux shell snippets
# self sign cert for localhost
openssl req -x509 -sha256 -nodes -newkey rsa:2048 -days 365 -keyout localhost.key -out localhost.crt
# find folder which content's size less than 10kb
find /volume1/Volume/fapfapbackup -mindepth 1 -maxdepth 1 -type d -exec du -ks {} + | awk '$1 <= 10' | cut -f 2-
# Send output to Telegram, JSON POST with curl
# telelog.sh
LOG=`cat <&0`
curl -H "Content-Type: application/json" \