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
# mongoengine class | |
class User(DynamicDocument): | |
date_created = DateTimeField(default=datetime.datetime.utcnow) | |
username = StringField(unique=True) | |
password = BinaryField(required=True) | |
email = EmailField(unique=True) | |
admin = BooleanField(default=False) | |
data_sets = DictField() | |
# Hashing & password checking functions |
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 matplotlib.pyplot as plt | |
data_points = {} | |
with open("test_data.txt", "r") as f: | |
for line in f: | |
date, temp = line.split("|") | |
temp = temp.strip() | |
data_points.update({date: temp}) |
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
#!/bin/bash | |
arg=$1 | |
red='\033[1;31m' | |
yellow='\033[1;33m' | |
cyan='\033[1;36m' | |
purple='\033[1;35m' | |
nl='\n' | |
nc='\033[0m' |
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 in_session(f): | |
@wraps(f) | |
def decorated_function(*args, **kwargs): | |
if session.get("LOGGED_IN") == False: | |
return redirect(url_for('login')) | |
return f(*args, **kwargs) | |
return decorated_function | |
# Usage -------------------------------------------------------- |
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
// trim polyfill to clear whitespace | |
if (!String.prototype.trim) { | |
String.prototype.trim = function() { | |
return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ""); | |
}; | |
} | |
var submit_btn = document.getElementById("acc_form_btn"); | |
submit_btn.addEventListener("click", function() { |
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 has_account(email): | |
email = email.strip() | |
user_query = User.objects(email=email) | |
status = False | |
for user in user_query: | |
if user.email == email: | |
status = True | |
else: | |
status = False | |
return status |
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
# Follow guide on https://developers.google.com/gmail/api/quickstart/python to obtain credentials | |
import httplib2 | |
import os | |
import oauth2client | |
from oauth2client import client, tools | |
import base64 | |
from email.mime.multipart import MIMEMultipart | |
from email.mime.text import MIMEText | |
from apiclient import errors, discovery |
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
// ES6 | |
document.getElementById("post_btn").addEventListener("click", (e) => { | |
e.preventDefault(); | |
let user_credentials = { | |
first_name: document.getElementById("first_name").value, | |
last_name: document.getElementById("last_name").value, | |
}; | |
fetch("http://127.0.0.1:5000/testing_fetch", { | |
method: "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
// Get the previous form data from sessionStorage | |
var previousForm = JSON.parse(sessionStorage.getItem("formData")); | |
// Iterate through the form fields and polulate the form with sessionStorage values | |
for (let item in previousForm) { | |
$(`#${item}`).val(`${previousForm[item]}`); | |
} | |
$("#submit").click(function(){ | |
// Build sessionStorage object on form submit click | |
var 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
import click | |
import json | |
def cprint(x=None): | |
""" | |
Pass any object into cprint to have it printed to the console in color! | |
json = yellow (json is pretty printed by default) | |
Python collections [list, dict, tuple] = green | |
Integers & floats = magenta |