Skip to content

Instantly share code, notes, and snippets.

View HamdyTawfeek's full-sized avatar

HamdyTawfeek

View GitHub Profile
function parseJwt (token) {
// https://stackoverflow.com/questions/38552003/how-to-decode-jwt-token-in-javascript
var base64Url = token.split('.')[1];
var base64 = decodeURIComponent(atob(base64Url).split('').map((c)=>{
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
return JSON.parse(base64);
};
# Import the Python Library
import sys
import bcrypt
#!{sys.executable} -m pip install bcrypt
password = b"studyhard"
# Hash a password for the first time, with a certain number of rounds
salt = bcrypt.gensalt(14)
hashed = bcrypt.hashpw(password, salt)
print(salt)
# Import Package
from cryptography.fernet import Fernet
# Generate a Key and Instantiate a Fernet Instance
key = Fernet.generate_key()
f = Fernet(key)
print(key)
# Define our message
plaintext = b"encryption is very useful"
# Install a pip package in the current Jupyter kernel
import sys
!{sys.executable} -m pip install python-jose
import json
from jose import jwt
from urllib.request import urlopen
# Configuration
# UPDATE THIS TO REFLECT YOUR AUTH0 ACCOUNT
# Import Python Package
import jwt
import base64
# Init our Data
payload = {'hamdy':'software engineer'}
algo = 'HS256' #HMAC-SHA 256
secret = 'learning'
# Encode a JWT
from functools import wraps
# Our Basic Function Defn
def print_name(name):
print(name)
print_name("jimmy")
# Let's add a simple decorator to inject a greeting
def add_greeting(f):
# Init the engine
import os
from sqlalchemy import create_engine, Column, String, Integer
database_filename = "test.db"
project_dir = os.path.dirname(os.path.abspath(''))
database_path = "sqlite:///{}".format(os.path.join(project_dir, database_filename))
engine = create_engine(database_path)