Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding my Case Study (Week 0) sessions task work #9

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
30 changes: 30 additions & 0 deletions Day 1 - Welcome JS - Harshit Gupta/Welcome.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>

<html lang="en">
<head>
<title>Welcome to Day 1 - Swiggy IPP Program (Round 2)</title>

<!-- Running External JavaScript file by including it here (in <script> tags 'src' attribute) in this webpage -->
<script type="text/javascript" src="script.js"></script>
</head>
<body>

<section style="margin: auto; text-align: center;">

<div id="head1" onmouseover="this.innerHTML = 'Congratulations, and Welcome to Day 1 of Swiggy IPP';"> Welcome </div> <!-- Inline Script, here with onmouseover attribute -->
<br/>
<div id="data1"></div>

<input type="text" placeholder="Enter something here" />

</section>

<!-- Internal Script -->
<script>
document.getElementsByTagName('input')[0].onblur = function(){
document.getElementById('data1').innerHTML = this.value;
}
</script>

</body>
</html>
15 changes: 15 additions & 0 deletions Day 1 - Welcome JS - Harshit Gupta/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Display Methods covered in session 1 used here

console.log('External Script linked!');

window.alert('Your website is under destructive attack! ;)');

var response = confirm('Press OK to continue');
console.log("User Response:", response);
if (response) {
document.write();
} else {
document.write('<h1>Oops!</h1>');
}

window.print();
65 changes: 65 additions & 0 deletions Day 2 - More on JS - Harshit Gupta/welcome.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!DOCTYPE html>

<html>

<head>
<title>Welcome to Day 2 - Swiggy IPP Program (Round 2)</title>
</head>
<body>

<div style="margin: auto; text-align: center;">

<div id="head1"> <u>Welcome</u> </div> <br/>
<p id="data1"></p>

<input type="text" id="test" placeholder="Enter something" style="padding: .5em; margin-bottom: .5em; box-shadow: 0 1px 4px; border: none;" />

</section>

<!-- Internal Script -->
<script>

'use strict'; // Using strict mode to ensure more reportings, including some of those which might have got ignored

let testData, dataPoint = document.getElementById('data1');
dataPoint.innerHTML = testData = "Something good is cooking!";
dataPoint.style.fontSize = "2.5em";
dataPoint.style.display = "block";
dataPoint.style.visibility = "visible";
dataPoint.style.margin = ".5em auto";

document.getElementById('test').value = "Default Entry";
// delete testData; // Can't delete in strict mode

var object1 = { id:1, firstName:"Harshit", lastName:"Gupta", fullName: function(){ return this.firstName + ' ' + this.lastName } }
const currentDate = new Date(), date1 = new Date(2022, 0, 4, currentDate.getHours(), currentDate.getMinutes(), currentDate.getSeconds(), currentDate.getMilliseconds());
console.log("Date of coding:", date1);

let array1 = [1,2,4,3,6,5,7];
array1.sort( (a, b) => { return b-a } ); // Array gets sorted in descending order, with the given compare function
document.write("<br/> Your Array: ", array1.toString());
document.write("<br/> Sum of your array = ", array1.reduce( (previousValue, currentValue ) => previousValue+currentValue ), "<br/>");
console.log([1,2,3].concat(...[4,5,6,7]), 'is same as', [1,2,3].concat(4,5,6,7), ', right?');

let tripleArrayTest = "";
for (let index=0; index<array1.length; index++) {
tripleArrayTest += array1[index];
}
for (let number of array1) { // not to be confused with for-in
tripleArrayTest += number;
}
array1.forEach( number => { tripleArrayTest+=number; } );

let uniqueSet = new Set([1, '1', 2, '2', 5, '5']);
console.log(uniqueSet, 'is a unique set (' + (uniqueSet instanceof Set) + ')');
console.log('Sets are (by type):', typeof uniqueSet);

let uniqueMap = new Map(uniqueSet.entries());
for (let value in new Array(6).fill(1)) { uniqueMap.delete(value);}
console.log('Equivalent Reduced Map:', uniqueMap);

</script>

</body>

</html>
32 changes: 32 additions & 0 deletions Day 3 - Node JS - Harshit Gupta/file_handling.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var http = require('http');
let fs = require('fs'); // fs is file system module
// To upload a file, npm install formidable module
// To send a mail, npm install nodemailer module

// Creating a local server that listens at hard-coded port 8080
http.createServer(function (req, res) {
fs.readFile("new.html", (error, data)=>{
if (error) console.log("Error:", error);
res.writeHead(200, { 'Content-Type':'text/html' });
res.write(data);
});
}).listen(8080, ()=>{ console.log("Server started listening at port 8080") });

// Opening a file in write mode
fs.open("new.html", 'w', (error)=>{
// To write/overwrite data, use: fs.writeFile('new.html', <data>);
if (error) throw error;
console.log('new.html file is saved!');
});

// Appending data at end of file (sometimes succeeded unlink operation just below it, leading to error)
fs.appendFile('new.html', '<div>New Data</div>', error =>{
if (error) throw error;
console.log('new.html file has been Updated!');
});

// Deleting a file
fs.unlink('new.html', error=>{
if (error) throw error;
console.log("new.html file has been deleted successfully!");
});
27 changes: 27 additions & 0 deletions Day 3 - Node JS - Harshit Gupta/file_upload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Inspired by & Credits: https://www.w3schools.com/nodejs/nodejs_uploadfiles.asp

var http = require('http');
var formidable = require('formidable');

http.createServer(function (req, res) {
// console.log(req.url, req.method)
if (req.url === '/upload' && req.method === "POST") {
var form = new formidable.IncomingForm();
form.parse(req, function (_err, _fields, files) {
var oldPath = files.filetoupload.filepath;
var newPath = './' + files.filetoupload.originalFilename;
fs.rename(oldPath, newPath, function(error) {
if (error) throw error;
res.write('File uploaded and moved!');
res.end();
});
});
}
else {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(`<form action="upload" method="POST" enctype="multipart/form-data">
<input type="file" name="file-to-upload"><br><input type="submit">
</form>`);
return res.end();
}
}).listen(8080, ()=>{console.info('Server started at port 8080')});
3 changes: 3 additions & 0 deletions Day 3 - Node JS - Harshit Gupta/my_first_node_module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exports.myDateTime = function () {
return Date();
}
8 changes: 8 additions & 0 deletions Day 3 - Node JS - Harshit Gupta/my_first_node_server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var http = require('http');
// let date = require('./my_first_node_module')

http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type':'text/plain' });
// res.write("Current Date is: ", date.myDateTime());
res.end("Hello World!");
}).listen(8080, ()=>{console.info('Server started at port 8080')});
126 changes: 126 additions & 0 deletions Day 3 - Node JS - Harshit Gupta/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions Day 3 - Node JS - Harshit Gupta/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "day3-intro",
"version": "1.0.0",
"description": "",
"scripts": {
"start": "node testfile",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Harshit Gupta",
"dependencies": {
"formidable": "^2.0.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const express = require('express');

const app = express();

app.get('/', (req, res)=>{
res.send("Welcome from your local server!");
});

app.listen(3000, () => {console.log("Server started listening on localhost:3000")});
9 changes: 9 additions & 0 deletions Day 4 - Node API Resources - Harshit Gupta/axios-sample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const axios = require('axios');

// Requesting using axios (GET request)
axios.get('https://jsonplaceholder.typicode.com/todos/1')
.then(response => {
console.log('Response Code:', response.status, response.statusText);
process.stdout.write(JSON.stringify(response.data));
})
.catch(error => console.error(error));
Loading