This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.route("/sitemap") | |
@app.route("/sitemap/") | |
@app.route("/sitemap.xml") | |
def sitemap(): | |
""" | |
Route to dynamically generate a sitemap of your website/application. | |
lastmod and priority tags omitted on static pages. | |
lastmod included on dynamic content such as blog posts. | |
""" | |
from flask import make_response, request, render_template |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<!-- Required meta tags --> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
<!-- Bootstrap CSS --> | |
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import jsonify, make_response, Response | |
from typing import Optional, Any | |
from http import HTTPStatus | |
class JSONResponse(object): | |
@classmethod | |
def _send_response(cls, status: int, data: Any, headers: Optional[dict] = None): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import click | |
import json | |
def cprint(x=None): | |
""" | |
Pass any object into cprint to have it printed to the console in color! | |
json = yellow (json is pretty printed by default) | |
Python collections [list, dict, tuple] = green | |
Integers & floats = magenta |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Version 1 - Not tested | |
from pygments.style import Style | |
from pygments.token import (Keyword, Name, Comment, String, | |
Error, Number, Operator, Generic) | |
class DarkStyle(Style): | |
default_style = "" | |
styles = { | |
Comment: '#608b4e', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def has_account(email): | |
email = email.strip() | |
user_query = User.objects(email=email) | |
status = False | |
for user in user_query: | |
if user.email == email: | |
status = True | |
else: | |
status = False | |
return status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pathlib import Path | |
import os | |
from sanic import Sanic | |
from motor.motor_asyncio import AsyncIOMotorClient | |
from app.config import get_config | |
from app.blueprints import view, ws, api | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pygments import highlight | |
from pygments.formatters.html import HtmlFormatter | |
from pygments.lexers import guess_lexer, get_lexer_for_filename, get_lexer_by_name | |
class HTMLCodeHighlighter: | |
""" Generate highlighted HTML snippets of code (pip install Pygments)""" | |
@classmethod | |
def _highlight(cls, code: str, lexer): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Optional, Union | |
class DoublyLinkedListNode: | |
def __init__(self, value: Optional = None, prev: Optional = None, next: Optional = None): | |
self.value = value | |
self.prev = prev | |
self.next = next |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Flask application profiler | |
Will run the Flask application and log profile data to stdout. | |
The `restrictions` parameter passed to `ProfilerMiddleware` is used to limit the number of items listed | |
in the report. | |
""" | |
import os | |
from werkzeug.middleware.profiler import ProfilerMiddleware |
NewerOlder