Skip to content

Commit 75450d5

Browse files
committed
completed the driver and added data to mongo
1 parent 885dbd4 commit 75450d5

File tree

11 files changed

+70
-70
lines changed

11 files changed

+70
-70
lines changed

Library/CSharp.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
## :rocket: Notes on Data Structures and Programming Techniques
44

5-
* [**Download**](/src/C/notes.pdf)
5+
* [**Download**](./src/C/notes.pdf)
66
* size: 2.4 MB
77

88
## :rocket: Everyday Data Structures - A practical guide to learning data structures simply and easily
99

10-
* [**Download**](/src/CSharp/Everyday-Data-Structures-A-practical-guide-to-learning-data-structures-simply-and-easily.pdf)
10+
* [**Download**](./src/CSharp/Everyday-Data-Structures-A-practical-guide-to-learning-data-structures-simply-and-easily.pdf)
1111
* size: 1.7 MB

Library/Cpp.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
## :rocket: Data Structures and Algorithm Analysis in c++ (Fourth Edition)
44

5-
* [**Download**](/src/C++/DataStructuresAndAlgorithmAnalysisInCpp_2014.pdf)
5+
* [**Download**](./src/C++/DataStructuresAndAlgorithmAnalysisInCpp_2014.pdf)
66
* size: 4.4 MB
77

88
## :rocket: THINK LIKE A PROGRAMMER
99

10-
* [**Download**](/src/C++/d_book_proqramlashdirma_23560.pdf)
10+
* [**Download**](./src/C++/d_book_proqramlashdirma_23560.pdf)
1111
* size: 7.5 MB

Library/Fsharp.md renamed to Library/FSharp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
## :rocket: Learning F# Functional Data Structures and Algorithms
44

5-
* [**Download**](/src/FSharp/Learning-FSharp-Functional-Data-Structures-and-Algorithms.pdf)
5+
* [**Download**](./src/FSharp/Learning-FSharp-Functional-Data-Structures-and-Algorithms.pdf)
66
* size: 3.9 MB

Library/JAVA.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
## :rocket: DATA STRUCTURES & ALGORITHMS in JAVA
44

5-
* [**Download**](/src/JAVA/Data-Structures-and-Algorithms-in-Java.pdf)
5+
* [**Download**](./src/JAVA/Data-Structures-and-Algorithms-in-Java.pdf)
66
* size: 10.4 MB
77

88
## :rocket: Java 9 Data Structures and Algorithms
99

10-
* [**Download**](/src/JAVA/java-9-data-structures-algorithms.pdf)
10+
* [**Download**](./src/JAVA/java-9-data-structures-algorithms.pdf)
1111
* size: 2.5 MB
1212

1313
## :rocket: Dynamic Programming - A Computational Tool
1414

15-
* [**Download**](/src/JAVA/Dynamic-Programming-A-Computational-Tool.pdf)
15+
* [**Download**](./src/JAVA/Dynamic-Programming-A-Computational-Tool.pdf)
1616
* size: 8.0 MB
1717

1818
## :rocket: A Practical Introduction to Data Structures and Algorithm Analysis Third Edition
1919

20-
* [**Download**](/src/JAVA/book.pdf)
20+
* [**Download**](./src/JAVA/book.pdf)
2121
* size: 2.2 MB

Library/JavaScript.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
## :rocket: A Common-Sense Guide to Data Structures and Algorithms - Level Up Your Core Programming Skills
44

5-
* [**Download**](/src/JAVASCRIPT/A-Common-Sense-Guide-to-Data-Structures-and-Algorithms-Level-Up-Your-Core-Programming-Skills.pdf)
5+
* [**Download**](./src/JAVASCRIPT/A-Common-Sense-Guide-to-Data-Structures-and-Algorithms-Level-Up-Your-Core-Programming-Skills.pdf)
66
* size: 6.6 MB
77

88
## :rocket: Data Structures & Algorithms with JavaScript
99

10-
* [**Download**](/src/JAVASCRIPT/Data-Structures-&-Algorithms-with-JavaScript.pdf)
10+
* [**Download**](./src/JAVASCRIPT/Data-Structures-&-Algorithms-with-JavaScript.pdf)
1111
* size: 8.7 MB
1212

1313
## :rocket: Learning JavaScript Data Structures and Algorithms - Second Edition
1414

15-
* [**Download**](/src/JAVASCRIPT/Learning-JavaScript-Data-Structures-and-Algorithms-Second-Edition.pdf)
16-
* size: 29.4 MB
15+
* [**Download**](./src/JAVASCRIPT/Learning-JavaScript-Data-Structures-and-Algorithms-Second-Edition.pdf)
16+
* size: 29.4 MB

