Skip to content

Commit db4261d

Browse files
committed
Added project files from How to call Native C++ Shared Objects from Node.js, Text to Speech in Node.js, Introduction to using XPath in JavaScript, How to Get Started With JS IPFS and Node.js
1 parent af65a71 commit db4261d

10 files changed

Lines changed: 210 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Import dependencies
2+
const IPFS = require("ipfs"); // vs js-ipfs-http-client
3+
4+
(async () => {
5+
6+
const node = await IPFS.create();
7+
console.log("Node started!");
8+
9+
try {
10+
11+
const files = [{
12+
path: "/tmp/myfile2.txt",
13+
content: `
14+
<!DOCTYPE html>
15+
<html>
16+
<head>
17+
<title>IPFS</title>
18+
</head>
19+
<body>
20+
<h1>Hi Node.js</h1>
21+
</body>
22+
</html>
23+
`
24+
}];
25+
26+
const file = {
27+
path: "/tmp/myfile2.txt",
28+
content: `
29+
<!DOCTYPE html>
30+
<html>
31+
<head>
32+
<title>IPFS</title>
33+
</head>
34+
<body>
35+
<h1>Hi Node.js 4</h1>
36+
</body>
37+
</html>
38+
`
39+
};
40+
41+
// for await (const result of node.add(file)) {
42+
// console.log(result.cid.toString());
43+
// }
44+
45+
// for await (const result of node.cat("Qma8GKVh93ogeAQ4FYBXmZDjKbb68RnhkWt16AyWnMA5h9")) {
46+
// console.log(result.toString());
47+
// }
48+
49+
// Generator functions - https://stackoverflow.com/questions/44593309/object-generator-function-not-doing-what-it-should-and-returning-no-result
50+
console.log((await node.cat("Qma8GKVh93ogeAQ4FYBXmZDjKbb68RnhkWt16AyWnMA5h9").next()).value.toString());
51+
52+
53+
} catch (error) {
54+
console.error("Node failed to start!", error);
55+
await node.stop();
56+
}
57+
58+
})();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "get-started-with-js-ipfs",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "app.js",
6+
"dependencies": {
7+
"bs58": "^4.0.1",
8+
"ipfs": "^0.41.0"
9+
},
10+
"devDependencies": {},
11+
"scripts": {
12+
"test": "echo \"Error: no test specified\" && exit 1"
13+
},
14+
"author": "",
15+
"license": "MIT"
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>XPath</title>
5+
<link rel="stylesheet" href="style.css">
6+
</head>
7+
<body>
8+
<div id="red-box"></div>
9+
<div id="green-box"></div>
10+
<div></div>
11+
<div id="blue-box">
12+
<div id="yellow-box"></div>
13+
<input type="email">
14+
</div>
15+
</body>
16+
</html>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
* {
2+
margin: 0px;
3+
padding: 0px;
4+
}
5+
6+
#red-box {
7+
width: 200px;
8+
height: 200px;
9+
background-color: red;
10+
display: inline-block;
11+
}
12+
13+
#green-box {
14+
width: 200px;
15+
height: 200px;
16+
background-color: green;
17+
display: inline-block;
18+
}
19+
20+
#blue-box {
21+
width: 404px;
22+
height: 404px;
23+
background-color: blue;
24+
display: inline-block;
25+
}
26+
27+
#yellow-box {
28+
width: 200px;
29+
height: 200px;
30+
background-color: yellow;
31+
display: inline-block;
32+
}

‎Text to Speech in Node.js/app.js‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Import dependencies
2+
const say = require("say");
3+
4+
// Use default system voice and speed
5+
say.speak("Today will make node speak");
6+
7+
// // Set the speed
8+
// say.speak("Hello!", "", 0.5);
9+
10+
// Stop the text currently being spoken
11+
// say.stop();
12+
13+
// Export Voice to file
14+
// const filename = "hello.wav";
15+
// say.export("Hello!", "", 0.75, filename, function (err) {
16+
// if (err) {
17+
// return console.error(err);
18+
// }
19+
20+
// console.log(`Text has been saved to ${filename}`);
21+
// });
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "make-your-computer-talk",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "app.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "MIT",
11+
"dependencies": {
12+
"say": "^0.16.0"
13+
}
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
extern "C" int Subtract(int num1, int num2)
2+
{
3+
return num1 - num2;
4+
}
5+
6+
extern "C" int Add(int num1, int num2)
7+
{
8+
return num1 + num2;
9+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Node 10 and lower
3+
npm i ffi
4+
https://www.npmjs.com/package/ffi
5+
https://github.com/node-ffi/node-ffi
6+
Node 11 and 12
7+
npm i @saleae/ffi
8+
https://www.npmjs.com/package/@saleae/ffi
9+
https://github.com/lxe/node-ffi/tree/node-12
10+
Node 13 and higher
11+
npm i ffi-napi
12+
https://www.npmjs.com/package/ffi-napi
13+
https://github.com/node-ffi-napi/node-ffi-napi
14+
*/
15+
16+
// Import dependencies
17+
const ffi = require("ffi-napi");
18+
19+
// Import math library
20+
const mathLibrary = new ffi.Library("./MathLibrary", {
21+
"Subtract": [
22+
"int", ["int", "int"]
23+
],
24+
"Add": [
25+
"int", ["int", "int"]
26+
]
27+
});
28+
29+
console.log(mathLibrary.Subtract(15, 5));
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "ffi-on-linux",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "app.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "MIT",
12+
"dependencies": {
13+
"ffi-napi": "^2.4.6"
14+
}
15+
}

0 commit comments

Comments
 (0)