Skip to content

Instantly share code, notes, and snippets.

@johndiego
johndiego / models.py
Created March 28, 2019 12:33 — forked from asyd/models.py
Flask SQLAlchemy multiple column unique constraint
class ComponentCommit(db.Model):
__tablename__ = 'component_version'
__table_args__ = (
db.UniqueConstraint('component_id', 'commit_id', name='unique_component_commit'),
)
id = db.Column(db.Integer, primary_key=True)
component_id = db.Column(db.Integer, db.ForeignKey("component.id"))
commit_id = db.Column(db.String)
branch = db.Column(db.String)
dependencies = db.Column(db.Text)
@johndiego
johndiego / MultiTenantFlask.py
Created March 11, 2019 01:27 — forked from TonyFrancis/MultiTenantFlask.py
Creating multi Tenant system with multiple Database. Switching between databases based on subdomain related to tenant
from functools import wraps
from flask import Flask, g, session, request, abort, jsonify
from flask_migrate import MigrateCommand, Migrate
from flask_script import Manager
from flask_sqlalchemy import SQLAlchemy
flask_app = Flask(__name__, static_folder='./static')
db = SQLAlchemy()
migrate = Migrate()
@johndiego
johndiego / 1-odbc.ini
Created February 24, 2019 05:39 — forked from andrius/1-odbc.ini
ODBC.ini for Asterisk PBX res_odbc, cdr_odbc and realtime integration #asterisk #odbc
; place this file to /etc (/etc/odbc.ini)
[mysql-asterisk]
Description = MySQL Asterisk database
; MySQL DB name
Database = asterisk
; User
User = asterisk
; Password
gravaCode = event['params']['path']['msisdn']['returncode']['message']['caller']
if returncode == 0:
if gravaCode == 0:
print('N3Rmonitor msgOK')
elif returncode == 999999:
print(f'returncode: {returncode}')
print(f'mensagem: {data}')
print(f"mensagem: {dadosassinante['msisdn']}")
print(f'caller: {gravaCode}')
print('N3Rmonitor msgERROTECNICO')
@johndiego
johndiego / Code128.py
Created October 3, 2018 03:34 — forked from supersighs/Code128.py
Python class for generating Code 128 barcodes
# courbB08.pil PIL Font file uuencoded
courB08_pil ="""eJztl91rFkcUxp+Zt7vGFYzVtiJKICgYlLRWkaBBVGgDraFGCH5gsQp+QMBqabAVRYJYAlakCkoh
CpYgxaLkIu1NvLBeSAStglpqL6xQAsVe2AuL5u2buH3mzGaYPf9AKWTl8d3nl7MzZ2bnazvea9+9
7+PurFWut5e0Zu+s7VybYfKavP7LK3X/5TlM4Q3/OWbyf1ARD/6mgb2SjwtPhbpnq0iKZ6ahrmCj
wqbxdgamRnHOA69jimN5zvIS8cDcUEeVdYzRAw1FHcJYXgPvG4s6Jlgj7xeEequS3wLeNvGvnrEO
tq+Jt82szT+b86+WHlgS2jHGuHF6YHnog1zaupxqCcy3t4X3rVG9iXhgjW+bsFQ80BaxRDywTrF1
VId6toPaqOI2UlsV20ptV2w7tUuxXVSXYl3UvoIZ9kFFPPBJ6D/HLD3QXbwjyDjI6YHPiz5FXiN7
SQ8cDu/N9/1h3veEOP/Oe6gvQnmuvYYe+NL3qYyNVDxw2seF8XKa+jrKJREPnFdx56l+xfqpS4pd
ogZUeQPU91FcKh64GveBeOCaKu8adUM9e4O6reJuU/cUu0c9VM8+pB6r/B5TI+rZEerPUpyhB/6K
5lsqHniuyntO1VR5Nb5CU86FHqZOsTqqXrF66o2ojlQ8zDwVN4+aX86FHqYpXg9YLeevWRzPc7LF
import csv
import io
from datetime import datetime
from django.core.files.storage import FileSystemStorage
from django.http import HttpResponse
from django.shortcuts import render
from django.template.loader import render_to_string
from django.utils import timezone
from weasyprint import HTML
from xlsxwriter import Workbook
@johndiego
johndiego / install-doceker.md
Created August 11, 2018 19:17 — forked from alimd/install-doceker.md
Install docker on linux as easy as possible

Install Docker on linux

Any distribution of architecture as easy as possible.

# Install docker latest version from original website
curl -fsSL https://get.docker.com/ | sh

# Adding your user to the "docker" group
sudo usermod -aG docker $(whoami)
## you will have to log out and back in for this to take effect!
@johndiego
johndiego / nginxproxy.md
Created July 18, 2018 03:52 — forked from soheilhy/nginxproxy.md
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers

@johndiego
johndiego / gist:7b40ee9bb1cc11e3b582bc672ae300a7
Created June 30, 2018 15:44 — forked from ratchit/gist:3942066
Flask MethodView decorators for individual request methods
from flask.views import MethodView
class MethodView(MethodView):
_decorators = {}
def dispatch_request(self, *args, **kwargs):
"""Derived MethodView dispatch to allow for decorators to be
applied to specific individual request methods - in addition
@johndiego
johndiego / gist:35619a5f3b69665f4fa16a6e92d1a0c0
Created June 14, 2018 19:10 — forked from jamiemarsland/gist:5e618baeda2dd5199d4a
Remove WooThemes credit in Storefront footer
add_action( 'init', 'custom_remove_footer_credit', 10 );
function custom_remove_footer_credit () {
remove_action( 'storefront_footer', 'storefront_credit', 20 );
add_action( 'storefront_footer', 'custom_storefront_credit', 20 );
}
function custom_storefront_credit() {
?>
<div class="site-info">