Skip to content

Instantly share code, notes, and snippets.

@youngsoul
youngsoul / ec2_cdk_example.py
Created March 7, 2022 19:01
CDK EC2 Instance Example
self.bastion_host = ec2.Instance(self, id=f'{resources_prefix}-bastion-host',
instance_type=ec2.InstanceType(instance_type_identifier='t2.micro'),
machine_image=ec2.AmazonLinuxImage(
edition=ec2.AmazonLinuxEdition.STANDARD,
generation=ec2.AmazonLinuxGeneration.AMAZON_LINUX_2,
virtualization=ec2.AmazonLinuxVirt.HVM,
storage=ec2.AmazonLinuxStorage.GENERAL_PURPOSE
),
vpc=self.vpc,
key_name='pryan-aws', # must create the key name manually first
@youngsoul
youngsoul / security_group_cdk.py
Created March 7, 2022 18:41
Example of CDK for security groups
self.bastion_sg = ec2.SecurityGroup(self, id=f'{resources_prefix}-bastion-sg',
security_group_name=f'{resources_prefix}-cdk-bastion-sg',
vpc=self.vpc,
description=f'{resources_prefix} SG for Bastion',
allow_all_outbound=True)
self.bastion_sg.add_ingress_rule(peer=ec2.Peer.ipv4('xxx.xxx.xxx.xx/32'), # only your machine
connection=ec2.Port.tcp(22),
description='SSH Access')
@youngsoul
youngsoul / vpc_cdk.py
Created March 7, 2022 18:36
Example CDK for a VPC
ec2.Vpc(self, id=f'{resources_prefix}-VPC',
cidr='10.40.0.0/16',
max_azs=1,
enable_dns_hostnames=True,
enable_dns_support=True,
subnet_configuration=[
ec2.SubnetConfiguration(
name="Public",
subnet_type=ec2.SubnetType.PUBLIC,
cidr_mask=24
@youngsoul
youngsoul / api_lambda_example_stack.py
Created March 4, 2022 20:51
simple example of cdk lambda/httpapi
from aws_cdk import (
Stack,
aws_apigatewayv2_alpha as api_gw,
aws_apigatewayv2_integrations_alpha as integrations,
CfnOutput,
aws_lambda_python_alpha as lambda_alpha_,
aws_lambda as _lambda
)
from constructs import Construct
@youngsoul
youngsoul / convert_tf_2_openvino.sh
Last active January 22, 2022 21:46
Script to convert a saved TF MobileNetV2 model to OpenVino and compile to .blob for use in OpenCV AI Kit ( OAK )
python -m mo --reverse_input_channels --batch 1 --mean_values \[127.5, 127.5, 127.5\] --scale_values \[127.5, 127.5, 127.5\] --saved_model_dir ./mask_detector --output_dir openvino_model
rm /Users/patrickryan/.cache/blobconverter/saved_model_openvino_2021.4_6shave.blob
blobconverter --openvino-xml ./openvino_model/saved_model.xml --openvino-bin ./openvino_model/saved_model.bin --shaves 6 --output-dir ./openvino_model --no-cache
@youngsoul
youngsoul / DepthAI_hello_world.py
Last active January 17, 2022 23:15
Example from the Luxonis DepthAI Tutorials expanded and added comments
import numpy as np # numpy - manipulate the packet data returned by depthai
import cv2 # opencv - display the video stream
import depthai # depthai - access the camera and its data packets
import blobconverter # blobconverter - compile and download MyriadX neural network blobs
"""
https://docs.luxonis.com/projects/api/en/latest/tutorials/hello_world/
Also used information from this example to pull the labels and label detections
https://docs.luxonis.com/projects/api/en/latest/samples/MobileNet/rgb_mobilenet/#rgb-mobilenetssd
@youngsoul
youngsoul / OAK-DepthAI-videostream.py
Created January 15, 2022 02:33
DepthAI-videostream.py
import cv2 # opencv - display the video stream
import depthai # depthai - access the camera and its data packets
def main():
# Create empty processing pipeline
pipeline = depthai.Pipeline()
# cam_rgb is a ColorCamera node.
# https://docs.luxonis.com/projects/api/en/latest/components/nodes/color_camera/
cam_rgb = pipeline.create(depthai.node.ColorCamera)
@youngsoul
youngsoul / DepthAI-video-stream-loop-snippet.py
Created January 15, 2022 02:30
DepthAI-video-stream-loop-snippet.py
with depthai.Device(pipeline) as device:
q_rgb = device.getOutputQueue("rgb")
frame = None
while True:
in_rgb = q_rgb.tryGet()
if in_rgb is not None:
frame = in_rgb.getCvFrame()
if frame is not None:
cv2.imshow("OAK-1", frame)
@youngsoul
youngsoul / sample_depthai_pipeline_snippet.py
Created January 15, 2022 02:27
sample_depthai_pipeline_snippet.py
# Create empty processing pipeline
pipeline = depthai.Pipeline()
# cam_rgb is a ColorCamera node.
# https://docs.luxonis.com/projects/api/en/latest/components/nodes/color_camera/
cam_rgb = pipeline.create(depthai.node.ColorCamera)
cam_rgb.setPreviewSize(400, 400)
# Set planar or interleaved data of preview output frames
cam_rgb.setInterleaved(False)
@youngsoul
youngsoul / docker-compose.yml
Last active September 16, 2021 18:50
Django / Postgres docker compose file
version: '3.8'
# .env.docker
# DATABASE_URL=postgres://postgres:postgres@db/mydb
# POSTGRES_USER=postgres
# POSTGRES_PASSWORD=postgres
# POSTGRES_DB=mydb
services:
web: