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 / 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 / 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 / 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 / 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 / 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 / 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 / keybindings.json
Last active February 23, 2025 11:42
my vscode settings
// Place your key bindings in this file to override the defaultsauto[]
[
{
"key": "cmd+b",
"command": "workbench.action.terminal.clear",
"when": "terminalFocus && terminalHasBeenCreated || terminalFocus && terminalProcessSupported"
},
{
"key": "cmd+k",
"command": "-workbench.action.terminal.clear",
@arshamalh
arshamalh / jwt_interval.go
Created June 10, 2022 21:57
Golang JWT and intervals (using goroutines and channels)
package main
import (
"fmt"
"time"
"github.com/golang-jwt/jwt"
)
func main() {
@arshamalh
arshamalh / Dockerfile
Last active September 21, 2023 23:11
Go and UI Multistage Dockerfile
FROM golang:1.21-alpine3.18 AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . ./
RUN CGO_ENABLED=0 GOOS=linux go build -a -o main .
FROM node:18-alpine3.15 AS frontend
WORKDIR /ui
COPY ui .
@arshamalh
arshamalh / interactiveShell.go
Last active November 2, 2022 08:55
Go simple interactive shell
package main
import (
"fmt"
"time"
)
const (
msg_welcome string = `
Welcome to Dockeroller!