Merge branch 'master' of github.com:LeCoupa/awesome-cheatsheets

This commit is contained in:
Julien Le Coupanec 2022-02-23 16:08:52 +01:00
commit 8dac93f947
8 changed files with 417 additions and 1 deletions

View File

@ -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
<p align="center"><a href="https://github.com/LeCoupa/awesome-cheatsheets/graphs/contributors">
<img src="https://contributors-img.web.app/image?repo=LeCoupa/awesome-cheatsheets" />
</a></p>

View File

@ -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

225
databases/mongodb.sh Normal file
View File

@ -0,0 +1,225 @@
# *****************************************************************************
# BASICS
# *****************************************************************************
# Connect MongoDB Shell
mongo # connects to mongodb://127.0.0.1:27017 by default
mongo --host <host> --port <port> -u <user> -p <pwd> # omit the password if you want a prompt
# Show All Databases
show dbs
# Show Current Database
db
# Create Or Switch Database
use <database_name>
# 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 } })

View File

@ -39,7 +39,7 @@
<strong></strong> and <b></b> <!-- Makes text contained in the tag as bold -->
<em></em> and <i></i> <!-- Alternative way to make the text contained in the tag as italic -->
<strike></strike> <!-- Creates a strike through the text element -->
<del></del> <!-- Creates a strike through the text element -->
<pre></pre> <!-- Preformatted monospace text block with some spacing intact -->
<blockquote></blockquote> <!-- Contains long paragraphs of quotations often cited -->
<abbr></abbr> <!-- Contains abbreviations while also making the full form avaialable -->

View File

@ -92,6 +92,7 @@ touch <filename> # creates or updates (edit) your file
mktemp -t <filename> # make a temp file in /tmp/ which is deleted at next boot (-d to make directory)
cat <filename> # displays file raw content (will not be interpreted)
cat -n <filename> # shows number of lines
nl <file.sh> # shows number of lines in file
cat filename1 > filename2 # Copy filename1 to filename2
cat filename1 >> filename2 # merge two files texts together
any_command > <filename> # '>' is used to perform redirections, it will set any_command's stdout to file instead of "real stdout" (generally /dev/stdout)
@ -206,6 +207,10 @@ read -p "prompt" <varname> # same as above but outputs a prompt to ask user fo
column -t <filename> # display info in pretty columns (often used with pipe)
let <varname> = <equation> # performs mathematical calculation using operators like +, -, *, /, %
export VARNAME=value # defines an environment variable (will be available in subprocesses)
export -f <funcname> # Exports function 'funcname'
export var1="var1 value" # Export and assign in the same statement
export <varname> # Copy Bash variable
declare -x <varname> # Copy Bash variable
array[0]=valA # how to define an array
array[1]=valB
@ -223,6 +228,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 +255,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 <x> # makes variable local - <x> must be an interger
##############################################################################
# FUNCTIONS

View File

@ -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.

View File

@ -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
*/
@ -38,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
*/
@ -81,6 +127,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
@ -97,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
@ -368,6 +459,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.
*/

View File

@ -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