Skip to content

Instantly share code, notes, and snippets.

View anandtripathi5's full-sized avatar
🎯
Focusing

Anand Tripathi anandtripathi5

🎯
Focusing
View GitHub Profile
@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 / 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-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 / 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 / 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
)
from celery import Celery
import celery_config
app = Celery(__name__)
app.config_from_object(celery_config)
@app.task()
def random_task():
pass
broker_url = "{}://{}:{}@{}:{}/{}".format(
broker_protocol,
broker_username,
broker_password,
broker_host,
broker_port,
broker_vhost)
worker_send_task_event = False
task_ignore_result = True
@anandtripathi5
anandtripathi5 / celery_config.py
Created April 21, 2021 09:00
Celery production ready configuration
broker_url = "{}://{}:{}@{}:{}/{}".format(
broker_protocol,
broker_username,
broker_password,
broker_host,
broker_port,
broker_vhost)
worker_send_task_event = False
task_ignore_result = True
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.4.8/socket.io.min.js"></script>
<script type="text/javascript" charset="utf-8">
const socket = io('http://localhost:5000')
socket.on('connect', () => {
console.log("socket connected");
});
</script>
from flask import Flask, render_template
from flask_socketio import SocketIO
# Initializing the flask object
app = Flask(__name__)
# Initializing the flask-websocketio
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)