Skip to content

Instantly share code, notes, and snippets.

View rahul-yr's full-sized avatar

Rahul Reddy rahul-yr

View GitHub Profile
@rahul-yr
rahul-yr / database.py
Created June 15, 2022 09:54
Here is the snippet for url shorteners.
import time
class MockDBOperations:
'''
Created a class to mimic the database operations.
You can use this class to implement the actual database operations.
'''
# Initialize the database
@rahul-yr
rahul-yr / models.py
Created June 15, 2022 09:42
Here I defined all the required methods for url_shorteners
from pydantic import BaseModel
# Define the model for the URL
class CreateUrlShortener(BaseModel):
url: str
# Config for pydantic to validate the data in the request body
class Config:
orm_mode = True
# Define the model for the URL Response
@rahul-yr
rahul-yr / fastapi-sample-main.py
Created June 15, 2022 08:27
This is a sample fast api code
from fastapi import FastAPI
from url_shortener import router
# Create the app
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@rahul-yr
rahul-yr / Procfile
Last active June 12, 2022 12:24
This is a file with commands for performing deployment to heroku
web : app-name
@rahul-yr
rahul-yr / thread_safe.go
Created June 11, 2022 12:41
Go Singleton pattern implementation
package main
import (
"log"
"sync"
"time"
)
// This is struct for mocking the connection.
type SQLConnection struct {
@rahul-yr
rahul-yr / non_thread_safe.go
Created June 11, 2022 12:36
Go Singleton pattern implementation
package main
import (
"log"
"sync"
"time"
)
// This is struct for mocking the connection.
type SQLConnection struct {
@rahul-yr
rahul-yr / go-http-chain-middlewares.go
Created May 26, 2022 07:39
Go HTTP chain middlewares
package main
import (
"fmt"
"log"
"net/http"
"time"
)
type CustomMiddlewares func(http.HandlerFunc) http.HandlerFunc
@rahul-yr
rahul-yr / docker-compose.yaml
Created April 2, 2022 06:55
Docker compose file for Mongodb with UI
version: '3.9'
services:
mongo:
container_name: myapp-mongo
image: mongo
restart: always
ports:
- "27017:27017"
import pyautogui
import time
while True:
try:
pyautogui.moveTo(20, 20, duration=1)
time.sleep(1)
pyautogui.moveTo(1000, 20, duration=1)
time.sleep(1)
git clone url
git fetch
git branch
git pull
git status
CRLF to LF
git config core.autocrlf false