Skip to content

Instantly share code, notes, and snippets.

@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 / 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;
@alexcreek
alexcreek / zpanel-ssl.conf
Last active February 2, 2016 04:37
apache config for enabling SSL on the zpanel login
# Configuration for ZPanel control panel.
# /etc/zpanel/configs/apache/zpanel-ssl.conf
# to use this config append the include directive below to /etc/zpanel/configs/apache/httpd.conf
# Include /etc/zpanel/configs/apache/zpanel-ssl.conf
<VirtualHost *:443>
ServerAdmin zadmin@localhost
DocumentRoot "/etc/zpanel/panel/"
ServerName www.foo.bar
@alexcreek
alexcreek / backup.sh
Last active May 18, 2023 13:59
simple backup script using rsync + tar
#!/bin/bash
TODAY=$(date +%Y%m%d)
TARGETS=( '/etc' '/home' '/root' '/var/www' )
BACKUP_ROOT='/backups'
BACKUP_DIR="${BACKUP_ROOT}/${TODAY}"
echo "$(date +%D" "%r): Beginning backup"
mkdir -p $BACKUP_DIR
for i in ${TARGETS[@]}; do
@alexcreek
alexcreek / iptables-template
Last active August 29, 2015 14:07
basic iptables ruleset
# Generated by iptables-save v1.4.12 on Tue Oct 21 17:32:08 2014
*nat
:PREROUTING ACCEPT [9:538]
:INPUT ACCEPT [9:538]
:OUTPUT ACCEPT [4:271]
:POSTROUTING ACCEPT [4:271]
COMMIT
# Completed on Tue Oct 21 17:32:08 2014
# Generated by iptables-save v1.4.12 on Tue Oct 21 17:32:08 2014
*mangle