I found an elegant soultion to our nested comments problems.
I found the Solution from StackOverflow:
[https://stackoverflow.com/a/36829986]
Originally, the comments will be inserted into the database one after another.
const express = require("express") | |
const app = express() | |
app.get("/", function(req, res) { | |
res.send(`<h1>Hello World</h1>`) | |
}) | |
app.listen(5000, function() { | |
console.log("Server is running on port 5000"); |
import { useState } from "react" | |
/** | |
* Takes a file from the file browser and | |
* converts into a base64 string | |
* Shows an alert when the file type does not match | |
* Function is outside so it can be portable | |
* @param {Blob} file | |
* @returns {Promise} | |
*/ |
// Fetch API | |
// Fetch is a built in browser API built into JavaScript. | |
fetch('https://example.com/api/') | |
.then(res => res.json()) | |
.then(data => data) | |
.catch(err => err) | |
fetch('https://example.com/api/') |
<span id="my_date">1999</span> | |
<script> | |
var d = new Date(); | |
document.getElementById("my_date").innerText = d.getFullYear(); | |
</script> |
# This function takes a date and converts into | |
# desired format dd-mm-yyyy | |
# Use inside a loop to make the conversion | |
def convert_date(dateobject): | |
return dateobject.strftime('%d-%m-%Y') | |
# Example | |
from datetime import datetime |
I found an elegant soultion to our nested comments problems.
I found the Solution from StackOverflow:
[https://stackoverflow.com/a/36829986]
Originally, the comments will be inserted into the database one after another.
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<title>Document</title> | |
<style> | |
table, | |
th, | |
td { |
/** | |
* @param {array} array which is an array of items to be shuffled | |
* A function which returns an array of random chests like: | |
* ['gold', 'half', 'silver'] | |
* or | |
* ['silver', 'gold', 'fifty'] | |
*/ | |
function shuffleArray(array) { | |
let output = []; | |
// While we still have items, keep rolling |
const multerOptions = { | |
storege: multer.memoryStorage(), | |
fileFilter(req, file, next) { | |
const isPhoto = file.mimetype.startsWith('image/'); | |
if(isPhoto) { | |
next(null, true) | |
} else { | |
next({message: 'You must supply an image'}, false) | |
} | |
} |
const infinityGauntlet = { | |
powerStone: { | |
equipped: true, | |
info: 'Controls all of the power in the universe. It can be used to augment or inhibit any force.', | |
use() { | |
if(this.equipped) { | |
return 'Using super strength to crash the moon and throw it over to the Avengers!!'; | |
} else { | |
return 'No power stone!' | |
} |