Skip to content

Instantly share code, notes, and snippets.

#
# With help from : https://github.com/jonbiemond
#
# requires:
# pip install flask flask_sqlalchemy
#
# run: flask --app sqlalchemy_to_josnable_dict.py init-db
# run: flask --app sqlalchemy_to_josnable_dict.py test-data
# run: flask --app sqlalchemy_to_josnable_dict.py get-user1
# run: flask --app sqlalchemy_to_josnable_dict.py get-user2
@carc1n0gen
carc1n0gen / flask-blueprint-subdomains.py
Last active February 19, 2021 15:30
Flask Blueprint Subdomains
from flask import Flask, Blueprint, url_for
app = Flask(__name__)
app.config['SERVER_NAME'] = 'app.local:5000'
bp1 = Blueprint('bp1', __name__, subdomain='app1')
bp2 = Blueprint('bp2', __name__, subdomain='app2')
@carc1n0gen
carc1n0gen / flask-domain-matching.py
Last active February 22, 2021 09:05
Flask Host Matching
from flask import Flask, url_for
app = Flask(__name__, host_matching=True, static_host='app1.local:5000')
@app.route('/', host='app1.local:5000')
def home1():
return url_for('home1')
@wtbarnes
wtbarnes / push-to-someone-elses-pr.md
Created March 5, 2020 04:49
Brief instructions for how to modify and push to someone else's PR on github

How to Push to Someone Else's Pull Request

Let's say contributor has submitted a pull request to your (author) project (repo). They have made changes on their branch feature and have proposed to merge this into origin/master, where

origin -> https://github.com/author/repo.git

Now say you would like to make commits to their PR and push those changes. First, add their fork as a remote called

@BarelyAliveMau5
BarelyAliveMau5 / modified_utf8.py
Last active August 23, 2023 17:58
python's version of java's modified utf8
# translated from: http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/94cc251d0c45/src/share/npt/utf.c
def utf8s_to_utf8m(string):
"""
:param string: utf8 encoded string
:return: modified utf8 encoded string
"""
new_str = []
i = 0
while i < len(string):
@fsteffenhagen
fsteffenhagen / sum_filesize.sh
Last active April 15, 2024 10:04
sum human readable file sizes with numfmt and awk
# Input: list of rows with format: "<filesize> filename", e.g.
# filesizes.txt
#######################
# 1000K file1.txt
# 200M file2.txt
# 2G file3.txt
#
# Output:
cat filesizes.txt | numfmt --from=iec | awk 'BEGIN {sum=0} {sum=sum+$1} END {printf "%.0f\n", sum}'
@mihow
mihow / load_dotenv.sh
Last active June 14, 2024 02:15
Load environment variables from dotenv / .env file in Bash
if [ ! -f .env ]
then
export $(cat .env | xargs)
fi
@yograterol
yograterol / gist:99c8e123afecc828cb8c
Created January 8, 2016 05:45
"gcc: error: /usr/lib/rpm/redhat/redhat-hardened-cc1: No such file or directory" workaround
"gcc: error: /usr/lib/rpm/redhat/redhat-hardened-cc1: No such file or directory" CentOS's and Fedora +22 workaround
Install `redhat-rpm-config`
$ sudo dnf install redhat-rpm-config
@wolph
wolph / warning_decorator.py
Created October 5, 2015 09:08
Decorator to ignore a specific number of Python warnings
import warnings
import functools
def ignore_warning(warning, count=None):
def _ignore_warning(function):
@functools.wraps(function)
def __ignore_warning(*args, **kwargs):
with warnings.catch_warnings(record=True) as ws:
# Catch all warnings of this type
@andrewseidl
andrewseidl / Clang-format Comparison.md
Last active April 10, 2024 04:10
Clang-format style comparison

This is a comparison of the different formatting styles including with clang-format.

Generated via:

styles=( LLVM Google Chromium Mozilla WebKit )
for style in $styles
do
  clang-format -style=$style ChLcpIterativeAPGD.h > ChLcpIterativeAPGD.$style.h

done