Skip to content

Instantly share code, notes, and snippets.

View MilovanTomasevic's full-sized avatar
🎯
Focusing

Milovan Tomašević MilovanTomasevic

🎯
Focusing
View GitHub Profile
import threading
from typing import Any
class PropagatingThread(threading.Thread):
"""A Threading Class that raises errors it caught, and returns the return value of the target on join."""
def __init__(self, *args, **kwargs):
self._target = None
self._args = ()
@Julian-Nash
Julian-Nash / flask_sitemap_generator.py
Last active May 4, 2024 13:03
Flask dynamic sitemap generator
@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
@cabecada
cabecada / gist:da8913830960a644755b18a02b65e184
Last active July 17, 2024 07:21
python postgres connection with retry example
#!/usr/bin/env python
#https://github.com/psycopg/psycopg2/issues/261
import psycopg2
ISOLEVEL = psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT
import time
@Nomane
Nomane / bump-version.sh
Last active January 15, 2024 02:49
Bump version shell script.
#!/bin/bash
# Thanks goes to @pete-otaqui for the initial gist:
# https://gist.github.com/pete-otaqui/4188238
#
# Original version modified by Marek Suscak
#
# works with a file called VERSION in the current directory,
# the contents of which should be a semantic version number
# such as "1.2.3" or even "1.2.3-beta+001.ab"
@niazangels
niazangels / celery-flask-progressbar.py
Created January 22, 2018 19:11
Simple progressbar with Flask + Celery
'''
testing celery progress reporting/polling
* start server
python tempserver.py
* start worker
celery -A tempserver.celery worker -c 1 --loglevel=DEBUG
* browse to localhost:5000/
'''
from flask import Flask, request, render_template_string
@huklee
huklee / MyLogger.py
Last active January 6, 2024 18:06
python Logger using example with Singleton Pattern
# -*- coding: utf-8 -*-
import logging
import os
import datetime
import time
class SingletonType(type):
_instances = {}
@ivanleoncz
ivanleoncz / flask_job_scheduler.py
Last active June 27, 2024 07:23
Demonstrating APScheduler on a Flask App.
#!/usr/bin/python3
""" Demonstrating APScheduler feature for small Flask App. """
from apscheduler.schedulers.background import BackgroundScheduler
from flask import Flask
def sensor():
""" Function for test purposes. """
print("Scheduler is alive!")
@oculushut
oculushut / downloadEnron.py
Last active April 10, 2023 23:43
Example for using Python to download file
##Python 2
#import urllib
#url = "https://www.cs.cmu.edu/~./enron/enron_mail_20150507.tgz"
#urllib.urlretrieve(url, filename="../enron_mail_20150507.tgz")
#print "download complete!"
##Python 3
import urllib.request
url = "https://www.cs.cmu.edu/~./enron/enron_mail_20150507.tgz"
print ("download start!")
@jriguera
jriguera / email_notify.py
Last active February 20, 2023 09:09
Email from Python with Jinja2
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Python 3 and compatibility with Python 2
from __future__ import unicode_literals, print_function
import os
import sys
import re
import logging
@doobeh
doobeh / home.html
Created January 19, 2016 14:04
More complete example of FieldList with FormField
<form method="post" action="">
{{ form.name}}
{{ form.hidden_tag() }}
<br/>
{% for entry in form.hours %}
{{ loop.index0|dow }}
{{ entry() }}
{% endfor %}
<input type="submit"/>
</form>