Friday, 12 July 2024

python docker deployment

Run comand

 

 FROM python:3.9-slim
WORKDIR /app
COPY ai-quiz-service/requirements.txt .
COPY config/dev.env /app/.env
RUN pip install --no-cache-dir -r requirements.txt
COPY app/ app/
ENV PYTHONPATH=/app
EXPOSE 8088
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8088"]

 

docker build --build-arg ENV_FILE=app/config/dev.env -t myfastapi:dev .


# Use an official Python runtime as a parent image
FROM python:3.10

# Set the working directory in the container
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

# Define build argument for the environment file
ARG ENV_FILE

# Copy the environment file from the build context to the container
COPY ${ENV_FILE} /app/.env

# Make port 80 available to the world outside this container
EXPOSE 8088

# Ensure the PYTHONPATH includes the /app directory
ENV PYTHONPATH=/app

# Run app.py when the container launches
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8088"]
 

 

 

 

Friday, 21 June 2024

git pull not working

 hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint:
hint:   git config pull.rebase false  # merge (the default strategy)
hint:   git config pull.rebase true   # rebase
hint:   git config pull.ff only       # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: Need to specify how to reconcile divergent branches.

git config pull.rebase false

Wednesday, 19 June 2024

Maximum number of request handled by springboot appliation

 https://medium.com/@haiou-a/spring-boot-how-many-requests-can-spring-boot-handle-simultaneously-a57b41bdba6a

 

 

Concurrent Request Handling

Therefore, we conclude: By default, the number of requests that Spring Boot can handle simultaneously = maximum connections (8192) + maximum waiting number (100), resulting in 8292.

 

Java equals() and hash() example

 

public class TrophyCalculationPayload {
private List<Integer> playerIds;
private Integer companyId;
private Integer gameId;
private String gameType;
private Integer point;
private Integer time;
private Integer highScore;
private Integer gameSessionId;
private String timeZone;
private Integer servedQuestionCount;
private Integer correctAnswerCount;

@Override
public boolean equals(Object other) {
if (this == other) {
System.out.println("first if");
return true;
}
if (other == null || getClass() != other.getClass()) {
System.out.println("second if");
return false;
}

TrophyCalculationPayload otherPayload = (TrophyCalculationPayload) other;

if( Objects.equals(companyId, otherPayload.companyId) &&
Objects.equals(gameId, otherPayload.gameId)) {
System.out.println("third if");
}
return true;
}

@Override
public int hashCode() {
return Objects.hash(companyId, gameId);
}
}
 
 public static void main(String[] args) {
TrophyCalculationPayload payload= new TrophyCalculationPayload(Arrays.asList(1,2,3),1,1,"game",1,1,1,1,"tz",1,1);
TrophyCalculationPayload payload1=new TrophyCalculationPayload(Arrays.asList(1,2,3),1,1,"game",1,1,1,1,"tz",1,1);
TrophyCalculationPayload payload3=payload1;
String name="pawan";
String name1="pawan";

String name2=new String("pawan");
String name3=new String("pawan");
System.out.println("--------"+ (name==name1));
System.out.println("--------"+ name.equals(name1));
System.out.println("--------"+name2.equals(name3));
System.out.println("--------"+name.equals(name1));
System.out.println("--------"+name1.equals(name));
//
System.out.println("--------"+payload.equals(payload1));
System.out.println("--------"+payload1.equals(payload3));
System.out.println("----payload----"+payload.hashCode());
System.out.println("----payload1----"+payload1.hashCode());
 
 Note In string class equals() method overided to compare compare content 
 But Object class equals() method overided to compare references.
 
 So when we compare 
 System.out.println("--------"+ name.equals(name1));
 
it retuns true;
but when compare User defined class then it return false,because  equals()
default overided behavior is to compare object references.


 


 
 
 
 
 

Saturday, 25 May 2024

Interview question java practical

Take a string and remove duplicate chars.


 import java.util.stream.Collectors;

public class Main {

  public static void main(String[] args) {

    System.out.println("Hello world!");

    String myName="pawan";

    String removedname=removeDuplicates(myName);

      System.out.println(removedname);

    

  }

  public static String removeDuplicates(String str) {

      // Convert the string to a stream of characters, remove duplicates and collect back to a string

      return str.chars()

                .distinct()

                .mapToObj(c -> String.valueOf((char) c))

                .collect(Collectors.joining());

  }

}