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
#/usr/bin/python3 | |
""" Demonstration of logging feature for a Flask App. """ | |
from logging.handlers import RotatingFileHandler | |
from flask import Flask, request, jsonify | |
from time import strftime | |
__author__ = "@ivanleoncz" | |
import logging |
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
[ req ] | |
default_bits = 2048 | |
distinguished_name = req_distinguished_name | |
attributes = req_attributes | |
prompt = no | |
[ req_distinguished_name ] | |
C = MX | |
ST = VE | |
L = XL |
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
package com.ivanlmj.myapp; | |
import android.content.Context; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.util.Log; |
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
#!/usr/bin/python3 | |
""" Determining validation of a password, against its hash. """ | |
import bcrypt | |
from getpass import getpass | |
# simulation of hashed password stored in a DBMS (MongoDB, MySQL, SQLite, etc.) | |
salt = bcrypt.gensalt() | |
db_password = "Guido*Py2017".encode('utf-8') | |
db_pass_hash = bcrypt.hashpw(db_password,salt) |
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
### Create, Read, Update and Delete | |
# SHOW DATABASES | |
> show databases | |
> show dbs | |
# DEFINE DATABASE FOR OPERATIONS | |
> use database_name | |
# CREATE DATABASE AND COLLECTIONS |
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
#!/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!") |
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
#!/usr/bin/python3 | |
""" Demonstration of PyMongo usage. """ | |
from bson.objectid import ObjectId | |
from datetime import datetime | |
from pymongo import MongoClient | |
__author__ = "@ivanleoncz" | |
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
""" Demonstrating SQLite3 query with data returned as JSON Array. """ | |
from json import dumps | |
__author__ = "@ivanleoncz" | |
import sqlite3 | |
def data_as_json(): | |
db = sqlite3.connect("app_db.sqlite3") |
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
#!/usr/bin/python3 | |
""" Obtaining all form fields (dynamically) from a POST request. | |
$ curl http://127.0.0.1:8000/post -d "name=Nemo&country=Norway" | |
$ curl http://127.0.0.1:8000/data -d "company=Axos Inc.&business=IT Outsourcing" | |
""" | |
from flask import abort, Flask, jsonify, request | |
__author__ = "@ivanleoncz" |
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 time | |
class Calc: | |
""" Arithmetic Operations for two numbers, per function. """ | |
def add(self, n1, n2): | |
""" Performs addition of two numbers. """ | |
time.sleep(5) # intentional sleep for measuring time consumed | |
return n1 + n2 | |
OlderNewer