Skip to content

Instantly share code, notes, and snippets.

@youngsoul
youngsoul / GridEnvironmentQLearner.py
Created October 18, 2020 15:53
QLearner for the Grid Reinforcement learning game
import numpy as np
import matplotlib.pyplot as plt
import pickle
import time
from matplotlib import style
from GridEnvironment import GridEnvironment
import re
import argparse
import pandas as pd
@youngsoul
youngsoul / GridEnvironment.py
Last active October 18, 2020 16:06
Environment for grid based Reinforcement learning game
import numpy as np
from scipy.spatial import distance
from PIL import Image, ImageDraw, ImageFont
import cv2
import time
class BaseBlob:
game_blobs = []
wall_blobs = []
@youngsoul
youngsoul / rds_mysql_tunnel.py
Created August 30, 2020 01:17
Access AWS RDS MySql through bastion box with SSHTunnelForwarder
import datetime
# https://docs.aws.amazon.com/lambda/latest/dg/services-rds-tutorial.html
# pip install sshtunnel
from sshtunnel import SSHTunnelForwarder
# pip install pymysql
import pymysql as db
import logging
@youngsoul
youngsoul / main_tello_script.py
Created June 14, 2020 14:19
Main Tello Process Script to start other processes: See https://github.com/youngsoul/tello-sandbox.git Tello_face_tracking.py for larger context
if __name__ == '__main__':
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
run_pid = True
track_face = True # True - cause the Tello to start to track/follow a face
save_video = True
fly = True
parent_conn, child_conn = Pipe()
@youngsoul
youngsoul / show_video_process.py
Created June 14, 2020 14:16
Tello Show Video Process. See https://github.com/youngsoul/tello-sandbox.git Tello_face_tracking.py for larger context
def show_video(exit_event, pipe_conn):
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
while True:
frame = pipe_conn.recv()
# display the frame to the screen
cv2.imshow("Drone Face Tracking", frame)
cv2.waitKey(1)
if cv2.waitKey(1) & 0xFF == ord('q'):
@youngsoul
youngsoul / video_writer.py
Last active June 14, 2020 14:13
Tello Video Writer Process. See https://github.com/youngsoul/tello-sandbox.git Tello_face_tracking.py for complete context
def video_recorder(pipe_conn, save_video, height=300, width=400):
global video_writer
# create a VideoWrite object, recoring to ./video.avi
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
if video_writer is None and save_video == True:
video_file = f"video_{datetime.now().strftime('%d-%m-%Y_%I-%M-%S_%p')}.mp4"
video_writer = cv2.VideoWriter(video_file, cv2.VideoWriter_fourcc(*'MP4V'), 30, (width, height))
from djitellopy import Tello
import time
# see: https://github.com/damiafuentes/DJITelloPy
print("Create Tello object")
tello = Tello()
print("Connect to Tello Drone")
tello.connect()
@youngsoul
youngsoul / Tello_flying_process.py
Created June 14, 2020 14:03
See https://github.com/youngsoul/tello-sandbox.git file Tello_face_tracking.py for complete context
def track_face_in_video_feed(exit_event, show_video_conn, video_writer_conn, run_pid, track_face, fly=False,
max_speed_limit=40):
"""
:param exit_event: Multiprocessing Event. When set, this event indicates that the process should stop.
:type exit_event:
:param show_video_conn: Pipe to send video frames to the process that will show the video
:type show_video_conn: multiprocessing Pipe
:param video_writer_conn: Pipe to send video frames to the process that will save the video frames
:type video_writer_conn: multiprocessing Pipe
@youngsoul
youngsoul / requestUnicornTestPayload
Created May 17, 2020 17:56
Payload to use to test requestUnicorn.js
{
"path": "/ride",
"httpMethod": "POST",
"headers": {
"Accept": "*/*",
"Authorization": "eyJraWQiOiJLTzRVMWZs",
"content-type": "application/json; charset=UTF-8"
},
"queryStringParameters": null,
"pathParameters": null,
@youngsoul
youngsoul / secured_token_api.txt
Created March 12, 2020 01:33
Output from a Cognito secured API Gateway endpoint passing in a valid token.
POST https://XXX.execute-api.us-east-1.amazonaws.com/test/add-note
Content-Type: application/json
token: eyJraLVmJHQ2JXVjIwdzFxcXNOUHlqb0ZoYXUxTWZTK2k0PSIsThisTokenIsNotValidButItWasWhenWeTested
{"note":"Bring home milk"}
###
POST https://XXX.execute-api.us-east-1.amazonaws.com/test/add-note