From c7fd1da457443614b6c46f289d19ff58f711ddd8 Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Wed, 20 Mar 2024 00:21:51 +0300 Subject: [PATCH 1/4] AppImage example --- projects/AppImage/.gitignore | 2 ++ projects/AppImage/MyApp.AppDir/AppRun | 5 +++ projects/AppImage/MyApp.AppDir/myapp.desktop | 6 ++++ projects/AppImage/README.md | 0 projects/AppImage/build.sh | 9 ++++++ projects/AppImage/example_app.c | 34 ++++++++++++++++++++ 6 files changed, 56 insertions(+) create mode 100644 projects/AppImage/.gitignore create mode 100755 projects/AppImage/MyApp.AppDir/AppRun create mode 100644 projects/AppImage/MyApp.AppDir/myapp.desktop create mode 100644 projects/AppImage/README.md create mode 100755 projects/AppImage/build.sh create mode 100644 projects/AppImage/example_app.c diff --git a/projects/AppImage/.gitignore b/projects/AppImage/.gitignore new file mode 100644 index 0000000..10d8a1c --- /dev/null +++ b/projects/AppImage/.gitignore @@ -0,0 +1,2 @@ +MyApp.AppDir/usr/bin/myapp +MyApp.AppDir/myapp.svg diff --git a/projects/AppImage/MyApp.AppDir/AppRun b/projects/AppImage/MyApp.AppDir/AppRun new file mode 100755 index 0000000..b5fcf21 --- /dev/null +++ b/projects/AppImage/MyApp.AppDir/AppRun @@ -0,0 +1,5 @@ +#!/bin/sh + +touch ~/ololo.names + +$APPDIR/usr/bin/myapp diff --git a/projects/AppImage/MyApp.AppDir/myapp.desktop b/projects/AppImage/MyApp.AppDir/myapp.desktop new file mode 100644 index 0000000..73aaf9e --- /dev/null +++ b/projects/AppImage/MyApp.AppDir/myapp.desktop @@ -0,0 +1,6 @@ +[Desktop Entry] +Name=MyApp +Exec=myapp +Icon=myapp +Type=Application +Categories=Utility; diff --git a/projects/AppImage/README.md b/projects/AppImage/README.md new file mode 100644 index 0000000..e69de29 diff --git a/projects/AppImage/build.sh b/projects/AppImage/build.sh new file mode 100755 index 0000000..72d08cf --- /dev/null +++ b/projects/AppImage/build.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +# build executable +tcc example_app.c -lGL -lglfw -o MyApp.AppDir/usr/bin/myapp + +# build icon +# ICON=MyApp.AppDir/myapp.png +# [ ! -f $ICON ] && convert /usr/share/icons/breeze/apps/48/smartgit.svg -transparent white $ICON +cp /usr/share/icons/breeze/apps/48/smartgit.svg MyApp.AppDir/myapp.svg diff --git a/projects/AppImage/example_app.c b/projects/AppImage/example_app.c new file mode 100644 index 0000000..3762e30 --- /dev/null +++ b/projects/AppImage/example_app.c @@ -0,0 +1,34 @@ +#include + +int main(void) { + GLFWwindow *window; + + /* Initialize the library */ + if (!glfwInit()) + return -1; + + /* Create a windowed mode window and its OpenGL context */ + window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL); + if (!window) { + glfwTerminate(); + return -1; + } + + /* Make the window's context current */ + glfwMakeContextCurrent(window); + + /* Loop until the user closes the window */ + while (!glfwWindowShouldClose(window)) { + /* Render here */ + glClear(GL_COLOR_BUFFER_BIT); + + /* Swap front and back buffers */ + glfwSwapBuffers(window); + + /* Poll for and process events */ + glfwPollEvents(); + } + + glfwTerminate(); + return 0; +} From afcda274175d7ebb99e4153254c9c2e72b14614f Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Wed, 20 Mar 2024 00:23:02 +0300 Subject: [PATCH 2/4] Check SSL details --- code/Python/ssl_expiry_datetime.py | 50 ++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 code/Python/ssl_expiry_datetime.py diff --git a/code/Python/ssl_expiry_datetime.py b/code/Python/ssl_expiry_datetime.py new file mode 100644 index 0000000..6b8102f --- /dev/null +++ b/code/Python/ssl_expiry_datetime.py @@ -0,0 +1,50 @@ +""" +https://stackoverflow.com/questions/41620369/how-to-get-ssl-certificate-details-using-python +""" + + +import socket +import ssl +import datetime + +domains = [ + 'iiiypuk.me', + 'a2s.su', + 'ya.ru' +] + + +def ssl_expiry_datetime(hostname): + ssl_dateformat = r'%b %d %H:%M:%S %Y %Z' + + context = ssl.create_default_context() + context.check_hostname = False + + conn = context.wrap_socket( + socket.socket(socket.AF_INET), + server_hostname=hostname, + ) + + # 5 second timeout + conn.settimeout(5.0) + + conn.connect((hostname, 443)) + ssl_info = conn.getpeercert() + + # Python datetime object + return datetime.datetime.strptime(ssl_info["notAfter"], ssl_dateformat) + + +if __name__ == "__main__": + for value in domains: + now = datetime.datetime.now() + try: + expire = ssl_expiry_datetime(value) + diff = expire - now + print( + "Domain name: {} Expiry Date: {} Expiry Day: {}".format( + value, expire.strftime("%Y-%m-%d"), diff.days + ) + ) + except Exception as e: + print(e) From 813b58a4b09b5fbdb8d8aef7a1ae995bb1ed691c Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Wed, 20 Mar 2024 00:27:28 +0300 Subject: [PATCH 3/4] CV: Camera->RTMP --- projects/CV/CapToRTMP/__main__.py | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 projects/CV/CapToRTMP/__main__.py diff --git a/projects/CV/CapToRTMP/__main__.py b/projects/CV/CapToRTMP/__main__.py new file mode 100644 index 0000000..5d86e4c --- /dev/null +++ b/projects/CV/CapToRTMP/__main__.py @@ -0,0 +1,42 @@ +import subprocess +import cv2 +rtmp_url = "rtmp://127.0.0.1:1935/stream/pupils_trace" + +# In my mac webcamera is 0, also you can set a video file name instead, for example "/home/user/demo.mp4" +path = 0 +cap = cv2.VideoCapture(path) + +# gather video info to ffmpeg +fps = int(cap.get(cv2.CAP_PROP_FPS)) +width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) +height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) + +# command and params for ffmpeg +command = ['ffmpeg', + '-y', + '-f', 'rawvideo', + '-vcodec', 'rawvideo', + '-pix_fmt', 'bgr24', + '-s', "{}x{}".format(width, height), + '-r', str(fps), + '-i', '-', + '-c:v', 'libx264', + '-pix_fmt', 'yuv420p', + '-preset', 'ultrafast', + '-f', 'flv', + rtmp_url] + +# using subprocess and pipe to fetch frame data +p = subprocess.Popen(command, stdin=subprocess.PIPE) + + +while cap.isOpened(): + ret, frame = cap.read() + if not ret: + print("frame read failed") + break + + # YOUR CODE FOR PROCESSING FRAME HERE + + # write to pipe + p.stdin.write(frame.tobytes()) From 22e024ab90fc8636b463c62888f65e707d60c177 Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Wed, 20 Mar 2024 00:28:23 +0300 Subject: [PATCH 4/4] CHANGES :) --- projects/Python/OpenCV_to_HTML/motion_detection.py | 3 +-- projects/Python/OpenCV_to_HTML/templates/index.html | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/projects/Python/OpenCV_to_HTML/motion_detection.py b/projects/Python/OpenCV_to_HTML/motion_detection.py index cfc0253..b881b8b 100644 --- a/projects/Python/OpenCV_to_HTML/motion_detection.py +++ b/projects/Python/OpenCV_to_HTML/motion_detection.py @@ -47,6 +47,5 @@ class SingleMotionDetector: (x, y, w, h) = cv2.boundingRect(c) (minX, minY) = (min(minX, x), min(minY, y)) (maxX, maxY) = (max(maxX, x + w), max(maxY, y + h)) - # otherwise, return a tuple of the thresholded image along - # with bounding box + # otherwise, return a tuple of the thresholded image along with bounding box return (thresh, (minX, minY, maxX, maxY)) diff --git a/projects/Python/OpenCV_to_HTML/templates/index.html b/projects/Python/OpenCV_to_HTML/templates/index.html index ea195cb..2675c52 100644 --- a/projects/Python/OpenCV_to_HTML/templates/index.html +++ b/projects/Python/OpenCV_to_HTML/templates/index.html @@ -23,7 +23,7 @@

OpenCV – Stream video to web browser/HTML page

- +