From 3efedb4deda93f114bfcb86d61b29e701e8868ae Mon Sep 17 00:00:00 2001 From: Zoheb Alli Khan Date: Thu, 3 Jun 2021 08:06:46 +0530 Subject: [PATCH 01/28] Two methods added --- backend/express.js | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 backend/express.js diff --git a/backend/express.js b/backend/express.js new file mode 100644 index 0000000..2a6b56f --- /dev/null +++ b/backend/express.js @@ -0,0 +1,51 @@ +/* ******************************************************************************************* + * API + * http://expressjs.com/en/api.html + * ******************************************************************************************* */ + +const express = require("express"); // Importing the express library. +const app = express(); // Intializing the imported express application + +/* ******************************************************************************************* + * GLOBAL OBJECTS + * http://expressjs.com/en/api.html#express.json + * ******************************************************************************************* */ + +Methods; + +express.json([options]); + +options: ` +inflate // to manage the deflated bodies like enabling and disabling + +limit // Controls the maximum request body size. + +reviver // It is passed directly to JSON.parse as an second argument + +type // This is used to determine the type of middleware will parse + +verify // It is an undefined function which used to verify the middleware parsing. + +`; + +express.raw([options]); + +options: ` +inflate // to manage the deflated bodies like enabling and disabling + +limit // Controls the maximum request body size. + +type // This is used to determine the type of middleware will parse + +verify // It is an undefined function which used to verify the middleware parsing. +`; + +express.Router([options]); + +options: ` +caseSensitive //Enables case sensitivity + +mergeParams //if param names of child and parent are conflicted then the child takes the precedence + +strict // Enables Strict routing +`; From 81add6e07b15939bafb6e6ff585b682aa2dd1669 Mon Sep 17 00:00:00 2001 From: Zoheb Alli Khan Date: Thu, 3 Jun 2021 09:54:44 +0530 Subject: [PATCH 02/28] Added all express methods --- backend/express.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/backend/express.js b/backend/express.js index 2a6b56f..9c9987c 100644 --- a/backend/express.js +++ b/backend/express.js @@ -49,3 +49,51 @@ mergeParams //if param names of child and parent are conflicted th strict // Enables Strict routing `; + +express.static(root, [options]); + +options: ` +dotfiles // determines how dotfiles are used + +etag // Operates etag generation + +extensions // Operates file extension fallback + +fallthrough // Enable or disable the immutable directive in the Cache-Control response header + +index // sends the specified directory index file + +LastModified // sets the Last-Modified header to the last modified date + +setHeaders // Function for setting HTTP headers to serve with the file +`; + +express.text([options]); + +options: ` +defaultCharset // Sets the default charset for the text context. + +inflate // to manage the deflated bodies like enabling and disabling + +limit // Controls the maximum request body size. + +type // This is used to determine the type of middleware will parse + +verify // It is an undefined function which used to verify the middleware parsing. +`; + +express.urlencoded([options]); + +options: ` +extended // it allows to choose between parsing the URL-encoded data or the qs library + +parameterLimit // It controls the no of params. + +inflate // to manage the deflated bodies like enabling and disabling + +limit // Controls the maximum request body size. + +type // This is used to determine the type of middleware will parse + +verify // It is an undefined function which used to verify the middleware parsing. +`; From 9731e6841b46e4c4252e5811119a54fb0d4f0382 Mon Sep 17 00:00:00 2001 From: Zoheb Alli Khan Date: Thu, 3 Jun 2021 09:59:08 +0530 Subject: [PATCH 03/28] Structured Components --- backend/express.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/backend/express.js b/backend/express.js index 9c9987c..f3e1c8c 100644 --- a/backend/express.js +++ b/backend/express.js @@ -16,28 +16,28 @@ Methods; express.json([options]); options: ` -inflate // to manage the deflated bodies like enabling and disabling +inflate // to manage the deflated bodies like enabling and disabling -limit // Controls the maximum request body size. +limit // Controls the maximum request body size. -reviver // It is passed directly to JSON.parse as an second argument +reviver // It is passed directly to JSON.parse as an second argument -type // This is used to determine the type of middleware will parse +type // This is used to determine the type of middleware will parse -verify // It is an undefined function which used to verify the middleware parsing. +verify // It is an undefined function which used to verify the middleware parsing. `; express.raw([options]); options: ` -inflate // to manage the deflated bodies like enabling and disabling +inflate // to manage the deflated bodies like enabling and disabling -limit // Controls the maximum request body size. +limit // Controls the maximum request body size. -type // This is used to determine the type of middleware will parse +type // This is used to determine the type of middleware will parse -verify // It is an undefined function which used to verify the middleware parsing. +verify // It is an undefined function which used to verify the middleware parsing. `; express.Router([options]); From 859556dc1ff8b5ac475cf94f74b2bc55c147feba Mon Sep 17 00:00:00 2001 From: Zoheb Alli Khan Date: Thu, 3 Jun 2021 12:04:27 +0530 Subject: [PATCH 04/28] App Properties --- backend/express.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/backend/express.js b/backend/express.js index f3e1c8c..935eb1f 100644 --- a/backend/express.js +++ b/backend/express.js @@ -11,7 +11,7 @@ const app = express(); // Intializing the imported express application * http://expressjs.com/en/api.html#express.json * ******************************************************************************************* */ -Methods; +```Methods```; express.json([options]); @@ -97,3 +97,10 @@ type // This is used to determine the type of middleware will verify // It is an undefined function which used to verify the middleware parsing. `; + +```Application`````; +Properties```app.local`; + +`app.locals.title = "My Cheatsheet"; +console.dir(app.locals.title)`; +app.mountpath`;``app.mountpath``const admin = express()`; From 24faa1e1c15ba28dbd0cf601122c58f5070a1148 Mon Sep 17 00:00:00 2001 From: Zoheb Alli Khan Date: Thu, 3 Jun 2021 14:20:43 +0530 Subject: [PATCH 05/28] Changes --- backend/express.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/express.js b/backend/express.js index 935eb1f..740bb7b 100644 --- a/backend/express.js +++ b/backend/express.js @@ -102,5 +102,9 @@ verify // It is an undefined function which used to verify the Properties```app.local`; `app.locals.title = "My Cheatsheet"; + console.dir(app.locals.title)`; -app.mountpath`;``app.mountpath``const admin = express()`; + +app.mountpath` + +``app.mountpath``const admin = express()`; From b9be6c4cbcb474a2232bca820106ebe05db3599d Mon Sep 17 00:00:00 2001 From: Zoheb Alli Khan Date: Thu, 3 Jun 2021 23:14:49 +0530 Subject: [PATCH 06/28] Added some cheatsheets --- backend/express.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/backend/express.js b/backend/express.js index 740bb7b..6796340 100644 --- a/backend/express.js +++ b/backend/express.js @@ -103,8 +103,20 @@ Properties```app.local`; `app.locals.title = "My Cheatsheet"; -console.dir(app.locals.title)`; +console.dir(app.locals.title)`; // Creating objects with local variables app.mountpath` -``app.mountpath``const admin = express()`; +``app.mountpath``const admin = express() +admin.get('/', function(req,res){ + console.log(admin.mountpath) + res.send('Admin Homepage') +}) + +app.use('', admin)`; // Mounting a sub - app + +``Event`` + +`admin.on('mount', (parent){ + console.log('Admin Mounted') +})` // \ No newline at end of file From 8008c44d4915d05ff4c1ac5df37e058367344e61 Mon Sep 17 00:00:00 2001 From: Zoheb Alli Khan Date: Fri, 4 Jun 2021 09:54:29 +0530 Subject: [PATCH 07/28] HTTP App Routes --- backend/express.js | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/backend/express.js b/backend/express.js index 6796340..a06fc0a 100644 --- a/backend/express.js +++ b/backend/express.js @@ -119,4 +119,43 @@ app.use('', admin)`; // Mounting a sub - app `admin.on('mount', (parent){ console.log('Admin Mounted') -})` // \ No newline at end of file +})` // Mounting on a parent app + +``Methods`` +`app.get('/', function(req, res){ + res.send('GET request to message') +})` // get requests to the specified path + +`app.post('/', function(req,res){ + res.send('POST request to a webpage') +})` + +`app.put('/', function(req,res){ + res.send('PUT request to a webpage') +})` + +`app.delete('/', function(req,res){ + res.send('DELETE request to a webpage') +})` + +`app.all('/', function(req,res,next){ + console.log('Accessing the secret section....') + next() +})` + +`app.param('user', function(req,res,next){ + User.find(id, function(err, user){ + if(err){ + next(err) + } else if (user){ + req.user = user + next() + } else { + next(new Error('Failed to load user')) + } + }) +})` + +`app.use(function(req,res,next){ + res.send('Hey There!') +})` \ No newline at end of file From e775f8e6757be753fe49cf665740395a8751f81d Mon Sep 17 00:00:00 2001 From: Zoheb Alli Khan Date: Fri, 4 Jun 2021 10:45:05 +0530 Subject: [PATCH 08/28] Request Method and Props --- backend/express.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/backend/express.js b/backend/express.js index a06fc0a..6814152 100644 --- a/backend/express.js +++ b/backend/express.js @@ -158,4 +158,24 @@ app.use('', admin)`; // Mounting a sub - app `app.use(function(req,res,next){ res.send('Hey There!') -})` \ No newline at end of file +})` + +```Request``` +``Methods`` + +`req.param('name')` + +``app.post('/', function (req, res, next) { + console.log(req.body) + res.json(req.body) +})`` + +`console.dir(req.cookies.name)` + +`console.dir(req.query.q)` + +`console.log(req.route) +res.send('GET')` + +`console.dir(req.signedCookies.user)` + From b995f9e2c410b41ff5deb584122af372b372f527 Mon Sep 17 00:00:00 2001 From: Zoheb Alli Khan Date: Fri, 4 Jun 2021 10:47:31 +0530 Subject: [PATCH 09/28] Distinction --- backend/express.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/express.js b/backend/express.js index 6814152..0ea6cd6 100644 --- a/backend/express.js +++ b/backend/express.js @@ -165,10 +165,12 @@ app.use('', admin)`; // Mounting a sub - app `req.param('name')` -``app.post('/', function (req, res, next) { +``Properties`` + +`app.post('/', function (req, res, next) { console.log(req.body) res.json(req.body) -})`` +})` `console.dir(req.cookies.name)` From 106d6565675da317e813240327fd9f0b9e97188f Mon Sep 17 00:00:00 2001 From: Zoheb Alli Khan Date: Fri, 4 Jun 2021 11:41:30 +0530 Subject: [PATCH 10/28] Response methods --- backend/express.js | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/backend/express.js b/backend/express.js index 0ea6cd6..7b082cf 100644 --- a/backend/express.js +++ b/backend/express.js @@ -163,9 +163,22 @@ app.use('', admin)`; // Mounting a sub - app ```Request``` ``Methods`` -`req.param('name')` +`req.get('content-type')` +`req.accepts('html')` + + `req.is('json')` + + `var range = req.range(1000) + if (range.type === 'bytes'){ + range.forEach(function(r){ + + }) + }` + ``Properties`` + +`req.param('name')` `app.post('/', function (req, res, next) { console.log(req.body) @@ -181,3 +194,24 @@ res.send('GET')` `console.dir(req.signedCookies.user)` + +```Response``` +``Methods`` + +`res.redirect('https://google.com')` + +`res.send({message: 'Awesome Stuffs'})` + +`res.json({alert: 'awesomecheatsheets'})` + +`const file = req.params.name; +res.sendFile(file, options, function(err){ + if(err){ + next(err) + }else{ + console.log('Sent:', file) + } +})` + +`res.render('index')` + From 862c1138923adc96c3bef6752dec31a5cb2e528a Mon Sep 17 00:00:00 2001 From: Zoheb Alli Khan Date: Fri, 4 Jun 2021 11:51:15 +0530 Subject: [PATCH 11/28] BodyParser --- backend/express.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/backend/express.js b/backend/express.js index 7b082cf..ebf7379 100644 --- a/backend/express.js +++ b/backend/express.js @@ -215,3 +215,10 @@ res.sendFile(file, options, function(err){ `res.render('index')` +```BodyParser``` + +`const BodyParser = require('body-parser') +app.use(BodyParser.json()) +app.use(BodyParser.urlencoded({ + extended: true +}))` \ No newline at end of file From 2fa3e1b155a31cb03a8eddfbe2a8940d1a107475 Mon Sep 17 00:00:00 2001 From: Zoheb Alli Khan Date: Fri, 4 Jun 2021 16:17:37 +0530 Subject: [PATCH 12/28] Whole Cheatsheet --- backend/express.js | 76 ++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/backend/express.js b/backend/express.js index ebf7379..d919bfb 100644 --- a/backend/express.js +++ b/backend/express.js @@ -2,6 +2,8 @@ * API * http://expressjs.com/en/api.html * ******************************************************************************************* */ +`npm i express --save` or`yarn add -D express``(-D saves it as a dev dependency)` +`yarn add -D @types/express``(Installing for TS)` const express = require("express"); // Importing the express library. const app = express(); // Intializing the imported express application @@ -13,7 +15,7 @@ const app = express(); // Intializing the imported express application ```Methods```; -express.json([options]); +`express.json([options]);` options: ` inflate // to manage the deflated bodies like enabling and disabling @@ -28,7 +30,7 @@ verify // It is an undefined function which used to verify th `; -express.raw([options]); +`express.raw([options]);` options: ` inflate // to manage the deflated bodies like enabling and disabling @@ -40,7 +42,7 @@ type // This is used to determine the type of middleware wi verify // It is an undefined function which used to verify the middleware parsing. `; -express.Router([options]); +`express.Router([options]);` options: ` caseSensitive //Enables case sensitivity @@ -50,7 +52,7 @@ mergeParams //if param names of child and parent are conflicted th strict // Enables Strict routing `; -express.static(root, [options]); +`express.static(root, [options]);` options: ` dotfiles // determines how dotfiles are used @@ -68,7 +70,7 @@ LastModified // sets the Last-Modified header to the last modified d setHeaders // Function for setting HTTP headers to serve with the file `; -express.text([options]); +`express.text([options]);` options: ` defaultCharset // Sets the default charset for the text context. @@ -82,7 +84,7 @@ type // This is used to determine the type of middleware will verify // It is an undefined function which used to verify the middleware parsing. `; -express.urlencoded([options]); +`express.urlencoded([options]);` options: ` extended // it allows to choose between parsing the URL-encoded data or the qs library @@ -103,7 +105,7 @@ Properties```app.local`; `app.locals.title = "My Cheatsheet"; -console.dir(app.locals.title)`; // Creating objects with local variables +console.dir(app.locals.title)`; `// Creating objects with local variables` app.mountpath` @@ -113,35 +115,35 @@ admin.get('/', function(req,res){ res.send('Admin Homepage') }) -app.use('', admin)`; // Mounting a sub - app +app.use('', admin)`; `// Mounting a sub - app` ``Event`` `admin.on('mount', (parent){ console.log('Admin Mounted') -})` // Mounting on a parent app +})` `// Mounting on a parent app` ``Methods`` `app.get('/', function(req, res){ res.send('GET request to message') -})` // get requests to the specified path +})` `// get requests to the specified path` `app.post('/', function(req,res){ res.send('POST request to a webpage') -})` +})` `// post request to the specified path` `app.put('/', function(req,res){ res.send('PUT request to a webpage') -})` +})` `// post request to the specified path` `app.delete('/', function(req,res){ res.send('DELETE request to a webpage') -})` +})` `// delete request to the specified path` `app.all('/', function(req,res,next){ console.log('Accessing the secret section....') next() -})` +})` `// Routing all types of HTTP request` `app.param('user', function(req,res,next){ User.find(id, function(err, user){ @@ -154,55 +156,55 @@ app.use('', admin)`; // Mounting a sub - app next(new Error('Failed to load user')) } }) -})` +})` `// Adding callback trigger to route parameters` `app.use(function(req,res,next){ res.send('Hey There!') -})` +})` `// To Invoke the middleware layer that you want to add` ```Request``` ``Methods`` -`req.get('content-type')` +`req.get('content-type')` `// Returns the specified HTTP req header` -`req.accepts('html')` +`req.accepts('html')` `// Checks if the specified content types are available or not` - `req.is('json')` +`req.is('json')` `// Requests the matching content-type` - `var range = req.range(1000) - if (range.type === 'bytes'){ - range.forEach(function(r){ - - }) - }` +`var range = req.range(1000) +if (range.type === 'bytes'){ + range.forEach(function(r){ + // Your code + }) +}` `// Range header parser` ``Properties`` -`req.param('name')` +`req.param('name')` `// Requests the param name when present` `app.post('/', function (req, res, next) { console.log(req.body) res.json(req.body) -})` +})` `// Data submitted in the request body` -`console.dir(req.cookies.name)` +`console.dir(req.cookies.name)` `// Contains cookies sent by the request` -`console.dir(req.query.q)` +`console.dir(req.query.q)` `// Query string parameter in the route` `console.log(req.route) -res.send('GET')` +res.send('GET')` `// Outputs all the layer, methods, path` -`console.dir(req.signedCookies.user)` +`console.dir(req.signedCookies.user)` `// Logs all the signed cookies sent by the request` ```Response``` ``Methods`` -`res.redirect('https://google.com')` +`res.redirect('https://google.com')` `// Redirects to the intended page` -`res.send({message: 'Awesome Stuffs'})` +`res.send({message: 'Awesome Stuffs'})` `// Response to the webpage` -`res.json({alert: 'awesomecheatsheets'})` +`res.json({alert: 'awesomecheatsheets'})` `// Response in JSON type` `const file = req.params.name; res.sendFile(file, options, function(err){ @@ -211,9 +213,9 @@ res.sendFile(file, options, function(err){ }else{ console.log('Sent:', file) } -})` +})` `// Sends file to the intended path` -`res.render('index')` +`res.render('index')` `// Rendering the intended file` ```BodyParser``` @@ -221,4 +223,4 @@ res.sendFile(file, options, function(err){ app.use(BodyParser.json()) app.use(BodyParser.urlencoded({ extended: true -}))` \ No newline at end of file +}))` `// Parses incoming request bodies` \ No newline at end of file From d4fe30f94ba2dedbcb1f524de726945b3a74d859 Mon Sep 17 00:00:00 2001 From: Zoheb Alli Khan Date: Fri, 4 Jun 2021 16:38:50 +0530 Subject: [PATCH 13/28] Added in Readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5436080..cd2aa74 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ Feel free to take a look. You might learn new things. They have been designed to #### Javascript - [Adonis.js](backend/adonis.js) +- [Express.js](backend/express.js) - [Feathers.js](backend/feathers.js) - [Moleculer](backend/moleculer.js) - [Node.js](backend/node.js) From b885d645fe94c83880bdbb47badb2ca1c8da5a05 Mon Sep 17 00:00:00 2001 From: yogesnsamy <28777569+yogesnsamy@users.noreply.github.com> Date: Fri, 17 Sep 2021 10:57:51 +0800 Subject: [PATCH 14/28] Update golang.md Use propercase in renaming the function in the `Testing` example --- languages/golang.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/languages/golang.md b/languages/golang.md index 11e7dfd..fcb35fa 100644 --- a/languages/golang.md +++ b/languages/golang.md @@ -641,7 +641,7 @@ func TestSum(t *testing.T) { x, y := 2, 4 expected := 2 + 4 - if !reflect.DeepEqual(sum(x, y), expected) { + if !reflect.DeepEqual(Sum(x, y), expected) { t.Fatalf("Function Sum not working as expected") } } From ae5f62c7f8964f510fa8a00c1b9b9b6e3c7082c3 Mon Sep 17 00:00:00 2001 From: CookieGamer733 <74946768+CookieGamer733@users.noreply.github.com> Date: Tue, 21 Sep 2021 12:24:24 -0500 Subject: [PATCH 15/28] Correct spelling. --- languages/java.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/languages/java.md b/languages/java.md index 7c9fd6a..1ab8c66 100644 --- a/languages/java.md +++ b/languages/java.md @@ -85,7 +85,7 @@ int c = a + b; double tan(double theta) //tangent of theta double toRadians(double degrees) // convert angle from degrees to radians double toDegrees(double radians) // convert angle from radians to degrees - double exp(doube a) // exponential (e^a) + double exp(double a) // exponential (e^a) double pow(double a, double p) //raise a to the bth power (a^b) double random() //random in [0,1) double sqrt(double a) //square root of a From 71e45aa43ef0b85ead5991bcf6314c698493acda Mon Sep 17 00:00:00 2001 From: Yash Date: Sat, 25 Sep 2021 14:31:50 +0530 Subject: [PATCH 16/28] Update python.md --- languages/python.md | 87 +++++++++++++++++++++++++++++++++------------ 1 file changed, 64 insertions(+), 23 deletions(-) diff --git a/languages/python.md b/languages/python.md index d85910b..aa59be2 100644 --- a/languages/python.md +++ b/languages/python.md @@ -134,7 +134,7 @@ - Lists are created using square brackets: -```py +```python thislist = ["apple", "banana", "cherry"] ``` @@ -147,18 +147,31 @@ thislist = ["apple", "banana", "cherry"] - To determine how many items a list has, use the `len()` function. - A list can contain different data types: -```py +```python list1 = ["abc", 34, True, 40, "male"] ``` - It is also possible to use the list() constructor when creating a new list -```py +```python thislist = list(("apple", "banana", "cherry")) # note the double round-brackets ``` +- pop() function removes the last value in the given list by default. + + ```python + thislist = ["apple", "banana", "cherry"] + + print(thislist.pop())# cherry + print(thislist.pop(0)) #apple + + ``` + + + ### Tuple + - Tuple is a collection which is ordered and unchangeable. Allows duplicate members. - A tuple is a collection which is ordered and unchangeable. - Tuples are written with round brackets. -```py +```python thistuple = ("apple", "banana", "cherry") ``` - Tuple items are ordered, unchangeable, and allow duplicate values. @@ -168,16 +181,16 @@ thistuple = ("apple", "banana", "cherry") - Tuples are unchangeable, meaning that we cannot change, add or remove items after the tuple has been created. - Since tuple are indexed, tuples can have items with the same value: - Tuples allow duplicate values: -```py +```python thistuple = ("apple", "banana", "cherry", "apple", "cherry") ``` - To determine how many items a tuple has, use the `len()`function: -```py +```python thistuple = ("apple", "banana", "cherry") print(len(thistuple)) ``` - To create a tuple with only one item, you have to add a comma after the item, otherwise Python will not recognize it as a tuple. -```py +```python thistuple = ("apple",) print(type(thistuple)) @@ -186,7 +199,7 @@ thistuple = ("apple") print(type(thistuple)) ``` - It is also possible to use the tuple() constructor to make a tuple. -```py +```python thistuple = tuple(("apple", "banana", "cherry")) # note the double round-brackets print(thistuple) @@ -195,7 +208,7 @@ print(thistuple) ### Set - Set is a collection which is unordered and unindexed. No duplicate members. - A set is a collection which is both unordered and unindexed. -```py +```python thisset = {"apple", "banana", "cherry"} ``` - Set items are unordered, unchangeable, and do not allow duplicate values. @@ -206,27 +219,38 @@ thisset = {"apple", "banana", "cherry"} - Sets are unchangeable, meaning that we cannot change the items after the set has been created. - Duplicate values will be ignored. - To determine how many items a set has, use the `len()` method. -```py +```python thisset = {"apple", "banana", "cherry"} print(len(thisset)) ``` - Set items can be of any data type: -```py +```python set1 = {"apple", "banana", "cherry"} set2 = {1, 5, 7, 9, 3} set3 = {True, False, False} set4 = {"abc", 34, True, 40, "male"} ``` - It is also possible to use the `set()` constructor to make a set. -```py +```python thisset = set(("apple", "banana", "cherry")) # note the double round-brackets ``` +- frozenset() is just an immutable version of Set. While elements of a set can be modified at any time, elements of the frozen set remain the same after creation. + +```python +set1 = {"apple", "banana", "cherry"} +frzset=frozenset(set1) +print(frzset) +``` + + + ### Dictionary + - Dictionary is a collection which is unordered and changeable. No duplicate members. - Dictionaries are used to store data values in key:value pairs. - Dictionaries are written with curly brackets, and have keys and values: -```py +```python thisdict = { "brand": "Ford", "model": "Mustang", @@ -234,7 +258,7 @@ thisdict = { } ``` - Dictionary items are presented in key:value pairs, and can be referred to by using the key name. -```py +```python thisdict = { "brand": "Ford", "model": "Mustang", @@ -246,11 +270,11 @@ print(thisdict["brand"]) - Dictionaries cannot have two items with the same key. - Duplicate values will overwrite existing values. - To determine how many items a dictionary has, use the `len()` function. -```py +```python print(len(thisdict)) ``` - The values in dictionary items can be of any data type -```py +```python thisdict = { "brand": "Ford", "electric": False, @@ -259,9 +283,26 @@ thisdict = { } ``` +- pop() Function is used to remove a specific value from a dictionary. You can only use key bot the value. Unlike Lists you have to give a value to this function + + ```python + car = { + "brand": "Ford", + "model": "Mustang", + "year": 1964 + } + + x = car.pop("model") + + print(x)# Mustang + print(car)#{'brand': 'Ford', 'year': 1964} + ``` + + + ### Conditional branching -```py +```python if condition: pass elif condition2: @@ -278,7 +319,7 @@ thisdict = { #### While loop - With the `while` loop we can execute a set of statements as long as a condition is true. - Example: Print i as long as i is less than 6 -```py +```python i = 1 while i < 6: print(i) @@ -296,7 +337,7 @@ while i < 6: - This is less like the for keyword in other programming languages, and works more like an iterator method as found in other object-orientated programming languages. - With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc. -```py +```python fruits = ["apple", "banana", "cherry"] for x in fruits: print(x) @@ -310,7 +351,7 @@ A nested loop is a loop inside a loop. - The "inner loop" will be executed one time for each iteration of the "outer loop": -```py +```python adj = ["red", "big", "tasty"] fruits = ["apple", "banana", "cherry"] @@ -320,19 +361,19 @@ for x in adj: ``` - for loops cannot be empty, but if you for some reason have a for loop with no content, put in the pass statement to avoid getting an error. -```py +```python for x in [0, 1, 2]: pass ``` ### Function definition -```py +```python def function_name(): return ``` ### Function call -```py +```python function_name() ``` From 31b098ac634ef15478392c90bc0d661ae7993916 Mon Sep 17 00:00:00 2001 From: nikolasmelui Date: Mon, 27 Sep 2021 13:09:02 +0300 Subject: [PATCH 17/28] Update node.js --- backend/node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/node.js b/backend/node.js index a2a21e1..6bce482 100644 --- a/backend/node.js +++ b/backend/node.js @@ -436,7 +436,7 @@ request.on('connect', function(response, socket, head) { }); // Emitted each t request.on('upgrade', function(response, socket, head) { }); // Emitted each time a server responds to a request with an upgrade. If this event isn't being listened for, clients receiving an upgrade header will have their connections closed. request.on('continue', function() { }); // Emitted when the server sends a '100 Continue' HTTP response, usually because the request contained 'Expect: 100-continue'. This is an instruction that the client should send the request body. -response.write(chunk, [encoding]); // This sends a chunk of the response body. If this merthod is called and response.writeHead() has not been called, it will switch to implicit header mode and flush the implicit headers. +response.write(chunk, [encoding]); // This sends a chunk of the response body. If this method is called and response.writeHead() has not been called, it will switch to implicit header mode and flush the implicit headers. response.writeContinue(); // Sends a HTTP/1.1 100 Continue message to the client, indicating that the request body should be sent. response.writeHead(statusCode, [reasonPhrase], [headers]); // Sends a response header to the request. response.setTimeout(msecs, callback); // Sets the Socket's timeout value to msecs. If a callback is provided, then it is added as a listener on the 'timeout' event on the response object. From c64afd2158bc54e06e4358a5889e156dda21109d Mon Sep 17 00:00:00 2001 From: Steven Tracey <70534545+nevetS-718@users.noreply.github.com> Date: Wed, 29 Sep 2021 10:10:15 -0400 Subject: [PATCH 18/28] Use http2 http2 is a more secure connection and in some cases can improve load times. --- tools/nginx.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/nginx.sh b/tools/nginx.sh index bd1c857..61ac713 100644 --- a/tools/nginx.sh +++ b/tools/nginx.sh @@ -165,7 +165,7 @@ server { # The majority of SSL options depend on what your application does or needs server { - listen 443 ssl; + listen 443 ssl http2; server_name example.com; ssl on; @@ -212,4 +212,4 @@ server { location / { proxy_pass http://node_js; } -} \ No newline at end of file +} From 09602e03fda1c2eff79d32d296c06269b80bb3e2 Mon Sep 17 00:00:00 2001 From: Yuguang Wang Date: Fri, 8 Oct 2021 11:11:28 +0800 Subject: [PATCH 19/28] Fix several typos in python.md --- languages/python.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/languages/python.md b/languages/python.md index aa59be2..1eaf23e 100644 --- a/languages/python.md +++ b/languages/python.md @@ -70,15 +70,15 @@ | yield | yields values instead of returning (are called generators) | returning keyword | | import | import libraries/modules/packages | import | | from | import specific function/classes from modules/packages | import | -| try | this block will be tried to get executed | execption handling | -| execpt | is any execption/error has occured it'll be executed | execption handling | -| finally | It'll be executed no matter execption occurs or not | execption handling | -| raise | throws any specific error/execption | execption handling | -| assert | throws an AssertionError if condition is false | execption handling | +| try | this block will be tried to get executed | exception handling | +| except | is any exception/error has occured it'll be executed | exception handling | +| finally | It'll be executed no matter exception occurs or not | exception handling | +| raise | throws any specific error/exception | exception handling | +| assert | throws an AssertionError if condition is false | exception handling | | async | used to define asynchronous functions/co-routines | asynchronous programming | | await | used to specify a point when control is taken back | asynchronous programming | | del | deletes/unsets any user defined data | variable handling | -| global | used to access variables defined outsied of function | variable handling | +| global | used to access variables defined outside of function | variable handling | | nonlocal | modify variables from different scopes | variable handling |
@@ -159,8 +159,8 @@ thislist = list(("apple", "banana", "cherry")) # note the double round-brackets ```python thislist = ["apple", "banana", "cherry"] - print(thislist.pop())# cherry - print(thislist.pop(0)) #apple + print(thislist.pop()) # cherry + print(thislist.pop(0)) #apple ``` @@ -194,7 +194,7 @@ print(len(thistuple)) thistuple = ("apple",) print(type(thistuple)) -#NOT a tuple +# NOT a tuple thistuple = ("apple") print(type(thistuple)) ``` From d66d0db292b05da53504ddd40edc3e461768174e Mon Sep 17 00:00:00 2001 From: tortumlu Date: Sun, 10 Oct 2021 19:53:15 +0300 Subject: [PATCH 20/28] add netstat command to bash commands --- languages/bash.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/languages/bash.sh b/languages/bash.sh index 4710b56..9b01f97 100644 --- a/languages/bash.sh +++ b/languages/bash.sh @@ -179,6 +179,7 @@ whois # gets whois information for domain dig # gets DNS information for domain dig -x # reverses lookup host wget # downloads file +netstat # Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships time # report time consumed by command execution From 4a0d72fc3541ee0e94c6ece127b3c24fbb463358 Mon Sep 17 00:00:00 2001 From: tortumlu Date: Sun, 10 Oct 2021 19:57:23 +0300 Subject: [PATCH 21/28] add resize2fs command to bash commands --- languages/bash.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/languages/bash.sh b/languages/bash.sh index 9b01f97..78e63a3 100644 --- a/languages/bash.sh +++ b/languages/bash.sh @@ -164,6 +164,7 @@ info # shows another documentation system for the specific c help # shows documentation about built-in commands and functions df # shows disk usage du # shows the disk usage of the files and directories in filename (du -s give only a total) +resize2fs # ext2/ext3/ext4 file system resizer last # lists your last logins ps -u yourusername # lists your processes kill # kills the processes with the ID you gave From a580e2d1751743bd597f407aea2726221a3ea886 Mon Sep 17 00:00:00 2001 From: tortumlu Date: Sun, 10 Oct 2021 19:59:19 +0300 Subject: [PATCH 22/28] add ctrl+a then e command to bash commands --- languages/bash.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/languages/bash.sh b/languages/bash.sh index 78e63a3..ec74a11 100644 --- a/languages/bash.sh +++ b/languages/bash.sh @@ -46,6 +46,7 @@ CTRL+X then ( # start recording a keyboard macro CTRL+X then ) # finish recording keyboard macro CTRL+X then E # recall last recorded keyboard macro CTRL+X then CTRL+E # invoke text editor (specified by $EDITOR) on current command line then execute resultes as shell commands +CTRAL+A then D # logout from screen but don't kill it, if any command exist, it will continue BACKSPACE # deletes one character backward DELETE # deletes one character under cursor From 40303cb79f64611aad1139bd1663c9f253f2f686 Mon Sep 17 00:00:00 2001 From: Erfan Ansari Date: Thu, 14 Oct 2021 20:12:34 +0330 Subject: [PATCH 23/28] Update git --- tools/git.sh | 87 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 81 insertions(+), 6 deletions(-) diff --git a/tools/git.sh b/tools/git.sh index 46573a0..c7048d0 100644 --- a/tools/git.sh +++ b/tools/git.sh @@ -4,15 +4,32 @@ git clone
# creates a git repo from given address (get the address fro git clone
-b # clones a git repo from the address into the given directory and checkout's the given branch git clone
-b --single-branch # Clones a single branch -git add file.txt # adds(stages) file.txt to the git +git add # adds(stages) file.txt to the git git add * # adds(stages) all new modifications, deletions, creations to the git git reset file.txt # Removes file.txt from the stage git reset --hard # Throws away all your uncommitted changes, hard reset files to HEAD +git reset --soft # moves the head pointer +git reset --mixed # moves the head pointer and then copies the files from the commit it is now pointing to the staging area, +# the default when no argument is provided +git reset -hard # moves the head pointer and then copies the files from the commit it is now pointing to the staging area +# and working directory thus, throw away all uncommitted changes + +# git reset +# 1. Move HEAD and current branch +# 2. Reset the staging area +# 3. Reset the working area + +# --soft = (1) +# --mixed = (1) & (2) (default) +# --hard = (1) & (2) & (3) + git rm file.txt # removes file.txt both from git and file system git rm --cached file.txt # only removes file.txt both from git index git status # shows the modifications and stuff that are not staged yet git branch # shows all the branches (current branch is shown with a star) +git branch -a # shows all the branches local and remote + git branch my-branch # creates my-branch git branch -d my-branch # deletes my-branch git checkout my-branch # switches to my-branch @@ -32,7 +49,13 @@ git remote add my-remote
# creates a remote (get the address from your git remote rm my-remote # Remove a remote git log # shows the log of commits +# git log by default uses less command so you can use these: f=next page, b=prev page, search=/, n=next match, p=prev match, q=quit +git log --no-pager # shows the log of commits without less command git log --oneline # shows the log of commits, each commit in a single line + +git log --oneline --graph --decorate # shows the log of commits, each commit in a single line with graph +git log --since=