From 734a77342fe3f7167d57f0339ee4d8a9edc932a2 Mon Sep 17 00:00:00 2001 From: "El. Abdellah" Date: Fri, 12 Nov 2021 11:28:07 +0100 Subject: [PATCH 01/12] Added mongoDB cheatSheet --- databases/mongodb.sh | 225 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 225 insertions(+) create mode 100644 databases/mongodb.sh diff --git a/databases/mongodb.sh b/databases/mongodb.sh new file mode 100644 index 0000000..e8da009 --- /dev/null +++ b/databases/mongodb.sh @@ -0,0 +1,225 @@ +# ***************************************************************************** +# BASICS +# ***************************************************************************** + +# Connect MongoDB Shell +mongo # connects to mongodb://127.0.0.1:27017 by default +mongo --host --port -u -p # omit the password if you want a prompt + +# Show All Databases +show dbs + + +# Show Current Database +db + + +# Create Or Switch Database +use + + +# Drop Database +db.dropDatabase() + + +# Create Collection +db.createCollection('posts') + + +# Show Collections +show collections + + +# ***************************************************************************** +# CRUD +# ***************************************************************************** + +# Insert Row +db.posts.insert({ + title: 'Post One', + body: 'Body of post one', + category: 'News', + tags: ['news', 'events'], + user: { + name: 'John Doe', + status: 'author' + }, + date: Date() +}) + + +# Insert Multiple Rows +db.posts.insertMany([ + { + title: 'Post Two', + body: 'Body of post two', + category: 'Technology', + date: Date() + }, + { + title: 'Post Three', + body: 'Body of post three', + category: 'News', + date: Date() + }, + { + title: 'Post Four', + body: 'Body of post three', + category: 'Entertainment', + date: Date() + } +]) + + +# Get All Rows +db.posts.find() + + +# Get All Rows Formatted +db.posts.find().pretty() + + +# Find One Row +db.posts.findOne({ category: 'News' }) + + +# Find Rows +db.posts.find({ category: 'News' }) + + +# Find Specific Fields +db.posts.find({ title: 'Post One' }, { + title: 1, + author: 1 +}) + + +# Update Row +db.posts.update({ title: 'Post Two' }, +{ + title: 'Post Two', + body: 'New body for post 2', + date: Date() +}, +{ + upsert: true +}) + + +# Update Specific Field +db.posts.update({ title: 'Post Two' }, +{ + $set: { + body: 'Body for post 2', + category: 'Technology' + } +}) + + +# Delete Row +db.posts.remove({ title: 'Post Four' }) + + +# ***************************************************************************** +# OTHER FUNCTIONS +# ***************************************************************************** + +# Sort Rows +db.posts.find().sort({ title: 1 }).pretty() # asc +db.posts.find().sort({ title: -1 }).pretty() # desc + + +# Count Rows +db.posts.find().count() +db.posts.find({ category: 'news' }).count() + + +# Limit Rows +db.posts.find().limit(2).pretty() + + +# Chaining +db.posts.find().limit(2).sort({ title: 1 }).pretty() + + +# Foreach +db.posts.find().forEach(function(doc) { + print("Blog Post: " + doc.title) +}) + + +# Increment Field (\$inc) +db.posts.update({ title: 'Post Two' }, +{ + $inc: { + likes: 5 + } +}) + + +# Rename Field +db.posts.update({ title: 'Post Two' }, +{ + $rename: { + likes: 'views' + } +}) + + +# Sub-Documents +db.posts.update({ title: 'Post One' }, +{ + $set: { + comments: [ + { + body: 'Comment One', + user: 'Mary Williams', + date: Date() + }, + { + body: 'Comment Two', + user: 'Harry White', + date: Date() + } + ] + } +}) + + +# Find By Element in Array (\$elemMatch) +db.posts.find({ + comments: { + $elemMatch: { + user: 'Mary Williams' + } + } + } +) + + +# Add Index +db.posts.createIndex({ title: 1 }) + + +# Drop Index +db.posts.dropIndex("title_1") + + +# Hide/Unhide Indexes +db.posts.hideIndex("title_1") +db.posts.unhideIndex("title_1") + + +# Text Search +db.posts.find({ + $text: { + $search: "\"Post O\"" + } +}) + + +# Greater & Less Than +db.posts.find({ views: { $gt: 2 } }) +db.posts.find({ views: { $gte: 7 } }) +db.posts.find({ views: { $lt: 7 } }) +db.posts.find({ views: { $lte: 7 } }) From 014126e4d71d7973d68842217a3bcabbf4a50f78 Mon Sep 17 00:00:00 2001 From: Jugid Date: Wed, 1 Dec 2021 22:45:46 +0100 Subject: [PATCH 02/12] More PHP elements --- languages/php.php | 89 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/languages/php.php b/languages/php.php index 876550e..def6f0c 100644 --- a/languages/php.php +++ b/languages/php.php @@ -11,9 +11,26 @@ echo ""; // Print a string or type that can be made into a string(I.E int, float print_r($arr); // Print anything, with type hints for array's and object's var_dump($arr); // Print anything, with type hints for any value and sizes +/** + * Usefull string manipulation methods + */ +$string = 'Awesome cheatsheets'; + +str_contains($string, 'cheat'); // Find if the string contains the specified string (PHP >= 8.0) +str_replace('Awesome', 'Bonjour', $string); // Replace all occurence (PHP >= 8.0) +strcmp($string, 'Awesome cheatsheets'); // Compare two strings +strpos($string, 'a', 0); // Get position in the string +str_split($string, 2); // Split the string +strrev($string); // Reverse a string +trim($string); // Strip whitespace from the beginning and end of a string +ucfirst($string); // Make a string's first character uppercase +lcfirst($string); // Make a string's first character lowercase +substr($string, 0, 4); // Return part of a string + /** * Declaring an Array */ + // Indexed Array $arr = array("John", "Doe", "Lorem", "Ipsum"); @@ -28,6 +45,16 @@ $arr = array ( array("Ipsum",170,150) ); +// Declaring array with short syntax +$arr = ["John", "Doe", "Lorem", "Ipsum"]; // Indexed Array +$arr = ["John"=>"10", "Doe"=>"200", "Doe"=>"3000", "Ipsum"=>"40000"]; // Associative Array +$arr = [ + ["John",100,180], + ["Doe",150,130], + ["Lorem",500,200], + ["Ipsum",170,150], // You can have a "," at the end without throwing syntax errors +]; + /** * Sorting an Array */ @@ -81,6 +108,26 @@ switch($arr) { default: } +/** + * Match (PHP >= 8.0) + * https://www.php.net/manual/fr/control-structures.match.php + */ +$food = 'apple'; +$return_value = match($food) { + 'apple', 'appel' => 'An apple', + 'banana' => 'A banana', + 'applepie' => 'An applepie', + default => 'A fruit' +}; + +//You can also use it as a conditionnal and throw exceptions +$str = 'Welcome to awesome cheatsheets'; +$return_value = match(true) { + str_contains($str, 'Welcome') && str_contains($str ,'to') => 'en-EN', + str_contains($str, 'Bonjour') && str_contains($str, 'sur') => 'fr-FR', + default => throw new Exception('Not a recognized language') +}; + /** * Global variables * http://php.net/manual/en/language.variables.superglobals.php @@ -368,6 +415,48 @@ class ClassWithLogger } +/** + * Enums (PHP >=8.1) + * https://www.php.net/manual/fr/language.types.enumerations.php + */ + + interface StateCode { + public function stateCode() : int; + } + + enum States implements StateCode { + case Running; + case Stopped; + + public function stateCode() : int { + return match($this) { + State::Running => '444', + State::Stopped => '666' + }; + } + } + + /** + * You can also declare backed Enums + */ + enum States : int implements StateCode { + case Running = 1; + case Stopped = 0; + + public function stateCode() : int { + return match($this) { + State::Running => '444', + State::Stopped => '666' + }; + } +} + + /** Enums can be use as a type */ + function notify(State $state) { + // ... + } + notify(State::Running); + /** * PHP Regex. */ From d5b2d4abb640aee277048aeac339422a9a1ec52f Mon Sep 17 00:00:00 2001 From: Jugid Date: Wed, 1 Dec 2021 23:04:16 +0100 Subject: [PATCH 03/12] Some more --- languages/php.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/languages/php.php b/languages/php.php index def6f0c..83d8da2 100644 --- a/languages/php.php +++ b/languages/php.php @@ -65,6 +65,25 @@ ksort($arr); // Sort associative arrays in ascending order, according to the key arsort($arr); // Sort associative arrays in descending order, according to the value. krsort($arr); // Sort associative arrays in descending order, according to the key. +/** + * Conditions + */ + + // If/Elseif/Else +if($i > 10) { + +} elseif( $i > 100) { + +} else { + +} + +// Ternary +$string = $state == 'Running' ? 'He is running' : 'I don\'t know'; + +// Null coalescing +$string = $startDate ?? ''; + /** * Ways of looping */ @@ -144,6 +163,31 @@ $_ENV; // php.ini options $argv; // Array of terminal arguments (filename included) $argc; // Number of arguments passed into terminal +/** + * Functions + */ + + // Simple function + function name($parameter); + + // Function with return type (void, int, float, string, array, object, mixed) + function name($parameter) : void; + + // Function with optionnal parameter + function name($parameter = '') : string; + + // Function with typed parameter (? means "can be null") + function name(?string $parameter) : ?string; + + // Function with union types (PHP >= 8.0) + function name(int|string $parameter1, array $parameter2) : int|string; + + // Function call + name('my_parameter'); + + // Null safe operator (PHP >= 8.0) + $myObject?->getName()?->startWith('A'); + /** * Class * http://php.net/manual/en/language.oop5.basic.php From 7c9ebfc0be46120a64421b81965eff9d48585599 Mon Sep 17 00:00:00 2001 From: rparwaiz <78734549+rparwaiz@users.noreply.github.com> Date: Thu, 2 Dec 2021 11:08:52 +0000 Subject: [PATCH 04/12] Update bash.sh --- languages/bash.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/languages/bash.sh b/languages/bash.sh index 21204cd..c0eeae1 100644 --- a/languages/bash.sh +++ b/languages/bash.sh @@ -206,6 +206,10 @@ read -p "prompt" # same as above but outputs a prompt to ask user fo column -t # display info in pretty columns (often used with pipe) let = # performs mathematical calculation using operators like +, -, *, /, % export VARNAME=value # defines an environment variable (will be available in subprocesses) +export -f # Exports function 'funcname' +export var1="var1 value" # Export and assign in the same statement +export # Copy Bash variable +declare -x # Copy Bash variable array[0]=valA # how to define an array array[1]=valB From 6b29cb5c7123bfd747edd39515bf8dee18fc6410 Mon Sep 17 00:00:00 2001 From: VesitoDev <88315648+VesitoDev@users.noreply.github.com> Date: Thu, 2 Dec 2021 15:35:56 +0200 Subject: [PATCH 05/12] added shortcuts in vscode.md (more info in deskcription) added general and basic editing shortcuts for vs code. I added those in the Linux category, I am not sure if they are the same for other OSs but in my resources, they said they are for Linux so if there are mistakes please correct them. Also, let me know if I should add more shortcuts. --- tools/vscode.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tools/vscode.md b/tools/vscode.md index f5a6e8b..f455b08 100644 --- a/tools/vscode.md +++ b/tools/vscode.md @@ -1,5 +1,39 @@ # Visual Studio CheatSheet +## Shortcuts + +### Linux + +#### General + +- `Ctrl`+`Shift`+`P`, `F1`: Show Command Palette +- `Ctrl`+`P`: Quick Open, Go to File +- `Ctrl`+`Shift`+`N`: New window/instance +- `Ctrl`+`W`: Close window/instance +- `Ctrl`+`,`: User Settings +- `Ctrl`+`K`, `Ctrl`+`S`: Keyboard Shortcuts + +#### Basic editing + +- `Ctrl`+`X`: Cut line (empty selection) +- `Ctrl`+`C`: Copy line (empty selection) +- `Ctrl`+`↓/↑`: Move line down / up +- `Ctrl`+`Shift`+`K`: Delete line +- `Ctrl`+`Enter` / `Ctrl`+`Shift`+`Enter`: Insert line below / above +- `Ctrl`+`Shift`+`\`: Jump to matching bracket +- `Ctrl`+`]` / `Ctrl`+`[`: Indent / Outdent line +- `Ctrl`+`Home` / `End`: Go to beginning / end of file +- `Ctrl`+`↑ / ↓`: Scroll line up / down +- `Alt`+`PgUp` / `PgDn`: Scroll page up / down +- `Ctrl`+`Shift`+`[ / ]`: Fold / unfold region +- `Ctrl`+`K`, `Ctrl`+`[ / ]`: Fold / unfold all subregions +- `Ctrl`+`K`, `Ctrl`+`0` / `Ctrl`+`K`, `Ctrl`+`J`: Fold /Unfold all regions +- `Ctrl`+`K`, `Ctrl`+`C`: Add line comment +- `Ctrl`+`K`, `Ctrl`+`U`: Remove line comment +- `Ctrl`+`/`: Toggle line comment +- `Ctrl`+`Shift`+`A`: Toggle block comment +- `Alt`+`Z`: Toggle word wrap + ## Useful Extensions ### HTML & CSS From c245e587309854cc36958ccb3e611206d7da9a06 Mon Sep 17 00:00:00 2001 From: Sheikh Haziq <41983383+sheikhhaziq@users.noreply.github.com> Date: Tue, 7 Dec 2021 20:34:25 +0530 Subject: [PATCH 06/12] Update javascript.js --- languages/javascript.js | 1 + 1 file changed, 1 insertion(+) diff --git a/languages/javascript.js b/languages/javascript.js index 932893e..9a8abfb 100644 --- a/languages/javascript.js +++ b/languages/javascript.js @@ -63,6 +63,7 @@ arr.length // Reflects the number of e arr.copyWithin(target, start, end) // Copies a sequence of array elements within the array. arr.fill(value, start, end) // Fills all the elements of an array from a start index to an end index with a static value. arr.pop() // Removes the last element from an array and returns that element. +arr.flat() // merges nested array into one single array arr.push([element1[, ...[, elementN]]]) // Adds one or more elements to the end of an array and returns the new length of the array. arr.reverse() // Reverses the order of the elements of an array in place — the first becomes the last, and the last becomes the first. arr.shift() // Removes the first element from an array and returns that element. From acb515c1716b06ebf3b3561a10218ad4d4585527 Mon Sep 17 00:00:00 2001 From: rparwaiz <78734549+rparwaiz@users.noreply.github.com> Date: Tue, 7 Dec 2021 16:53:56 +0000 Subject: [PATCH 07/12] Update bash.sh typeset -l # makes variable local - must be an interger declare -l # uppercase values in the variable are converted to lowercase declare -A # makes it an associative array --- languages/bash.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/languages/bash.sh b/languages/bash.sh index 21204cd..b1ecce3 100644 --- a/languages/bash.sh +++ b/languages/bash.sh @@ -223,6 +223,8 @@ declare -F # displays function names without definitions declare -i # the variables are treated as integers declare -r # makes the variables read-only declare -x # marks the variables for export via the environment +declare -l # uppercase values in the variable are converted to lowercase +declare -A # makes it an associative array ${varname:-word} # if varname exists and isn't null, return its value; otherwise return word ${varname:word} # if varname exists and isn't null, return its value; otherwise return word @@ -248,6 +250,7 @@ ${#varname} # returns the length of the value of the variable a $(UNIX command) # command substitution: runs the command and returns standard output +typeset -l # makes variable local - must be an interger ############################################################################## # FUNCTIONS From 4c1da007c0802e9813af5e22e9e91626c2bfafb1 Mon Sep 17 00:00:00 2001 From: rparwaiz <78734549+rparwaiz@users.noreply.github.com> Date: Thu, 9 Dec 2021 15:59:43 +0000 Subject: [PATCH 08/12] Update bash.sh --- languages/bash.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/languages/bash.sh b/languages/bash.sh index 21204cd..8edab8a 100644 --- a/languages/bash.sh +++ b/languages/bash.sh @@ -92,6 +92,7 @@ touch # creates or updates (edit) your file mktemp -t # make a temp file in /tmp/ which is deleted at next boot (-d to make directory) cat # displays file raw content (will not be interpreted) cat -n # shows number of lines +nl # shows number of lines in file cat filename1 > filename2 # Copy filename1 to filename2 cat filename1 >> filename2 # merge two files texts together any_command > # '>' is used to perform redirections, it will set any_command's stdout to file instead of "real stdout" (generally /dev/stdout) From 8b92343e9e30eabf9524b29afa221466494c4e57 Mon Sep 17 00:00:00 2001 From: AnuragSharma122 <82510045+AnuragSharma122@users.noreply.github.com> Date: Tue, 21 Dec 2021 18:19:54 +0530 Subject: [PATCH 09/12] I have added a part of database in this file --- backend/django.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/backend/django.py b/backend/django.py index 38b920d..50f53bd 100644 --- a/backend/django.py +++ b/backend/django.py @@ -37,6 +37,15 @@ # Use underscores in URL pattern names rather than dashes. +# ***************************************************************************** +# CODING STYLE > DATABASE +# ***************************************************************************** + +# 1.Register your app in admin file in your app folder to use admin panel in django +# 2.Create a superuser using command python manage.py createsuperuser +# 3.Remember to migrate after you change anything in your models.py file +# 4.Use /admin/ page to add data in your tables for testing purpose + # ***************************************************************************** # Deployment From 9edc51c045342d441559dae74320cac9fd186986 Mon Sep 17 00:00:00 2001 From: Ekram Asif Date: Sun, 2 Jan 2022 00:11:24 +0600 Subject: [PATCH 10/12] Contributors Added on README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index cd2aa74..b994dc2 100644 --- a/README.md +++ b/README.md @@ -128,3 +128,9 @@ Feel free to take a look. You might learn new things. They have been designed to ## 🙌🏼 How to Contribute? You are more than welcome to contribute and build your own cheat sheet for your favorite programming language, framework or development tool. Just submit changes via pull request and I will review them before merging. + +## Our valuable Contributors👩‍💻👨‍💻 : + +

+ +

From 3b578313c39176cbac4d5b5fe56486393d1610df Mon Sep 17 00:00:00 2001 From: Harold AO Date: Mon, 17 Jan 2022 20:55:47 +0100 Subject: [PATCH 11/12] strike replaced by del (strike is obsolete) --- frontend/html5.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/html5.html b/frontend/html5.html index 3d4910e..06bc17a 100644 --- a/frontend/html5.html +++ b/frontend/html5.html @@ -39,7 +39,7 @@ and and - +
                                       
 
From 4c3bde64f9234092ad494fa0bafc7332dac4735b Mon Sep 17 00:00:00 2001 From: Julien Le Coupanec Date: Sat, 22 Jan 2022 11:38:46 +0100 Subject: [PATCH 12/12] docs: update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b994dc2..3aea5c8 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ Feel free to take a look. You might learn new things. They have been designed to You are more than welcome to contribute and build your own cheat sheet for your favorite programming language, framework or development tool. Just submit changes via pull request and I will review them before merging. -## Our valuable Contributors👩‍💻👨‍💻 : +## 👩‍💻👨‍💻 Our valuable Contributors