Skip to content

Instantly share code, notes, and snippets.

@qtangs
qtangs / terraform_state_cloudformation_template.yml
Created November 21, 2020 13:12
CloudFormation Template for creating S3 bucket and DynamoDB table to hold Terraform state and locks
View terraform_state_cloudformation_template.yml
AWSTemplateFormatVersion: 2010-09-09
Description: >
Template for creating S3 bucket and DynamoDB table to hold Terraform state and locks
Validate: aws cloudformation validate-template --template-body file://terraform_state.yml
Deploy: aws cloudformation create-stack --region us-east-1 --stack-name Terraform-State-Resources --enable-termination-protection --template-body file://terraform_state.yml --parameters ParameterKey=TerraformStateBucketPrefix,ParameterValue=terraform-state ParameterKey=TerraformStateLockTableName,ParameterValue=terraform-state-locks
Parameters:
TerraformStateBucketPrefix:
Type: String
Default: terraform-state
Description: A prefix for S3 bucket name, account id will be added to ensure global uniqueness
View flow_schema.json
{
"$schema": "http://json-schema.org/draft-06/schema#",
"$ref": "#/definitions/Flow",
"definitions": {
"Flow": {
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"type": "string"
@qtangs
qtangs / get_layer_packages.sh
Last active August 21, 2021 02:51
Get packages for AWS Lambda Layer
View get_layer_packages.sh
#!/bin/bash
export PKG_DIR="python"
rm -rf ${PKG_DIR} && mkdir -p ${PKG_DIR}
docker run --rm -v $(pwd):/foo -w /foo lambci/lambda:build-python3.6 \
pip install -r requirements.txt --no-deps -t ${PKG_DIR}
@qtangs
qtangs / challenges.md
Created June 10, 2020 02:51
2020 Code Challenges
View challenges.md

Problem #1 (Kubernetes)

We will be using kubernetes to manage our containers, and we need to know how basic kubernetes objects work, and how to provision them.

Challenge

Write the k8 config required to deploy a basic nginx webserver with this image nginxdemos/hello, using minikube to provision your cluster control plane.

Your resulting created objects should look similar to the likes of the below:

NAME                                     READY   STATUS    RESTARTS   AGE
pod/nginx-hello-world-84c67f76c4-4g5sd   1/1     Running   0          6s
@qtangs
qtangs / hello_world.sh
Last active March 15, 2020 09:17
Covid 19 Dashboard hello_world.sh
View hello_world.sh
python -c '''
import dash; import dash_html_components as html; app = dash.Dash(); app.layout=html.H1("Yay! It works!"); app.run_server()
'''
@qtangs
qtangs / setup.sh
Last active March 15, 2020 09:07
Covid 19 Dashboard setup.sh
View setup.sh
cd covid-19-dashboard
python -m venv venv # or python3 -m venv venv
source venv/bin/activate
pip list # ensure that only pip and setuptools are listed
echo "dash==1.9.1" > requirements.txt
pip install -r requirements.txt
@qtangs
qtangs / file_structure.txt
Last active March 12, 2020 16:52
Covid 19 Dashboard file_structure.txt
View file_structure.txt
covid-19-dashboard
|_ dashboard
|_ assets
|_ data
|_ model.py
|_ view.py
|_ controller.py
|_ app.py
|_ .gitignore
|_ Procfile
@qtangs
qtangs / run_app.sh
Created March 12, 2020 15:26
Covid 19 Dashboard run_app.sh
View run_app.sh
python app.py
### Output:
Running on http://127.0.0.1:8050/
Debugger PIN: 853-611-907
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
Running on http://127.0.0.1:8050/
@qtangs
qtangs / app.py
Last active March 12, 2020 15:18
Covid 19 Dashboard app.py
View app.py
import dash
import dash_core_components as dcc
import dash_html_components as html
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div(children=[
html.H1(children='Hello Dash'),
View clean_covid_19_data.py
import pandas as pd
COUNTRY_COLUMN = "Country/Region"
LOCATION_COLUMN = "Location"
DATE_COLUMN = "Date"
TYPE_COLUMN = "Type"
INFECTED_COLUMN = "Infected"
RECOVERED_COLUMN = "Recovered"
DEATHS_COLUMN = "Deaths"
CURRENT_COLUMN = "Current"