Skip to content

Instantly share code, notes, and snippets.

View mrtj's full-sized avatar

Janos Tolgyesi mrtj

View GitHub Profile
@mrtj
mrtj / stream_to_s3.py
Last active March 28, 2024 04:18
Download a file and stream it directly to an #aws S3 bucket without saving it locally
#!/usr/bin/env python3
import boto3
import requests
import tqdm
from urllib.parse import urlparse
def stream_to_s3(
source_url,
target_url,
@mrtj
mrtj / test-launch.py
Last active November 18, 2023 17:51
Python port of GStreamer RTSP Server test-launch.c
import gi
gi.require_version('Gst', '1.0')
gi.require_version('GstRtspServer', '1.0')
from gi.repository import GLib, Gst, GstRtspServer
Gst.init(None)
import argparse
parser = argparse.ArgumentParser(description='GStreamer RTSP server test-launch')
@mrtj
mrtj / aws_iot_direct_call.py
Created September 30, 2020 15:25
Call any AWS service directly using the credentials of AWS IoT device certificate
'''
A snippet demonstrating how an AWS IoT device can make direct calls to every AWS
service using only the device certificate and private key.
For more info see the docs at https://docs.aws.amazon.com/iot/latest/developerguide/authorizing-direct-aws.html
to create the role and the role alias. To get the AWS IoT credential provider endpoint of your account you can use
$ aws iot describe-endpoint --endpoint-type iot:CredentialProvider
Dependencies: requests and boto3
@mrtj
mrtj / backpack-annotation-example.py
Last active June 20, 2022 20:56
Example usage of backpack.annotation module
import panoramasdk
from backpack.annotation import (
Point, LabelAnnotation, RectAnnotation, TimestampAnnotation,
OpenCVImageAnnotationDriver,
PanoramaMediaAnnotationDriver
)
class Application(panoramasdk.node):
def __init__(self):
@mrtj
mrtj / kvsskyline-usage.py
Last active June 20, 2022 20:55
Example usage of backpack.kvs.KVSSkyLine class
import panoramasdk
from backpack.kvs import KVSSkyLine, KVSFileCredentialsHandler
# You might want to read these values from Panorama application parameters
stream_region = 'us-east-1'
stream_name = 'panorama-video'
# The example Dockerfile writes static configuration variables to this file
# If you change the .env file path in the Dockerfile, you should change it also here
DOTENV_PATH = '/panorama/.env'
import functools
def lazy_property(func):
''' Caches the return value of a function, and turns it into a property.
Intended to be used as a function decorator::
>>> class Foo:
>>> @lazy_property
>>> def bar(self):
@mrtj
mrtj / parse_telegram_export.py
Last active April 7, 2022 10:10
Parse the html export of a Telegram chat
''' The parse_telegram_export function in this gist parses the html export of a Telegram chat.
You should have [BeautifulSoup](https://www.crummy.com/software/BeautifulSoup/bs4/) and
[dateutil](https://dateutil.readthedocs.io/) installed. It extracts the sender name, the
message date and time, the message text and the links in the message.
'''
from bs4 import BeautifulSoup
import dateutil
def parse_telegram_export(html_str, tz_name=None):
@mrtj
mrtj / local_ref.py
Last active March 13, 2022 14:07
Use local references in jsonschema python package
import os
import json
from pathlib import Path
from urllib.parse import urljoin
import jsonschema
def add_local_schemas_to(resolver, schema_folder, base_uri, schema_ext='.schema.json'):
''' Add local schema instances to a resolver schema cache.
class Application(panoramasdk.node):
# ...
def process_media(self, stream):
image_data, ratio = self.preprocess(stream.image, self.MODEL_INPUT_SIZE)
inference_results = self.call(
{self.MODEL_INPUT_NAME: image_data}, self.MODEL_NODE
)
self.process_results(inference_results, stream, ratio)