-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e1558b3
Showing
225 changed files
with
15,593 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 4 | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
function hello(name) { | ||
console.log(`Hello ${name}`); | ||
} | ||
hello("Node.js"); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const quote = | ||
"Any app that can be written in JavaScript, will eventually be written in JavaScript. Jeff Atwood"; | ||
|
||
console.log(quote); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const quote = ` | ||
Any app that can be written in JavaScript, | ||
will eventually be written in JavaScript. | ||
-- Jeff Atwood. | ||
`; | ||
|
||
console.log(quote); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const quotes = [ | ||
`Any app that can be written in JavaScript, | ||
will eventually be written in JavaScript. | ||
-- Jeff Atwood. | ||
`, | ||
`JavaScript is the only language that I'm aware of | ||
that people feel they don't need to learn before | ||
they start using it. | ||
-- Douglas Crockford | ||
`, | ||
`Code never lies, comments sometimes do. | ||
-- Anonymous | ||
`, | ||
]; | ||
|
||
const randomIdx = Math.floor(Math.random() * quotes.length); | ||
|
||
console.log(quotes[randomIdx]); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const quotes = require("./quotes.json"); | ||
|
||
const randomIdx = Math.floor(Math.random() * quotes.length); | ||
|
||
console.log(quotes[randomIdx]); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const fs = require("fs"); | ||
|
||
fs.readFile("./data/003.txt", "utf-8", (err, data) => { | ||
if (err) { | ||
console.log("Error while reading quote file"); | ||
return; | ||
} | ||
console.log(data); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const fs = require("fs"); | ||
|
||
fs.readdir("./data", (err, files) => { | ||
if (err) { | ||
console.log("Error while reading data directory"); | ||
return; | ||
} | ||
console.log(files); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const fs = require("fs"); | ||
|
||
const QUOTES_DIR = "./data"; | ||
|
||
fs.readdir(QUOTES_DIR, (err, files) => { | ||
if (err) { | ||
console.log("Error while reading data directory"); | ||
return; | ||
} | ||
|
||
const randomIdx = Math.floor(Math.random() * files.length); | ||
const quoteFile = `${QUOTES_DIR}/${files[randomIdx]}`; | ||
|
||
fs.readFile(quoteFile, "utf-8", (err, data) => { | ||
if (err) { | ||
console.log("Error while reading quote file"); | ||
return; | ||
} | ||
console.log(data.toString()); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const fs = require("fs"); | ||
|
||
const QUOTES_DIR = "./data"; | ||
|
||
fs.readdir(QUOTES_DIR, (err, files) => { | ||
if (err) { | ||
console.log("Error while reading data directory"); | ||
process.exitCode = 1; | ||
return; | ||
} | ||
|
||
const randomIdx = Math.floor(Math.random() * files.length); | ||
const quoteFile = `${QUOTES_DIR}/${files[randomIdx]}`; | ||
|
||
fs.readFile(quoteFile, "utf-8", (err, data) => { | ||
if (err) { | ||
console.log("Error while reading quote file"); | ||
process.exitCode = 1; | ||
return; | ||
} | ||
console.log(data); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const fs = require("fs"); | ||
|
||
const QUOTES_DIR = "./data"; | ||
|
||
fs.readdir(QUOTES_DIR, (err, files) => { | ||
if (err) { | ||
console.error(`Error while reading ${QUOTES_DIR} directory`); | ||
process.exitCode = 1; | ||
return; | ||
} | ||
|
||
const randomIdx = Math.floor(Math.random() * files.length); | ||
const quoteFile = `${QUOTES_DIR}/${files[randomIdx]}`; | ||
|
||
fs.readFile(quoteFile, "utf-8", (err, data) => { | ||
if (err) { | ||
console.error(`Error while reading ${quoteFile} file`); | ||
process.exitCode = 1; | ||
return; | ||
} | ||
console.log(data.toString()); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const fs = require("fs"); | ||
|
||
const QUOTES_DIR = "./data"; | ||
|
||
fs.readdir(QUOTES_DIR, { withFileTypes: true }, (err, files) => { | ||
if (err) { | ||
console.error(`Error while reading ${QUOTES_DIR} directory`); | ||
process.exitCode = 1; | ||
return; | ||
} | ||
|
||
const txtFiles = files | ||
.filter((f) => f.isFile() && f.name.endsWith(".txt")) | ||
.map((f) => f.name); | ||
|
||
const randomIdx = Math.floor(Math.random() * txtFiles.length); | ||
const quoteFile = `${QUOTES_DIR}/${txtFiles[randomIdx]}`; | ||
|
||
fs.readFile(quoteFile, "utf-8", (err, data) => { | ||
if (err) { | ||
console.error(`Error while reading ${quoteFile} file`); | ||
process.exitCode = 1; | ||
return; | ||
} | ||
console.log(data.toString()); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const fs = require("fs"); | ||
|
||
const QUOTES_DIR = process.argv[2]; | ||
|
||
fs.readdir(QUOTES_DIR, { withFileTypes: true }, (err, files) => { | ||
if (err) { | ||
console.error(`Error while reading ${QUOTES_DIR} directory`); | ||
process.exitCode = 1; | ||
return; | ||
} | ||
|
||
const txtFiles = files | ||
.filter((f) => f.isFile() && f.name.endsWith(".txt")) | ||
.map((f) => f.name); | ||
|
||
const randomIdx = Math.floor(Math.random() * txtFiles.length); | ||
const quoteFile = `${QUOTES_DIR}/${txtFiles[randomIdx]}`; | ||
|
||
fs.readFile(quoteFile, "utf-8", (err, data) => { | ||
if (err) { | ||
console.error(`Error while reading ${quoteFile} file`); | ||
process.exitCode = 1; | ||
return; | ||
} | ||
console.log(data.toString()); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const fs = require("fs/promises"); | ||
|
||
const QUOTES_DIR = process.argv[2]; | ||
|
||
fs.readdir(QUOTES_DIR, { withFileTypes: true }) | ||
.then((files) => { | ||
const txtFiles = files | ||
.filter((f) => f.isFile() && f.name.endsWith(".txt")) | ||
.map((f) => f.name); | ||
|
||
const randomIdx = Math.floor(Math.random() * txtFiles.length); | ||
const quoteFile = `${QUOTES_DIR}/${txtFiles[randomIdx]}`; | ||
|
||
return fs.readFile(quoteFile, "utf-8"); | ||
}) | ||
.then((data) => { | ||
console.log(data.toString()); | ||
}) | ||
.catch((err) => { | ||
console.error(`Error: ${err.message}`); | ||
process.exitCode = 1; | ||
return; | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import fs from "fs/promises"; | ||
|
||
const QUOTES_DIR = process.argv[2]; | ||
|
||
try { | ||
const files = await fs.readdir(QUOTES_DIR, { withFileTypes: true }); | ||
const txtFiles = files | ||
.filter((f) => f.isFile() && f.name.endsWith(".txt")) | ||
.map((f) => f.name); | ||
|
||
const randomIdx = Math.floor(Math.random() * txtFiles.length); | ||
const quoteFile = `${QUOTES_DIR}/${txtFiles[randomIdx]}`; | ||
|
||
const data = await fs.readFile(quoteFile, "utf-8"); | ||
console.log(data.toString()); | ||
} catch (err) { | ||
console.error(`Error: ${err.message}`); | ||
process.exitCode = 1; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Non si abita un Paese, si abita una lingua. | ||
Una patria è questo, e niente altro. | ||
-- Emil Cioran |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Pubblicare un libro comporta lo stesso genere di noie | ||
di un matrimonio o di un funerale. | ||
-- Emil Cioran |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Un libro che lascia il lettore uguale | ||
a com'era prima di leggerlo è un libro fallito. | ||
-- Emil Cioran |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Si tira un aforisma come si tira uno schiaffo. | ||
-- Emil Cioran |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Non si scrive perché si ha qualcosa da dire | ||
ma perché si ha voglia di dire qualcosa. | ||
-- Emil Cioran |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Il fatto che la vita non abbia alcun senso è una ragione di vivere | ||
– la sola, del resto. | ||
-- Emil Cioran |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[ | ||
"Any app that can be written in JavaScript,\nwill eventually be written in JavaScript.\n\t\t\t-- Jeff Atwood", | ||
"JavaScript is the only language that I'm aware of\nthat people feel they don't need to learn before\nthey start using it.\n\t\t\t-- Douglas Crockford", | ||
"Code never lies, comments sometimes do.\n\t\t\t-- Anonymous" | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const http = require("http"); | ||
|
||
const server = http.createServer((req, res) => { | ||
res.end("Benvenuto nella biblioteca HTTP"); | ||
}); | ||
|
||
server.listen(3000, () => { | ||
console.log("Server running"); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const http = require("http"); | ||
|
||
const host = "127.0.0.1"; | ||
const port = 3000; | ||
|
||
const server = http.createServer((req, res) => { | ||
res.statusCode = 200; | ||
res.end("Benvenuto nella biblioteca HTTP"); | ||
}); | ||
|
||
server.listen(port, host, () => { | ||
console.log(`Server running at http://${host}:${port}/`); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const http = require("http"); | ||
|
||
const host = "127.0.0.1"; | ||
const port = 3000; | ||
|
||
const server = http.createServer((req, res) => { | ||
res.statusCode = 200; | ||
res.end('{"message": "Benvenuto nella biblioteca HTTP"}'); | ||
}); | ||
|
||
server.listen(port, host, () => { | ||
console.log(`Server running at http://${host}:${port}/`); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const http = require("http"); | ||
|
||
const host = "127.0.0.1"; | ||
const port = 3000; | ||
|
||
const server = http.createServer((req, res) => { | ||
res.statusCode = 200; | ||
res.setHeader("Content-Type", "application/json"); | ||
res.end(JSON.stringify({ message: "Benvenuto nella biblioteca HTTP" })); | ||
}); | ||
|
||
server.listen(port, host, () => { | ||
console.log(`Server running at http://${host}:${port}/`); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const http = require("http"); | ||
|
||
const host = "127.0.0.1"; | ||
const port = 3000; | ||
|
||
const server = http.createServer((req, res) => { | ||
const acceptJson = req.headers.accept === "application/json"; | ||
const acceptText = req.headers.accept === "text/plain"; | ||
|
||
if (acceptJson) { | ||
res.statusCode = 200; | ||
res.setHeader("Content-Type", "application/json"); | ||
res.end(JSON.stringify({ message: "Benvenuto nella biblioteca HTTP" })); | ||
} else if (acceptText) { | ||
res.statusCode = 200; | ||
res.setHeader("Content-Type", "text/plain"); | ||
res.end("Benvenuto nella biblioteca HTTP"); | ||
} else { | ||
res.statusCode = 406; | ||
res.end(); | ||
} | ||
}); | ||
|
||
server.listen(port, host, () => { | ||
console.log(`Server running at http://${host}:${port}/`); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const http = require("http"); | ||
|
||
const host = "127.0.0.1"; | ||
const port = 3000; | ||
|
||
function resJson(res) { | ||
res.statusCode = 200; | ||
res.setHeader("Content-Type", "application/json"); | ||
res.end(JSON.stringify({ message: "Benvenuto nella biblioteca HTTP" })); | ||
} | ||
|
||
function resText(res) { | ||
res.statusCode = 200; | ||
res.setHeader("Content-Type", "text/plain"); | ||
res.end("Benvenuto nella biblioteca HTTP"); | ||
} | ||
|
||
const server = http.createServer((req, res) => { | ||
const acceptJson = req.headers.accept === "application/json"; | ||
const acceptText = req.headers.accept === "text/plain"; | ||
const acceptAnyText = req.headers.accept === "text/*"; | ||
const acceptAnyType = req.headers.accept === "*/*"; | ||
|
||
if (acceptJson) { | ||
resJson(res); | ||
} else if (acceptText || acceptAnyText || acceptAnyType) { | ||
resText(res); | ||
} else { | ||
res.statusCode = 406; | ||
res.end(); | ||
} | ||
}); | ||
|
||
server.listen(port, host, () => { | ||
console.log(`Server running at http://${host}:${port}/`); | ||
}); |
Oops, something went wrong.