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
const mongoose = require('mongoose'); | |
const express = require('express'); | |
const app = express(); | |
const PORT = 3000; | |
app.use(express.json()); | |
// Set mongoose strictQuery | |
mongoose.set('strictQuery', true); |
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
require('dotenv').config(); | |
// TODO move to singleton pattern | |
const mongoose = require("mongoose") | |
mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true }, (err)=> { | |
console.log("DB Error", err) | |
}); | |
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
my_graph = { | |
'A': [('B', 5), ('C', 3), ('E', 11)], | |
'B': [('A', 5), ('C', 1), ('F', 2)], | |
'C': [('A', 3), ('B', 1), ('D', 1), ('E', 5)], | |
'D': [('C',1 ), ('E', 9), ('F', 3)], | |
'E': [('A', 11), ('C', 5), ('D', 9)], | |
'F': [('B', 2), ('D', 3)] | |
} | |
def shortest_path(graph, start, target = ''): |
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 arithmetic_arranger(problems, show_answers=False): | |
n = len(problems) | |
ans_objects = [] | |
if n > 5: | |
return "Error: Too many problems." | |
for i, problem in enumerate(problems): | |
first, oper, second = problem.split(" ") | |
l1, l2 = len(first), len(second) |
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 re | |
import secrets | |
import string | |
def generate_password(length=16, nums=1, special_chars=1, uppercase=1, lowercase=1): | |
# Define the possible characters for the password | |
letters = string.ascii_letters | |
digits = string.digits |
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 square_root_bisection(square_target, tolerance=1e-7, max_iterations=100): | |
if square_target < 0: | |
raise ValueError('Square root of negative number is not defined in real numbers') | |
if square_target == 1: | |
root = 1 | |
print(f'The square root of {square_target} is 1') | |
elif square_target == 0: | |
root = 0 | |
print(f'The square root of {square_target} is 0') | |
else: |
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 add_expense(expenses, amount, category): | |
expenses.append({'amount': amount, 'category': category}) | |
def print_expenses(expenses): | |
for expense in expenses: | |
print(f'Amount: {expense["amount"]}, Category: {expense["category"]}') | |
def total_expenses(expenses): | |
return sum(map(lambda expense: expense['amount'], expenses)) | |
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
<div id="container"></div> |
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
<div id="container"></div> |
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 Graph(v){ | |
this.vertices = v; | |
this.edges = 0; | |
this.adj = [] | |
for(var i=0; i<this.vertices; ++i){ | |
this.adj[i]=[]; | |
// this.adj[i].push(""); | |
} | |
this.addEdge = addEdge; | |
this.showGraph = showGraph; |
NewerOlder