Skip to content

Instantly share code, notes, and snippets.

View nmagee's full-sized avatar

Neal Magee nmagee

View GitHub Profile
@nmagee
nmagee / assignment.py
Created March 1, 2021 21:22
FastAPI stack for assignment
#!/usr/bin/env python3
import os
import requests
from fastapi import FastAPI
from typing import Optional
from pydantic import BaseModel
app = FastAPI()
@nmagee
nmagee / convert-to-json.sh
Last active March 21, 2022 22:22
Converts CSV into JSON
#!/bin/bash
jq --slurp --raw-input --raw-output \
'split("\n") | .[1:] | map(split(",")) |
map({"id": .[0],
"fname": .[1],
"lname": .[2],
"email": .[3],
"ipv4": .[5]})' \
mock_data.csv > mock_data.json
#!/bin/bash
set -e
## --------------------------------------------------------------
## OKAY - but simple
## The script has a proper shebang line and has been
## chmod to 755 so it can be executed.
@nmagee
nmagee / detabify.py
Created February 18, 2021 19:37
Convert TSV to CSV using re.sub
#!/usr/bin/env python3
import io
import re
def convert(file_name):
# Open csv file
file_name="new_mock_data"
csv = io.open(file_name + ".csv", mode="w", encoding="utf-8")
@nmagee
nmagee / python-orchestrator.py
Created February 18, 2021 19:24
How to call a bash command from within python3
#!/usr/bin/env python3
# How to run a bash command from within a python3 script.
## -----------------------------------------------------------
## BAD
## This solution looks good but is a bad practice. as os.system
## and os.spawn are older and being replaced. This may not work
@nmagee
nmagee / simple-sns-publish.py
Created November 12, 2020 16:57
A demo of publishing an SNS message. Update with the ARN of your own SNS Topic.
#!/usr/bin/env python3
import json
import boto3
import datetime
sns = boto3.client('sns')
response = sns.publish(
TopicArn="arn:aws:sns:us-east-1:555566667777:simple-topic",
@nmagee
nmagee / index.html
Last active November 11, 2021 21:22
PA Submission form for S3+CloudFront
<!DOCTYPE html>
<html>
<head>
<title>CS4740 - CloudFront+SNS+Lambda+SNS+Dynamo Application</title>
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.780.0.min.js"></script>
<link href="https://getbootstrap.com/docs/4.5/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
</head>
<body>
<script type="text/javascript">
@nmagee
nmagee / describe-instances.py
Created October 1, 2020 17:09
Python3 snippet to iterate out InstanceIds in EC2.
import boto3
ec2 = boto3.client('ec2')
response = ec2.describe_instances()
for r in response['Reservations']:
for i in r['Instances']:
print(i['InstanceId'])
@nmagee
nmagee / apache2-remote-bootstrap
Created September 24, 2020 14:58
Fetches a remote shell script to execute for bootstrapping
#!/bin/bash
curl -O https://gist.githubusercontent.com/nmagee/5636d0355d48998f91502dd811a7401c/raw/6833433672715308fff57f86792d1246ba5fe677/apache2-bootstrap.sh
/bin/bash apache2-bootstrap.sh
@nmagee
nmagee / apache2-bootstrap.sh
Created September 24, 2020 14:53
Bootstraps Amazon Linux 2 with apache2 daemon
#!/bin/bash
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd