Skip to content

Instantly share code, notes, and snippets.

View anandtripathi5's full-sized avatar
🎯
Focusing

Anand Tripathi anandtripathi5

🎯
Focusing
View GitHub Profile
from celery import Celery
import celery_config
app = Celery(__name__)
app.config_from_object(celery_config)
@app.task()
def random_task():
pass
@anandtripathi5
anandtripathi5 / create_multiple_records.sql
Last active May 15, 2021 16:00
Gist will create towns table and will insert 100k records in towns table using generate_series
CREATE TABLE towns (
id SERIAL UNIQUE NOT NULL,
code VARCHAR(10) NOT NULL, -- not unique
article TEXT,
name TEXT NOT NULL -- not unique
);
insert into towns (
code, article, name
)
@anandtripathi5
anandtripathi5 / flask-1-0.py
Created May 22, 2021 11:39
This is the minimal example of server in Flask 1.0
from flask import Flask
app = Flask('__name__')
@app.route('/hello', methods=['GET', 'POST'])
def hello_world():
return 'This is the hello world api request'
@anandtripathi5
anandtripathi5 / flask-2-0.py
Last active April 1, 2022 11:20
This is a minimal example of Flask 2.0
from flask import Flask
app = Flask('__name__')
@app.get('/hello')
@app.post('/hello')
def hello():
return 'This is the awesome hello api request'
@anandtripathi5
anandtripathi5 / async-await-flask.py
Last active May 22, 2021 12:15
Flask 2.0 now supports asynchronous route handlers
from flask import Flask
import asyncio
app = Flask(__name__)
@app.get("/data")
async def get_data():
await asyncio.sleep(1)
return 'Hello'
@anandtripathi5
anandtripathi5 / flask_from_file.py
Created May 22, 2021 15:50
Flask import configuration from toml file
import toml
from flask import Flask
app = Flask('__name__')
app.config.from_file('config.toml', toml.load)
@anandtripathi5
anandtripathi5 / xkcd_comic_flask.py
Last active June 5, 2021 08:42
Render random xkcd comic in flask application
import time
from random import randint
import requests as requests
from flask import Flask
app = Flask(__name__)
def get_xkcd_image():
@anandtripathi5
anandtripathi5 / multiple_xkcd_comic_flask.py
Created June 5, 2021 08:55
Render multiple xkcd comic in Flask application
import time
from random import randint
import requests as requests
from flask import Flask
app = Flask(__name__)
def get_xkcd_image():
@anandtripathi5
anandtripathi5 / async_flask_api_with_httpx.py
Last active December 10, 2024 19:55
Asynchronous flask api call with httpx library. Render multiple xkcd pages from comic using async api calls in flask 2.0
import asyncio
import time
from random import randint
import httpx
from flask import Flask
app = Flask(__name__)
# function converted to coroutine
@anandtripathi5
anandtripathi5 / sonarqube-docker-compose.yml
Created June 15, 2021 16:15
Sonarqube docker compose file to spint Sonarqube container and a postgres container for the data of Sonarqube
version: "3"
services:
sonarqube:
image: sonarqube:8.5.1-community
container_name: sonarqube
hostname: sonarqube
ports:
- 9000:9000
environment: