Skip to content

Instantly share code, notes, and snippets.

@alexcreek
alexcreek / openssl.md
Last active August 19, 2022 06:46
OpenSSL cheat sheet

Creating

Create a csr and key

openssl req -new -out fqdn.csr -newkey rsa:2048 -nodes -keyout fqdn.key -subj /C=US/ST=State/L=City/O=Company/CN=fqdn

Create a self signed cert and key

openssl req -x509 -days 365 -out fqdn.crt -newkey rsa:2048 -nodes -keyout fqdn.key -subj /C=US/ST=State/L=City/O=Company/CN=fqdn
@alexcreek
alexcreek / renew-token.py
Last active June 23, 2022 01:14
Use your existing tdameritrade refresh_token to create a new refresh_token valid for another 90 days
#!/usr/bin/env python3
# https://developer.tdameritrade.com/content/authentication-faq
from requests import post
import os
import sys
try:
refresh_token = os.environ['REFRESH_TOKEN']
client_id = os.environ['CLIENT_ID']
@alexcreek
alexcreek / datetime.md
Last active April 1, 2022 05:24
python datetime examples

https://docs.python.org/3/library/datetime.html

from datetime import datetime as dt

In [119]: dt.now()
Out[119]: datetime.datetime(2021, 12, 17, 23, 29, 32, 946086)

In [180]: dt.now(timezone.utc)
Out[180]: datetime.datetime(2021, 12, 18, 4, 51, 10, 734244, tzinfo=datetime.timezone.utc)
@alexcreek
alexcreek / shell-parameter-reference.md
Last active December 18, 2021 03:09
Shell parameter expansion examples

replace()

${parameter/old/new} - replace one occurrence

${parameter//old/new} - replace all occurrences

~ ✘  f=asdf.txt
~ ✘  echo ${f/txt/md}
asdf.md
@alexcreek
alexcreek / git.md
Last active December 18, 2021 03:08
git cheat sheet

Show me all commits since the previous tag option 1 - hard mode

git --no-pager log --oneline --no-merges --decorate=no $(git describe --tags --abbrev=0)..

Show me all commits since the previous tag option 2 - ez mode

# with git-extras installed https://github.com/tj/git-extras
# update the changlog format first 
git config changelog.format "%h %s"
@alexcreek
alexcreek / getopts.sh
Last active December 17, 2021 23:40
How to use getopts in bash
#!/bin/bash
usage() {
echo "Usage: $(basename "$0") [-v] [-f filename] [-g group] positional-param"
exit 1
}
if [[ "$#" -lt 1 ]]; then
usage
fi
@alexcreek
alexcreek / argparse.py
Last active December 18, 2021 02:49
python argparse example
#!/usr/bin/env python3
# https://docs.python.org/3.9/library/argparse.html
import argparse
def parse_arguments():
parser = argparse.ArgumentParser(description='Argument Parser Template')
parser.add_argument('-b', '--basic', help='basic arg consuming option')
parser.add_argument('-v', '--verbose', help='increase output verbosity, flag', action='store_true')
parser.add_argument('-g', '--greedy', help='greedy narg=* arg', nargs='*')
parser.add_argument('-c', '--choices', help='choices demonstration', choices=['list', 'of', 'choices'])
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
KillMode=none
ExecStartPre=/usr/sbin/nginx -t
ExecStartPre=-/usr/bin/pkill -SIGQUIT nginx
#!/bin/bash
temp_ruleset=$(mktemp)
nginx_ruleset="# Generated by iptables-save v1.4.21 on Fri Jan 9 18:21:29 2015
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT DROP [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -p icmp -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT
@alexcreek
alexcreek / kibana-reverse-proxy.conf
Last active August 29, 2015 14:08
nginx reverse proxy config for kibana, includes authentication, ssl and support for elasticsearch plugins
server {
listen *:80 ;
#listen *:443;
server_name localhost;
access_log /var/log/nginx/kibana.access.log;
#ssl on;
#ssl_certificate /etc/nginx/ssl/logstash.pem;
#ssl_certificate_key /etc/nginx/ssl/logstash.pem;