Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
"""
Test Case 1
Note that the graph should be copied into a CSV file test.csv to test your program.
Description: This test gives you a simple adjacency matrix of a graph and a value of 4 for n.
"""

"""
graph:
0,1,1,0
1,0,0,0
1,0,0,1
0,0,1,0

n:
2

Output:
1
2
2
1
"""
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
"""
Test Case 2
Note that the graph should be copied into a CSV file test.csv to test your program.
Description: Fully connected graph with n=2; therefore, it is not ncolorable
"""

"""
graph:
1,1,1
1,1,1
1,1,1

n:
2

Output:
Graph cannot be colored
"""
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
"""
Test Case 3
Note that the graph should be copied into a CSV file test.csv to test your program.
Description: Fully connected graph with 3 nodes and n=3. Each node should have its own color
"""

"""
graph:
1,1,1
1,1,1
1,1,1

n:
3

Output:
1
2
3
"""
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
"""
Test Case 4
Note that the graph should be copied into a CSV file test.csv to test your program.
Description: Sample graph with 4 nodes and n=3
"""

"""
graph:
0,1,1,1
1,0,1,0
1,1,0,1
1,0,1,0

n:
3

Output:
1
2
3
2
"""
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
"""
Test Case 5
Note that the graph should be copied into a CSV file test.csv to test your program.
Description: Sample graph with 4 nodes and n=2
"""

"""
graph:
0,1,0,0
1,0,1,1
0,1,0,0
0,1,0,0

n:
2

Output:
1
2
1
1
"""
12 changes: 12 additions & 0 deletions Postman_Lab_URL_Shortener/Cards/1-1-1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!--title={Getting everything set up}-->

We need to make sure we have everything we need set up and installed before moving on with the project:

```Node.js
npm init

npm i express mongoose ejs

npm i --save-dev nodemon
```

9 changes: 0 additions & 9 deletions Postman_Lab_URL_Shortener/Cards/1.md

This file was deleted.

34 changes: 0 additions & 34 deletions Postman_Lab_URL_Shortener/Cards/10-1-1.md

This file was deleted.

3 changes: 0 additions & 3 deletions Postman_Lab_URL_Shortener/Cards/10-1.md

This file was deleted.

5 changes: 0 additions & 5 deletions Postman_Lab_URL_Shortener/Cards/10.md

This file was deleted.

38 changes: 21 additions & 17 deletions Postman_Lab_URL_Shortener/Cards/2-1-1.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
<!--title={Basic HTML Framework}-->
<!--title={Creating Server.js and Index.ejs}-->

We’ll need only a text input box, a button, and a script tag to create our URL shortener.
Edit the `package.json` file to have this line:

First create an HTML file called `index.html`, as there is only a need for those two elements (a text input box and a button).
```json
"scripts": {
"devStart": "nodemon server.js"
```

So let’s start adding our three main elements:
`server.js` will have a basic skeleton that will allow you to run the URL Shortener through your browser:

```html
<html>
<body>
<input type=”url” id=”urlinput”>
<button onclick=”shorturl()”>Shorten The URL</button>
<script src=”main.js”></script>
</body>
</html>
```
```javascript
const express = require('express')
const app = express()

app.get('/',(req, res) => {
res.render('index')
})

The first element in our HTML file is `input` where we will type/paste our long URL. We will give it an id name of `urlinput` so it would be easy to access in the JavaScript.
app.listen(process.env.PORT || 5000);
```

The next element is a `button`. When we click this button, our long URL will be shortened due to its `onclick` function. Inside the `shorturl()` function there will be commands necessary to shorten the URL.
Finally, your `index.ejs` file should only have one line:

At the end we have a `script` called `main.js` where all our main JavaScript code will be. The above-mentioned `shorturl()` function will be also there.
```
Hello World
```

So, for now, our HTML part is complete.
This will be enough to create a simple webpage and display a message in your browser.
12 changes: 0 additions & 12 deletions Postman_Lab_URL_Shortener/Cards/2-1.md

This file was deleted.

7 changes: 0 additions & 7 deletions Postman_Lab_URL_Shortener/Cards/2.md

This file was deleted.

42 changes: 38 additions & 4 deletions Postman_Lab_URL_Shortener/Cards/3-1-1.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,42 @@
<!--title={Storing our Endpoint}-->
<!--title={Fleshing out Index.ejs}-->

This can be done as follows:
Your `index.ejs` should now look as follows:

```javascript
var endpoint = "https://www.jsonstore.io/8ba4fd855086288421f770482e372ccb5a05d906269a34da5884f39eed0418a1";
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1>URL Shrinker</h1>
<form action="/shortUrls" method="POST">
<label for="fullUrl">Url</label>
<input type="url" name="fullUrl" id="fullUrl">
<button type="submit">Shrink</button>
</form>

<table>
<thead>
<tr>
<th>Full URL</th>
<th>Short URL</th>
<th>Clicks</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://www.google.com/">https://www.google.com/</a></td>
<td><a href="/123456">/123456</a></td>
<td>10</td>
</tr>
</tbody>
</table>
</body>
</html>
```

This gives us the basic form of our webpage, as well as all of the UI elements that we will need.
5 changes: 0 additions & 5 deletions Postman_Lab_URL_Shortener/Cards/3.md

This file was deleted.

59 changes: 41 additions & 18 deletions Postman_Lab_URL_Shortener/Cards/4-1-1.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,45 @@
<!--title={Creating a Link between Short and Long URL}-->
<!--title={Lots of Styling}-->

`getrandom()` can be defined as below:
The `index.ejs` will now look like this:

```javascript
function getrandom()
{
var random_string = Math.random().toString(32).substring(2, 5)
+ Math.random().toString(32).substring(2, 5);
return random_string();
}
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<title>Document</title>
</head>
<body>
<div class="container">
<h1>URL Shrinker</h1>
<form action="/shortUrls" method="POST" class="my-4 form-inline">
<label for="fullUrl" class="sr-only">Url</label>
<input required placeholder="Url" type="url" name="fullUrl" id="fullUrl" class="form-control col mr-2">
<button class="btn btn-success" type="submit">Shrink</button>
</form>

<table class="table table-striped table-responsive">
<thead>
<tr>
<th>Full URL</th>
<th>Short URL</th>
<th>Clicks</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://www.google.com/">https://www.google.com/</a></td>
<td><a href="/123456">/123456</a></td>
<td>10</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
```

First, we initiated a function called `getrandom`. Then we initialized a variable called `random_string` and gave it a value.

We then called the `random` function from `Math` , `Math.random()` returns a random number between 0 (inclusive), and 1 (exclusive).

Then we transform the returned number to a string using `toString()` and we give it an argument of 32 so that we get a proper string not a binary, hexadecimal or octal.

Then we use `substring(2,5)` as well to slice the string and maintain the size of the string. Then again we follow the same procedure to get another chunk of a random string, and finally we add both chunks of the string using `+`.

And don’t forget to add a `return` statement to actually return our random string.
This is all the styling that you will do for this lab. This is just so that the final product doesn't look *completely* ugly.
5 changes: 0 additions & 5 deletions Postman_Lab_URL_Shortener/Cards/4-1.md

This file was deleted.

3 changes: 0 additions & 3 deletions Postman_Lab_URL_Shortener/Cards/4.md

This file was deleted.

Loading