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 enum | |
@enum.unique | |
class HTTPStatusCode(enum.IntEnum): | |
""" Enumeration for HTTP status codes. | |
Example usage: | |
HttpStatusCode.OK.value # 100 | |
HttpStatusCode.INTERNAL_SERVER_ERROR.value # 500 |
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
# Add the following to the end of your .bashrc | |
# Basic PS1 | |
export PS1="\u@wsl: \w\n$ " | |
# Quick access to wsl directory | |
alias wsl="cd /mnt/c/wsl" | |
alias ..="cd .." | |
# cd to wsl folder on launch (All working files shared between the linux subsystem and windows) |
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 re | |
from urllib.parse import urlsplit | |
links = [ | |
# eligible links | |
"google.com/home", | |
"http://google.com/home", | |
"https://google.com/home", | |
"www.google.com/home", |
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
# 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 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 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 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 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 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 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", |