Skip to content

Instantly share code, notes, and snippets.

View nicc777's full-sized avatar
🏠
Working from home

Nico Coetzee nicc777

🏠
Working from home
  • Utrecht, Netherlands
View GitHub Profile
@nicc777
nicc777 / localclient-glusterfs-mount.sh
Last active May 7, 2022 13:46
GlusterFS Cluster Using MultiPass
#!/bin/sh
HF=/etc/hosts
MP=/glusterfs-data
echo "Updating /etc/hosts"
IP1=$(multipass info glusterfs1 | grep IPv4 | awk '{print $2}')
IP2=$(multipass info glusterfs2 | grep IPv4 | awk '{print $2}')
sudo sed -i '/glusterfs1/d' $HF
sudo sed -i '/glusterfs2/d' $HF
@nicc777
nicc777 / install_glusterfs_clinet_on_k3s_nodes.sh
Created May 25, 2022 08:29
Provision GlusterFS Mount Points in K3s Nodes running on Multipass
#!/bin/bash
for node in node1 node2 node3 ;do
multipass exec $node -- sudo DEBIAN_FRONTEND=noninteractive apt update
multipass exec $node -- sudo DEBIAN_FRONTEND=noninteractive apt install -yq software-properties-common
multipass exec $node -- sudo DEBIAN_FRONTEND=noninteractive add-apt-repository -y ppa:gluster/glusterfs-7
multipass exec $node -- sudo DEBIAN_FRONTEND=noninteractive apt update
multipass exec $node -- sudo DEBIAN_FRONTEND=noninteractive apt install -y glusterfs-client
multipass exec $node -- sudo mkdir -p /opt/local-path-provisioner
multipass exec $node -- sudo chmod 777 /opt/local-path-provisioner
@nicc777
nicc777 / embedding-cognito-js-in-simple-html.md
Created May 30, 2022 05:28
Getting the AWS Cognito JavaScript LIbrary (Steps)

Use Case

These steps demonstrate how to get the JavaScript library for AWS Cognito integration when using simple HTML and JavaScript - no frameworks like ReactJS, or other Node type projects.

Prerequisites

Even though you may not want to use a framework, you still require a relatively new stable version of nodejs

My approach:

@nicc777
nicc777 / install_aws_cli_v2_using_pip.md
Created June 18, 2022 08:09
Install AWS CLI Version 2 using pip

Command:

pip3 install git+https://github.com/aws/aws-cli.git@v2
@nicc777
nicc777 / aws_boto3_and_lambda_functions.md
Last active September 2, 2022 11:24
Python Code Templates

AWS / Boto3 Functions and Lambda Functions

Module header functions

Prerequisite funtion defined early in a module:

import boto3
import traceback
import os
@nicc777
nicc777 / cloudwatch_log_stream_to_file.md
Last active March 7, 2023 13:21
AWS CLI and CloudWatch - Retrieve a log stream to a local file

Assuming you have LOG_GROUP_NAME and STREAM_NAME as environment variables, you can run the following:

aws logs get-log-events --log-group-name "$LOG_GROUP_NAME" --log-stream-name "$STREAM_NAME" | yq -o=json | jq '.events[] | .timestamp, .message' > stream.log

The log entries with timestamp and message will now be in the file stream.log

Another way to format the output (prevent splitting lines for timestamp and message fields):

@nicc777
nicc777 / aws_http_api_to_python_lambda_template.md
Created August 11, 2022 04:44
AWS Lambda Function Template for AWS HTTP API Gateway Proxy Requests

The function is for a SAM template that looks something like the following:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Example Template for AWS HTTP API to Python Lambda Function

Parameters:
  StageNameParameter:
    Type: String
@nicc777
nicc777 / dynamic_dns_using_aws_howto.md
Last active September 21, 2023 16:58
Using AWS for managing your PC dynamic DNS entry

Summary of info I got from this post on 2022-09-11

Shell script:

#!/bin/bash

#Variable Declaration - Change These
HOSTED_ZONE_ID="XXXXXXXXXXXX"
NAME="example.com."
@nicc777
nicc777 / pySmtpSend.py
Created September 29, 2022 09:23
Python raw SMTP ()unauthenticated)
#!/usr/bin/python
import smtplib
import os
SMTP_SERVER = os.getenv('SMTP_SERVER', 'localhost')
SMTP_PORT = os.getenv('SMTP_PORT', '25')
SENDER_EMAIL_ADDR = os.getenv('SENDER_EMAIL_ADDR', '[email protected]')
SENDER_NAME = os.getenv('SENDER_NAME', 'NO-REPLY')
RECEIVER_EMAIL_ADDR = os.getenv('RECEIVER_EMAIL_ADDR', 'root@localhost')
RECEIVER_NAME = os.getenv('RECEIVER_NAME', 'Root')
@nicc777
nicc777 / dump_to_json.py
Created October 28, 2022 07:03
Dumping dicts to json in Python, where the dict has `datetime` or `tzlocal` objets
import json
import datetime
from dateutil.tz import tzlocal # pip3 install python-dateutil
your_dict = {} # Data...
json.dumps(your_dict, sort_keys=True, default=str)