Skip to content

Instantly share code, notes, and snippets.

@youngsoul
youngsoul / run-webots.sh
Created April 15, 2024 12:25
shell script to activate python virtual env, before starting Webots
source venv/bin/activate
/Applications/Webots.app/Contents/MacOS/Webots
@youngsoul
youngsoul / libsvm_to_csv.py
Created October 25, 2023 17:19
read libsvm files and create csv files from them
from typing import Tuple
import pandas as pd
def read_libsvm_file(filename) -> Tuple[list[dict], set]:
data = [] # array of json records
unique_columns = set()
with open(filename, "r") as f:
@youngsoul
youngsoul / rect-hotspot.py
Last active August 22, 2023 02:34
used to create rectangular hotspots on an image
'''
This script will allow one to draw rectangles on an image and upon mouse release it will print the
upper left corner (x,y) and the lower right corner (x,y) values along with the scaled values.
usage: python rect-hotspot.py --image-path ../images/8x8matrix_expansion.png --width 600 --show-hotspots
usage:
python rect-hotspot.py --read-only --image ../images/8x8matrix_expansion.png --width 600 --show-hotspots --filename 8x8-matrix-hotspots.csv
@youngsoul
youngsoul / montyhall.py
Created May 30, 2023 16:51
Monty Hall Simulator
import random
"""
Monty Hall Simulation
"""
if __name__ == '__main__':
switch_win_count = 0
for i in range(0,1000):
@youngsoul
youngsoul / python_gitignore
Created May 3, 2023 13:38
gitignore file for python projects
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
@youngsoul
youngsoul / Makefile
Created April 24, 2023 20:49
Docker Makerfile
# @ suppresses the normal 'echo' of the command that is executed.
# - means ignore the exit status of the command that is executed (normally, a non-zero exit status would stop that part of the build).
# + means 'execute this command under make -n' (or 'make -t' or 'make -q') when commands are not normally executed.
# Containers ids, name is the container name in the docker-compose file
db-id=$(shell docker ps -q -f "name=particle-dashboard-db-container" | head -n 1)
web-id=$(shell docker ps -q -f "name=particle-dashboard-web-container" | head -n 1)
show-ids:
@echo "web container id: " $(web-id)
@youngsoul
youngsoul / grant_lambda_secrets_read.py
Created March 11, 2022 22:46
Grant Lambda secrets read permission
# give the lambda read access to the secrets manager
db_credentials_secret.grant_read(lb1)
@youngsoul
youngsoul / httpapi_cdk_example.py
Created March 11, 2022 22:41
HttpApi CDK Example
api = api_gw.HttpApi(self, f'{resource_prefix}-Test API Lambda',
default_integration=integrations.HttpLambdaIntegration(id="lb1-lambda-proxy",
handler=lb1))
@youngsoul
youngsoul / lambda_cdk_example.py
Created March 11, 2022 22:30
Lambda CDK Example
lb1 = lambda_alpha_.PythonFunction(self, f"{resource_prefix}-function",
entry="./rds_lambda",
index="rds_lambda.py",
handler="lambda_handler",
runtime=_lambda.Runtime.PYTHON_3_9,
vpc=vpc,
vpc_subnets=ec2.SubnetSelection(
subnet_type=ec2.SubnetType.PRIVATE_WITH_NAT
),
security_groups=[
bastion_host = ec2.Instance(self, id=f'{resource_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=vpc,
key_name='pryan-aws', # must create the key name manually first