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
function charNumSort(array) { | |
return array | |
.map((word) => ({ word, characters: new Set(word.toLowerCase().split('')) })) | |
.sort((a, b) => { | |
if (a.characters.size === b.characters.size) { | |
return b.word.length - a.word.length | |
} | |
return a.characters.size - b.characters.size | |
}) | |
.map(({ word }) => word) |
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
const expect = require('chai').expect; | |
// Implementation of flatten(array) | |
function flatten(array) { | |
// early return if it is not an array or if empty | |
if (!array || !Array.isArray(array)) { | |
return; | |
} | |
return array.reduce((flattened, element) => { | |
return flattened.concat(Array.isArray(element) ? flatten(element) : [element]); |
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
const storage = require('./hostStorage'); | |
app.post('/upload', async (req, res) => { | |
try { | |
await storage.store(req.files.file); | |
res.sendStatus(200); | |
} | |
catch(err) { | |
res.sendStatus(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
const baseStorageFolder = './storage'; | |
const store = file => { | |
const filePath = `${baseStorageFolder}/${file.name}`; | |
return new Promise((res, rej) => file.mv(filePath, err => { | |
if (err) { | |
rej(); | |
return; | |
} | |
res(); | |
})); |
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
let http = require('http'); | |
const url = require('url'); | |
let fs = require('fs'); | |
const PORT=8000; | |
http.createServer((req, res) => { | |
let requestUrl = url.parse(req.url); | |
res.writeHead(200); | |
let stream = fs.createReadStream(__dirname + (requestUrl.pathname === '/' ? '/index.html' : requestUrl.pathname)); |
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
const backendPort = 8001; | |
const instance = axios.create({ baseURL: `http://localhost:${backendPort}` }); | |
async function upload(e) { | |
let files = this.files; | |
let formData = new FormData(); | |
formData.append('file', files[0]); | |
const configuration = { headers: { 'content-type': 'multipart/form-data' } }; | |
let response = await instance.post('/upload', formData, configuration); | |
alert('upload done!'); |
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
const express = require('express'); | |
const app = express(); | |
const http = require('http').Server(app); | |
const fileUpload = require('express-fileupload'); | |
const cors = require('cors'); | |
app.use(fileUpload()); | |
app.use(cors()); | |
const backendPort = 8001; |
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | |
<html lang="en"> | |
<head> | |
<meta http-equiv="content-type" content="text/html; charset=utf-8"> | |
<title>My uploading page</title> | |
</head> | |
<body> | |
<fieldset> | |
<legend>Avatar section</legend> | |
<div> |
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
{ | |
"undef": true, | |
"unused": true, | |
"curly": true, | |
"indent": 4, | |
"devel": true, | |
"browser": true, | |
"worker": true, | |
"jasmine": true, | |
"globals": { |
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
Show hidden characters
{ | |
"disallowCommaBeforeLineBreak": null, | |
"disallowDanglingUnderscores": null, | |
"disallowEmptyBlocks": true, | |
"disallowImplicitTypeConversion": [ "string" ], | |
"disallowKeywordsOnNewLine": [ ], | |
"disallowKeywords": [ "with" ], | |
"disallowMixedSpacesAndTabs": true, | |
"disallowMultipleLineBreaks": true, | |
"disallowMultipleLineStrings": true, |