Library/Misc.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,65 +2,65 @@
22

33
## :rocket: Algorithms and Data Structures by N. Wirth
44

5-
* [**Download**](/src/AD.pdf)
5+
* [**Download**](./src/AD.pdf)
66
* size: 2.4 MB
77

88
## :rocket: Data Structures and Algorithms: Annotated Reference with Examples First Edition
99

10-
* [**Download**](/src/Dsa.pdf)
10+
* [**Download**](./src/Dsa.pdf)
1111
* size: 1.1 MB
1212

1313
## :rocket: Algorithms to Live By - Brian Christian
1414

15-
* [**Download**](/src/Algorithms-to-Live-By-Brian-Christian.pdf)
15+
* [**Download**](./src/Algorithms-to-Live-By-Brian-Christian.pdf)
1616
* size: 3.8 MB
1717

1818
## :rocket: Algorithms Unlocked - Thomas H. Cormen
1919

20-
* [**Download**](/src/Algorithms-Unlocked-Thomas-H.-Cormen.pdf)
20+
* [**Download**](./src/Algorithms-Unlocked-Thomas-H.-Cormen.pdf)
2121
* size: 4.1 MB
2222

2323
## :rocket: Disk-Based Algorithms for Big Data
2424

25-
* [**Download**](/src/Disk-Based-Algorithms-for-Big-Data.pdf)
25+
* [**Download**](./src/Disk-Based-Algorithms-for-Big-Data.pdf)
2626
* size: 19.2 MB
2727

2828
## :rocket: Essential Algorithms - A Practical Approach to Computer Algorithms
2929

30-
* [**Download**](/src/Essential-Algorithms-A-Practical-Approach-to-Computer-Algorithms.pdf)
30+
* [**Download**](./src/Essential-Algorithms-A-Practical-Approach-to-Computer-Algorithms.pdf)
3131
* size: 10.3 MB
3232

3333
## :rocket: Hacker's Delight - Second Edition
3434

35-
* [**Download**](/src/Hacker%27s-Delight-Second-Edition.pdf)
35+
* [**Download**](./src/Hacker%27s-Delight-Second-Edition.pdf)
3636
* size: 12.8 MB
3737

3838
## :rocket: Introduction to Algorithms - Third Edition
3939

40-
* [**Download**](/src/Introduction-to-Algorithms-Third-Edition.pdf)
40+
* [**Download**](./src/Introduction-to-Algorithms-Third-Edition.pdf)
4141
* size: 5.1 MB
4242

4343
## :rocket: Introduction to Algorithms
4444

45-
* [**Download**](/src/Introduction-to-Algorithms.pdf)
45+
* [**Download**](./src/Introduction-to-Algorithms.pdf)
4646
* size: 14.5 MB
4747

4848
## :rocket: Mathematics and Physics for Programmers - Second Edition
4949

50-
* [**Download**](/src/Mathematics-and-Physics-for-Programmers-Second-Edition.pdf)
50+
* [**Download**](./src/Mathematics-and-Physics-for-Programmers-Second-Edition.pdf)
5151
* size: 8.0 MB
5252

5353
## :rocket: Sets, Logic and Maths for Computing
5454

55-
* [**Download**](/src/Sets,-Logic-and-Maths-for-Computing.pdf)
55+
* [**Download**](./src/Sets,-Logic-and-Maths-for-Computing.pdf)
5656
* size: 2.4 MB
5757

5858
## :rocket: The Algorithm Design Manual - Second Edition
5959

60-
* [**Download**](/src/The-Algorithm-Design-Manual-Second-Edition.pdf)
60+
* [**Download**](./src/The-Algorithm-Design-Manual-Second-Edition.pdf)
6161
* size: 11.5 MB
6262

6363
## :rocket: The Master Algorithm - Pedro Domingos
6464

65-
* [**Download**](/src/The-Master-Algorithm-Pedro-Domingos.pdf)
65+
* [**Download**](./src/The-Master-Algorithm-Pedro-Domingos.pdf)
6666
* size: 4.0 MB

Library/PHP.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
## :rocket: PHP 7 Data Structures and Algorithms
44

5-
* [**Download**](/src/PHP/PHP-7-Data-Structures-and-Algorithms.pdf)
5+
* [**Download**](./src/PHP/PHP-7-Data-Structures-and-Algorithms.pdf)
66
* size: 5.4 MB

Library/Python.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
## :rocket: Data Structures and Algorithms in Python
44

5-
* [**Download**](/src/PYTHON/Data-Structures-and-Algorithms-in-Python.pdf)
5+
* [**Download**](./src/PYTHON/Data-Structures-and-Algorithms-in-Python.pdf)
66
* size: 6.9 MB
77

