Skip to content

Instantly share code, notes, and snippets.

View arshamalh's full-sized avatar
:octocat:
This Octacat is my pet!

Mohammad Reza Karimi arshamalh

:octocat:
This Octacat is my pet!
View GitHub Profile
@arshamalh
arshamalh / FastAPI_boiler_plate.py
Created April 3, 2022 14:33
Boilerplate for FastAPI returning UI, CORS, routers.
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from routes import routes_group_1, routes_group_2
api_app = FastAPI(title="api app")
api_app.add_middleware(
CORSMiddleware,
@arshamalh
arshamalh / calculator_api_server.go
Created March 5, 2022 20:04
Simple calculator API server in Golang
package main
import (
"encoding/json"
"fmt"
"math"
"net/http"
// go get "github.com/gorilla/mux"
"github.com/gorilla/mux"
)
@arshamalh
arshamalh / making_json_with_maps.go
Created March 5, 2022 00:13
Reading and writing JSON objects in Golang
package main
import (
"encoding/json"
"fmt"
)
func main() {
myJson := map[string]interface{}{
"name": "Arsham",
@arshamalh
arshamalh / Dockerfile
Last active August 3, 2022 21:24
Typescript multistage dockerfile
# Improvement after each stage: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o4htns2axmh87lieoclw.png
# Resource 1 => https://simplernerd.com/docker-typescript-production/
# Resource 2 => https://medium.com/@ankit.wal/the-why-and-how-of-multi-stage-docker-build-with-typescript-example-bcadbce2686c
FROM node:18-alpine3.15 as ts-compiler
WORKDIR /usr/app
COPY package*.json ./
COPY tsconfig.json ./
RUN npm install --include=dev
COPY src src
RUN ["npm", "run", "build"]
@arshamalh
arshamalh / pymongo_assistant_01.py
Last active March 23, 2022 11:04
Pymongo Assistant
"""
Written by Arsham Arya
Some snippets around pymongo package to prevent my confusion.
"""
from pymongo import MongoClient
# Initializing
client = MongoClient("mongodb://username:password@host:port/default_db?authSource=admin")
database = client.get_database("db_name")
collection = database.get_collection("collection_name")
@arshamalh
arshamalh / 1_running_scrapy_from_anothor_python_file.py
Last active February 7, 2022 13:58
Running Scrapy spider along fastAPI or APScheduler, from another script or main.py.
from scrapy import crawler
from scrapy.utils.project import get_project_settings
# pip install crochet
from crochet import setup as crochet_setup, run_in_reactor
crochet_setup()
runner = crawler.CrawlerRunner(get_project_settings())
@run_in_reactor
@arshamalh
arshamalh / config.py
Last active November 14, 2025 21:46
Python best way to import environment variables for development and production
"""
Written by Arsham Arya
I'm not sure it's the best way,
So any contribution makes everyone happy!
"""
from os import environ
# pip install python-dotenv
from dotenv import dotenv_values
@arshamalh
arshamalh / paginating_tmdb_trends_through_api.py
Last active November 14, 2025 21:50
Getting TMDB trends using their API
@arshamalh
arshamalh / compound_index_pymongo.py
Created January 21, 2022 15:38
Making compound unique index in Mongodb using pymongo
# Compound unique indexs are indexes made of multiple columns together.
# For example if we have this data:
"""
("arsham", 930)
"""
# We can have ("arsham", 920), ("arsham", 910), Also we can have ("atousa", 930)
# but we can't have ("arsham", 930) again.
# I hope I explained it well enough. 😊
from pymongo import MongoClient, ASCENDING
@arshamalh
arshamalh / contact_book.py
Created January 15, 2022 09:12
simple Tkinter contact book.
from tkinter import *
from tkinter import messagebox
root = Tk()
root.geometry("480x170")
root.title("Raha Contacts books")
Name = StringVar()
Number = StringVar()
Address = StringVar()