From 1ccb16f652594f02120c57dca2e242ed9e0cdbe7 Mon Sep 17 00:00:00 2001 From: Marcello Lamonaca Date: Wed, 18 Oct 2023 12:10:59 +0200 Subject: [PATCH 1/4] make dependabot update github-actions --- .github/dependabot.yml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 9ccfa63..b90dd75 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,13 +1,22 @@ version: 2 updates: - - package-ecosystem: "pip" # See documentation for possible values - directory: "/" # Location of package manifests + - package-ecosystem: "pip" + directory: "/" schedule: interval: "weekly" commit-message: prefix: "Poetry" include: "scope" ignore: - # ignore patch updates - dependency-name: "*" update-types: ["version-update:semver-patch"] + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + commit-message: + prefix: "Github Actions" + include: "scope" + ignore: + - dependency-name: "*" + update-types: ["version-update:semver-minor"] From f25179843483f6152a570e8c109b0ba59be6c1cc Mon Sep 17 00:00:00 2001 From: Marcello Lamonaca Date: Fri, 20 Oct 2023 17:51:58 +0200 Subject: [PATCH 2/4] show copy button in code snippets --- mkdocs.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/mkdocs.yml b/mkdocs.yml index 8635c98..62eefa4 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -59,6 +59,7 @@ theme: - navigation.tabs.sticky - navigation.footer - toc.follow + - content.code.copy markdown_extensions: From 09b46d5c571aea87674c3c2ab1c11a824ec48276 Mon Sep 17 00:00:00 2001 From: Marcello Lamonaca Date: Fri, 20 Oct 2023 18:16:19 +0200 Subject: [PATCH 3/4] improve regex notes --- docs/misc/regular-expressions.md | 256 +++++++++++++++++++++++++------ 1 file changed, 209 insertions(+), 47 deletions(-) diff --git a/docs/misc/regular-expressions.md b/docs/misc/regular-expressions.md index 0409c89..09c4252 100644 --- a/docs/misc/regular-expressions.md +++ b/docs/misc/regular-expressions.md @@ -1,66 +1,228 @@ # Common Regex Syntax -## Character Types +A **regular expression** is a *pattern* that the regular expression engine attempts to match in input text. A pattern consists of one or more character literals, operators, or constructs. -`\d` any digit (0-9) -`\D` any non digit character -`\s` whitespace (space, tab, new line) -`\S` any non whitespace characters -`\w` any alphanumeric character (a-z, A-Z) -`\W` any non alphanumeric character -`\b` whitespace surrounding words (only at row start or end) -`\B` whitespace surrounding words (not at row start or end) -`\A` search only at string start -`\Z` search only at string end -`.` any characters but newline (CRLF, CR, LF) +## Character Classes + +A **character class** matches any one of a set of characters. + +- `[character_group]`:: matches any single character in *character_group*. +- `[^character_group]`: matches any single character **not** in *character_group*. +- `[first-last]`: matches any single character in range from *first* to *last*. +- `.`: matches any single character except `\n`. +- `\p{name}`: matches any single character in the Unicode general category or named block specified by *name*. +- `\P{name}`: matches any single character **not** in the Unicode general category or named block specified by *name*. +- `\w`: matches any word character. +- `\W`: matches any **non** word character. +- `\s`: matches any whitespace character. +- `\S`: matches any **non** whitespace character. +- `\d`: matches any decimal digit. +- `\D`: matches any character other than a decimal digit. + +> **Note**: `^`, `\`, `-` and `]` must be escaped to be used in ranges. (`[ \] \[ \^ \- ]`) + +## Anchors + +**Anchors**, or atomic zero-width assertions, cause a match to succeed or fail depending on the current position in the string, but they do not cause the engine to advance through the string or consume characters. + +- `^`: The match must be at the *start* of a string/line. +- `$`: The match must be at the *end* of a string/line. +- `\A`: The match must occur at the start of the string. +- `\Z`: The match must occur at the end of the string or before `\n` at the end of the string. +- `\z`: The match must occur at the end of the string. +- `\G`: The match must occur at the point where the previous match ended, or if there was no previous match, at the position in the string where matching started. +- `\b`: The match must occur on a boundary between a `\w` (alphanumeric) and a `\W` (non-alphanumeric) character. +- `\B`: The match must not occur on a `\b` boundary. + +## Grouping Constructs + +**Grouping constructs** delineate subexpressions of a regular expression and typically capture substrings of an input string. + +### Subexpressions + +```regex title="Regex Syntax" linenums="1" +(subexpression) +``` + +The *subexpression* is any valid regular expression pattern. + +Captures that use parentheses are numbered automatically from left to right based on the order of the opening parentheses in the regular expression, starting from `1`. The capture that's numbered `0` is the text matched by the entire regular expression pattern. + +> **Note**: named capture groups are always ordered last, after non-named capture groups. + +It's possible to access the captured group in the following ways: + +- By using the *backreference construct* within the regular expression. + + The matched subexpression is referenced in the same regular expression by using the syntax `\number`, where number is the ordinal number of the captured subexpression. + +- By using the *named backreference construct* within the regular expression. + + The matched subexpression is referenced in the same regular expression by using the syntax `\k`, where name is the name of a capturing group, or `\k`, where number is the ordinal number of a capturing group. + + A capturing group has a default name that is identical to its ordinal number. For more information, see Named matched subexpressions later in this topic. + +- By using the `$number` *replacement sequence* where number is the ordinal number of the captured subexpression. + +### Named Subexpressions + +```regex title="Regex Syntax" linenums="1" +(? subexpression) +(?'name' subexpression) +``` + +THe *name* is a valid group name, and *subexpression* is any valid regular expression pattern. *name* must not contain any punctuation characters and cannot begin with a number. + +It's possible to access the named captured group in the following ways: + +- By using the named *backreference construct* within the regular expression. + + The matched subexpression is referenced in the same regular expression by using the syntax `\k`, where name is the name of the captured subexpression. + +- By using the *backreference construct* within the regular expression. + + The matched subexpression is referenced in the same regular expression by using the syntax `\number`, where number is the ordinal number of the captured subexpression. + + Named matched subexpressions are numbered consecutively from left to right after matched subexpressions. + +- By using the `${name}` *replacement sequence* where name is the name of the captured subexpression. +- By using the `$number` *replacement sequence* where number is the ordinal number of the captured subexpression. + +### Noncapturing groups + +```regex title="Regex Syntax" linenums="1" +(?:subexpression) +``` + +The *subexpression* is any valid regular expression pattern. The noncapturing group construct is typically used when a quantifier is applied to a group, but the substrings captured by the group are of no interest. + +### Zero-width positive lookahead assertions + +```regex title="Regex Syntax" linenums="1" +(?= subexpression) +``` + +The *subexpression* is any regular expression pattern. For a match to be successful, the input string must match the regular expression pattern in subexpression, although the matched substring is not included in the match result. A zero-width positive lookahead assertion does not backtrack. + +Typically, a zero-width positive lookahead assertion is found at the end of a regular expression pattern. It defines a substring that must be found at the end of a string for a match to occur but that should not be included in the match. It is also useful for preventing excessive backtracking. + +It's possible to use a zero-width positive lookahead assertion to ensure that a particular captured group begins with text that matches a subset of the pattern defined for that captured group. + +### Zero-width negative lookahead assertions + +```regex title="Regex Syntax" linenums="1" +(?! subexpression) +``` + +The *subexpression* is any regular expression pattern. For the match to be successful, the input string must not match the regular expression pattern in subexpression, although the matched string is not included in the match result. + +A zero-width negative lookahead assertion is typically used either at the beginning or at the end of a regular expression. At the beginning of a regular expression, it can define a specific pattern that should not be matched when the beginning of the regular expression defines a similar but more general pattern to be matched. In this case, it is often used to limit backtracking. At the end of a regular expression, it can define a subexpression that cannot occur at the end of a match. + +### Zero-width positive lookbehind assertions + +```regex title="Regex Syntax" linenums="1" +(?<= subexpression) +``` + +The *subexpression* is any regular expression pattern. For a match to be successful, subexpression must occur at the input string to the left of the current position, although subexpression is not included in the match result. A zero-width positive lookbehind assertion does not backtrack. + +Zero-width positive lookbehind assertions are typically used at the beginning of regular expressions. The pattern that they define is a precondition for a match, although it is not a part of the match result. + +### Zero-width negative lookbehind assertions + +```regex title="Regex Syntax" linenums="1" +(? subexpression) +``` + +Hte *subexpression* is any regular expression pattern. For a match to be successful, subexpression must not occur at the input string to the left of the current position. However, any substring that does not match subexpression is not included in the match result. + +Zero-width negative lookbehind assertions are typically used at the beginning of regular expressions. The pattern that they define precludes a match in the string that follows. They are also used to limit backtracking when the last character or characters in a captured group must not be one or more of the characters that match that group's regular expression pattern. + +### Atomic groups + +```regex title="Regex Syntax" linenums="1" +(?> subexpression ) +``` + +The *subexpression* is any regular expression pattern. + +Ordinarily, if a regular expression includes an optional or alternative matching pattern and a match does not succeed, the regular expression engine can branch in multiple directions to match an input string with a pattern. If a match is not found when it takes the first branch, the regular expression engine can back up or backtrack to the point where it took the first match and attempt the match using the second branch. This process can continue until all branches have been tried. + +The `(?>subexpression)` language construct disables backtracking. The regular expression engine will match as many characters in the input string as it can. When no further match is possible, it will not backtrack to attempt alternate pattern matches. (That is, the subexpression matches only strings that would be matched by the subexpression alone; it does not attempt to match a string based on the subexpression and any subexpressions that follow it.) ## Quantifiers -`+` one or more repetitions -`*` zero or more repetitions -`?` zero or one repetition -`{m}` exactly *m* times -`{m, n}` at least *m* times, at most *n* times +A quantifier specifies how many instances of the previous element (which can be a character, a group, or a character class) must be present in the input string for a match to occur. -The `*`, `x`, and `?` qualifiers are all greedy; they match as much text as possible -Adding `?` *after* the qualifier makes it perform the match in non-greedy or minimal fashion; as few characters as possible will be matched. +- `*`: Matches the previous element zero or more times. +- `+`: Matches the previous element one or more times. +- `?`: Matches the previous element zero or one time. +- `{n}`: Matches the previous element exactly n times. +- `{n}`: Matches the previous element at least n times. +- `{n,m}`: Matches the previous element at least n times, but no more than m times. +- `*?`: Matches the previous element zero or more times, but as few times as possible. +- `+?`: Matches the previous element one or more times, but as few times as possible. +- `??`: Matches the previous element zero or one time, but as few times as possible. +- `{n}?`: Matches the preceding element exactly n times. +- `{n}?`: Matches the previous element at least n times, but as few times as possible. +- `{n,m}?`: Matches the previous element between n and m times, but as few times as possible. -## Special Characters +## Alternation Constructs -`\a, \b, \f, \n, \r, \t, \u, \U, \v, \x, \\, \?, \*, \+ , \., \^, \$` special characters -`\(`, `\)`, `\[`, `\]` brackets escaping +Alternation constructs modify a regular expression to enable either/or matching. -## Delimiters +- `|`: Matches any one element separated by the vertical bar (`|`) character. -`^` match must be at start of string/line -`$` match must be at end of string/line -`^__$` match must be whole string +## Backreference Constructs -## Character classes +A backreference allows a previously matched subexpression to be identified subsequently in the same regular expression. -`[__]` one of the characters in the class (`[ab]` --> a or b) -`[__]{m , n}` consecutive characters in the class (`[aeiou]{2}` --> ae, ao, ...) -`[a-z]` sequence of lowercase characters -`[A-Z]` sequence of uppercase characters -`[a-zA-Z]` sequence of lowercase or uppercase characters -`[a-z][A-Z]` sequence of lowercase characters followed by sequence of uppercase characters -`[^__]` anything but the elements of the class (include `\n` to avoid matching line endings) +`\number`: Backreference. Matches the value of a numbered subexpression. +`\k`: Named backreference. Matches the value of a named expression. -`^`, `\`, `-` and `]` must be escaped to be used in classes: `[ \]\[\^\- ]` +## Substitutions -## Groups +Substitutions are regular expression language elements that are supported in replacement patterns. -`(__)` capturing group -`(?:__)` non-capturing group -`(REGEX_1 | REGEX_2)` match in multiple regex (R1 OR R2) -`(?=__)` match only if `__` is next substring -`(?!__)` match only if `__` is not next substring -`(?<=__)` match only if `__` is previous substring -`(?` refers to n-th group +## Special Constructs -## Special Cases +- `(.*)`: Matches anything +- `(.*?)`: Matches anything, but as few times as possible +- `(?# comment )`: code comment, can be in the middle of the pattern -`(.*)` match anything -`(.*?)` match anything, non-greedy match +Brackets escapes: + +- `\(` +- `\)` +- `\[` +- `\]` + +Special characters escapes: + +- `\a` +- `\b` +- `\f` +- `\n` +- `\r` +- `\t` +- `\u` +- `\U` +- `\v` +- `\x` +- `\\` +- `\?` +- `\*` +- `\+` +- `\.` +- `\^` +- `\$` From b308443203be044cc007e639d86dcf3dbb3b1bd8 Mon Sep 17 00:00:00 2001 From: Marcello Lamonaca Date: Fri, 20 Oct 2023 18:22:46 +0200 Subject: [PATCH 4/4] show line numbers in conde snippets --- docs/containers/docker.md | 28 +-- docs/containers/kubernetes.md | 11 +- docs/databases/mongo-db.md | 56 ++--- docs/databases/redis.md | 12 +- docs/databases/sql.md | 52 ++-- docs/devices/ios/content-view.md | 34 +-- docs/languages/assembly/assembly.md | 18 +- docs/languages/bash/commands.md | 16 +- docs/languages/bash/scripting.md | 28 +-- docs/languages/c/c.md | 74 +++--- docs/languages/css/css.md | 128 +++++----- docs/languages/dotnet/asp.net/blazor.md | 21 +- docs/languages/dotnet/asp.net/filters.md | 18 +- docs/languages/dotnet/asp.net/middleware.md | 12 +- docs/languages/dotnet/asp.net/minimal-api.md | 49 ++-- docs/languages/dotnet/asp.net/razor-syntax.md | 18 +- docs/languages/dotnet/asp.net/signalr.md | 22 +- docs/languages/dotnet/asp.net/web-forms.md | 8 +- .../dotnet/csharp/async-programming.md | 10 +- docs/languages/dotnet/csharp/collections.md | 20 +- docs/languages/dotnet/csharp/csharp.md | 230 +++++++++--------- docs/languages/dotnet/csharp/linq.md | 8 +- .../dotnet/csharp/reactive-extensions.md | 2 +- docs/languages/dotnet/csharp/unit-tests.md | 6 +- docs/languages/dotnet/database/ado.net.md | 8 +- .../dotnet/database/entity-framework.md | 16 +- docs/languages/html/html.md | 70 +++--- docs/languages/java/dao.md | 6 +- .../java/java-collection-framework.md | 10 +- docs/languages/java/java.md | 134 +++++----- docs/languages/java/spring/pom.xml.md | 2 +- docs/languages/java/spring/spring-project.md | 12 +- docs/languages/java/web/servlet.md | 4 +- docs/languages/javascript/ajax.md | 8 +- docs/languages/javascript/dom.md | 20 +- docs/languages/javascript/events-animation.md | 8 +- docs/languages/javascript/javascript.md | 106 ++++---- docs/languages/javascript/jquery.md | 38 +-- .../javascript/react/react-router.md | 12 +- .../languages/javascript/react/react-tests.md | 12 +- docs/languages/javascript/react/react.md | 26 +- .../languages/javascript/react/redux-tests.md | 12 +- docs/languages/javascript/react/redux.md | 32 +-- docs/languages/javascript/svelte/svelte.md | 24 +- docs/languages/kotlin/kotlin.md | 28 +-- docs/languages/markdown.md | 16 +- docs/languages/php/composer.md | 10 +- docs/languages/php/database.md | 12 +- docs/languages/php/dependency-injection.md | 10 +- docs/languages/php/php.md | 116 ++++----- docs/languages/php/plates-templating.md | 18 +- docs/languages/php/psr-7.md | 2 +- docs/languages/php/simple-mvc/rest-api.md | 4 +- docs/languages/php/simple-mvc/simple-mvc.md | 13 +- docs/languages/php/unit-tests.md | 20 +- docs/languages/php/web.md | 16 +- docs/languages/powershell/commands.md | 2 +- docs/languages/powershell/scripting.md | 54 ++-- docs/languages/python/libs/beautiful-soup.md | 18 +- docs/languages/python/libs/numpy.md | 34 +-- docs/languages/python/libs/pandas.md | 92 +++---- docs/languages/python/libs/requests.md | 26 +- docs/languages/python/libs/seaborn.md | 30 +-- docs/languages/python/libs/tkinter.md | 86 +++---- docs/languages/python/modules/argparse.md | 32 +-- docs/languages/python/modules/ftplib.md | 6 +- docs/languages/python/modules/json.md | 6 +- docs/languages/python/modules/logging.md | 4 +- docs/languages/python/modules/shutil.md | 2 +- docs/languages/python/modules/smtplib.md | 2 +- docs/languages/python/modules/socket.md | 4 +- docs/languages/python/modules/sqlite.md | 12 +- .../languages/python/modules/time-datetime.md | 4 +- docs/languages/python/modules/unittest.md | 2 +- docs/languages/python/python.md | 98 ++++---- docs/languages/rust/cargo.md | 16 +- docs/languages/rust/rust.md | 152 ++++++------ docs/languages/rust/unit-tests.md | 4 +- docs/languages/swift/swift.md | 56 ++--- docs/misc/git.md | 4 +- docs/misc/graph-ql.md | 40 +-- docs/misc/ssh.md | 8 +- 82 files changed, 1249 insertions(+), 1251 deletions(-) diff --git a/docs/containers/docker.md b/docs/containers/docker.md index 0f40f89..f738a75 100644 --- a/docs/containers/docker.md +++ b/docs/containers/docker.md @@ -63,7 +63,7 @@ VMs incur a lot of overhead beyond what is being consumed by your application lo ### [`docker run`](https://docs.docker.com/engine/reference/commandline/run/) -```sh +```sh linenums="1" docker run # run selected app inside a container (downloaded from Docker Hub if missing from image) docker run -d|--detach # run docker container in the background (does not occupy stdout & stderr) docker run -i|--interactive # run docker container in interactive mode (read stdin) @@ -80,7 +80,7 @@ docker run --name= # set container name ### [`docker container`](https://docs.docker.com/engine/reference/commandline/container/) -```sh +```sh linenums="1" docker container ls # list of currently running containers docker container ls -a|--all # list of all containers, running and exited docker container rm # remove one or more containers @@ -97,7 +97,7 @@ docker container exec # exec a command inside a container ### [`docker image`](https://docs.docker.com/engine/reference/commandline/image/) -```sh +```sh linenums="1" docker image ls # list of existing images docker image rm # remove one or more images docker image prune # remove unused images @@ -106,20 +106,20 @@ docker image pull # download an image w/o starting the container ### [`docker build`](https://docs.docker.com/engine/reference/commandline/build/) -```sh +```sh linenums="1" docker build -t -f # build image with specific tag (usually user/app:version) docker build -t -f --build-arg ARG=value # pass args to ARG steps ``` ### [`docker push`](https://docs.docker.com/engine/reference/commandline/push/) -```sh +```sh linenums="1" docker push # publish image to registry (defaults to Docker Hub) ``` ## [Dockerfile](https://docs.docker.com/engine/reference/builder/) -```docker +```docker linenums="1" # starting image or scratch FROM : @@ -149,7 +149,7 @@ ENTRYPOINT ### `CMD` vs `ENTRYPOINT` -`CMD` is used to provide all the default scenarios which can be overridden. _Anything_ defined in CMD can be overridden by passing arguments in `docker run` command. +`CMD` is used to provide all the default scenarios which can be overridden. *Anything* defined in CMD can be overridden by passing arguments in `docker run` command. `ENTRYPOINT` is used to define a specific executable (and it's arguments) to be executed during container invocation which cannot be overridden. The user can however define arguments to be passed in the executable by adding them in the `docker run` command. @@ -160,7 +160,7 @@ With multi-stage builds, it's possible to use multiple `FROM` statements in the It's possible to selectively copy artifacts from one stage to another, leaving behind everything not wanted in the final image. -```docker +```docker linenums="1" FROM : AS RUN # install external dependencies (apt get ...) @@ -186,7 +186,7 @@ COPY --from= CMD ["executable"] # run app ``` -```docker +```docker linenums="1" FROM mcr.microsoft.com/dotnet/: AS runtime RUN # install external dependencies (apt get ...) @@ -219,7 +219,7 @@ ENTRYPOINT ["dotnet", ".dll"] Starting container networks: `bridge` (default), `none`, `host`. -```sh +```sh linenums="1" docker run --network=none/host # specify a non-default network to be used docker network ls # list all available networks ``` @@ -233,7 +233,7 @@ None: Containers are not attached to a network and cannot access other container ## User-defined Networks -```sh +```sh linenums="1" docker network create \ --driver NETWORK_TYPE \ --subnet GATEWAY_TP/SUBNET_MASK_SIZE @@ -250,7 +250,7 @@ Docker has an internal DNS that allows finding other container by their name ins ## File System -```sh +```sh linenums="1" /var/lib/docker |_ |_containers @@ -270,7 +270,7 @@ To modify a file during while the container runs docker creates a local copy in **volume mounting**: create a volume under the docker installation folder (`/var/lib/docker/volumes/`). **bind mounting**: link docker to an exiting folder to be used as a volume. -```sh +```sh linenums="1" docker run -v : : # older command for bind mounting docker run --mount type=bind, source=:, target= : # modern command for bind mounting ``` @@ -287,7 +287,7 @@ Using Compose is basically a three-step process: 2. Define the services that make up your app in `docker-compose.yml` so they can be run together in an isolated environment. 3. Run `docker-compose up` and Compose starts and runs the entire app. -```yaml +```yaml linenums="1" version: 3.x services: : diff --git a/docs/containers/kubernetes.md b/docs/containers/kubernetes.md index 0d790ea..e600461 100644 --- a/docs/containers/kubernetes.md +++ b/docs/containers/kubernetes.md @@ -96,7 +96,7 @@ As pods successfully complete, the Job tracks the successful completions. When a ## Kubernetes Configuration -Each kubernetes configuration file is composed by 3 parts: +Each kubernetes configuration file is composed by 3 parts: - metadata - specification @@ -110,7 +110,7 @@ Each kubernetes configuration file is composed by 3 parts: ### `kubectl get` -```sh +```sh linenums="1" kubectl config get-contexts # list available contexts kubectl get namespaces # list namespaces inside current context @@ -121,11 +121,12 @@ kubectl get pod [-n|--namespace ] -o|--output jsonpath='{.spec. ### `kubectl exec` -```sh +```sh linenums="1" kubectl exec [-i|--stdin] [-t|--tty] [-n|--namespace ] [-c|--container ] -- # execute a command inside a container ``` + ### `kubectl logs` -```sh +```sh linenums="1" kubectl logs [-f|--follow] [-n|--namespace ] [-c|--container] # get pod/container logs -``` \ No newline at end of file +``` diff --git a/docs/databases/mongo-db.md b/docs/databases/mongo-db.md index d63a43d..cf8e586 100644 --- a/docs/databases/mongo-db.md +++ b/docs/databases/mongo-db.md @@ -25,7 +25,7 @@ MongoDB automatically creates an `ObjectId()` if it's not provided. To create a database is sufficient to switch towards a non existing one with `use ` (implicit creation). The database is not actually created until a document is inserted. -```sh +```sh linenums="1" show dbs # list all databases use # use a particular database show collections # list all collection for the current database @@ -38,7 +38,7 @@ db..insertOne({document}) # implicit collection creation ## Operators (MQL Syntax) -```json +```json linenums="1" /* --- Update operators --- */ { "$inc": { "": "", ... } } // Increment value { "$set": { "": "", ... } } // Set value @@ -79,7 +79,7 @@ db..insertOne({document}) # implicit collection creation > **Note**: `$` is used to access the value of the field dynamically -```json +```json linenums="1" { "$expr": { "" } } // aggregation expression, variables, conditional expressions { "$expr": { "$": [ "$", "$" ] } } // compare field values (operators use aggregation syntax) ``` @@ -95,7 +95,7 @@ Insertion results: - error -> rollback - success -> entire documents gets saved -```sh +```sh linenums="1" # explicit collection creation, all options are optional db.createCollection( , { @@ -128,7 +128,7 @@ db..insertMany([ { document }, { document } ] , { "ordered": false } ### Querying -```sh +```sh linenums="1" db..findOne() # find only one document db..find(filter) # show selected documents db..find().pretty() # show documents formatted @@ -172,7 +172,7 @@ db..find().hint( { $natural : -1 } ) # force the query to perform a [Update Operators](https://docs.mongodb.com/manual/reference/operator/update/ "Update Operators Documentation") -```sh +```sh linenums="1" db..replaceOne(filter, update, options) db..updateOne(filter, update, {upsert: true}) # modify document if existing, insert otherwise @@ -181,7 +181,7 @@ db..updateOne(filter, { "$push": { ... }, "$set": { ... }, { "$inc": ### Deletion -```sh +```sh linenums="1" db..deleteOne(filter, options) db..deleteMany(filter, options) @@ -199,7 +199,7 @@ Utility to import all docs into a specified collection. If the collection already exists `--drop` deletes it before reuploading it. **WARNING**: CSV separators must be commas (`,`) -```sh +```sh linenums="1" mongoimport --uri= @@ -218,7 +218,7 @@ mongoimport Utility to export documents into a specified file. -```sh +```sh linenums="1" mongoexport --collection= --uri= @@ -272,7 +272,7 @@ Indexes _slow down writing operations_ since the index must be updated at every ### Diagnosis and query planning -```sh +```sh linenums="1" db..find({...}).explain() # explain won't accept other functions db.explain()..find({...}) # can accept other functions db.explain("executionStats")..find({...}) # more info @@ -280,7 +280,7 @@ db.explain("executionStats")..find({...}) # more info ### Index Creation -```sh +```sh linenums="1" db..createIndex( , ) db..createIndex( { "": , "": , ... } ) # normal, compound or multikey (field is array) index @@ -302,7 +302,7 @@ db..createIndex( ### [Index Management](https://docs.mongodb.com/manual/tutorial/manage-indexes/) -```sh +```sh linenums="1" # view all db indexes db.getCollectionNames().forEach(function(collection) { indexes = db[collection].getIndexes(); @@ -339,7 +339,7 @@ handling connections, requests and persisting the data. ### Basic Shell Helpers -```sh +```sh linenums="1" db.() # database interaction db..() # collection interaction rs.(); # replica set deployment and management @@ -378,7 +378,7 @@ Log Verbosity Level: - `0`: Default Verbosity (Information) - `1 - 5`: Increases the verbosity up to Debug messages -```sh +```sh linenums="1" db.getLogComponents() # get components and their verbosity db.adminCommand({"getLog": ""}) # retrieve logs (getLog must be run on admin db -> adminCommand) db.setLogLevel(, ""); # set log level (output is OLD verbosity levels) @@ -404,7 +404,7 @@ Events captured by the profiler: > **Note**: Logs are saved in the `system.profile` _capped_ collection. -```sh +```sh linenums="1" db.setProfilingLevel(n) # set profiler level db.setProfilingLevel(1, { slowms: }) db.getProfilingStatus() # check profiler status @@ -454,7 +454,7 @@ Built-in Roles Groups and Names: - Backup/Restore: `backup`, `restore` - Super User: `root` -```sh +```sh linenums="1" db.createUser( { user: "", @@ -509,7 +509,7 @@ Variable syntax in aggregations: Filters the documents to pass only the documents that match the specified condition(s) to the next pipeline stage. -```sh +```sh linenums="1" db..aggregate([ { "$match": { "" } }, @@ -541,7 +541,7 @@ Passes along the documents with the requested fields to the next stage in the pi - [`$sum`][$sum_docs] - [`$avg`][$avg_docs] -```sh +```sh linenums="1" db..aggregate([ { "$project": { @@ -598,7 +598,7 @@ db..aggregate([ Adds new fields to documents (can be result of computation). `$addFields` outputs documents that contain _all existing fields_ from the input documents and newly added fields. -```sh +```sh linenums="1" db..aggregate({ { $addFields: { : , ... } } }) @@ -610,7 +610,7 @@ db..aggregate({ The $`group` stage separates documents into groups according to a "group key". The output is one document for each unique group key. -```sh +```sh linenums="1" db..aggregate([ { "$group": { @@ -629,7 +629,7 @@ db..aggregate([ Deconstructs an array field from the input documents to output a document for each element. Each output document is the input document with the value of the array field replaced by the element -```sh +```sh linenums="1" db..aggregate([ { "$unwind": "" } @@ -647,7 +647,7 @@ db..aggregate([ ### [`$count` Aggregation Stage][$count_docs] -```sh +```sh linenums="1" db..aggregate([ { "$count": "" } ]) @@ -657,7 +657,7 @@ db..aggregate([ ### [`$sort` Aggregation Stage][$sort_docs] -```sh +```sh linenums="1" db..aggregate([ { "$sort": { @@ -676,7 +676,7 @@ db..aggregate([ ### [`$skip` Aggregation Stage][$skip_docs] -```sh +```sh linenums="1" db..aggregate([ { "$skip": "" } ]) @@ -686,7 +686,7 @@ db..aggregate([ ### [`$limit` Aggregation Stage][$limit_docs] -```sh +```sh linenums="1" db..aggregate([ { "$limit": "" } ]) @@ -701,7 +701,7 @@ The `$lookup` stage adds a new array field to each input document. The new array > **Note**: To combine elements from two different collections, use the [`$unionWith`][$unionWith_docs] pipeline stage. -```sh +```sh linenums="1" db..aggregate([ { "$lookup": { @@ -724,7 +724,7 @@ Performs a recursive search on a collection, with options for restricting the se The collection on which the aggregation is performed and the `from` collection can be the same (in-collection search) or different (cross-collection search) -```sh +```sh linenums="1" db..aggregate([ { $graphLookup: { @@ -754,7 +754,7 @@ Each output document contains two fields: an `_id` field containing the distinct The documents are sorted by count in descending order. -```sh +```sh linenums="1" db..aggregate([ { $sortByCount: } ]) diff --git a/docs/databases/redis.md b/docs/databases/redis.md index a130b89..df1436e 100644 --- a/docs/databases/redis.md +++ b/docs/databases/redis.md @@ -10,14 +10,14 @@ Often Redis it is called a *data structure* server because it has outer key-valu ### Server Startup -```bash +```bash linenums="1" redis-server # start the server redis-cli ``` ### [Key-Value Pairs](https://redis.io/commands#generic) -```sh +```sh linenums="1" SET [ EX ] # store a key-value pair, TTL optional GET # read a key content EXISTS # check if a key exists @@ -40,7 +40,7 @@ PERSIST # make the key permanent A list is a series of ordered values. -```sh +```sh linenums="1" RPUSH ... # add one or more values to the end of the list LPUSH ... # add one or more values to the start of a list @@ -55,7 +55,7 @@ RPOP # remove and return the last item fro the list A set is similar to a list, except it does not have a specific order and each element may only appear once. -```sh +```sh linenums="1" SADD ... # add one or more values to the set (return 0 if values are already inside) SREM # remove the given member from the set, return 1 or 0 to signal if the member was actually there or not. SPOP # remove and return value from the set @@ -72,7 +72,7 @@ Sets are a very handy data type, but as they are unsorted they don't work well f A sorted set is similar to a regular set, but now each value has an associated score. This score is used to sort the elements in the set. -```sh +```sh linenums="1" ZADD # add a value with it's score ZRANGE # return a subset of the sortedSet @@ -84,7 +84,7 @@ ZRANGE # return a subset of the sortedSet Hashes are maps between string fields and string values, so they are the perfect data type to represent objects. -```sh +```sh linenums="1" HSET [ ... ] # set the string of a hash field HSETNX # set the value of a hash field, only if the field does not exist diff --git a/docs/databases/sql.md b/docs/databases/sql.md index 1870cbb..3504865 100644 --- a/docs/databases/sql.md +++ b/docs/databases/sql.md @@ -2,7 +2,7 @@ ## DDL -```sql +```sql linenums="1" show databases; -- mostra database CREATE DATABASE ; -- database creation use ; -- usa un database particolare @@ -16,7 +16,7 @@ show tables; -- mostra tabelle del database ### Table Creation -```sql +```sql linenums="1" CREATE TABLE (