"No one is harder on a talented person than the person themselves" - Linda Wilkinson ; "Trust your guts and don't follow the herd" ; "Validate direction not destination" ;
Showing posts with label Flask. Show all posts
Showing posts with label Flask. Show all posts

November 07, 2023

REST APIs











Code Review Checklist

The rules are:

𝟭. 𝗔𝘃𝗼𝗶𝗱 𝗖𝗼𝗺𝗽𝗹𝗲𝘅 𝗙𝗹𝗼𝘄: Steer clear of tricky control structures; stick to simple loops and conditionals.

𝟮. 𝗕𝗼𝘂𝗻𝗱 𝗟𝗼𝗼𝗽𝘀: Ensure loops have a clear exit point to prevent endless looping.

𝟯. 𝗔𝘃𝗼𝗶𝗱 𝗛𝗲𝗮𝗽 𝗔𝗹𝗹𝗼𝗰𝗮𝘁𝗶𝗼𝗻: Favor stack or static memory allocation to dodge memory leaks.

𝟰. 𝗨𝘀𝗲 𝗦𝗵𝗼𝗿𝘁 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝘀: Keep functions concise, handling a single task. This goes along well with Clean Code practices (Signe responsibility principle).

𝟱. 𝗥𝘂𝗻𝘁𝗶𝗺𝗲 𝗔𝘀𝘀𝗲𝗿𝘁𝗶𝗼𝗻𝘀: Utilize assertions to catch unexpected conditions.

𝟲. 𝗟𝗶𝗺𝗶𝘁𝗲𝗱 𝗗𝗮𝘁𝗮 𝗦𝗰𝗼𝗽𝗲: Keep the scope narrow to maintain clarity. Use the smallest scope for your variables (e.g., private or protected in C#).

𝟳. 𝗖𝗵𝗲𝗰𝗸 𝗥𝗲𝘁𝘂𝗿𝗻 𝗩𝗮𝗹𝘂𝗲𝘀: Always check the return values of functions, handling any errors.

𝟴. 𝗦𝗽𝗮𝗿𝘀𝗲 𝗣𝗿𝗲𝗽𝗿𝗼𝗰𝗲𝘀𝘀𝗼𝗿 𝗨𝘀𝗲: Minimize preprocessor directives for readability.

𝟵. 𝗟𝗶𝗺𝗶𝘁 𝗣𝗼𝗶𝗻𝘁𝗲𝗿 𝗨𝘀𝗲: Simplify pointer use and avoid function pointers for clearer code.

𝟭𝟬. 𝗖𝗼𝗺𝗽𝗶𝗹𝗲 𝗪𝗶𝘁𝗵 𝗔𝗹𝗹 𝗪𝗮𝗿𝗻𝗶𝗻𝗴𝘀 𝗘𝗻𝗮𝗯𝗹𝗲𝗱: Address all compiler warnings to catch potential issues early. This is often neglected in many projects!

Coding Guidelines

How I spend my time as a developer:

  • 10% writing code
  • 20% refactoring
  • 70% reading code

This is why I optimize my code for readability while still in the writing stage.

It always pays off in the long run.

And I know the next engineer reading that code will be thankful.

So think about this next time you're hurrying to finish a task.

Here's a checklist in no particular order:

  • Variables defined close to where they are used
  • Fluent syntax structured vertically
  • Names are descriptive
  • 80 characters per line
  • Early return principle

Keep Exploring!!!

February 10, 2023

EC2 - AWS Flask Deployment Example

Deploying Sample API code 


Creating an EC2 Free t2 instance

Basic Ubuntu


Allow Access


Save Public IP

Launch Instance


Run Updated Packages and the below commands



Ref - Simplified code example Link

Allow Access to Port 80. HTTP




Run from browser and access APIs

Keep Exploring!!!

January 25, 2023

Docker Custom Examples

Some minor fixes working with git project


Keep Exploring!!!

Best practice for container-based deployment system 

  • Use a container-orchestration system such as Kubernetes or Docker Swarm to manage and deploy your containers.
  • Use a container registry such as Docker Hub or Quay to store and manage your container images.
  • Use a continuous integration system such as Jenkins or Travis CI to automate the build and deployment of your containers.
  • Monitor your containers and applications using tools such as Prometheus or Grafana to ensure they are running optimally.
  • Use a service mesh such as Istio or Linkerd to manage the communication between your services.
  • Use a logging and monitoring system such as ELK or Splunk to track the performance of your containers and applications.
  • Use a security scanning tool such as Twistlock or Aqua Security to ensure your containers are secure.
  • Use a configuration management system such as Ansible or Chef to manage the configuration of your containers.
  • Use a deployment automation tool such as Helm or Terraform to automate the deployment of your containers.
  • Use a cloud provider such as Amazon Web Services or Google Cloud Platform to host your containers.

Keep Exploring!!!

October 16, 2020

Examples Flask vs Fast API

Recently FastAPI I could see more posts/recommendations compared to flask API in a performance context. A basic example of implementation with flask vs Fast API. The format  /syntax, request differences you can spot by comparing them.




CI / CD

DevOps with Github






Makefile


Happy Learning!!!

April 10, 2018

Day #103 - Hosting a flask Rest API

This post is on hosting a flask / rest API. This requires flask package. In Python 3.4 It was straight forward implementation

To execute run the code in python console - python example_gist.py



The following links were useful
link1, link2, chromeextension



Happy Learning!!!