Skip to content

Instantly share code, notes, and snippets.

View muhammadqazi's full-sized avatar
🎯
Focusing

Muhammad Qazi muhammadqazi

🎯
Focusing
View GitHub Profile
@muhammadqazi
muhammadqazi / dream.js
Created February 15, 2024 19:49
Dream :/
function achieve(dream) {
return new Promise((resolve, reject) => {
setTimeout(() => {
const successRate = Math.random();
if (
dream.size === "BIG" &&
dream.priority === "HIGH" &&
successRate > 0.5
) {
resolve("Congratulations! Dream achieved!");
@muhammadqazi
muhammadqazi / mid.java
Created November 21, 2022 05:45
mid.java
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
public class Midterm {
private final String student_file;
public Midterm(String student_file) {
this.student_file = student_file;
@muhammadqazi
muhammadqazi / deploy_fastapi.md
Last active September 18, 2022 05:53
Deploying FastAPI Apps Over HTTPS with Traefik Proxy.

Deploy Fastapi on DigitalOcean

Deploying FastAPI Apps Over HTTPS with Traefik Proxy.

Before deployment there are some steps which needs to be followed.

Dockerize application

To dockerize your application make sure you have a docker installed in your local machine, Add the following file to your application directory Dockerfile, .dockerignore and docker-compose.yml

@muhammadqazi
muhammadqazi / google.go
Created February 6, 2022 11:16
Go-Authentication
const (
qrFilename = "/tmp/qr.png"
)
var secret = []byte{'H', 'e', 'l', 'l', 'o', '!', 0xDE, 0xAD, 0xBE, 0xEF}
func HandleGoogleAuthenticate(response http.ResponseWriter, request *http.Request) {
var google models.GoogleAuthenticate
@muhammadqazi
muhammadqazi / Code.go
Created February 6, 2022 11:02
Go-Authentication
var table = [...]byte{'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}
func HandleCodeGenerator(max int) string {
b := make([]byte, max)
n, err := io.ReadAtLeast(rand.Reader, b, max)
if n != max {
panic(err)
}
for i := 0; i < len(b); i++ {
b[i] = table[int(b[i])%len(table)]
@muhammadqazi
muhammadqazi / email-service.go
Created February 6, 2022 10:55
Go-Authentication
func HandleEmailService(email string, code int) {
godotenv.Load(".env")
sender := os.Getenv("email")
Senderauth := os.Getenv("password")
to := []string{email}
@muhammadqazi
muhammadqazi / SignIn.go
Created February 6, 2022 10:51
Go-Authentication
func HandleSignin(response http.ResponseWriter, request *http.Request) {
if request.Method != "POST" {
response.WriteHeader(http.StatusMethodNotAllowed)
response.Write([]byte("{\"message\": \"Method not allowed\"}"))
return
}
var user model.AuthenticationModel
@muhammadqazi
muhammadqazi / database.go
Created February 6, 2022 10:50
Go-Authentication
func HandleDatabaseInsert(DBname string, CollectionName string, email string, phone int, password string, fname string, lname string, uid string, created time.Time, updated time.Time, token string, code int, agent interface{}) bool {
ctx, client := HandleDBConnection()
collection := client.Database(DBname).Collection(CollectionName)
_, errInsert := collection.InsertOne(ctx, bson.M{
"email": email,
"phone": phone,
"password": password,
@muhammadqazi
muhammadqazi / SignUp.go
Created February 6, 2022 10:46
Go-Authentication
func HandleSignup(response http.ResponseWriter, request *http.Request) {
if request.Method != "POST" {
response.WriteHeader(http.StatusMethodNotAllowed)
response.Write([]byte("{\"message\": \"Method not allowed\"}"))
return
}
var user model.UserModel
var result model.ResponseModel
@muhammadqazi
muhammadqazi / user-struct.go
Created February 6, 2022 10:42
Go-Authentication
type UserModel struct {
ID primitive.ObjectID `bson:"_id"`
First_name string `json:"first_name" validate:"required,min=2,max=100"`
Last_name string `json:"last_name" validate:"required,min=2,max=100"`
Password string `json:"Password" validate:"required,min=6,max=20"`
Email string `json:"email" validate:"email,required"`
Phone int `json:"phone" validate:"required"`
Token string `json:"token"`
Refresh_token string `json:"refresh_token"`