3/06/2023

t2 ec2 instance spec and price table

 

a table with the specs and hourly prices for T2 instances as of March 2023 in the US East (N. Virginia) region:

Instance TypevCPUsMemory (GiB)Network PerformanceBaseline PerformanceCPU Credits/hrHourly Price
t2.nano10.5Low to Moderate1 vCPU for a 1h 12m burst$0.0036$0.0058
t2.micro11.0Low to Moderate1 vCPU for a 2h 24m burst$0.0072$0.0116
t2.small12.0Low to Moderate1 vCPU for a 4h 48m burst$0.0144$0.0230
t2.medium24.0Low to Moderate2 vCPUs for a 4h 48m burst$0.0287$0.0464
t2.large28.0Low to Moderate2 vCPUs for a 7h 12m burst$0.0575$0.0928
t2.xlarge416.0Moderate4 vCPUs for a 5h 24m burst$0.1150$0.1856
t2.2xlarge832.0Moderate8 vCPUs for a 4h 4.8m burst$0.2300$0.3712

Note that the prices and specifications may vary depending on the region and other factors.


www.marearts.com

🙇🏻‍♂️

3/03/2023

run shell script in parallel and kill all shell when it stop

 refer to shell script



.

#!/bin/bash

# Run each script in the background
./loop_invocations.sh &
./loop_invocations.sh &
./loop_invocations.sh &
./loop_invocations.sh &

./loop_ping.sh &

# Define a function to kill all child processes
function kill_children {
echo "Stopping all child processes..."
pkill -P $$
exit 0
}

# Trap the SIGINT signal and call the function to kill child processes
trap kill_children SIGINT

# Wait for all background jobs to complete
wait

..




In this example, the kill_children function uses pkill to find and kill all child processes of the current process. The $$ variable represents the PID of the current process. The trap command sets up a handler for the SIGINT signal that calls the kill_children function. When the script is stopped with CTRL+C, the kill_children function is called, which kills all child processes before exiting the script.




Thank you.

www.marearts.com

3/01/2023

Folder existing check in s3 bucket, python example code

Check folder exist in s3 bucket

refer to code:

.

import boto3
import botocore.exceptions

s3 = boto3.client('s3')
bucket_name = 'your-bucket-name'
folder_path = 'f1/f2/f3/f4/'

try:
response = s3.list_objects_v2(Bucket=bucket_name, Prefix=folder_path)
if 'Contents' in response or 'CommonPrefixes' in response:
print(f"Folder {folder_path} exists in bucket {bucket_name}")
else:
print(f"Folder {folder_path} does not exist in bucket {bucket_name}")
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == "NoSuchBucket":
print(f"Bucket {bucket_name} does not exist")
else:
raise

..


thank you

🙇🏻‍♂️

www.marearts.com

2/27/2023

Useful Docker Commands: List, Stop, Remove, Logs, Build, Push, Pull, and Delete Images

 

refer to cmd


.

# List all running containers
docker ps

# List all containers, including stopped ones
docker ps -a

# Stop a running container
docker stop <container-id>

# Remove a stopped container
docker rm <container-id>

# View logs from a container
docker logs <container-id>

# Execute a command in a running container
docker exec <container-id> <command>

# Build an image from a Dockerfile
docker build -t <image-name> <path-to-dockerfile>

# Push an image to a Docker registry
docker push <registry>/<image-name>

# Pull an image from a Docker registry
docker pull <registry>/<image-name>

# Remove all Docker images using prune option
docker image prune -a -f

..


Thank you.

🙇🏻‍♂️

www.marearts.com

Uploading Multiple Files to a Flask API using cURL example code

refer to code:


curl cmd.

.

curl -X POST -H "Content-Type: multipart/form-data" -H "Content-Type: application/json" -F 'data=@data.json;type=application/json' -H "Content-Type: image/jpeg" -F 'image=@image.jpg;type=image/jpeg' http://your-api-url.com/your-endpoint

..


flask code

.

from flask import Flask, request
import json

app = Flask(__name__)

@app.route('/your-endpoint', methods=['POST'])
def handle_upload():
if 'data' not in request.files:
return 'No data file uploaded', 400
if 'image' not in request.files:
return 'No image file uploaded', 400
data_file = request.files['data']
image_file = request.files['image']
if data_file.content_type != 'application/json':
return 'Invalid data file format', 400
if not is_valid_image_type(image_file.content_type):
return 'Invalid image file format', 400
# read the JSON data from the file
data = json.load(data_file)
# read the image data from the file
image_data = image_file.read()
# do something with the file data
return 'File upload successful'

def is_valid_image_type(content_type):
valid_image_types = ['image/jpeg', 'image/png', 'image/gif']
return content_type in valid_image_types

..


In this updated cURL command, the content type headers for the request and each file are specified using multiple -H flags. The Content-Type header for the request is set to multipart/form-data, which is the required encoding for file uploads. The content type for the JSON file is set to application/json, and the content type for the image file is set to image/jpeg. Note that you should adjust the content types as needed for your specific file formats.

With these changes, you should be able to upload a JSON file and an image file to your Flask API using cURL. The uploaded files will be checked for errors in the API code and then processed as needed.


Than you.

🙇🏻‍♂️

www.marearts.com

save tokeniser from AutoTokenizer, AutoProcessor

 refer to code:

.

from transformers import AutoTokenizer, AutoProcessor

model_name_or_path = 'nielsr/layoutlmv3-finetuned-funsd'
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
processor = AutoProcessor.from_pretrained(model_name_or_path)

# Save tokenizer
tokenizer.save_pretrained('tokenizer_dir')

# Save processor
processor.save_pretrained('processor_dir')

..


🙇🏻‍♂️

www.marearts.com

2/26/2023

split filename and dir using os.path.split

 refer to code


.

import os

path = '/Users/source_code/final_data/test/X51006647933.jpg'

# Split the path into directory name and file name
dirname, filename = os.path.split(path)

# Print the file name
print(filename) # Output: X51006647933.jpg

..


Thank you.

🙇🏻‍♂️

www.marearts.com