This file contains hidden or 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
| function send_form(form, form_id, url, type, inner_ajax, formData) { | |
| // form validation and sending of form items | |
| if ( form[0].checkValidity() && isFormDataEmpty(formData) == false ) { // checks if form is empty | |
| event.preventDefault(); | |
| // inner AJAX call | |
| inner_ajax(url, type, formData); | |
| } |
This file contains hidden or 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
| function modular_ajax(url, type, formData) { | |
| // Most simple modular AJAX building block | |
| $.ajax({ | |
| url: url, | |
| type: type, | |
| data: formData, | |
| processData: false, | |
| contentType: false, | |
| beforeSend: function() { | |
| // show the preloader (progress bar) |
This file contains hidden or 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
| # rendering contact.html template and making JSON response | |
| from flask import Flask, render_template, jsonify | |
| # using Flask-WTF CSRF protection for AJAX requests | |
| from flask_wtf.csrf import CSRFProtect | |
| # initializing app | |
| app = Flask(__name__) | |
| # protecting our app | |
| csrf = CSRFProtect(app) | |
| @app.route('/contact', methods=['GET', 'POST']) |
This file contains hidden or 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
| var csrf_token = "{{ csrf_token() }}"; | |
| $.ajaxSetup({ | |
| beforeSend: function(xhr, settings) { | |
| if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) { | |
| xhr.setRequestHeader("X-CSRFToken", csrf_token); | |
| } | |
| } | |
| }); |
This file contains hidden or 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 show_docstring(): | |
| """Print function description to user""" | |
| print("Using __doc__ method:") | |
| print(show_docstring.__doc__) | |
| print("Using help() function:") | |
| help(show_docstring) | |
| $ show_docstring(); | |
| "Using __doc__ method:" |
This file contains hidden or 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 power(a, b): | |
| """Returns arg1 raised to power arg2.""" | |
| return a**b |
This file contains hidden or 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 suggest_places(auth_key, city): | |
| """Returns longitude and latitude of first suggested location in the Netherlands from Postcode API. | |
| :param auth_key: authorization key for Postcode API | |
| :type auth_key: str | |
| :param city: textual input for city names to match in Postcode API | |
| :type city: str | |
| :rtype: (str, str), str, str | |
| :return: (longitude, latitude), Postcode API status code, Postcode API error message |
This file contains hidden or 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 multiply(a, b, c=0): | |
| """Return sum of multiplication of all arguments. | |
| :param a: arg1 | |
| :type a: int | |
| :param b: arg2 | |
| :type b: int | |
| :param c: arg3, defaults to 0 | |
| :type c: int, optional |
This file contains hidden or 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 sys | |
| import argparse | |
| import logging | |
| from logging import critical, error, info, warning, debug | |
| import numpy as np | |
| import seaborn as sn | |
| import pandas as pd | |
| import random |
This file contains hidden or 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 read_corpus(corpus_file, binary): | |
| """Read input document and return the textual reviews and the sentiment or genre.""" | |
| documents = [] | |
| labels = [] | |
| with open(corpus_file, 'r', encoding='utf-8') as f: | |
| for line in f: | |
| tokens = line.strip().split() | |
| documents.append(tokens[3:]) |