88
## :rocket: Data Structures and Algorithms with Python
99

10-
* [**Download**](/src/PYTHON/Data-Structures-and-Algorithms-with-Python.pdf)
10+
* [**Download**](./src/PYTHON/Data-Structures-and-Algorithms-with-Python.pdf)
1111
* size: 13.4 MB
1212

1313
## :rocket: Python Algorithms - Mastering Basic Algorithms in the Python Language - Second Edition
1414

15-
* [**Download**](/src/PYTHON/Python-Algorithms-Mastering-Basic-Algorithms-in-the-Python-Language-Second-Edition.pdf)
15+
* [**Download**](./src/PYTHON/Python-Algorithms-Mastering-Basic-Algorithms-in-the-Python-Language-Second-Edition.pdf)
1616
* size: 5.0 MB
1717

1818
## :rocket: Grokking Algorithms - An illustrated guide for programmers and other curious people
1919

20-
* [**Download**](/src/PYTHON/Grokking-Algorithms-An-illustrated-guide-for-programmers-and-other-curious-people.pdf)
20+
* [**Download**](./src/PYTHON/Grokking-Algorithms-An-illustrated-guide-for-programmers-and-other-curious-people.pdf)
2121
* size: 26.0 MB

docs/driver.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
const Book = require('./models/Book');
2-
// const mongoose = require('mongoose');
2+
const mongoose = require('mongoose');
33
let fs = require('fs');
44
require('dotenv').config();
55

6-
// mongoose.connect(process.env.MONGO_DB, {useNewUrlParser: true});
6+
mongoose.connect(process.env.MONGODB_URI, {
7+
useNewUrlParser: true,
8+
useUnifiedTopology: true,
9+
useCreateIndex: true
10+
});
711

8-
// const db = mongoose.connection;
12+
const db = mongoose.connection;
913

10-
// db.on('error',console.error.bind(console, 'Connection error:'));
14+
db.on('error',console.error.bind(console, 'Connection error:'));
1115

1216
const SEED_FILE = '../Library/Library.md';
1317
fs.readFile(SEED_FILE, (err,buf)=>{
@@ -22,11 +26,14 @@ fs.readFile(SEED_FILE, (err,buf)=>{
2226
fileNames.push(filename[2])
2327
}
2428
}
25-
addToMongo(fileNames);
29+
extractDataFromMarkdown(fileNames);
2630
})
2731

2832
// traversing fileNames and extract data
29-
const addToMongo = (fileNames)=>{
33+
const extractDataFromMarkdown = (fileNames)=>{
34+
const DOWNLOAD_URL = "https://github.com/GauravWalia19/Free-Algorithms-Books/raw/master/Library/";
35+
const VIEW_URL = "https://github.com/GauravWalia19/Free-Algorithms-Books/blob/master/Library/";
36+
3037
for(let i=0;i<fileNames.length;i++){
3138
let objectDatabase = [];
3239
let readFileName = '../Library/'+fileNames[i]; // reading files path
@@ -49,19 +56,36 @@ const addToMongo = (fileNames)=>{
4956
}
5057
object={
5158
name: arr[j].split('## :rocket: ')[1],
52-
url: "",
59+
view: "",
5360
size: "",
5461
language
5562
}
5663
}else if(arr[j].search("Download") != -1){
57-
object.url=arr[j].split(/([()])/)[2]
64+
let url = arr[j].split(/([()])/)[2];
65+
object.download = url.replace('./', DOWNLOAD_URL);
66+
object.view = url.replace('./', VIEW_URL);
5867
}else if(arr[j].search("size:") != -1){
5968
object.size=arr[j].split("* size: ")[1]
6069
}
6170
}
6271
objectDatabase.push(object); // pushing last created object
63-
console.log(objectDatabase);
72+
addDataToMongo(objectDatabase);
6473
})
65-
break;
74+
}
75+
}
76+
77+
const addDataToMongo = (objectDatabase)=>{
78+
for(let i=0;i<objectDatabase.length;i++){
79+
let book = new Book(
80+
objectDatabase[i]
81+
);
82+
book.save((err, book)=>{
83+
if(err)
84+
{
85+
console.log(err.message);
86+
}else{
87+
console.log("Book Added: " + objectDatabase[i].name);
88+
}
89+
});
6690
}
6791
}

docs/models/Book.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ const Book = new Schema({
88
required: true,
99
unique: true
1010
},
11-
url: {
11+
view: {
12+
type: String,
13+
required: true
14+
},
15+
download: {
1216
type: String,
1317
required: true
1418
},

0 commit comments

Comments
 (0)