Saturday, November 18, 2023

GIT stash and POP

 Best way to keep git changes without commiting.

1) git stash


To get back changes:

2) git stash pop



Wednesday, October 25, 2023

Thursday, October 19, 2023

letsencrypt manual certificate creation

 sudo certbot certonly  --manual -d domain name --preferred-challenges dns


create .well-known folder and create acme-server folder inside it


Use --preferred-challenges dns if dns validation are needed.


copy below cerificates

/etc/letsencrypt/live/domain/fullchain.pem

/etc/letsencrypt/live/domain/privkey.pem

Wednesday, October 18, 2023

Friday, October 6, 2023

Load testing with locust

 pip install locust

create file locustfile.py

start with locust

open web using : 

http://localhost:8089/


Sample user file:

from locust import HttpUser, task

class LoadUser(HttpUser):
@task
def load(self):
self.client.get("/sleep_30/")

Deploy Gunicorn using PM2

 Use below command:

 pm2 --name=py-api start "cd ~/code/python_tasks && source venv/bin/activate && cd api && gunicorn -k gevent app:app -b 0.0.0.0:5050 -w 2 --error-logfile /var/log/gunicorn/error.log --access-logfile /var/log/gunicorn/access.log --capture-output --log-level debug"

Monday, September 18, 2023

SVG to JSX converter

 use:

https://svg2jsx.com/


It will convert svg to JSX for react


How to edit SVG?

use: https://boxy-svg.com/

Friday, September 8, 2023

Script to build and launch Spring boot

 cd webapp

config="dev"

JVMMaxHeapSize="1512"

echo "Parameter passed to run the server for $config configuration"

echo "Max heap size defined $JVMMaxHeapSize MB "

mvn clean install "-Dhk.conf=$config" "-Dhk.jvm.memory=$JVMMaxHeapSize"

cd ..

cd sb-web

#mvn -e -X exec:exec "-Dhk.conf=$config" "-Dhk.jvm.memory=$JVMMaxHeapSize" -Dgpg.skip

./mvnw spring-boot:run

cd ..

sample s3 policies

 {

    "Version": "2012-10-17",

    "Statement": [

        {

            "Sid": "PublicReadGetObject",

            "Effect": "Allow",

            "Principal": "*",

            "Action": "s3:GetObject",

            "Resource": "arn:aws:s3:::bn/*"

        }

    ]

}


cors:

[

    {

        "AllowedHeaders": [

            "*"

        ],

        "AllowedMethods": [

            "GET",

            "PUT",

            "POST",

            "DELETE"

        ],

        "AllowedOrigins": [

            "*"

        ],

        "ExposeHeaders": [

            "ETag"

        ]

    }

]


{

    "Version": "2012-10-17",

    "Statement": [

        {

            "Sid": "PublicReadGetObject",

            "Effect": "Allow",

            "Principal": "*",

            "Action": "s3:GetObject",

            "Resource": "arn:aws:s3:::bn/*",

            "Condition": {

                "StringLike": {

                    "aws:Referer": "https://*.x.com/*"

                }

            }

        },

        {

            "Sid": "PublicReadGetObject2",

            "Effect": "Allow",

            "Principal": {

                "AWS": "arn:aws:iam::7788:user/suser"

            },

            "Action": "s3:GetObject",

            "Resource": "arn:aws:s3:::bn/*",

            "Condition": {}

        }

    ]

}

Thursday, August 10, 2023

Tuesday, June 27, 2023

Keep Python package requirements using requirements.txt

 Use pip freeze > requirements.txt to save pip package list.


Use pip install -r requirements.txt to install packages from requirements.txt


Note: Alway run python scripts from venv (Virtual Environment)

Tuesday, March 21, 2023

Using Python with MongoDB transaction

 import math

import sys

mgc=getMongoConnection()
mgd=mgc.DB
tcoll=mgd.testcoll
with mgc.start_session() as session:

with session.start_transaction():
test_obj = {'test1': True, 'date': datetime.now()}
tcoll.insert_one(test_obj,session=session)
test_obj = {'test2': True, 'date': datetime.now()}
y=1/0
tcoll.insert_one(test_obj,session=session)
session.commit_transaction()

Friday, February 24, 2023

How to fix Data label not showing issue in React recharts

 How to fix Data label not showing issue in React recharts


Answer: Disable Animation


<Bar isAnimationActive={false}></Bar>

Monday, February 20, 2023