Merge branch 'main' into @CheatSheets/vue
No files matched your search
@@ -0,0 +1,50 @@
|
||||
module.exports = {
|
||||
extends: ['@commitlint/config-conventional'],
|
||||
rules: {
|
||||
'type-enum': [
|
||||
2,
|
||||
'always',
|
||||
[
|
||||
'feat', // new feature
|
||||
'fix', // bug fix
|
||||
'docs', // documentation update
|
||||
'style', // code formatting, no logic changes
|
||||
'refactor', // code refactoring
|
||||
'perf', // performance optimization
|
||||
'test', // add tests
|
||||
'chore', // build process or auxiliary tool changes
|
||||
'ci', // CI/CD related changes
|
||||
'build', // build system or external dependency changes
|
||||
'revert' // revert commit
|
||||
]
|
||||
],
|
||||
'scope-enum': [
|
||||
2,
|
||||
'always',
|
||||
[
|
||||
'search', // search functionality
|
||||
'theme', // theme related
|
||||
'css', // style files
|
||||
'js', // JavaScript files
|
||||
'content', // content files
|
||||
'build', // build related
|
||||
'deps', // dependency updates
|
||||
'config', // configuration files
|
||||
'docs', // documentation
|
||||
'layout', // layout templates
|
||||
'widget', // components
|
||||
'gulp', // Gulp tasks
|
||||
'hexo', // Hexo related
|
||||
'markdown', // Markdown processing
|
||||
'seo', // SEO optimization
|
||||
'a11y', // accessibility
|
||||
'perf' // performance related
|
||||
]
|
||||
],
|
||||
'subject-case': [2, 'never', ['start-case', 'pascal-case', 'upper-case']],
|
||||
'subject-empty': [2, 'never'],
|
||||
'subject-full-stop': [2, 'never', '.'],
|
||||
'type-case': [2, 'always', 'lower-case'],
|
||||
'type-empty': [2, 'never']
|
||||
}
|
||||
};
|
||||
@@ -1,7 +0,0 @@
|
||||
root = true
|
||||
|
||||
[*.md]
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
insert_final_newline = true
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
name: Cheatsheet request
|
||||
about: For request cheatsheet and reference.
|
||||
title: "Cheatsheet request: "
|
||||
title: 'Cheatsheet request: '
|
||||
labels: request
|
||||
assignees: Fechin
|
||||
---
|
||||
@@ -8,32 +8,82 @@
|
||||
ehthumbs.db
|
||||
Thumbs.db
|
||||
nohup.out
|
||||
*.tmp
|
||||
*.temp
|
||||
|
||||
# Python files #
|
||||
# Environment files #
|
||||
######################
|
||||
.python-version
|
||||
.env
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.python-version
|
||||
.venv
|
||||
.ipynb_checkpoints
|
||||
|
||||
# Logs #
|
||||
######################
|
||||
*.log
|
||||
|
||||
# Editor files #
|
||||
######################
|
||||
.idea
|
||||
.vscode
|
||||
|
||||
# Node files #
|
||||
######################
|
||||
node_modules/
|
||||
dist/
|
||||
logs/
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# Editor files #
|
||||
######################
|
||||
.idea/
|
||||
.vscode/
|
||||
*.swp
|
||||
*.swo
|
||||
*~
|
||||
.vim/
|
||||
.emacs.d/
|
||||
.sublime-*
|
||||
|
||||
# Node.js #
|
||||
######################
|
||||
node_modules/
|
||||
dist/
|
||||
build/
|
||||
coverage/
|
||||
.nyc_output/
|
||||
.cache/
|
||||
.parcel-cache/
|
||||
.next/
|
||||
.nuxt/
|
||||
.vuepress/dist/
|
||||
.serverless/
|
||||
.fusebox/
|
||||
.dynamodb/
|
||||
.tern-port
|
||||
package-lock.json
|
||||
|
||||
# Testing #
|
||||
######################
|
||||
.jest/
|
||||
.coverage/
|
||||
junit.xml
|
||||
test-results/
|
||||
|
||||
# Other files #
|
||||
# Build artifacts #
|
||||
######################
|
||||
themes/coo/source/css/style.css
|
||||
public/
|
||||
db.json
|
||||
*.tgz
|
||||
*.tar.gz
|
||||
|
||||
# Security #
|
||||
######################
|
||||
.npmrc
|
||||
.yarnrc
|
||||
.pnpm-store/
|
||||
|
||||
# Misc #
|
||||
######################
|
||||
.eslintcache
|
||||
.stylelintcache
|
||||
.prettierignore
|
||||
@@ -0,0 +1,36 @@
|
||||
# <type>[optional scope]: <description>
|
||||
#
|
||||
# [optional body]
|
||||
#
|
||||
# [optional footer(s)]
|
||||
#
|
||||
# Commit Types:
|
||||
# feat: New feature
|
||||
# fix: Bug fix
|
||||
# docs: Documentation update
|
||||
# style: Code formatting, no logic changes
|
||||
# refactor: Code refactoring, neither new feature nor bug fix
|
||||
# perf: Performance optimization
|
||||
# test: Add tests
|
||||
# chore: Build process or auxiliary tool changes
|
||||
# ci: CI/CD related changes
|
||||
# build: Build system or external dependency changes
|
||||
# revert: Revert commit
|
||||
#
|
||||
# Scope Examples:
|
||||
# search, theme, css, js, content, build, deps, config, docs
|
||||
# layout, widget, gulp, hexo, markdown, seo, a11y, perf
|
||||
#
|
||||
# Examples:
|
||||
# feat(search): add fuzzy search with highlighting
|
||||
# fix(css): resolve mobile layout overflow issue
|
||||
# docs(readme): update installation instructions
|
||||
# chore(deps): upgrade tailwindcss to v3.4.0
|
||||
# perf(js): optimize search performance with debouncing
|
||||
# style(css): format tailwind classes according to prettier
|
||||
#
|
||||
# Guidelines:
|
||||
# - Use imperative mood: "add" not "added" or "adds"
|
||||
# - Start with lowercase
|
||||
# - No period at the end
|
||||
# - Keep description concise, under 50 characters
|
||||
@@ -0,0 +1 @@
|
||||
npx commitlint --edit $1
|
||||
@@ -0,0 +1 @@
|
||||
npx lint-staged
|
||||
@@ -0,0 +1,10 @@
|
||||
module.exports = {
|
||||
// JavaScript files
|
||||
'*.{js,mjs}': ['eslint --fix', 'prettier --write'],
|
||||
|
||||
// CSS files
|
||||
'*.css': ['stylelint --fix', 'prettier --write'],
|
||||
|
||||
// All other files that Prettier supports
|
||||
'*.{md,json,yml,yaml}': ['prettier --write']
|
||||
};
|
||||
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"MD003": false,
|
||||
"MD013": false,
|
||||
"MD014": false,
|
||||
"MD024": false,
|
||||
"MD033": false,
|
||||
"MD040": false,
|
||||
"MD010": {
|
||||
"code_blocks": true,
|
||||
"spaces_per_tab": 2
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,44 @@
|
||||
# Minimized files
|
||||
**.min.css
|
||||
fuse_*.js
|
||||
# Dependencies
|
||||
node_modules/
|
||||
pnpm-lock.yaml
|
||||
package-lock.json
|
||||
|
||||
# Build outputs
|
||||
public/
|
||||
dist/
|
||||
.hexo/
|
||||
|
||||
# Generated files
|
||||
db.json
|
||||
themes/coo/source/css/style.css
|
||||
|
||||
# Third-party libraries
|
||||
themes/coo/source/js/fuse_*.js
|
||||
*.min.js
|
||||
*.min.css
|
||||
|
||||
# Large asset files
|
||||
source/assets/image/
|
||||
source/assets/icon/
|
||||
*.png
|
||||
*.jpg
|
||||
*.jpeg
|
||||
*.gif
|
||||
*.svg
|
||||
*.ico
|
||||
|
||||
# Logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# OS generated files
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# IDE files
|
||||
.vscode/
|
||||
.idea/
|
||||
|
||||
# Temporary files
|
||||
*.tmp
|
||||
*.temp
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"printWidth": 120,
|
||||
"proseWrap": "always",
|
||||
"plugins": ["prettier-plugin-tailwindcss"]
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
module.exports = {
|
||||
// Basic configuration
|
||||
semi: true,
|
||||
trailingComma: 'none',
|
||||
singleQuote: true,
|
||||
printWidth: 100,
|
||||
tabWidth: 2,
|
||||
useTabs: false,
|
||||
endOfLine: 'lf',
|
||||
|
||||
// Plugin configuration
|
||||
plugins: ['prettier-plugin-tailwindcss'],
|
||||
|
||||
// File-specific configuration
|
||||
overrides: [
|
||||
{
|
||||
files: '*.md',
|
||||
options: {
|
||||
proseWrap: 'preserve',
|
||||
printWidth: 80
|
||||
}
|
||||
},
|
||||
{
|
||||
files: '*.yml',
|
||||
options: {
|
||||
singleQuote: false
|
||||
}
|
||||
},
|
||||
{
|
||||
files: '*.json',
|
||||
options: {
|
||||
trailingComma: 'none'
|
||||
}
|
||||
},
|
||||
{
|
||||
files: ['themes/coo/source/css/*.css'],
|
||||
options: {
|
||||
printWidth: 120
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
module.exports = {
|
||||
extends: ['stylelint-config-standard'],
|
||||
rules: {
|
||||
// Tailwind CSS compatibility
|
||||
'at-rule-no-unknown': [
|
||||
true,
|
||||
{
|
||||
ignoreAtRules: ['tailwind', 'apply', 'variants', 'responsive', 'screen', 'layer']
|
||||
}
|
||||
],
|
||||
// Disable @apply deprecation warning, as this is a Tailwind CSS feature
|
||||
'at-rule-no-deprecated': null,
|
||||
// Allow duplicate selectors, as this is common in generated CSS
|
||||
'no-descending-specificity': null,
|
||||
'no-duplicate-selectors': null,
|
||||
// Allow camelCase class names
|
||||
'selector-class-pattern': null,
|
||||
// Allow camelCase ID selectors
|
||||
'selector-id-pattern': null,
|
||||
// Allow unknown properties (Tailwind generated CSS variables)
|
||||
'property-no-unknown': null,
|
||||
// Allow unknown type selectors (custom elements)
|
||||
'selector-type-no-unknown': null,
|
||||
// Allow unknown declaration values
|
||||
'declaration-property-value-no-unknown': null,
|
||||
// Allow duplicate custom properties
|
||||
'declaration-block-no-duplicate-custom-properties': null,
|
||||
// Allow multiple declarations on single line
|
||||
'declaration-block-single-line-max-declarations': null,
|
||||
// Allow decimal precision
|
||||
'number-max-precision': null,
|
||||
// Allow unknown media feature values
|
||||
'media-feature-name-value-no-unknown': null,
|
||||
// Allow non-kebab-case keyframe names
|
||||
'keyframes-name-pattern': null,
|
||||
// Allow empty source files
|
||||
'no-empty-source': null
|
||||
},
|
||||
ignoreFiles: [
|
||||
'node_modules/**/*',
|
||||
'public/**/*',
|
||||
'themes/coo/source/css/highlightjs/**/*',
|
||||
'**/*.min.css'
|
||||
]
|
||||
};
|
||||
@@ -12,9 +12,10 @@ sheet that could be improved, feel free to submit a [pull request](#-contributin
|
||||
|
||||
## 👀 Live Demonstration
|
||||
|
||||
Note: The original domain for this project was quickref.me, which was acquired by a US-based company. Since then, cheatsheets.zip is the primary and maintained domain (All within the bounds of the agreements).
|
||||
Note: The original domain for this project was quickref.me, which was acquired by a US-based company. Since then,
|
||||
cheatsheets.zip is the primary and maintained domain (All within the bounds of the agreements).
|
||||
|
||||
You can view the most up-to-date cheat sheets live at [https://cheatsheets.zip](https://cheatsheets.zip/).
|
||||
You can view the most up-to-date cheat sheets live at [https://cheatsheets.zip](https://cheatsheets.zip/).
|
||||
|
||||
[](https://cheatsheets.zip)
|
||||
|
||||
@@ -25,33 +26,58 @@ Reference provides cheat sheets for the following:
|
||||
<details>
|
||||
<summary>Programming</summary>
|
||||
|
||||
- [Bash](https://cheatsheets.zip/bash.html): This is a quick reference cheat sheet to getting started with Linux bash shell scripting.
|
||||
- [Bash](https://cheatsheets.zip/bash.html): This is a quick reference cheat sheet to getting started with Linux bash
|
||||
shell scripting.
|
||||
- [C](https://cheatsheets.zip/c.html): C quick reference cheat sheet that provides basic syntax and methods.
|
||||
- [C++](https://cheatsheets.zip/cpp.html): C++ quick reference cheat sheet that provides basic syntax and methods.
|
||||
- [C#](https://cheatsheets.zip/cs.html): C# quick reference cheat sheet that provides basic syntax and methods.
|
||||
- [CSS 3](https://cheatsheets.zip/css.html): This is a quick reference cheat sheet for CSS goodness, listing selector syntax, properties, units and other useful bits of information.
|
||||
- [Dart](https://cheatsheets.zip/dart.html): A Dart cheat sheet with the most important concepts, functions, methods, and more. A complete quick reference for beginners.
|
||||
- [Docker](https://cheatsheets.zip/docker.html): This is a quick reference cheat sheet for [Docker](https://docs.docker.com/get-started/). And you can find the most common Docker commands here.
|
||||
- [ES6](https://cheatsheets.zip/es6.html): A quick reference cheat sheet of what’s new in JavaScript for ES2015, ES2016, ES2017, ES2018 and beyond
|
||||
- [Go](https://cheatsheets.zip/go.html): This cheat sheet provided basic syntax and methods to help you using [Go](https://go.dev/).
|
||||
- [GraphQL](https://cheatsheets.zip/graphql.html): This quick reference cheat sheet provides a brief overview of GraphQL.
|
||||
- [Hook](https://cheatsheets.zip/hook.html): The [Hook](https://github.com/hook-lang/hook/) cheat sheet is a one-page reference sheet for the Hook programming language.
|
||||
- [HTML](https://cheatsheets.zip/html.html): This HTML quick reference cheat sheet lists the common HTML and HTML5 tags in readable layout.
|
||||
- [INI](https://cheatsheets.zip/ini.html): This is a quick reference cheat sheet for understanding and writing INI-format configuration files.
|
||||
- [Java](https://cheatsheets.zip/java.html): This cheat sheet is a crash course for Java beginners and help review the basic syntax of the Java language.
|
||||
- [JavaScript](https://cheatsheets.zip/javascript.html): A JavaScript cheat sheet with the most important concepts, functions, methods, and more. A complete quick reference for beginners.
|
||||
- [jQuery](https://cheatsheets.zip/jquery.html): This [jQuery](https://jquery.com/) cheat sheet is a great reference for both beginners and experienced developers.
|
||||
- [Kubernetes](https://cheatsheets.zip/kubernetes.html): This page contains a list of commonly used kubectl commands and flags.
|
||||
- [LaTeX](https://cheatsheets.zip/latex.html): This cheat sheet summarizes a reference list of [LaTeX](https://www.latex-project.org/) commonly used display math notation and some application examples of [KaTeX](https://katex.org/).
|
||||
- [Laravel](https://cheatsheets.zip/laravel.html): [Laravel](https://laravel.com/docs/8.x/) is an expressive and progressive web application framework for PHP. This cheat sheet provides a reference for common commands and features for Laravel 8.
|
||||
- [MATLAB](https://cheatsheets.zip/matlab.html): This quick reference cheat sheet provides an example introduction to using the [MATLAB](https://mathworks.cn/) scientific computing language to get started quickly
|
||||
- [CSS 3](https://cheatsheets.zip/css.html): This is a quick reference cheat sheet for CSS goodness, listing selector
|
||||
syntax, properties, units and other useful bits of information.
|
||||
- [Dart](https://cheatsheets.zip/dart.html): A Dart cheat sheet with the most important concepts, functions, methods,
|
||||
and more. A complete quick reference for beginners.
|
||||
- [Docker](https://cheatsheets.zip/docker.html): This is a quick reference cheat sheet for
|
||||
[Docker](https://docs.docker.com/get-started/). And you can find the most common Docker commands here.
|
||||
- [ES6](https://cheatsheets.zip/es6.html): A quick reference cheat sheet of what’s new in JavaScript for ES2015, ES2016,
|
||||
ES2017, ES2018 and beyond
|
||||
- [Go](https://cheatsheets.zip/go.html): This cheat sheet provided basic syntax and methods to help you using
|
||||
[Go](https://go.dev/).
|
||||
- [GraphQL](https://cheatsheets.zip/graphql.html): This quick reference cheat sheet provides a brief overview of
|
||||
GraphQL.
|
||||
- [Hook](https://cheatsheets.zip/hook.html): The [Hook](https://github.com/hook-lang/hook/) cheat sheet is a one-page
|
||||
reference sheet for the Hook programming language.
|
||||
- [HTML](https://cheatsheets.zip/html.html): This HTML quick reference cheat sheet lists the common HTML and HTML5 tags
|
||||
in readable layout.
|
||||
- [INI](https://cheatsheets.zip/ini.html): This is a quick reference cheat sheet for understanding and writing
|
||||
INI-format configuration files.
|
||||
- [Java](https://cheatsheets.zip/java.html): This cheat sheet is a crash course for Java beginners and help review the
|
||||
basic syntax of the Java language.
|
||||
- [JavaScript](https://cheatsheets.zip/javascript.html): A JavaScript cheat sheet with the most important concepts,
|
||||
functions, methods, and more. A complete quick reference for beginners.
|
||||
- [jQuery](https://cheatsheets.zip/jquery.html): This [jQuery](https://jquery.com/) cheat sheet is a great reference for
|
||||
both beginners and experienced developers.
|
||||
- [Kubernetes](https://cheatsheets.zip/kubernetes.html): This page contains a list of commonly used kubectl commands and
|
||||
flags.
|
||||
- [LaTeX](https://cheatsheets.zip/latex.html): This cheat sheet summarizes a reference list of
|
||||
[LaTeX](https://www.latex-project.org/) commonly used display math notation and some application examples of
|
||||
[KaTeX](https://katex.org/).
|
||||
- [Laravel](https://cheatsheets.zip/laravel.html): [Laravel](https://laravel.com/docs/8.x/) is an expressive and
|
||||
progressive web application framework for PHP. This cheat sheet provides a reference for common commands and features
|
||||
for Laravel 8.
|
||||
- [MATLAB](https://cheatsheets.zip/matlab.html): This quick reference cheat sheet provides an example introduction to
|
||||
using the [MATLAB](https://mathworks.cn/) scientific computing language to get started quickly
|
||||
- [Markdown](https://cheatsheets.zip/markdown.html): This is a quick reference cheat sheet to the Markdown syntax.
|
||||
- [PHP](https://cheatsheets.zip/php.html): This [PHP](https://www.php.net/manual/en/) cheat sheet provides a reference for quickly looking up the correct syntax for the code you use most frequently.
|
||||
- [Python](https://cheatsheets.zip/python.html): The [Python](https://www.python.org/) cheat sheet is a one-page reference sheet for the Python 3 programming language.
|
||||
- [Rust](https://cheatsheets.zip/rust.html): The Rust quick reference cheat sheet that aims at providing help on writing basic syntax and methods.
|
||||
- [Sass](https://cheatsheets.zip/sass.html): This is a quick reference cheat sheet that lists the most useful features of [SASS](https://sass-lang.com).
|
||||
- [TOML](https://cheatsheets.zip/toml.html): This is a quick reference cheat sheet to the TOML format configuration file syntax.
|
||||
- [YAML](https://cheatsheets.zip/yaml.html): This is a quick reference cheat sheet for understanding and writing YAML format configuration files.
|
||||
- [PHP](https://cheatsheets.zip/php.html): This [PHP](https://www.php.net/manual/en/) cheat sheet provides a reference
|
||||
for quickly looking up the correct syntax for the code you use most frequently.
|
||||
- [Python](https://cheatsheets.zip/python.html): The [Python](https://www.python.org/) cheat sheet is a one-page
|
||||
reference sheet for the Python 3 programming language.
|
||||
- [Rust](https://cheatsheets.zip/rust.html): The Rust quick reference cheat sheet that aims at providing help on writing
|
||||
basic syntax and methods.
|
||||
- [Sass](https://cheatsheets.zip/sass.html): This is a quick reference cheat sheet that lists the most useful features
|
||||
of [SASS](https://sass-lang.com).
|
||||
- [TOML](https://cheatsheets.zip/toml.html): This is a quick reference cheat sheet to the TOML format configuration file
|
||||
syntax.
|
||||
- [YAML](https://cheatsheets.zip/yaml.html): This is a quick reference cheat sheet for understanding and writing YAML
|
||||
format configuration files.
|
||||
|
||||
</details>
|
||||
|
||||
@@ -116,18 +142,23 @@ Reference provides cheat sheets for the following:
|
||||
|
||||
- [NumPy](https://cheatsheets.zip/numpy.html): [NumPy](https://numpy.org/) is the fundamental package for scientific
|
||||
computing with Python. This cheat sheet is a quick reference for NumPy beginners.
|
||||
- [Pandas](https://cheatsheets.zip/pandas.html): [Pandas](https://pandas.pydata.org/) is a powerful data analysis and manipulation library for Python. This quick reference cheat sheet provides an overview of essential Pandas functions, methods, and DataFrame operations.
|
||||
- [Pandas](https://cheatsheets.zip/pandas.html): [Pandas](https://pandas.pydata.org/) is a powerful data analysis and
|
||||
manipulation library for Python. This quick reference cheat sheet provides an overview of essential Pandas functions,
|
||||
methods, and DataFrame operations.
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Database</summary>
|
||||
|
||||
- [MySQL](https://cheatsheets.zip/mysql.html): The SQL cheat sheet provides you with the most commonly used SQL statements for your reference.
|
||||
- [Neo4j](https://cheatsheets.zip/neo4j.html): A Neo4j cheat sheet with getting started resources and information on how to query the database with Cypher.
|
||||
- [PostgreSQL](https://cheatsheets.zip/postgres.html): The [PostgreSQL](https://www.postgresql.org/docs/current/) cheat sheet provides you with the common PostgreSQL commands and statements.
|
||||
- [Redis](https://cheatsheets.zip/redis.html): This is a [Redis](https://redis.io/) quick reference cheat sheet that lists examples of redis commands
|
||||
|
||||
- [MySQL](https://cheatsheets.zip/mysql.html): The SQL cheat sheet provides you with the most commonly used SQL
|
||||
statements for your reference.
|
||||
- [Neo4j](https://cheatsheets.zip/neo4j.html): A Neo4j cheat sheet with getting started resources and information on how
|
||||
to query the database with Cypher.
|
||||
- [PostgreSQL](https://cheatsheets.zip/postgres.html): The [PostgreSQL](https://www.postgresql.org/docs/current/) cheat
|
||||
sheet provides you with the common PostgreSQL commands and statements.
|
||||
- [Redis](https://cheatsheets.zip/redis.html): This is a [Redis](https://redis.io/) quick reference cheat sheet that
|
||||
lists examples of redis commands
|
||||
|
||||
</details>
|
||||
|
||||
@@ -267,28 +298,39 @@ Reference provides cheat sheets for the following:
|
||||
|
||||
</details>
|
||||
|
||||
|
||||
<details>
|
||||
<summary>Shaders</summary>
|
||||
|
||||
- [Unity Shader Graph](https://cheatsheets.zip/unity-shader-graph.html): This is a visual cheat-sheet for the Unity Shader Graph. This tool is used to create custom shaders material in Unity, a popular game engine.
|
||||
- [Unity Shader Graph](https://cheatsheets.zip/unity-shader-graph.html): This is a visual cheat-sheet for the Unity
|
||||
Shader Graph. This tool is used to create custom shaders material in Unity, a popular game engine.
|
||||
|
||||
</details>
|
||||
|
||||
|
||||
<details>
|
||||
<summary>Other</summary>
|
||||
|
||||
- [ASCII Code](https://cheatsheets.zip/ascii-code.html): This cheat sheet is a complete list of ASCII Code Table with their numbers and names.
|
||||
- [Aspect Ratio](https://cheatsheets.zip/aspect-ratio.html): This cheat sheet lists some common aspect ratios and their pixel resolutions. Always confirm your final delivery ratio when shooting.
|
||||
- [CheatSheets](https://cheatsheets.zip/quickref.html): This is the magic syntax variant manual that you can use on CheatSheets.zip, It’s a good practice for contributors.
|
||||
- [Emoji](https://cheatsheets.zip/emoji.html): Some of the emoji codes are not super easy to remember, so here is a little cheat sheet.
|
||||
- [Google Search](https://cheatsheets.zip/google-search.html): This quick reference cheat sheet lists of Google advanced search operators.
|
||||
- [HTML Characters Entities](https://cheatsheets.zip/html-char.html): This cheat sheet is a complete list of HTML entities with their numbers and names. Also included is a full list of ASCII characters that can be represented in HTML.
|
||||
- [ISO 639-1 Language Code](https://cheatsheets.zip/iso-639-1.html): This is a list of the ISO language codes that conform to the ISO 639-1 standard, it provide reference for multi-language website.
|
||||
- [HTTP Status Code](https://cheatsheets.zip/http-status-code.html): The http status codes cheat sheet. A quick reference to every HTTP status code.
|
||||
- [MIME types](https://cheatsheets.zip/mime.html): This cheat sheet lists some common MIME types for the Web. You can look in the [IANA/MIME Media Types registry](http://www.iana.org/assignments/media-types/index.html) which contains all registered MIME types.
|
||||
- [Resolutions](https://cheatsheets.zip/resolutions.html): This cheat sheet lists screen sizes, viewport size and CSS media queries for popular Phones, Tablets, Laptops and Watches
|
||||
- [ASCII Code](https://cheatsheets.zip/ascii-code.html): This cheat sheet is a complete list of ASCII Code Table with
|
||||
their numbers and names.
|
||||
- [Aspect Ratio](https://cheatsheets.zip/aspect-ratio.html): This cheat sheet lists some common aspect ratios and their
|
||||
pixel resolutions. Always confirm your final delivery ratio when shooting.
|
||||
- [CheatSheets](https://cheatsheets.zip/quickref.html): This is the magic syntax variant manual that you can use on
|
||||
CheatSheets.zip, It’s a good practice for contributors.
|
||||
- [Emoji](https://cheatsheets.zip/emoji.html): Some of the emoji codes are not super easy to remember, so here is a
|
||||
little cheat sheet.
|
||||
- [Google Search](https://cheatsheets.zip/google-search.html): This quick reference cheat sheet lists of Google advanced
|
||||
search operators.
|
||||
- [HTML Characters Entities](https://cheatsheets.zip/html-char.html): This cheat sheet is a complete list of HTML
|
||||
entities with their numbers and names. Also included is a full list of ASCII characters that can be represented in
|
||||
HTML.
|
||||
- [ISO 639-1 Language Code](https://cheatsheets.zip/iso-639-1.html): This is a list of the ISO language codes that
|
||||
conform to the ISO 639-1 standard, it provide reference for multi-language website.
|
||||
- [HTTP Status Code](https://cheatsheets.zip/http-status-code.html): The http status codes cheat sheet. A quick
|
||||
reference to every HTTP status code.
|
||||
- [MIME types](https://cheatsheets.zip/mime.html): This cheat sheet lists some common MIME types for the Web. You can
|
||||
look in the [IANA/MIME Media Types registry](http://www.iana.org/assignments/media-types/index.html) which contains
|
||||
all registered MIME types.
|
||||
- [Resolutions](https://cheatsheets.zip/resolutions.html): This cheat sheet lists screen sizes, viewport size and CSS
|
||||
media queries for popular Phones, Tablets, Laptops and Watches
|
||||
|
||||
</details>
|
||||
|
||||
@@ -317,10 +359,13 @@ Reference provides cheat sheets for the following:
|
||||
|
||||
## 🤝 Contributing
|
||||
|
||||
We would like to extend our gratitude to you for considering a contribution to Reference. Your support is what makes
|
||||
this project a truly resource. Please note that the primary domain for accessing the most up-to-date content is
|
||||
[cheatsheets.zip](https://cheatsheets.zip). Feel free to
|
||||
[submit issues](https://github.com/Fechin/reference/issues/new?assignee=Fechin) and enhancement requests.
|
||||
|
||||
We would like to extend our gratitude to you for considering a contribution to Reference. Your support is what makes this project a truly resource. Please note that the primary domain for accessing the most up-to-date content is [cheatsheets.zip](https://cheatsheets.zip). Feel free to [submit issues](https://github.com/Fechin/reference/issues/new?assignee=Fechin) and enhancement requests.
|
||||
|
||||
For consistency, we encourage you to refer to the [https://cheatsheets.zip/quickref](https://cheatsheets.zip/quickref) when creating or editing cheat sheets. To get started with development, follow these steps:
|
||||
For consistency, we encourage you to refer to the [https://cheatsheets.zip/quickref](https://cheatsheets.zip/quickref)
|
||||
when creating or editing cheat sheets. To get started with development, follow these steps:
|
||||
|
||||
1. Clone Github repo `git clone https://github.com/Fechin/reference.git`
|
||||
2. Install `npm` package manager (Read
|
||||
@@ -338,7 +383,7 @@ file should include a front matter section with the following format:
|
||||
title: CheatSheets
|
||||
date: 2020-11-25 18:28:43
|
||||
icon: icon-style
|
||||
background: bg-emerald-600
|
||||
background: bg-indigo-600
|
||||
tags:
|
||||
categories:
|
||||
- Other
|
||||
@@ -352,8 +397,6 @@ Only the `title` and `intro` fields are required, and the other options can be l
|
||||
<img src="https://contrib.rocks/image?repo=Fechin/reference" />
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
## 🐦 Follow us on Twitter
|
||||
|
||||
[](https://twitter.com/FechinLi)
|
||||
@@ -361,9 +404,9 @@ Only the `title` and `intro` fields are required, and the other options can be l
|
||||
Stay up-to-date with our project by following us on Twitter! Get all the latest news and updates right in your feed.
|
||||
It's the perfect way to stay in the loop.
|
||||
|
||||
<a href="https://www.buymeacoffee.com/randy8080"><img src="https://img.buymeacoffee.com/button-api/?text=Buy me a coffee&emoji=&slug=randy8080&button_colour=40DCA5&font_colour=ffffff&font_family=Cookie&outline_colour=000000&coffee_colour=FFDD00" /></a>
|
||||
<a href="https://buymeacoffee.com/cheatsheets.zip"><img src="https://img.buymeacoffee.com/button-api/?text=Buy me a coffee&emoji=&slug=cheatsheets.zip&button_colour=40DCA5&font_colour=ffffff&font_family=Cookie&outline_colour=000000&coffee_colour=FFDD00" /></a>
|
||||
|
||||
## 📃 License
|
||||
|
||||
The project is licensed under the [GPL-3.0](https://github.com/Fechin/reference/blob/main/LICENSE) License and is maintained
|
||||
by [Fechin](https://github.com/Fechin).
|
||||
The project is licensed under the [GPL-3.0](https://github.com/Fechin/reference/blob/main/LICENSE) License and is
|
||||
maintained by [Fechin](https://github.com/Fechin).
|
||||
@@ -45,6 +45,7 @@ render_drafts: false
|
||||
post_asset_folder: false
|
||||
relative_link: false
|
||||
future: true
|
||||
syntax_highlighter: # empty to disable built-in syntax highlighting
|
||||
highlight:
|
||||
enable: false
|
||||
|
||||
@@ -132,6 +133,7 @@ markdown:
|
||||
linkify: false
|
||||
typographer: false
|
||||
quotes: "“”‘’"
|
||||
langPrefix: "hljs language-"
|
||||
anchors:
|
||||
level: 2
|
||||
collisionSuffix: ""
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
const js = require('@eslint/js');
|
||||
const globals = require('globals');
|
||||
|
||||
module.exports = [
|
||||
js.configs.recommended,
|
||||
{
|
||||
languageOptions: {
|
||||
ecmaVersion: 2022,
|
||||
sourceType: 'module',
|
||||
globals: {
|
||||
...globals.browser,
|
||||
...globals.node
|
||||
}
|
||||
},
|
||||
rules: {
|
||||
'no-unused-vars': 'warn',
|
||||
'no-console': 'off'
|
||||
}
|
||||
},
|
||||
{
|
||||
files: ['**/*.js'],
|
||||
languageOptions: {
|
||||
sourceType: 'script',
|
||||
globals: {
|
||||
...globals.node,
|
||||
...globals.browser
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
files: ['source/sw.js'],
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.serviceworker
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
files: ['themes/coo/scripts/**/*.js'],
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.node,
|
||||
hexo: 'readonly'
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
files: ['themes/coo/source/js/main.js'],
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.browser,
|
||||
Fuse: 'readonly'
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
ignores: [
|
||||
'node_modules/**',
|
||||
'public/**',
|
||||
'db.json',
|
||||
'.deploy_git/**',
|
||||
'themes/coo/source/js/fuse_*.js'
|
||||
]
|
||||
}
|
||||
];
|
||||
@@ -1,44 +1,44 @@
|
||||
const gulp = require("gulp");
|
||||
const htmlmin = require("gulp-htmlmin");
|
||||
const htmlclean = require("gulp-htmlclean");
|
||||
const version = require("gulp-version-number");
|
||||
const terser = require("gulp-terser");
|
||||
const gulp = require('gulp');
|
||||
const htmlmin = require('gulp-htmlmin');
|
||||
const htmlclean = require('gulp-htmlclean');
|
||||
const version = require('gulp-version-number');
|
||||
const terser = require('gulp-terser');
|
||||
|
||||
// Compress js files
|
||||
gulp.task("js", function () {
|
||||
gulp.task('js', function () {
|
||||
return gulp
|
||||
.src(["./public/js/main.js"])
|
||||
.src(['./public/js/main.js'])
|
||||
.pipe(
|
||||
terser({
|
||||
compress: true,
|
||||
}),
|
||||
compress: true
|
||||
})
|
||||
)
|
||||
.pipe(gulp.dest("./public/js"));
|
||||
.pipe(gulp.dest('./public/js'));
|
||||
});
|
||||
|
||||
// Build html files
|
||||
gulp.task("html", function () {
|
||||
gulp.task('html', function () {
|
||||
return gulp
|
||||
.src("./public/**/*.html")
|
||||
.src('./public/**/*.html')
|
||||
.pipe(htmlclean())
|
||||
.pipe(
|
||||
htmlmin({
|
||||
removeComments: true,
|
||||
minifyJS: true,
|
||||
minifyCSS: true,
|
||||
minifyURLs: true,
|
||||
}),
|
||||
minifyURLs: true
|
||||
})
|
||||
)
|
||||
.pipe(
|
||||
version({
|
||||
append: {
|
||||
key: "_v",
|
||||
key: '_v',
|
||||
cover: 1,
|
||||
to: ["css", "js", "png", "jpg", "woff2"],
|
||||
},
|
||||
}),
|
||||
to: ['css', 'js', 'png', 'jpg', 'woff2']
|
||||
}
|
||||
})
|
||||
)
|
||||
.pipe(gulp.dest("./public"));
|
||||
.pipe(gulp.dest('./public'));
|
||||
});
|
||||
|
||||
gulp.task("default", gulp.parallel("js", "html"));
|
||||
gulp.task('default', gulp.parallel('js', 'html'));
|
||||
@@ -12,69 +12,94 @@
|
||||
"build:css": "npx postcss themes/coo/source/css/style.tailwindcss -o themes/coo/source/css/style.css",
|
||||
"build:generate": "npx hexo generate",
|
||||
"build:gulp": "npx gulp --max-old-space-size=4096",
|
||||
"format": "prettier --write"
|
||||
"format": "prettier --write .",
|
||||
"format:check": "prettier --check .",
|
||||
"lint": "eslint themes/coo/source/js/**/*.js --fix",
|
||||
"lint:check": "eslint themes/coo/source/js/**/*.js",
|
||||
"lint:css": "stylelint **/*.css --fix",
|
||||
"test": "run-s lint:check format:check",
|
||||
"audit": "pnpm audit --audit-level moderate",
|
||||
"audit:fix": "pnpm audit --fix",
|
||||
"security:check": "pnpm audit && pnpm outdated",
|
||||
"deps:check": "npx npm-check-updates",
|
||||
"deps:update": "npx npm-check-updates -u && pnpm install",
|
||||
"prepare": "husky",
|
||||
"commit": "cz"
|
||||
},
|
||||
"hexo": {
|
||||
"version": "5.4.2"
|
||||
"version": "7.3.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"eslint": "^8.57.1",
|
||||
"gulp": "^4.0.2",
|
||||
"gulp-cli": "^2.3.0",
|
||||
"gulp": "^5.0.1",
|
||||
"gulp-cli": "^3.1.0",
|
||||
"gulp-ext-replace": "^0.3.0",
|
||||
"gulp-htmlclean": "^2.7.22",
|
||||
"gulp-htmlmin": "^5.0.1",
|
||||
"gulp-minify-css": "^1.2.4",
|
||||
"gulp-postcss": "^9.1.0",
|
||||
"gulp-postcss": "^10.0.0",
|
||||
"gulp-uglify-es": "^3.0.0",
|
||||
"gulp-version-number": "^0.2.4",
|
||||
"hexo": "^5.4.2",
|
||||
"hexo": "^7.3.0",
|
||||
"hexo-browsersync": "^0.3.0",
|
||||
"hexo-cli": "^4.3.2",
|
||||
"hexo-excerpt": "^1.3.1",
|
||||
"hexo-filter-nofollow": "^2.0.2",
|
||||
"hexo-generator-index": "^2.0.0",
|
||||
"hexo-generator-sitemap": "^2.2.0",
|
||||
"hexo-log": "^3.2.0",
|
||||
"hexo-pagination": "^2.0.0",
|
||||
"hexo-fs": "^5.0.0",
|
||||
"hexo-generator-index": "^4.0.0",
|
||||
"hexo-generator-sitemap": "^3.0.1",
|
||||
"hexo-log": "^4.1.0",
|
||||
"hexo-pagination": "^4.0.0",
|
||||
"hexo-related-popular-posts": "^5.0.1",
|
||||
"hexo-renderer-ejs": "^2.0.0",
|
||||
"hexo-renderer-markdown-it": "^5.0.0",
|
||||
"hexo-renderer-stylus": "^2.1.0",
|
||||
"hexo-server": "^2.0.0",
|
||||
"markdown-it-abbr": "^1.0.4",
|
||||
"markdown-it-anchor": "^8.6.7",
|
||||
"hexo-renderer-stylus": "^3.0.1",
|
||||
"hexo-server": "^3.0.0",
|
||||
"hexo-util": "^3.3.0",
|
||||
"highlight.js": "^11.11.1",
|
||||
"markdown-it-abbr": "^2.0.0",
|
||||
"markdown-it-anchor": "^9.2.0",
|
||||
"markdown-it-attrs": "^4.3.1",
|
||||
"markdown-it-checkbox": "^1.1.0",
|
||||
"markdown-it-emoji": "^2.0.2",
|
||||
"markdown-it-footnote": "^3.0.3",
|
||||
"markdown-it-emoji": "^3.0.0",
|
||||
"markdown-it-footnote": "^4.0.0",
|
||||
"markdown-it-highlight-lines": "^1.0.2",
|
||||
"markdown-it-highlightjs": "^3.6.0",
|
||||
"markdown-it-ins": "^3.0.1",
|
||||
"markdown-it-multimd-table": "^4.2.3",
|
||||
"markdown-it-highlightjs": "^4.2.0",
|
||||
"markdown-it-ins": "^4.0.0",
|
||||
"markdown-it-shortcode-tag": "^1.1.0",
|
||||
"markdown-it-sub": "^1.0.0",
|
||||
"markdown-it-sup": "^1.0.0",
|
||||
"markdown-it-sub": "^2.0.0",
|
||||
"markdown-it-sup": "^2.0.0",
|
||||
"markdown-it-task-lists": "^2.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^19.8.1",
|
||||
"@commitlint/config-conventional": "^19.8.1",
|
||||
"autoprefixer": "^10.4.21",
|
||||
"commitizen": "^4.3.1",
|
||||
"cssnano": "^7.0.7",
|
||||
"cz-conventional-changelog": "^3.3.0",
|
||||
"eslint": "^9.29.0",
|
||||
"eslint-config-prettier": "^10.1.5",
|
||||
"gulp-clean-css": "^4.3.0",
|
||||
"gulp-filesize": "^0.0.6",
|
||||
"gulp-javascript-obfuscator": "^1.1.6",
|
||||
"gulp-replace": "^1.1.4",
|
||||
"gulp-rev": "^9.0.0",
|
||||
"gulp-rev": "^11.0.0",
|
||||
"gulp-terser": "^2.1.0",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"postcss": "^8.5.5",
|
||||
"postcss-cli": "^9.1.0",
|
||||
"postcss-import": "^14.1.0",
|
||||
"postcss-minify": "^1.2.0",
|
||||
"husky": "^9.1.7",
|
||||
"lint-staged": "^16.1.2",
|
||||
"npm-run-all2": "^8.0.4",
|
||||
"postcss": "^8.5.6",
|
||||
"postcss-cli": "^11.0.1",
|
||||
"postcss-import": "^16.1.1",
|
||||
"prettier": "^3.5.3",
|
||||
"prettier-plugin-tailwindcss": "^0.5.14",
|
||||
"sync-request": "^6.1.0",
|
||||
"tailwindcss": "^3.4.17",
|
||||
"tailwindcss-animate": "^1.0.7",
|
||||
"tailwindcss-cli": "^0.1.2"
|
||||
"prettier-plugin-tailwindcss": "^0.6.12",
|
||||
"stylelint": "^16.20.0",
|
||||
"stylelint-config-standard": "^38.0.0",
|
||||
"tailwindcss": "^3.4.14",
|
||||
"tailwindcss-animate": "^1.0.7"
|
||||
},
|
||||
"config": {
|
||||
"commitizen": {
|
||||
"path": "./node_modules/cz-conventional-changelog"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
module.exports = {
|
||||
plugins: {
|
||||
"postcss-import": { path: "themes/coo/source/css" },
|
||||
tailwindcss: { config: "./tailwind.config.js" },
|
||||
'postcss-import': { path: 'themes/coo/source/css' },
|
||||
tailwindcss: { config: './tailwind.config.js' },
|
||||
autoprefixer: {},
|
||||
"postcss-minify": {},
|
||||
},
|
||||
...(process.env.NODE_ENV === 'production' ? { cssnano: {} } : {})
|
||||
}
|
||||
};
|
||||
@@ -4,12 +4,14 @@ date: 2024-03-20 12:00:00
|
||||
icon: icon-alpine
|
||||
background: bg-blue-600
|
||||
tags:
|
||||
- linux
|
||||
- server
|
||||
- container
|
||||
- linux
|
||||
- server
|
||||
- container
|
||||
categories:
|
||||
- Operating System
|
||||
intro: A comprehensive cheatsheet for Alpine Linux, covering package management, system administration, networking, and more. Alpine Linux is a security-oriented, lightweight Linux distribution based on musl libc and busybox.
|
||||
- Operating System
|
||||
intro:
|
||||
A comprehensive cheatsheet for Alpine Linux, covering package management, system administration, networking, and more.
|
||||
Alpine Linux is a security-oriented, lightweight Linux distribution based on musl libc and busybox.
|
||||
---
|
||||
|
||||
# Alpine Linux Cheatsheet
|
||||
@@ -17,6 +19,7 @@ intro: A comprehensive cheatsheet for Alpine Linux, covering package management,
|
||||
## Package Management (apk)
|
||||
|
||||
### Basic Package Operations
|
||||
|
||||
```bash
|
||||
# Update package index
|
||||
apk update
|
||||
@@ -41,6 +44,7 @@ apk list --installed
|
||||
```
|
||||
|
||||
### Advanced Package Operations
|
||||
|
||||
```bash
|
||||
# Add package from testing repository
|
||||
apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing <package-name>
|
||||
@@ -55,6 +59,7 @@ apk cache clean
|
||||
## System Administration
|
||||
|
||||
### Service Management (OpenRC)
|
||||
|
||||
```bash
|
||||
# Start a service
|
||||
rc-service <service-name> start
|
||||
@@ -76,6 +81,7 @@ rc-status
|
||||
```
|
||||
|
||||
### System Information
|
||||
|
||||
```bash
|
||||
# Show system information
|
||||
uname -a
|
||||
@@ -94,6 +100,7 @@ uptime
|
||||
```
|
||||
|
||||
### Network Configuration
|
||||
|
||||
```bash
|
||||
# Show network interfaces
|
||||
ip addr show
|
||||
@@ -112,6 +119,7 @@ vi /etc/network/interfaces
|
||||
```
|
||||
|
||||
### User Management
|
||||
|
||||
```bash
|
||||
# Add a new user
|
||||
adduser <username>
|
||||
@@ -132,6 +140,7 @@ cat /etc/passwd
|
||||
## File System Operations
|
||||
|
||||
### Basic File Operations
|
||||
|
||||
```bash
|
||||
# Create directory
|
||||
mkdir <directory-name>
|
||||
@@ -155,6 +164,7 @@ chown <user>:<group> <file>
|
||||
## Container Operations
|
||||
|
||||
### Docker Support
|
||||
|
||||
```bash
|
||||
# Install Docker
|
||||
apk add docker
|
||||
@@ -169,6 +179,7 @@ rc-update add docker default
|
||||
## System Maintenance
|
||||
|
||||
### Disk Operations
|
||||
|
||||
```bash
|
||||
# Check disk space
|
||||
df -h
|
||||
@@ -184,6 +195,7 @@ umount /mnt/<mountpoint>
|
||||
```
|
||||
|
||||
### Backup and Restore
|
||||
|
||||
```bash
|
||||
# Create tar archive
|
||||
tar -czf backup.tar.gz /path/to/backup
|
||||
@@ -198,6 +210,7 @@ lbu package /media/backup.apkovl.tar.gz
|
||||
## Tips and Tricks
|
||||
|
||||
### Common Configuration Files
|
||||
|
||||
- `/etc/apk/repositories` - Package repositories
|
||||
- `/etc/network/interfaces` - Network configuration
|
||||
- `/etc/hostname` - System hostname
|
||||
@@ -205,6 +218,7 @@ lbu package /media/backup.apkovl.tar.gz
|
||||
- `/etc/resolv.conf` - DNS configuration
|
||||
|
||||
### Environment Variables
|
||||
|
||||
```bash
|
||||
# Set environment variable
|
||||
export VARIABLE=value
|
||||
@@ -217,6 +231,7 @@ echo "export VARIABLE=value" >> ~/.profile
|
||||
```
|
||||
|
||||
### System Logs
|
||||
|
||||
```bash
|
||||
# View system logs
|
||||
less /var/log/messages
|
||||
@@ -231,6 +246,7 @@ tail -f /var/log/messages
|
||||
## Security
|
||||
|
||||
### Firewall (using iptables)
|
||||
|
||||
```bash
|
||||
# Install iptables
|
||||
apk add iptables
|
||||
@@ -246,6 +262,7 @@ iptables -A INPUT -p tcp --dport 22 -j ACCEPT
|
||||
```
|
||||
|
||||
### SSH Configuration
|
||||
|
||||
```bash
|
||||
# Generate SSH key
|
||||
ssh-keygen -t rsa -b 4096
|
||||
@@ -260,6 +277,7 @@ vi /etc/ssh/sshd_config
|
||||
## Troubleshooting
|
||||
|
||||
### Common Commands
|
||||
|
||||
```bash
|
||||
# Check system logs for errors
|
||||
dmesg | grep -i error
|
||||
@@ -275,4 +293,4 @@ netstat -tuln
|
||||
|
||||
# Check disk health
|
||||
smartctl -a /dev/sda # Requires smartmontools package
|
||||
```
|
||||
```
|
||||
@@ -3,8 +3,7 @@ title: Arduino Programming
|
||||
date: 2024-05-29 8:58:31
|
||||
background: bg-[#387f83]
|
||||
label:
|
||||
tags: -cpp
|
||||
-I/O
|
||||
tags: -cpp -I/O
|
||||
categories:
|
||||
- Programming
|
||||
intro: |
|
||||
@@ -42,7 +41,8 @@ plugins:
|
||||
|
||||
- Select the Port:
|
||||
|
||||
- Go to Tools > Port and select the port that the Arduino is connected to (it usually shows as COMx on Windows, /dev/cu.usbmodemxxxx on macOS, and /dev/ttyUSBx on Linux).
|
||||
- Go to Tools > Port and select the port that the Arduino is connected to (it usually shows as COMx on Windows,
|
||||
/dev/cu.usbmodemxxxx on macOS, and /dev/ttyUSBx on Linux).
|
||||
|
||||
## Basic Structure
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
title: Aspect Ratio
|
||||
date: 2022-09-21 10:28:43
|
||||
background: bg-emerald-600
|
||||
background: bg-indigo-600
|
||||
tags:
|
||||
- photo
|
||||
- image
|
||||
|
||||
@@ -1,238 +1,243 @@
|
||||
---
|
||||
title: HTML Canvas
|
||||
date: 2024-05-28 22:16:42
|
||||
background: bg-[#cc5534]
|
||||
tags:
|
||||
- web
|
||||
categories:
|
||||
- Programming
|
||||
intro: |
|
||||
This HTML Canvas quick reference cheat sheet lists the common HTML5 Canvas design tags in readable layout.
|
||||
plugins:
|
||||
- copyCode
|
||||
- runCode
|
||||
---
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Basic Setup
|
||||
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Canvas Example</title>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="myCanvas" width="500" height="400" style="border:1px solid #000000;"></canvas>
|
||||
<script src="script.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
### Getting the Context
|
||||
|
||||
```js
|
||||
const canvas = document.getElementById("myCanvas");
|
||||
const ctx = canvas.getContext("2d");
|
||||
```
|
||||
|
||||
## Drawing Shapes
|
||||
|
||||
### Rectangles
|
||||
|
||||
```js
|
||||
ctx.fillStyle = "red";
|
||||
ctx.fillRect(10, 10, 150, 100); // x, y, width, height
|
||||
|
||||
ctx.strokeStyle = "blue";
|
||||
ctx.lineWidth = 5;
|
||||
ctx.strokeRect(200, 10, 150, 100); // x, y, width, height
|
||||
|
||||
ctx.clearRect(15, 15, 30, 30); // x, y, width, height
|
||||
```
|
||||
|
||||
## Paths
|
||||
|
||||
### Lines
|
||||
|
||||
```js
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(50, 50); // Starting point
|
||||
ctx.lineTo(200, 50); // Ending point
|
||||
ctx.lineTo(200, 200); // Next line ending point
|
||||
ctx.closePath(); // Connects the end point to the start point
|
||||
ctx.stroke();
|
||||
```
|
||||
|
||||
### Circles
|
||||
|
||||
```js
|
||||
ctx.beginPath();
|
||||
ctx.arc(150, 150, 75, 0, 2 * Math.PI); // x, y, radius, startAngle, endAngle
|
||||
ctx.fillStyle = "green";
|
||||
ctx.fill();
|
||||
ctx.stroke();
|
||||
```
|
||||
|
||||
### Arcs
|
||||
|
||||
```js
|
||||
ctx.beginPath();
|
||||
ctx.arc(150, 150, 75, 0, Math.PI); // x, y, radius, startAngle, endAngle
|
||||
ctx.stroke();
|
||||
```
|
||||
|
||||
## Bezier and Quadratic Curves
|
||||
|
||||
### Quadratic Curve
|
||||
|
||||
```js
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(50, 250);
|
||||
ctx.quadraticCurveTo(200, 100, 400, 250); // cpX, cpY, endX, endY
|
||||
ctx.stroke();
|
||||
```
|
||||
|
||||
### Bezier Curve
|
||||
|
||||
```js
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(50, 300);
|
||||
ctx.bezierCurveTo(150, 100, 350, 500, 450, 300); // cp1X, cp1Y, cp2X, cp2Y, endX, endY
|
||||
ctx.stroke();
|
||||
```
|
||||
|
||||
### Text
|
||||
|
||||
```js
|
||||
ctx.font = "30px Arial";
|
||||
ctx.fillStyle = "black";
|
||||
ctx.fillText("Hello Canvas", 10, 50); // text, x, y
|
||||
|
||||
ctx.strokeText("Hello Canvas", 10, 100); // text, x, y
|
||||
```
|
||||
|
||||
### Images
|
||||
|
||||
```js
|
||||
const img = new Image();
|
||||
img.src = "path/to/image.jpg";
|
||||
img.onload = () => {
|
||||
ctx.drawImage(img, 10, 10); // img, x, y
|
||||
ctx.drawImage(img, 50, 50, 100, 100); // img, x, y, width, height
|
||||
ctx.drawImage(img, 100, 100, 100, 100, 150, 150, 200, 200); // img, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight
|
||||
};
|
||||
```
|
||||
|
||||
## Transformations
|
||||
|
||||
### Translation
|
||||
|
||||
```js
|
||||
ctx.translate(100, 100); // x, y
|
||||
ctx.fillRect(0, 0, 50, 50);
|
||||
```
|
||||
|
||||
### Rotation
|
||||
|
||||
```js
|
||||
ctx.rotate((Math.PI / 180) * 45); // Angle in radians
|
||||
ctx.fillRect(100, 100, 50, 50);
|
||||
```
|
||||
|
||||
### Scaling
|
||||
|
||||
```js
|
||||
ctx.scale(2, 2); // x, y
|
||||
ctx.fillRect(50, 50, 50, 50);
|
||||
```
|
||||
|
||||
## Gradients
|
||||
|
||||
### Linear Gradient
|
||||
|
||||
```js
|
||||
const linearGradient = ctx.createLinearGradient(0, 0, 200, 0); // x0, y0, x1, y1
|
||||
linearGradient.addColorStop(0, "red");
|
||||
linearGradient.addColorStop(1, "blue");
|
||||
ctx.fillStyle = linearGradient;
|
||||
ctx.fillRect(10, 10, 200, 100);
|
||||
```
|
||||
|
||||
### Radial Gradient
|
||||
|
||||
```js
|
||||
const radialGradient = ctx.createRadialGradient(75, 50, 5, 90, 60, 100); // x0, y0, r0, x1, y1, r1
|
||||
radialGradient.addColorStop(0, "red");
|
||||
radialGradient.addColorStop(1, "blue");
|
||||
ctx.fillStyle = radialGradient;
|
||||
ctx.fillRect(10, 10, 200, 100);
|
||||
```
|
||||
|
||||
### Patterns
|
||||
|
||||
```js
|
||||
const img = new Image();
|
||||
img.src = "path/to/image.jpg";
|
||||
img.onload = () => {
|
||||
const pattern = ctx.createPattern(img, "repeat"); // 'repeat', 'repeat-x', 'repeat-y', 'no-repeat'
|
||||
ctx.fillStyle = pattern;
|
||||
ctx.fillRect(0, 0, 300, 300);
|
||||
};
|
||||
```
|
||||
|
||||
### Shadows
|
||||
|
||||
```js
|
||||
ctx.shadowColor = "rgba(0, 0, 0, 0.5)";
|
||||
ctx.shadowBlur = 10;
|
||||
ctx.shadowOffsetX = 5;
|
||||
ctx.shadowOffsetY = 5;
|
||||
|
||||
ctx.fillStyle = "red";
|
||||
ctx.fillRect(100, 100, 100, 100);
|
||||
```
|
||||
|
||||
## Compositing
|
||||
|
||||
### Global Alpha
|
||||
|
||||
```js
|
||||
ctx.globalAlpha = 0.5;
|
||||
ctx.fillStyle = "red";
|
||||
ctx.fillRect(100, 100, 100, 100);
|
||||
|
||||
ctx.fillStyle = "blue";
|
||||
ctx.fillRect(150, 150, 100, 100);
|
||||
```
|
||||
|
||||
### Global Composite Operation
|
||||
|
||||
```js
|
||||
ctx.globalCompositeOperation = "source-over"; // Default
|
||||
ctx.fillStyle = "red";
|
||||
ctx.fillRect(100, 100, 100, 100);
|
||||
|
||||
ctx.globalCompositeOperation = "destination-over";
|
||||
ctx.fillStyle = "blue";
|
||||
ctx.fillRect(150, 150, 100, 100);
|
||||
```
|
||||
|
||||
### Animations
|
||||
|
||||
```js
|
||||
let x = 0;
|
||||
function draw() {
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
ctx.fillStyle = "blue";
|
||||
ctx.fillRect(x, 100, 50, 50);
|
||||
x += 2;
|
||||
requestAnimationFrame(draw);
|
||||
}
|
||||
draw();
|
||||
```
|
||||
|
||||
## Also read
|
||||
|
||||
- [MDN doc ](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API)
|
||||
---
|
||||
title: HTML Canvas
|
||||
date: 2024-05-28 22:16:42
|
||||
background: bg-[#cc5534]
|
||||
tags:
|
||||
- web
|
||||
categories:
|
||||
- Programming
|
||||
intro: |
|
||||
This HTML Canvas quick reference cheat sheet lists the common HTML5 Canvas design tags in readable layout.
|
||||
plugins:
|
||||
- copyCode
|
||||
- runCode
|
||||
---
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Basic Setup
|
||||
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Canvas Example</title>
|
||||
</head>
|
||||
<body>
|
||||
<canvas
|
||||
id="myCanvas"
|
||||
width="500"
|
||||
height="400"
|
||||
style="border:1px solid #000000;"
|
||||
></canvas>
|
||||
<script src="script.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
### Getting the Context
|
||||
|
||||
```js
|
||||
const canvas = document.getElementById('myCanvas');
|
||||
const ctx = canvas.getContext('2d');
|
||||
```
|
||||
|
||||
## Drawing Shapes
|
||||
|
||||
### Rectangles
|
||||
|
||||
```js
|
||||
ctx.fillStyle = 'red';
|
||||
ctx.fillRect(10, 10, 150, 100); // x, y, width, height
|
||||
|
||||
ctx.strokeStyle = 'blue';
|
||||
ctx.lineWidth = 5;
|
||||
ctx.strokeRect(200, 10, 150, 100); // x, y, width, height
|
||||
|
||||
ctx.clearRect(15, 15, 30, 30); // x, y, width, height
|
||||
```
|
||||
|
||||
## Paths
|
||||
|
||||
### Lines
|
||||
|
||||
```js
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(50, 50); // Starting point
|
||||
ctx.lineTo(200, 50); // Ending point
|
||||
ctx.lineTo(200, 200); // Next line ending point
|
||||
ctx.closePath(); // Connects the end point to the start point
|
||||
ctx.stroke();
|
||||
```
|
||||
|
||||
### Circles
|
||||
|
||||
```js
|
||||
ctx.beginPath();
|
||||
ctx.arc(150, 150, 75, 0, 2 * Math.PI); // x, y, radius, startAngle, endAngle
|
||||
ctx.fillStyle = 'green';
|
||||
ctx.fill();
|
||||
ctx.stroke();
|
||||
```
|
||||
|
||||
### Arcs
|
||||
|
||||
```js
|
||||
ctx.beginPath();
|
||||
ctx.arc(150, 150, 75, 0, Math.PI); // x, y, radius, startAngle, endAngle
|
||||
ctx.stroke();
|
||||
```
|
||||
|
||||
## Bezier and Quadratic Curves
|
||||
|
||||
### Quadratic Curve
|
||||
|
||||
```js
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(50, 250);
|
||||
ctx.quadraticCurveTo(200, 100, 400, 250); // cpX, cpY, endX, endY
|
||||
ctx.stroke();
|
||||
```
|
||||
|
||||
### Bezier Curve
|
||||
|
||||
```js
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(50, 300);
|
||||
ctx.bezierCurveTo(150, 100, 350, 500, 450, 300); // cp1X, cp1Y, cp2X, cp2Y, endX, endY
|
||||
ctx.stroke();
|
||||
```
|
||||
|
||||
### Text
|
||||
|
||||
```js
|
||||
ctx.font = '30px Arial';
|
||||
ctx.fillStyle = 'black';
|
||||
ctx.fillText('Hello Canvas', 10, 50); // text, x, y
|
||||
|
||||
ctx.strokeText('Hello Canvas', 10, 100); // text, x, y
|
||||
```
|
||||
|
||||
### Images
|
||||
|
||||
```js
|
||||
const img = new Image();
|
||||
img.src = 'path/to/image.jpg';
|
||||
img.onload = () => {
|
||||
ctx.drawImage(img, 10, 10); // img, x, y
|
||||
ctx.drawImage(img, 50, 50, 100, 100); // img, x, y, width, height
|
||||
ctx.drawImage(img, 100, 100, 100, 100, 150, 150, 200, 200); // img, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight
|
||||
};
|
||||
```
|
||||
|
||||
## Transformations
|
||||
|
||||
### Translation
|
||||
|
||||
```js
|
||||
ctx.translate(100, 100); // x, y
|
||||
ctx.fillRect(0, 0, 50, 50);
|
||||
```
|
||||
|
||||
### Rotation
|
||||
|
||||
```js
|
||||
ctx.rotate((Math.PI / 180) * 45); // Angle in radians
|
||||
ctx.fillRect(100, 100, 50, 50);
|
||||
```
|
||||
|
||||
### Scaling
|
||||
|
||||
```js
|
||||
ctx.scale(2, 2); // x, y
|
||||
ctx.fillRect(50, 50, 50, 50);
|
||||
```
|
||||
|
||||
## Gradients
|
||||
|
||||
### Linear Gradient
|
||||
|
||||
```js
|
||||
const linearGradient = ctx.createLinearGradient(0, 0, 200, 0); // x0, y0, x1, y1
|
||||
linearGradient.addColorStop(0, 'red');
|
||||
linearGradient.addColorStop(1, 'blue');
|
||||
ctx.fillStyle = linearGradient;
|
||||
ctx.fillRect(10, 10, 200, 100);
|
||||
```
|
||||
|
||||
### Radial Gradient
|
||||
|
||||
```js
|
||||
const radialGradient = ctx.createRadialGradient(75, 50, 5, 90, 60, 100); // x0, y0, r0, x1, y1, r1
|
||||
radialGradient.addColorStop(0, 'red');
|
||||
radialGradient.addColorStop(1, 'blue');
|
||||
ctx.fillStyle = radialGradient;
|
||||
ctx.fillRect(10, 10, 200, 100);
|
||||
```
|
||||
|
||||
### Patterns
|
||||
|
||||
```js
|
||||
const img = new Image();
|
||||
img.src = 'path/to/image.jpg';
|
||||
img.onload = () => {
|
||||
const pattern = ctx.createPattern(img, 'repeat'); // 'repeat', 'repeat-x', 'repeat-y', 'no-repeat'
|
||||
ctx.fillStyle = pattern;
|
||||
ctx.fillRect(0, 0, 300, 300);
|
||||
};
|
||||
```
|
||||
|
||||
### Shadows
|
||||
|
||||
```js
|
||||
ctx.shadowColor = 'rgba(0, 0, 0, 0.5)';
|
||||
ctx.shadowBlur = 10;
|
||||
ctx.shadowOffsetX = 5;
|
||||
ctx.shadowOffsetY = 5;
|
||||
|
||||
ctx.fillStyle = 'red';
|
||||
ctx.fillRect(100, 100, 100, 100);
|
||||
```
|
||||
|
||||
## Compositing
|
||||
|
||||
### Global Alpha
|
||||
|
||||
```js
|
||||
ctx.globalAlpha = 0.5;
|
||||
ctx.fillStyle = 'red';
|
||||
ctx.fillRect(100, 100, 100, 100);
|
||||
|
||||
ctx.fillStyle = 'blue';
|
||||
ctx.fillRect(150, 150, 100, 100);
|
||||
```
|
||||
|
||||
### Global Composite Operation
|
||||
|
||||
```js
|
||||
ctx.globalCompositeOperation = 'source-over'; // Default
|
||||
ctx.fillStyle = 'red';
|
||||
ctx.fillRect(100, 100, 100, 100);
|
||||
|
||||
ctx.globalCompositeOperation = 'destination-over';
|
||||
ctx.fillStyle = 'blue';
|
||||
ctx.fillRect(150, 150, 100, 100);
|
||||
```
|
||||
|
||||
### Animations
|
||||
|
||||
```js
|
||||
let x = 0;
|
||||
function draw() {
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
ctx.fillStyle = 'blue';
|
||||
ctx.fillRect(x, 100, 50, 50);
|
||||
x += 2;
|
||||
requestAnimationFrame(draw);
|
||||
}
|
||||
draw();
|
||||
```
|
||||
|
||||
## Also read
|
||||
|
||||
- [MDN doc ](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API)
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
title: Chmod
|
||||
date: 2021-07-01 10:51:44
|
||||
background: bg-emerald-600
|
||||
background: bg-indigo-600
|
||||
tags:
|
||||
- permission
|
||||
categories:
|
||||
|
||||
@@ -221,11 +221,11 @@ lengthOfString.Contains("How"); // => true
|
||||
|
||||
### General .NET Terms {.col-span-2}
|
||||
|
||||
| Term | Definition |
|
||||
| ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| Runtime | A collection of services that are required to execute a given compiled unit of code. |
|
||||
| Term | Definition |
|
||||
| ----------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| Runtime | A collection of services that are required to execute a given compiled unit of code. |
|
||||
| Common Language Runtime (CLR) | Primarily locates, loads, and managed .NET objects. The CLR also handles memory management, application hosting, coordination of threads, performing security checks, and other low-level details. |
|
||||
| Managed code | Code that compiles and runs on .NET runtime. C#/F#/VB are examples. |
|
||||
| Unmanaged code | Code that compiles straight to machine code and cannot be directly hosted by the .NET runtime. Contains no free memory management, garbage collection, etc. DLLs created from C/C++ are examples. |
|
||||
| Managed code | Code that compiles and runs on .NET runtime. C#/F#/VB are examples. |
|
||||
| Unmanaged code | Code that compiles straight to machine code and cannot be directly hosted by the .NET runtime. Contains no free memory management, garbage collection, etc. DLLs created from C/C++ are examples. |
|
||||
|
||||
{.show-header}
|
||||
@@ -49,7 +49,7 @@ CSS is rich in capabilities and is more than simply laying out pages.
|
||||
|
||||
```html
|
||||
<div class="classname"></div>
|
||||
<div class="class1 ... classn"></div>
|
||||
<div class="class1 classn ..."></div>
|
||||
```
|
||||
|
||||
Support multiple classes on one element.
|
||||
@@ -94,8 +94,8 @@ See: [Colors](#css-colors)
|
||||
|
||||
```css
|
||||
background-color: blue;
|
||||
background-image: url("nyan-cat.gif");
|
||||
background-image: url("../image.png");
|
||||
background-image: url('nyan-cat.gif');
|
||||
background-image: url('../image.png');
|
||||
```
|
||||
|
||||
See: [Backgrounds](#css-backgrounds)
|
||||
@@ -106,7 +106,7 @@ See: [Backgrounds](#css-backgrounds)
|
||||
.page-title {
|
||||
font-weight: bold;
|
||||
font-size: 30px;
|
||||
font-family: "Courier New";
|
||||
font-family: 'Courier New';
|
||||
}
|
||||
```
|
||||
|
||||
@@ -216,7 +216,7 @@ h3.section-heading {
|
||||
#### Attribute Selector
|
||||
|
||||
```css
|
||||
div[attribute="SomeValue"] {
|
||||
div[attribute='SomeValue'] {
|
||||
background-color: red;
|
||||
}
|
||||
```
|
||||
@@ -395,8 +395,8 @@ text-transform: lowercase;
|
||||
|
||||
```css
|
||||
@font-face {
|
||||
font-family: "Glegoo";
|
||||
src: url("../Glegoo.woff");
|
||||
font-family: 'Glegoo';
|
||||
src: url('../Glegoo.woff');
|
||||
}
|
||||
```
|
||||
|
||||
@@ -484,7 +484,12 @@ background:
|
||||
url(paper.gif) left top repeat;
|
||||
|
||||
background: rgb(2, 0, 36);
|
||||
background: linear-gradient(90deg, rgba(2, 0, 36, 1) 0%, rgba(13, 232, 230, 1) 35%, rgba(0, 212, 255, 1) 100%);
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
rgba(2, 0, 36, 1) 0%,
|
||||
rgba(13, 232, 230, 1) 35%,
|
||||
rgba(0, 212, 255, 1) 100%
|
||||
);
|
||||
```
|
||||
|
||||
## CSS The Box Model
|
||||
@@ -914,8 +919,8 @@ Any legal length value, like px or %. 0 is the default value
|
||||
.grid-container {
|
||||
display: grid;
|
||||
grid-template-areas:
|
||||
"nav nav . ."
|
||||
"nav nav . .";
|
||||
'nav nav . .'
|
||||
'nav nav . .';
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1003,7 +1008,7 @@ body {
|
||||
|
||||
h3::before {
|
||||
counter-increment: section;
|
||||
content: "Section." counter(section);
|
||||
content: 'Section.' counter(section);
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1015,7 +1020,7 @@ ol {
|
||||
|
||||
li::before {
|
||||
counter-increment: section;
|
||||
content: counters(section, ".") " ";
|
||||
content: counters(section, '.') ' ';
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -89,6 +89,7 @@ print(upperCase); //Print: NICOLA
|
||||
|
||||
/* Comments like these are also supported. */
|
||||
```
|
||||
|
||||
### multiline String
|
||||
|
||||
```dart
|
||||
@@ -99,7 +100,6 @@ print('''My long string''');
|
||||
//this will help for only long strings
|
||||
```
|
||||
|
||||
|
||||
### Imports
|
||||
|
||||
```dart
|
||||
@@ -227,7 +227,6 @@ for(var number in numbers){
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### for in loop
|
||||
|
||||
```dart
|
||||
@@ -248,7 +247,6 @@ for(var number in numbers){
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## Collections {.cols-2}
|
||||
|
||||
### Lists
|
||||
@@ -286,7 +284,7 @@ Set<String> names = {}; // This works, too.
|
||||
// a map is an object that associates keys and values
|
||||
var person = Map<String, String>();
|
||||
// To initialize the map, do this:
|
||||
|
||||
|
||||
person['lastName'] = 'Tesla';
|
||||
|
||||
print(person); //Print: {firstName: Nicola, lastName: Tesla}
|
||||
@@ -664,7 +662,9 @@ userObject?.userName?.toString()
|
||||
|
||||
// The preceeding code returns null and never calls toString() if either userObject or userObject.userName is null
|
||||
```
|
||||
|
||||
### enum in dart
|
||||
|
||||
```dart
|
||||
defination: An enum (short for "enumeration") is a special data type that enables a variable to be a set of predefined constants. Enums are used to define variables that can only take one out of a small set of possible values. They help make code more readable and less error-prone by providing meaningful names to these sets of values.
|
||||
|
||||
@@ -700,5 +700,3 @@ void main() {
|
||||
|
||||
|
||||
```
|
||||
|
||||
|
||||
@@ -255,8 +255,10 @@ class Customer(models.Model)
|
||||
|
||||
#### To access the ChoiceField value in the template, we need to do the following in the template:
|
||||
|
||||
- In Django templates you can use the "`get_FOO_display()`" method, that will return the readable alias for the field, where `'FOO'` is the name of the field.
|
||||
- If the choices are stored in the variable `CHOICES` and the model field storing the selected choice is `'type'` then you can directly use
|
||||
- In Django templates you can use the "`get_FOO_display()`" method, that will return the readable alias for the field,
|
||||
where `'FOO'` is the name of the field.
|
||||
- If the choices are stored in the variable `CHOICES` and the model field storing the selected choice is `'type'` then
|
||||
you can directly use
|
||||
|
||||
```html
|
||||
<!-- Here, X is the model instance -->
|
||||
@@ -891,9 +893,8 @@ class ArticleForm(ModelForm):
|
||||
|
||||
```html
|
||||
<form action="" method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<button type="submit">{% trans 'Submit' %}</button>
|
||||
{% csrf_token %} {{ form.as_p }}
|
||||
<button type="submit">{% trans 'Submit' %}</button>
|
||||
</form>
|
||||
```
|
||||
|
||||
@@ -955,7 +956,8 @@ messages.error(request, 'Login error')
|
||||
|
||||
```html
|
||||
<!-- Display flash messages in template -->
|
||||
{% if messages %} {% for message in messages %} {% message %} {% message.tags %} {% endfor %} {% endif %}
|
||||
{% if messages %} {% for message in messages %} {% message %} {% message.tags %}
|
||||
{% endfor %} {% endif %}
|
||||
```
|
||||
|
||||
## User Model
|
||||
@@ -1086,7 +1088,8 @@ urlpatterns += path('', include('django.contrib.auth.urls'))
|
||||
<a href="{% url 'logout' %}">Logout</a>
|
||||
|
||||
<!-- Check if user login -->
|
||||
{% if request.user.is_authenticated %} Logged in as: {{ request.user.username }} {% endif %}
|
||||
{% if request.user.is_authenticated %} Logged in as: {{ request.user.username }}
|
||||
{% endif %}
|
||||
```
|
||||
|
||||
#### Authorization: LoginRequiredMixin and login_required
|
||||
|
||||
@@ -8,8 +8,7 @@ tags:
|
||||
- Framework
|
||||
categories:
|
||||
- Programming
|
||||
intro:
|
||||
EJS(Embedded JavaScript) is a simple templating language that lets you generate HTML markup with plain JavaScript.
|
||||
intro: EJS(Embedded JavaScript) is a simple templating language that lets you generate HTML markup with plain JavaScript.
|
||||
plugins:
|
||||
- copyCode
|
||||
- runCode
|
||||
@@ -45,9 +44,9 @@ $ ejs hello.ejs -o hello.html
|
||||
### Render with Data
|
||||
|
||||
```js
|
||||
let ejs = require("ejs");
|
||||
let ejs = require('ejs');
|
||||
|
||||
let people = ["geddy", "neil", "alex"];
|
||||
let people = ['geddy', 'neil', 'alex'];
|
||||
let tpl = '<%= people.join(", "); %>';
|
||||
|
||||
let html = ejs.render(tpl, { people: people });
|
||||
@@ -61,7 +60,7 @@ Pass EJS a template string and some data.
|
||||
```html
|
||||
<script src="https://unpkg.com/ejs"></script>
|
||||
<script>
|
||||
let people = ["geddy", "neil", "alex"];
|
||||
let people = ['geddy', 'neil', 'alex'];
|
||||
let html = ejs.render('<%= people.join(", "); %>', { people: people });
|
||||
console.log(html);
|
||||
</script>
|
||||
@@ -110,7 +109,7 @@ $ ejs hello.ejs -f data.json -o hello.html
|
||||
### Method {.col-span-2}
|
||||
|
||||
```js
|
||||
let ejs = require("ejs");
|
||||
let ejs = require('ejs');
|
||||
let template = ejs.compile(str, options);
|
||||
|
||||
template(data);
|
||||
@@ -176,15 +175,15 @@ To include a template, needs a file name option, paths are relative
|
||||
### Custom delimiters
|
||||
|
||||
```js
|
||||
let ejs = require("ejs"),
|
||||
users = ["geddy", "neil", "alex"];
|
||||
let ejs = require('ejs'),
|
||||
users = ['geddy', 'neil', 'alex'];
|
||||
|
||||
// Just one template
|
||||
ejs.render('<?= users.join(" | "); ?>', { users: users }, { delimiter: "?" });
|
||||
ejs.render('<?= users.join(" | "); ?>', { users: users }, { delimiter: '?' });
|
||||
// => 'geddy | neil | alex'
|
||||
|
||||
// Or globally
|
||||
ejs.delimiter = "$";
|
||||
ejs.delimiter = '$';
|
||||
ejs.render('<$= users.join(" | "); $>', { users: users });
|
||||
// => 'geddy | neil | alex'
|
||||
```
|
||||
@@ -192,8 +191,8 @@ ejs.render('<$= users.join(" | "); $>', { users: users });
|
||||
### Caching
|
||||
|
||||
```js
|
||||
let ejs = require("ejs"),
|
||||
LRU = require("lru-cache");
|
||||
let ejs = require('ejs'),
|
||||
LRU = require('lru-cache');
|
||||
|
||||
// LRU cache with 100-item limit
|
||||
ejs.cache = LRU(100);
|
||||
@@ -202,9 +201,9 @@ ejs.cache = LRU(100);
|
||||
### Custom file loader
|
||||
|
||||
```js
|
||||
let ejs = require("ejs");
|
||||
let ejs = require('ejs');
|
||||
let myFileLoader = function (filePath) {
|
||||
return "myFileLoader: " + fs.readFileSync(filePath);
|
||||
return 'myFileLoader: ' + fs.readFileSync(filePath);
|
||||
};
|
||||
|
||||
ejs.fileLoader = myFileLoader;
|
||||
@@ -232,12 +231,12 @@ ejs.fileLoader = myFileLoader;
|
||||
<div id="output"></div>
|
||||
<script src="ejs.min.js"></script>
|
||||
<script>
|
||||
let people = ["geddy", "neil", "alex"],
|
||||
let people = ['geddy', 'neil', 'alex'],
|
||||
html = ejs.render('<%= people.join(", "); %>', { people: people });
|
||||
// With jQuery:
|
||||
$("#output").html(html);
|
||||
$('#output').html(html);
|
||||
// Vanilla JS:
|
||||
document.getElementById("output").innerHTML = html;
|
||||
document.getElementById('output').innerHTML = html;
|
||||
</script>
|
||||
```
|
||||
|
||||
|
||||
@@ -79,13 +79,13 @@ Same as: Math.pow(2, 8)
|
||||
#### New string methods
|
||||
|
||||
```js
|
||||
"hello".repeat(3);
|
||||
"hello".includes("ll");
|
||||
"hello".startsWith("he");
|
||||
"hello".padStart(8); // "hello"
|
||||
"hello".padEnd(8); // "hello"
|
||||
"hello".padEnd(8, "!"); // hello!!!
|
||||
"\u1E9B\u0323".normalize("NFC");
|
||||
'hello'.repeat(3);
|
||||
'hello'.includes('ll');
|
||||
'hello'.startsWith('he');
|
||||
'hello'.padStart(8); // "hello"
|
||||
'hello'.padEnd(8); // "hello"
|
||||
'hello'.padEnd(8, '!'); // hello!!!
|
||||
'\u1E9B\u0323'.normalize('NFC');
|
||||
```
|
||||
|
||||
#### New Number Methods
|
||||
@@ -93,7 +93,7 @@ Same as: Math.pow(2, 8)
|
||||
```js
|
||||
Number.EPSILON;
|
||||
Number.isInteger(Infinity); // false
|
||||
Number.isNaN("NaN"); // false
|
||||
Number.isNaN('NaN'); // false
|
||||
```
|
||||
|
||||
#### New Math methods
|
||||
@@ -108,7 +108,7 @@ Math.imul(Math.pow(2, 32) - 1, Math.pow(2, 32) - 2); // 2
|
||||
|
||||
```js
|
||||
//return a real array
|
||||
Array.from(document.querySelectorAll("*"));
|
||||
Array.from(document.querySelectorAll('*'));
|
||||
//similar to new Array(...), but without the special single-argument behavior
|
||||
Array.of(1, 2, 3);
|
||||
```
|
||||
@@ -171,7 +171,7 @@ class Dog {
|
||||
}
|
||||
}
|
||||
|
||||
const dog = new Dog("putty");
|
||||
const dog = new Dog('putty');
|
||||
//console.log(this.#name)
|
||||
//Private identifiers are not allowed outside class bodies.
|
||||
dog.printName();
|
||||
@@ -256,15 +256,15 @@ async function run () {
|
||||
#### Arrays
|
||||
|
||||
```js {1}
|
||||
const [first, last] = ["Nikola", "Tesla"];
|
||||
const [first, last] = ['Nikola', 'Tesla'];
|
||||
```
|
||||
|
||||
#### Objects
|
||||
|
||||
```js {1}
|
||||
let { title, author } = {
|
||||
title: "The Silkworm",
|
||||
author: "R. Galbraith",
|
||||
title: 'The Silkworm',
|
||||
author: 'R. Galbraith'
|
||||
};
|
||||
```
|
||||
|
||||
@@ -297,7 +297,7 @@ function greet({ name, greeting }) {
|
||||
---
|
||||
|
||||
```js
|
||||
greet({ name: "Larry", greeting: "Ahoy" });
|
||||
greet({ name: 'Larry', greeting: 'Ahoy' });
|
||||
```
|
||||
|
||||
Destructuring of objects and arrays can also be done in function parameters
|
||||
@@ -305,7 +305,7 @@ Destructuring of objects and arrays can also be done in function parameters
|
||||
### Defaults
|
||||
|
||||
```js {1}
|
||||
function greet({ name = "Rauno" } = {}) {
|
||||
function greet({ name = 'Rauno' } = {}) {
|
||||
console.log(`Hi ${name}!`);
|
||||
}
|
||||
```
|
||||
@@ -314,7 +314,7 @@ function greet({ name = "Rauno" } = {}) {
|
||||
|
||||
```js
|
||||
greet(); // Hi Rauno!
|
||||
greet({ name: "Larry" }); // Hi Larry!
|
||||
greet({ name: 'Larry' }); // Hi Larry!
|
||||
```
|
||||
|
||||
### Reassign keys
|
||||
@@ -360,7 +360,7 @@ Use the `rest(...)` operator to extract some keys individually and the rest of t
|
||||
```js {2}
|
||||
const options = {
|
||||
...defaults,
|
||||
visible: true,
|
||||
visible: true
|
||||
};
|
||||
```
|
||||
|
||||
@@ -388,7 +388,7 @@ const users = [
|
||||
#### No array expansion
|
||||
|
||||
```js
|
||||
const users = admins.concat(editors).concat(["rstacruz"]);
|
||||
const users = admins.concat(editors).concat(['rstacruz']);
|
||||
```
|
||||
|
||||
The spread operator allows you to build new arrays in the same way. See:
|
||||
@@ -401,7 +401,7 @@ The spread operator allows you to build new arrays in the same way. See:
|
||||
#### Default parameters
|
||||
|
||||
```js {1}
|
||||
function greet(name = "Jerry") {
|
||||
function greet(name = 'Jerry') {
|
||||
return `Hello ${name}`;
|
||||
}
|
||||
```
|
||||
@@ -460,13 +460,13 @@ Like a function, but preserves `this`. See: [Arrow functions](https://babeljs.io
|
||||
### Parameter setting default value
|
||||
|
||||
```js
|
||||
function log(x, y = "World") {
|
||||
function log(x, y = 'World') {
|
||||
console.log(x, y);
|
||||
}
|
||||
|
||||
log("Hello"); // Hello World
|
||||
log("Hello", "China"); // Hello China
|
||||
log("Hello", ""); // Hello
|
||||
log('Hello'); // Hello World
|
||||
log('Hello', 'China'); // Hello China
|
||||
log('Hello', ''); // Hello
|
||||
```
|
||||
|
||||
### Used in conjunction with destructuring assignment defaults
|
||||
@@ -506,7 +506,7 @@ same below:
|
||||
```js
|
||||
module.exports = {
|
||||
hello: hello,
|
||||
bye: bye,
|
||||
bye: bye
|
||||
};
|
||||
```
|
||||
|
||||
@@ -517,8 +517,8 @@ See: [Object Literals Enhanced](https://babeljs.io/learn-es2015/#enhanced-object
|
||||
```js {2}
|
||||
const App = {
|
||||
start() {
|
||||
console.log("running");
|
||||
},
|
||||
console.log('running');
|
||||
}
|
||||
};
|
||||
//Same as: App = { start: function () {···} }
|
||||
```
|
||||
@@ -543,9 +543,9 @@ See: [Object Literals Enhanced](https://babeljs.io/learn-es2015/#enhanced-object
|
||||
### Computed property name
|
||||
|
||||
```js {3}
|
||||
let event = "click";
|
||||
let event = 'click';
|
||||
let handlers = {
|
||||
[`on${event}`]: true,
|
||||
[`on${event}`]: true
|
||||
};
|
||||
//Same as: handlers = { 'onclick': true }
|
||||
```
|
||||
@@ -567,35 +567,35 @@ Object.entries(fatherJS)
|
||||
### Imports import
|
||||
|
||||
```js
|
||||
import "helpers";
|
||||
import 'helpers';
|
||||
//aka: require('···')
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```js
|
||||
import Express from "express";
|
||||
import Express from 'express';
|
||||
//aka: const Express = require('···').default || require('···')
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```js
|
||||
import { indent } from "helpers";
|
||||
import { indent } from 'helpers';
|
||||
//aka: const indent = require('···').indent
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```js
|
||||
import * as Helpers from "helpers";
|
||||
import * as Helpers from 'helpers';
|
||||
//aka: const Helpers = require('···')
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```js
|
||||
import { indentSpaces as indent } from "helpers";
|
||||
import { indentSpaces as indent } from 'helpers';
|
||||
//aka: const indent = require('···').indentSpaces
|
||||
```
|
||||
|
||||
@@ -625,8 +625,8 @@ export const pi = 3.14159;
|
||||
---
|
||||
|
||||
```js
|
||||
const firstName = "Michael";
|
||||
const lastName = "Jackson";
|
||||
const firstName = 'Michael';
|
||||
const lastName = 'Jackson';
|
||||
const year = 1958;
|
||||
export { firstName, lastName, year };
|
||||
```
|
||||
@@ -634,7 +634,7 @@ export { firstName, lastName, year };
|
||||
---
|
||||
|
||||
```js
|
||||
export * from "lib/math";
|
||||
export * from 'lib/math';
|
||||
```
|
||||
|
||||
`export` is the new `module.exports`. See: [Module exports](https://babeljs.io/learn-es2015/#modules)
|
||||
@@ -662,8 +662,8 @@ export {
|
||||
### Dynamically load modules
|
||||
|
||||
```js
|
||||
button.addEventListener("click", (event) => {
|
||||
import("./dialogBox.js")
|
||||
button.addEventListener('click', (event) => {
|
||||
import('./dialogBox.js')
|
||||
.then((dialogBox) => {
|
||||
dialogBox.open();
|
||||
})
|
||||
@@ -678,7 +678,7 @@ button.addEventListener("click", (event) => {
|
||||
### import() allows module paths to be dynamically generated
|
||||
|
||||
```js
|
||||
const main = document.querySelector("main");
|
||||
const main = document.querySelector('main');
|
||||
|
||||
import(`./modules/${someVariable}.js`)
|
||||
.then((module) => {
|
||||
@@ -695,7 +695,7 @@ import(`./modules/${someVariable}.js`)
|
||||
which returns the meta information of the current module
|
||||
|
||||
```js
|
||||
new URL("data.txt", import.meta.url);
|
||||
new URL('data.txt', import.meta.url);
|
||||
```
|
||||
|
||||
In the Node.js environment, `import.meta.url` always returns a local path, that is, a string of the `file:URL` protocol,
|
||||
@@ -706,14 +706,14 @@ such as `file:/// home/user/foo.js`
|
||||
#### static import
|
||||
|
||||
```js
|
||||
import json from "./package.json" assert { type: "json" };
|
||||
import json from './package.json' assert { type: 'json' };
|
||||
//Import all objects in the json file
|
||||
```
|
||||
|
||||
#### Dynamic Import
|
||||
|
||||
```js
|
||||
const json = await import("./package.json", { assert: { type: "json" } });
|
||||
const json = await import('./package.json', { assert: { type: 'json' } });
|
||||
```
|
||||
|
||||
## Generators
|
||||
@@ -751,9 +751,9 @@ let fibonacci = {
|
||||
next() {
|
||||
[pre, cur] = [cur, pre + cur];
|
||||
return { done: false, value: cur };
|
||||
},
|
||||
}
|
||||
};
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
for (var n of fibonacci) {
|
||||
|
||||
@@ -34,11 +34,11 @@ plugins:
|
||||
- Entry file `index.js` add code:
|
||||
|
||||
```js
|
||||
const express = require("express");
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
app.get("/", (req, res) => {
|
||||
res.send("Hello World!");
|
||||
app.get('/', (req, res) => {
|
||||
res.send('Hello World!');
|
||||
});
|
||||
app.listen(port, () => {
|
||||
console.log(`Listening port on ${port}`);
|
||||
@@ -103,7 +103,7 @@ $ DEBUG=myapp:*npm start
|
||||
### Application
|
||||
|
||||
```js
|
||||
var express = require("express");
|
||||
var express = require('express');
|
||||
var app = express();
|
||||
|
||||
console.dir(app.locals.title);
|
||||
@@ -192,9 +192,9 @@ console.dir(app.locals.email);
|
||||
### Response
|
||||
|
||||
```js
|
||||
app.get("/", function (req, res) {
|
||||
app.get('/', function (req, res) {
|
||||
console.dir(res.headersSent); //false
|
||||
res.send("OK");
|
||||
res.send('OK');
|
||||
console.dir(res.headersSent); //true
|
||||
});
|
||||
```
|
||||
@@ -250,7 +250,7 @@ will handle any request ending in `/events`
|
||||
|
||||
```js
|
||||
//depends on where the router "use()"
|
||||
router.get("/events", (req, res, next) => {
|
||||
router.get('/events', (req, res, next) => {
|
||||
//..
|
||||
});
|
||||
```
|
||||
@@ -260,8 +260,8 @@ router.get("/events", (req, res, next) => {
|
||||
The `res` object represents the HTTP response sent by the `Express` application when it receives an HTTP request
|
||||
|
||||
```js
|
||||
app.get("/user/:id", (req, res) => {
|
||||
res.send("user" + req.params.id);
|
||||
app.get('/user/:id', (req, res) => {
|
||||
res.send('user' + req.params.id);
|
||||
});
|
||||
```
|
||||
|
||||
@@ -271,8 +271,8 @@ A `req` object represents an `HTTP` request and has properties for the request q
|
||||
headers, etc.
|
||||
|
||||
```js
|
||||
app.get("/user/:id", (req, res) => {
|
||||
res.send("user" + req.params.id);
|
||||
app.get('/user/:id', (req, res) => {
|
||||
res.send('user' + req.params.id);
|
||||
});
|
||||
```
|
||||
|
||||
@@ -290,15 +290,15 @@ End the response process. This method actually comes from the Node core, specifi
|
||||
|
||||
```js
|
||||
res.json(null);
|
||||
res.json({ user: "tobi" });
|
||||
res.status(500).json({ error: "message" });
|
||||
res.json({ user: 'tobi' });
|
||||
res.status(500).json({ error: 'message' });
|
||||
```
|
||||
|
||||
### app.all
|
||||
|
||||
```js
|
||||
app.all("/secret", function (req, res, next) {
|
||||
console.log("access secret section...");
|
||||
app.all('/secret', function (req, res, next) {
|
||||
console.log('access secret section...');
|
||||
next(); // Pass control to the next handler
|
||||
});
|
||||
```
|
||||
@@ -306,43 +306,43 @@ app.all("/secret", function (req, res, next) {
|
||||
### app.delete
|
||||
|
||||
```js
|
||||
app.delete("/", function (req, res) {
|
||||
res.send("DELETE request to homepage");
|
||||
app.delete('/', function (req, res) {
|
||||
res.send('DELETE request to homepage');
|
||||
});
|
||||
```
|
||||
|
||||
### app.disable(name)
|
||||
|
||||
```js
|
||||
app.disable("trust proxy");
|
||||
app.get("trust proxy");
|
||||
app.disable('trust proxy');
|
||||
app.get('trust proxy');
|
||||
// => false
|
||||
```
|
||||
|
||||
### app.disabled(name)
|
||||
|
||||
```js
|
||||
app.disabled("trust proxy");
|
||||
app.disabled('trust proxy');
|
||||
// => true
|
||||
|
||||
app.enable("trust proxy");
|
||||
app.disabled("trust proxy");
|
||||
app.enable('trust proxy');
|
||||
app.disabled('trust proxy');
|
||||
// => false
|
||||
```
|
||||
|
||||
### app.engine(ext, callback)
|
||||
|
||||
```js
|
||||
var engines = require("consolidate");
|
||||
var engines = require('consolidate');
|
||||
|
||||
app.engine("haml", engines.haml);
|
||||
app.engine("html", engines.hogan);
|
||||
app.engine('haml', engines.haml);
|
||||
app.engine('html', engines.hogan);
|
||||
```
|
||||
|
||||
### app.listen([port[, host[, backlog]]][, callback])
|
||||
|
||||
```js
|
||||
var express = require("express");
|
||||
var express = require('express');
|
||||
|
||||
var app = express();
|
||||
app.listen(3000);
|
||||
@@ -351,24 +351,24 @@ app.listen(3000);
|
||||
### Routing
|
||||
|
||||
```js
|
||||
const express = require("express");
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
|
||||
//Respond to "hello world" when making a GET request to the homepage
|
||||
app.get("/", (req, res) => {
|
||||
res.send("hello world");
|
||||
app.get('/', (req, res) => {
|
||||
res.send('hello world');
|
||||
});
|
||||
```
|
||||
|
||||
```js
|
||||
// GET method routing
|
||||
app.get("/", (req, res) => {
|
||||
res.send("GET request to the homepage");
|
||||
app.get('/', (req, res) => {
|
||||
res.send('GET request to the homepage');
|
||||
});
|
||||
|
||||
// POST method routing
|
||||
app.post("/", (req, res) => {
|
||||
res.send("POST request to the homepage");
|
||||
app.post('/', (req, res) => {
|
||||
res.send('POST request to the homepage');
|
||||
});
|
||||
```
|
||||
|
||||
@@ -376,26 +376,26 @@ app.post("/", (req, res) => {
|
||||
|
||||
```js
|
||||
function logOriginalUrl(req, res, next) {
|
||||
console.log("ReqURL:", req.originalUrl);
|
||||
console.log('ReqURL:', req.originalUrl);
|
||||
next();
|
||||
}
|
||||
|
||||
function logMethod(req, res, next) {
|
||||
console.log("Request Type:", req.method);
|
||||
console.log('Request Type:', req.method);
|
||||
next();
|
||||
}
|
||||
|
||||
const log = [logOriginalUrl, logMethod];
|
||||
|
||||
app.get("/user/:id", log, (req, res, next) => {
|
||||
res.send("User Info");
|
||||
app.get('/user/:id', log, (req, res, next) => {
|
||||
res.send('User Info');
|
||||
});
|
||||
```
|
||||
|
||||
### Using templates
|
||||
|
||||
```js
|
||||
app.set("view engine", "pug");
|
||||
app.set('view engine', 'pug');
|
||||
```
|
||||
|
||||
Create a `Pug` template file named `index.pug` in the `views` directory with the following content
|
||||
@@ -412,10 +412,10 @@ Create a route to render the `index.pug` file. If the view engine property is no
|
||||
must be specified
|
||||
|
||||
```js
|
||||
app.get("/", (req, res) => {
|
||||
res.render("index", {
|
||||
title: "Hey",
|
||||
message: "Hello there!",
|
||||
app.get('/', (req, res) => {
|
||||
res.render('index', {
|
||||
title: 'Hey',
|
||||
message: 'Hello there!'
|
||||
});
|
||||
});
|
||||
```
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
title: FastAPI
|
||||
date: 2025-06-07 18:40:00
|
||||
background: bg-[#059669]
|
||||
title: FastAPI
|
||||
date: 2025-06-07 18:40:00
|
||||
background: bg-[#3730a3]
|
||||
tags:
|
||||
- web
|
||||
- python
|
||||
@@ -40,8 +40,6 @@ def root():
|
||||
uvicorn main:app --reload
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Routing & Parameters {.cols-3}
|
||||
|
||||
### Path Parameter
|
||||
@@ -68,8 +66,6 @@ def filter_data(limit: int = 10, active: bool = True):
|
||||
return {"limit": limit, "active": active}
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Request Body & Validation {.cols-3}
|
||||
|
||||
### Using Pydantic
|
||||
@@ -98,8 +94,6 @@ def create(item: Item):
|
||||
return item
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Forms, Files, Headers {.cols-3}
|
||||
|
||||
### Form Input
|
||||
@@ -132,8 +126,6 @@ def info(ua: str = Header(None)):
|
||||
return {"UA": ua}
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Middleware & Dependency {.cols-2}
|
||||
|
||||
### Middleware
|
||||
@@ -159,8 +151,6 @@ def secure(_: bool = Depends(auth)):
|
||||
return {"secure": True}
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Errors & JSON API {.cols-2}
|
||||
|
||||
### HTTP Error
|
||||
@@ -183,8 +173,6 @@ def get_data():
|
||||
return {"status": "ok"}
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Templates & Static {.cols-2}
|
||||
|
||||
### Mount Static
|
||||
@@ -201,8 +189,6 @@ from fastapi.templating import Jinja2Templates
|
||||
templates = Jinja2Templates("templates")
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Routers & Structure {.cols-2}
|
||||
|
||||
### Routers (Blueprints)
|
||||
@@ -230,14 +216,12 @@ project/
|
||||
└── models/
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Docs & Status {.cols-2}
|
||||
|
||||
### Built-in Docs
|
||||
|
||||
* Swagger: `/docs`
|
||||
* ReDoc: `/redoc`
|
||||
- Swagger: `/docs`
|
||||
- ReDoc: `/redoc`
|
||||
|
||||
### Custom Status Code
|
||||
|
||||
@@ -248,4 +232,3 @@ from fastapi import status
|
||||
def create():
|
||||
return {"msg": "Created"}
|
||||
```
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
title: Flask
|
||||
date: 2025-06-07 19:05:00
|
||||
background: bg-[#3598db]
|
||||
title: Flask
|
||||
date: 2025-06-07 19:05:00
|
||||
background: bg-[#3598db]
|
||||
tags:
|
||||
- web
|
||||
- python
|
||||
@@ -42,8 +42,6 @@ export FLASK_APP=app.py
|
||||
flask run
|
||||
```
|
||||
|
||||
|
||||
|
||||
## App Config & Environment {.cols-3}
|
||||
|
||||
### App Object
|
||||
@@ -62,13 +60,11 @@ app.config.from_pyfile("config.py")
|
||||
|
||||
### Common Config Keys
|
||||
|
||||
| Key | Description |
|
||||
| | -- |
|
||||
| `DEBUG` | Enable debug mode |
|
||||
| Key | Description |
|
||||
| | -- |
|
||||
| `DEBUG` | Enable debug mode |
|
||||
| `SECRET_KEY` | For sessions/cookies |
|
||||
| `ENV` | Set to 'development' |
|
||||
|
||||
|
||||
| `ENV` | Set to 'development' |
|
||||
|
||||
## Routing & Methods {.cols-3}
|
||||
|
||||
@@ -96,8 +92,6 @@ def user(name):
|
||||
return f"User: {name}"
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Request & Response {.cols-3}
|
||||
|
||||
### Request Object
|
||||
@@ -112,9 +106,9 @@ def data():
|
||||
|
||||
### Request Attributes
|
||||
|
||||
* `request.args`: Query params
|
||||
* `request.form`: Form data
|
||||
* `request.json`: JSON body
|
||||
- `request.args`: Query params
|
||||
- `request.form`: Form data
|
||||
- `request.json`: JSON body
|
||||
|
||||
### Custom Response
|
||||
|
||||
@@ -128,8 +122,6 @@ def custom():
|
||||
return res
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Templates & Static {.cols-3}
|
||||
|
||||
### Render Template
|
||||
@@ -146,17 +138,17 @@ def page():
|
||||
|
||||
```html
|
||||
<h1>Hello {{ name }}</h1>
|
||||
{% if name %}<p>Hi!</p>{% endif %}
|
||||
{% if name %}
|
||||
<p>Hi!</p>
|
||||
{% endif %}
|
||||
```
|
||||
|
||||
### Static Files
|
||||
|
||||
```html
|
||||
<link href="{{ url_for('static', filename='style.css') }}">
|
||||
<link href="{{ url_for('static', filename='style.css') }}" />
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Sessions & Cookies {.cols-2}
|
||||
|
||||
### Using Sessions
|
||||
@@ -183,8 +175,6 @@ def cookie():
|
||||
return resp
|
||||
```
|
||||
|
||||
|
||||
|
||||
## JSON API & Middleware {.cols-2}
|
||||
|
||||
### JSON Response
|
||||
@@ -210,8 +200,6 @@ def after(res):
|
||||
return res
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Error Handling & Blueprints {.cols-2}
|
||||
|
||||
### Error Handling
|
||||
@@ -236,8 +224,6 @@ def dash():
|
||||
app.register_blueprint(admin)
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Project Structure {.cols-2}
|
||||
|
||||
### File Structure
|
||||
|
||||
@@ -61,7 +61,7 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: "14"
|
||||
node-version: '14'
|
||||
- run: npm install -g bats
|
||||
- run: bats -v
|
||||
```
|
||||
@@ -192,7 +192,7 @@ jobs:
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: "14"
|
||||
node-version: '14'
|
||||
|
||||
# step 3
|
||||
- name: Install dependencies
|
||||
@@ -242,7 +242,7 @@ jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
CUSTOM_VARIABLE: "Hello, World!" # Custom variable defined using env:
|
||||
CUSTOM_VARIABLE: 'Hello, World!' # Custom variable defined using env:
|
||||
steps:
|
||||
- name: Check environment variable
|
||||
run: echo "Value of CUSTOM_VAR is $CUSTOM_VAR"
|
||||
|
||||
@@ -16,11 +16,11 @@ intro: |
|
||||
|
||||
### Actions
|
||||
|
||||
| Shortcut | Action |
|
||||
| -------------- | ------------------- |
|
||||
| `Alt+Super+8` | Turn zoom on or off |
|
||||
| `Alt+Super+=` | Zoom in |
|
||||
| `Alt+Super+-` | Zoom out |
|
||||
| Shortcut | Action |
|
||||
| ------------- | ------------------- |
|
||||
| `Alt+Super+8` | Turn zoom on or off |
|
||||
| `Alt+Super+=` | Zoom in |
|
||||
| `Alt+Super+-` | Zoom out |
|
||||
|
||||
{.shortcuts}
|
||||
|
||||
@@ -35,86 +35,84 @@ intro: |
|
||||
|
||||
### Screenshots
|
||||
|
||||
| Shortcut | Action |
|
||||
| ------------------- | --------------------------------- |
|
||||
| `Shift+Ctrl+Alt+R` | Record a screencast interactively |
|
||||
| `Shift+Print` | Take a screenshot |
|
||||
| `Print` | Take a screenshot interactively |
|
||||
| `Alt+Print` | Take a screenshot of a window |
|
||||
| Shortcut | Action |
|
||||
| ------------------ | --------------------------------- |
|
||||
| `Shift+Ctrl+Alt+R` | Record a screencast interactively |
|
||||
| `Shift+Print` | Take a screenshot |
|
||||
| `Print` | Take a screenshot interactively |
|
||||
| `Alt+Print` | Take a screenshot of a window |
|
||||
|
||||
{.shortcuts}
|
||||
|
||||
### System
|
||||
|
||||
| Shortcut | Action |
|
||||
| --------------- | ------------------------------ |
|
||||
| `Super+N` | Focus the active notification |
|
||||
| `Super+L` | Lock screen |
|
||||
| `Ctrl+Alt+Del` | Log out |
|
||||
| `Super+F10` | Open the application menu |
|
||||
| `Super+Escape` | Restore the keyboard shortcuts |
|
||||
| `Super+A` | Show all applications |
|
||||
| `Super+V` | Show the notification list |
|
||||
| `Super+S` | Show the overview |
|
||||
| `Alt+F2` | Show the run command prompt |
|
||||
| Shortcut | Action |
|
||||
| -------------- | ------------------------------ |
|
||||
| `Super+N` | Focus the active notification |
|
||||
| `Super+L` | Lock screen |
|
||||
| `Ctrl+Alt+Del` | Log out |
|
||||
| `Super+F10` | Open the application menu |
|
||||
| `Super+Escape` | Restore the keyboard shortcuts |
|
||||
| `Super+A` | Show all applications |
|
||||
| `Super+V` | Show the notification list |
|
||||
| `Super+S` | Show the overview |
|
||||
| `Alt+F2` | Show the run command prompt |
|
||||
|
||||
{.shortcuts}
|
||||
|
||||
### Typing
|
||||
|
||||
| Shortcut | Action |
|
||||
| ---------------------- | ------------------------------- |
|
||||
| `Super+space` | Switch to next typing source |
|
||||
| `Shift+Super+Space` | Switch to previous input source |
|
||||
| Shortcut | Action |
|
||||
| ------------------- | ------------------------------- |
|
||||
| `Super+space` | Switch to next typing source |
|
||||
| `Shift+Super+Space` | Switch to previous input source |
|
||||
|
||||
{.shortcuts}
|
||||
|
||||
### Windows
|
||||
|
||||
| Shortcut | Action |
|
||||
| -------------- | ------------------------- |
|
||||
| `Alt+Space` | Activate the window menu |
|
||||
| `Alt+F1` | Close the window |
|
||||
| `Super+H` | Hide window |
|
||||
| `Super+Up` | Maximize window |
|
||||
| `Alt+F7` | Move window |
|
||||
| `Alt+F8` | Resize Window |
|
||||
| `Super+Down` | Restore window |
|
||||
| `Alt+F10` | Toggle maximization state |
|
||||
| `Super+Left` | View split on left |
|
||||
| `Super+Right` | View split on right |
|
||||
| Shortcut | Action |
|
||||
| ------------- | ------------------------- |
|
||||
| `Alt+Space` | Activate the window menu |
|
||||
| `Alt+F1` | Close the window |
|
||||
| `Super+H` | Hide window |
|
||||
| `Super+Up` | Maximize window |
|
||||
| `Alt+F7` | Move window |
|
||||
| `Alt+F8` | Resize Window |
|
||||
| `Super+Down` | Restore window |
|
||||
| `Alt+F10` | Toggle maximization state |
|
||||
| `Super+Left` | View split on left |
|
||||
| `Super+Right` | View split on right |
|
||||
|
||||
{.shortcuts}
|
||||
|
||||
### Navigation
|
||||
|
||||
| Shortcut | Action |
|
||||
| ------------------------- | -------------------------------------- |
|
||||
| `Ctrl+Super+D` | Hide all normal windows |
|
||||
| `Super+Page Up` | Move to workspace on the left |
|
||||
| `Super+Page Down` | Move to workspace on the right |
|
||||
| `Shift+Super+Down` | Move window one monitor down |
|
||||
| `Shift+Super+Left` | Move window one monitor to the left |
|
||||
| `Shift+Super+Right` | Move window one monitor to the right |
|
||||
| `Shift+Super+Up` | Move window one monitor up |
|
||||
| `Shift+Super+Page Up` | Move window one workspace to the left |
|
||||
| `Shift+Super+Page Down` | Move window one workspace to the right |
|
||||
| `Shift+Super+End` | Move window to last workspace |
|
||||
| `Shift+Super+Home` | Move window to workspace 1 |
|
||||
| `Super+Tab` | Switch applications |
|
||||
| `Ctrl+Alt+Tab` | Switch system controls |
|
||||
| `Ctrl+Alt+Escape` | Switch system controls directly |
|
||||
| `Super+End` | Switch to last workspace |
|
||||
| `Super+Home` | Switch to workspace 1 |
|
||||
| `Alt+Tab` | Switch windows |
|
||||
| `Alt+Escape` | Switch windows directly |
|
||||
| `Alt+F6` | Switch windows of an app directly |
|
||||
| `Super+` | Switch windows of an application |
|
||||
| Shortcut | Action |
|
||||
| ----------------------- | -------------------------------------- |
|
||||
| `Ctrl+Super+D` | Hide all normal windows |
|
||||
| `Super+Page Up` | Move to workspace on the left |
|
||||
| `Super+Page Down` | Move to workspace on the right |
|
||||
| `Shift+Super+Down` | Move window one monitor down |
|
||||
| `Shift+Super+Left` | Move window one monitor to the left |
|
||||
| `Shift+Super+Right` | Move window one monitor to the right |
|
||||
| `Shift+Super+Up` | Move window one monitor up |
|
||||
| `Shift+Super+Page Up` | Move window one workspace to the left |
|
||||
| `Shift+Super+Page Down` | Move window one workspace to the right |
|
||||
| `Shift+Super+End` | Move window to last workspace |
|
||||
| `Shift+Super+Home` | Move window to workspace 1 |
|
||||
| `Super+Tab` | Switch applications |
|
||||
| `Ctrl+Alt+Tab` | Switch system controls |
|
||||
| `Ctrl+Alt+Escape` | Switch system controls directly |
|
||||
| `Super+End` | Switch to last workspace |
|
||||
| `Super+Home` | Switch to workspace 1 |
|
||||
| `Alt+Tab` | Switch windows |
|
||||
| `Alt+Escape` | Switch windows directly |
|
||||
| `Alt+F6` | Switch windows of an app directly |
|
||||
| `Super+` | Switch windows of an application |
|
||||
|
||||
{.shortcuts}
|
||||
|
||||
|
||||
## Also see
|
||||
|
||||
- [Gnome Shell Cheatsheet](https://wiki.gnome.org/Projects/GnomeShell/CheatSheet)
|
||||
_(www.gnome.org)_
|
||||
- [Gnome Shell Cheatsheet](https://wiki.gnome.org/Projects/GnomeShell/CheatSheet) _(www.gnome.org)_
|
||||
@@ -2,20 +2,21 @@
|
||||
title: GnuPG
|
||||
categories:
|
||||
- Linux Command
|
||||
intro:
|
||||
A cheatsheet for GnuPG, the encryption and signing software.
|
||||
intro: A cheatsheet for GnuPG, the encryption and signing software.
|
||||
---
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Software
|
||||
|
||||
Gpg4win and the GPG Suite have OS-specific features.
|
||||
|
||||
* [GnuPG](https://gnupg.org/)
|
||||
* [Gpg4win](https://www.gpg4win.org/) (Windows)
|
||||
* [GPG Suite](https://gpgtools.org/) (macOS)
|
||||
- [GnuPG](https://gnupg.org/)
|
||||
- [Gpg4win](https://www.gpg4win.org/) (Windows)
|
||||
- [GPG Suite](https://gpgtools.org/) (macOS)
|
||||
|
||||
Sometimes GPG keys are referred as PGP keys. They're interchangeable, as they follow the [OpenPGP Standard](https://www.rfc-editor.org/rfc/rfc9580.html).
|
||||
Sometimes GPG keys are referred as PGP keys. They're interchangeable, as they follow the
|
||||
[OpenPGP Standard](https://www.rfc-editor.org/rfc/rfc9580.html).
|
||||
|
||||
### Create a key-pair
|
||||
|
||||
@@ -210,8 +211,8 @@ $ gpg --export --armor <ID>
|
||||
|
||||
### PowerShell Commands
|
||||
|
||||
When you do a full restart, the GPG agent might not automatically start. Add
|
||||
the GnuPG's IPC tool to Startup Apps using PowerShell:
|
||||
When you do a full restart, the GPG agent might not automatically start. Add the GnuPG's IPC tool to Startup Apps using
|
||||
PowerShell:
|
||||
|
||||
```shell script
|
||||
$ $shell = New-Object -ComObject WScript.Shell
|
||||
|
||||
@@ -1030,7 +1030,9 @@ func main() {
|
||||
## Go File I/O {.cols-2}
|
||||
|
||||
### Reading a File
|
||||
|
||||
Read the contents of a file into memory.
|
||||
|
||||
```go
|
||||
data, err := os.ReadFile("file.txt")
|
||||
if err != nil {
|
||||
@@ -1039,7 +1041,9 @@ if err != nil {
|
||||
```
|
||||
|
||||
### Writing to a File
|
||||
|
||||
Write data to a file with specific permissions (e.g., 0644 for read-write).
|
||||
|
||||
```go
|
||||
err := os.WriteFile("file.txt", []byte("Hello, Go!"), 0644)
|
||||
```
|
||||
@@ -1047,7 +1051,9 @@ err := os.WriteFile("file.txt", []byte("Hello, Go!"), 0644)
|
||||
## Go Testing {.cols-2}
|
||||
|
||||
### Unit Test
|
||||
|
||||
Unit Test: A basic unit test follows the below naming convention and uses t.Errorf() to report failures.
|
||||
|
||||
```go
|
||||
func TestAdd(t *testing.T) {
|
||||
result := add(2, 3)
|
||||
@@ -1058,7 +1064,9 @@ func TestAdd(t *testing.T) {
|
||||
```
|
||||
|
||||
### Unit Test
|
||||
|
||||
Benchmark: Benchmark tests measure performance, using b.N to control iterations.
|
||||
|
||||
```go
|
||||
func BenchmarkAdd(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
@@ -1069,15 +1077,18 @@ func BenchmarkAdd(b *testing.B) {
|
||||
|
||||
## Go JSON Handling {.cols-2}
|
||||
|
||||
### JSON Encoding
|
||||
|
||||
### JSON Encoding
|
||||
Convert a Go struct to JSON.
|
||||
|
||||
```go
|
||||
data, _ := json.Marshal(person)
|
||||
```
|
||||
|
||||
### JSON Decoding
|
||||
|
||||
Parse JSON data into a Go struct.
|
||||
|
||||
```go
|
||||
json.Unmarshal(data, &person)
|
||||
```
|
||||
@@ -1085,6 +1096,7 @@ json.Unmarshal(data, &person)
|
||||
## Go Server {.cols-2}
|
||||
|
||||
### net/http (Standard Library)
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
@@ -1107,6 +1119,7 @@ func main() {
|
||||
```
|
||||
|
||||
### gorilla/mux
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
@@ -1130,6 +1143,7 @@ func main() {
|
||||
```
|
||||
|
||||
### chi
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
@@ -1152,6 +1166,7 @@ func main() {
|
||||
```
|
||||
|
||||
### gin
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
@@ -1172,6 +1187,7 @@ func main() {
|
||||
```
|
||||
|
||||
### fiber
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
@@ -1190,7 +1206,9 @@ func main() {
|
||||
app.Listen(":8084")
|
||||
}
|
||||
```
|
||||
|
||||
### beego
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
|
||||
@@ -90,49 +90,49 @@ intro: |
|
||||
|
||||
### Search on emails
|
||||
|
||||
| Operator | Description | Category |
|
||||
| ----------------- | ----------------------------------------------------------------------------------------------------- | ---------- |
|
||||
| `+` | Prefix - Force exact match on single phrase | Basic,Mail |
|
||||
| `()` | Allows grouping of operators and helps dictate order | Basic,Mail |
|
||||
| `-` | Excludes a word from results | Basic,Mail |
|
||||
| `""` | Allows searching for a specific phrase - exact match search. Individual word prevents synonyms | Basic,Mail |
|
||||
| `OR`/`AND` | Boolean search function for OR searches as Google defaults to AND between words - must be all caps | Basic,Mail |
|
||||
| `after:` | Allows you to search drive or mail for files modified or mail sent/received anytime after a set date | Drive,Mail |
|
||||
| `before:` | Allows you to search drive or mail for files modified or mail sent/received before a certain date | Drive,Mail |
|
||||
| `is:starred` | Searches only items that have been starred in drive | Drive,Mail |
|
||||
| `from:` | Specify the sender in google mail | Mail |
|
||||
| `to:` | Specify the recipient in google mail | Mail |
|
||||
| `cc:` | Search by a recipient that was copied into an email | Mail |
|
||||
| `bcc:` | Search by a recipient that was blind copied into an email | Mail |
|
||||
| `older:` | Search for messages older than a certain date | Mail |
|
||||
| `newer:` | Search for messages newer than a certain date | Mail |
|
||||
| `Search` | for a message with a google sheet attached | Mail |
|
||||
| `Search` | for a message with a google presentation attached | Mail |
|
||||
| `AROUND` | Similar to the normal google search function, allows you to search for keywords near each other. | Mail |
|
||||
| `subject:` | Search by keywords featured in the subject line | Mail |
|
||||
| `{}` | Use for OR in mail instead of the OR function | Mail |
|
||||
| `label:` | Search for messages that have a certain label | Mail |
|
||||
| `has:attachment` | Search for messages that have an item attached | Mail |
|
||||
| `has:drive` | Search for messages with a google drive attached | Mail |
|
||||
| `has:document` | Search for messages with a google doc attached | Mail |
|
||||
| `has:youtube` | Search for a message containing a youtube video | Mail |
|
||||
| `list:` | Search for all messages from a particular mailing list | Mail |
|
||||
| `in:anywhere` | Includes all folders in your search, including spam and bin | Mail |
|
||||
| `is:important` | Search for messages that have been marked as important | Mail |
|
||||
| `label:important` | Same as is:important | Mail |
|
||||
| `is:snoozed` | Searches for messages that have been snoozed | Mail |
|
||||
| `is:unread` | Searches for unread messages | Mail |
|
||||
| `is:read` | searches for read messages only | Mail |
|
||||
| `has:yellow-star` | Searches for messages with coloured star icon | Mail |
|
||||
| `has:blue-info` | Searches for messages with colourd icon | Mail |
|
||||
| `is:chat` | Searches for messagse from chat | Mail |
|
||||
| `deliveredto:` | Search by email address for delivered messages | Mail |
|
||||
| `category:` | Searches by messages based on category. Follow the colon with the categoy name, i.e. category:primary | Mail |
|
||||
| `size:` | Messages larger than a certain size in bytes | Mail |
|
||||
| `larger:` | Messages larger than a certain size in bytes | Mail |
|
||||
| `smaller:` | Messages smaller than a certain size in bytes | Mail |
|
||||
| `has:userlabels` | Search for messages that have custom user labels | Mail |
|
||||
| `has:nouserlabels`| Search for messages that have no custom user labels | Mail |
|
||||
| Operator | Description | Category |
|
||||
| ------------------ | ----------------------------------------------------------------------------------------------------- | ---------- |
|
||||
| `+` | Prefix - Force exact match on single phrase | Basic,Mail |
|
||||
| `()` | Allows grouping of operators and helps dictate order | Basic,Mail |
|
||||
| `-` | Excludes a word from results | Basic,Mail |
|
||||
| `""` | Allows searching for a specific phrase - exact match search. Individual word prevents synonyms | Basic,Mail |
|
||||
| `OR`/`AND` | Boolean search function for OR searches as Google defaults to AND between words - must be all caps | Basic,Mail |
|
||||
| `after:` | Allows you to search drive or mail for files modified or mail sent/received anytime after a set date | Drive,Mail |
|
||||
| `before:` | Allows you to search drive or mail for files modified or mail sent/received before a certain date | Drive,Mail |
|
||||
| `is:starred` | Searches only items that have been starred in drive | Drive,Mail |
|
||||
| `from:` | Specify the sender in google mail | Mail |
|
||||
| `to:` | Specify the recipient in google mail | Mail |
|
||||
| `cc:` | Search by a recipient that was copied into an email | Mail |
|
||||
| `bcc:` | Search by a recipient that was blind copied into an email | Mail |
|
||||
| `older:` | Search for messages older than a certain date | Mail |
|
||||
| `newer:` | Search for messages newer than a certain date | Mail |
|
||||
| `Search` | for a message with a google sheet attached | Mail |
|
||||
| `Search` | for a message with a google presentation attached | Mail |
|
||||
| `AROUND` | Similar to the normal google search function, allows you to search for keywords near each other. | Mail |
|
||||
| `subject:` | Search by keywords featured in the subject line | Mail |
|
||||
| `{}` | Use for OR in mail instead of the OR function | Mail |
|
||||
| `label:` | Search for messages that have a certain label | Mail |
|
||||
| `has:attachment` | Search for messages that have an item attached | Mail |
|
||||
| `has:drive` | Search for messages with a google drive attached | Mail |
|
||||
| `has:document` | Search for messages with a google doc attached | Mail |
|
||||
| `has:youtube` | Search for a message containing a youtube video | Mail |
|
||||
| `list:` | Search for all messages from a particular mailing list | Mail |
|
||||
| `in:anywhere` | Includes all folders in your search, including spam and bin | Mail |
|
||||
| `is:important` | Search for messages that have been marked as important | Mail |
|
||||
| `label:important` | Same as is:important | Mail |
|
||||
| `is:snoozed` | Searches for messages that have been snoozed | Mail |
|
||||
| `is:unread` | Searches for unread messages | Mail |
|
||||
| `is:read` | searches for read messages only | Mail |
|
||||
| `has:yellow-star` | Searches for messages with coloured star icon | Mail |
|
||||
| `has:blue-info` | Searches for messages with colourd icon | Mail |
|
||||
| `is:chat` | Searches for messagse from chat | Mail |
|
||||
| `deliveredto:` | Search by email address for delivered messages | Mail |
|
||||
| `category:` | Searches by messages based on category. Follow the colon with the categoy name, i.e. category:primary | Mail |
|
||||
| `size:` | Messages larger than a certain size in bytes | Mail |
|
||||
| `larger:` | Messages larger than a certain size in bytes | Mail |
|
||||
| `smaller:` | Messages smaller than a certain size in bytes | Mail |
|
||||
| `has:userlabels` | Search for messages that have custom user labels | Mail |
|
||||
| `has:nouserlabels` | Search for messages that have no custom user labels | Mail |
|
||||
|
||||
### Some other useful search operators
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
title: Grep
|
||||
date: 2020-11-25 18:28:43
|
||||
background: bg-emerald-400
|
||||
background: bg-indigo-400
|
||||
tags:
|
||||
- egrep
|
||||
- search
|
||||
|
||||
@@ -38,7 +38,7 @@ Hook features a modern syntax similar to `C`.
|
||||
### Hello, world!
|
||||
|
||||
```js
|
||||
println("Hello, World!");
|
||||
println('Hello, World!');
|
||||
// Hello, World!
|
||||
```
|
||||
|
||||
@@ -99,9 +99,9 @@ Numbers can be integers or floating-point.
|
||||
### Strings
|
||||
|
||||
```js
|
||||
let empty = "";
|
||||
let empty = '';
|
||||
|
||||
let name = "John";
|
||||
let name = 'John';
|
||||
|
||||
let message = 'Hello, "John"!';
|
||||
```
|
||||
@@ -122,7 +122,7 @@ Ranges are a sequence of integers.
|
||||
### Arrays
|
||||
|
||||
```js
|
||||
let fruits = ["apple", "banana", "cherry"];
|
||||
let fruits = ['apple', 'banana', 'cherry'];
|
||||
|
||||
println(fruits);
|
||||
// ["apple", "banana", "cherry"]
|
||||
@@ -200,9 +200,9 @@ Semi-colons are required and empty statements are not allowed.
|
||||
|
||||
```js
|
||||
{
|
||||
println("Hello");
|
||||
println('Hello');
|
||||
{
|
||||
println("World");
|
||||
println('World');
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -242,7 +242,7 @@ Identifiers are case-sensitive.
|
||||
```js
|
||||
var x; // x contains nil
|
||||
x = 5; // now, x contains a number
|
||||
x = "foo"; // a string
|
||||
x = 'foo'; // a string
|
||||
|
||||
println(x);
|
||||
```
|
||||
@@ -380,7 +380,7 @@ In Hook, the ternary operator is `if else`.
|
||||
let x = 10;
|
||||
|
||||
if (x > 5) {
|
||||
println("x is greater than 5");
|
||||
println('x is greater than 5');
|
||||
}
|
||||
// x is greater than 5
|
||||
```
|
||||
@@ -393,11 +393,11 @@ The `if` statement.
|
||||
let x = 11;
|
||||
|
||||
if (x == 5) {
|
||||
println("x is 5");
|
||||
println('x is 5');
|
||||
} else if (x == 10) {
|
||||
println("x is 10");
|
||||
println('x is 10');
|
||||
} else {
|
||||
println("x is neither 5 nor 10");
|
||||
println('x is neither 5 nor 10');
|
||||
}
|
||||
// x is neither 5 nor 10
|
||||
```
|
||||
@@ -514,7 +514,7 @@ Use `continue` to skip the rest of the loop body.
|
||||
### Indexing a string
|
||||
|
||||
```js
|
||||
let s = "Hello";
|
||||
let s = 'Hello';
|
||||
|
||||
println(s[0]); // H
|
||||
println(s[1]); // e
|
||||
@@ -537,7 +537,7 @@ Pass a range to slice a string.
|
||||
### Concatening strings
|
||||
|
||||
```js
|
||||
let greeting = "Hi" + " there!";
|
||||
let greeting = 'Hi' + ' there!';
|
||||
|
||||
println(greeting);
|
||||
// Hi there!
|
||||
@@ -731,9 +731,9 @@ Recursion is supported.
|
||||
```js
|
||||
println(type(5));
|
||||
// number
|
||||
println("1" + to_string(2));
|
||||
println('1' + to_string(2));
|
||||
// 12
|
||||
println(len("foo"));
|
||||
println(len('foo'));
|
||||
// 3
|
||||
```
|
||||
|
||||
@@ -922,7 +922,7 @@ import hashing as h;
|
||||
```
|
||||
|
||||
```js
|
||||
let d = h.sha256("Hello, world!");
|
||||
let d = h.sha256('Hello, world!');
|
||||
|
||||
println(hex(d));
|
||||
// 315f5bdb76d078c43b8ac0064e4a...
|
||||
@@ -953,7 +953,7 @@ Use `json` module for working with JSON.
|
||||
### Errors {.col-span-2}
|
||||
|
||||
```js
|
||||
println(to_int("foo"));
|
||||
println(to_int('foo'));
|
||||
|
||||
// runtime error: type error: argument #1 is not a convertible string
|
||||
// at to_int() in <native>
|
||||
@@ -965,7 +965,7 @@ Hook uses panic mode for error handling. When an error occurs, the interpreter s
|
||||
### Syntax error
|
||||
|
||||
```js
|
||||
println("Hello, World!");
|
||||
println('Hello, World!');
|
||||
|
||||
// syntax error: unexpected end of file
|
||||
// at main() in example.hk:1,25
|
||||
@@ -976,7 +976,7 @@ Hook has a strict syntax.
|
||||
### Panic
|
||||
|
||||
```js
|
||||
panic("Something went wrong");
|
||||
panic('Something went wrong');
|
||||
|
||||
// panic: Something went wrong
|
||||
// at main() in example.hk:1
|
||||
@@ -987,7 +987,7 @@ Use the `panic` built-in function to raise an error.
|
||||
### Assert {.col-span-2}
|
||||
|
||||
```js
|
||||
assert(5 > 10, "5 is not greater than 10");
|
||||
assert(5 > 10, '5 is not greater than 10');
|
||||
|
||||
// assert: 5 is not greater than 10
|
||||
// at main() in example.hk:1
|
||||
|
||||
@@ -78,7 +78,13 @@ See: [The \<a> Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Ele
|
||||
### Image Tag
|
||||
|
||||
```html {.wrap}
|
||||
<img loading="lazy" src="https://xxx.png" alt="Describe image here" width="400" height="400" />
|
||||
<img
|
||||
loading="lazy"
|
||||
src="https://xxx.png"
|
||||
alt="Describe image here"
|
||||
width="400"
|
||||
height="400"
|
||||
/>
|
||||
```
|
||||
|
||||
---
|
||||
@@ -170,7 +176,7 @@ See: [The Inline Frame element](https://developer.mozilla.org/en-US/docs/Web/HTM
|
||||
|
||||
```html
|
||||
<script type="text/javascript">
|
||||
let text = "Hello CheatSheets.zip";
|
||||
let text = 'Hello CheatSheets.zip';
|
||||
alert(text);
|
||||
</script>
|
||||
```
|
||||
@@ -277,7 +283,10 @@ See: [The Inline Frame element](https://developer.mozilla.org/en-US/docs/Web/HTM
|
||||
|
||||
```html {.wrap}
|
||||
<video controls="" width="100%">
|
||||
<source src="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4" type="video/mp4" />
|
||||
<source
|
||||
src="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4"
|
||||
type="video/mp4"
|
||||
/>
|
||||
Sorry, your browser doesn't support embedded videos.
|
||||
</video>
|
||||
```
|
||||
@@ -292,7 +301,10 @@ See: [The Inline Frame element](https://developer.mozilla.org/en-US/docs/Web/HTM
|
||||
### HTML5 Audio
|
||||
|
||||
```html {.wrap}
|
||||
<audio controls src="https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3">
|
||||
<audio
|
||||
controls
|
||||
src="https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3"
|
||||
>
|
||||
Your browser does not support the audio element.
|
||||
</audio>
|
||||
```
|
||||
@@ -306,7 +318,9 @@ audio element. </audio>
|
||||
### HTML5 Ruby
|
||||
|
||||
```html {.wrap}
|
||||
<ruby> 汉 <rp>(</rp><rt>hàn</rt><rp>)</rp> 字 <rp>(</rp><rt>zì</rt><rp>)</rp> </ruby>
|
||||
<ruby>
|
||||
汉 <rp>(</rp><rt>hàn</rt><rp>)</rp> 字 <rp>(</rp><rt>zì</rt><rp>)</rp>
|
||||
</ruby>
|
||||
```
|
||||
|
||||
#### ↓ Preview
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
title: HTMX
|
||||
date: 2025-06-07 19:30:00
|
||||
background: bg-[#ff5f4d]
|
||||
title: HTMX
|
||||
date: 2025-06-07 19:30:00
|
||||
background: bg-[#ff5f4d]
|
||||
tags:
|
||||
- frontend
|
||||
- javascript
|
||||
@@ -14,8 +14,6 @@ plugins:
|
||||
- copyCode
|
||||
---
|
||||
|
||||
|
||||
|
||||
## Getting Started {.cols-3}
|
||||
|
||||
### CDN Import
|
||||
@@ -27,11 +25,7 @@ plugins:
|
||||
### Basic Usage
|
||||
|
||||
```html
|
||||
<button
|
||||
hx-get="/hello"
|
||||
hx-target="#result">
|
||||
Say Hi
|
||||
</button>
|
||||
<button hx-get="/hello" hx-target="#result">Say Hi</button>
|
||||
<div id="result"></div>
|
||||
```
|
||||
|
||||
@@ -42,8 +36,6 @@ plugins:
|
||||
<p>Hello from server</p>
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Core Attributes {.cols-3}
|
||||
|
||||
### `hx-get`, `hx-post`, etc.
|
||||
@@ -63,28 +55,24 @@ plugins:
|
||||
### `hx-trigger`
|
||||
|
||||
```html
|
||||
<input
|
||||
hx-get="/search"
|
||||
<input
|
||||
hx-get="/search"
|
||||
hx-trigger="keyup changed delay:300ms"
|
||||
hx-target="#results" />
|
||||
hx-target="#results"
|
||||
/>
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Swap & Out of Band {.cols-3}
|
||||
|
||||
### `hx-swap`
|
||||
|
||||
```html
|
||||
<div
|
||||
hx-get="/frag"
|
||||
hx-swap="innerHTML">
|
||||
</div>
|
||||
<div hx-get="/frag" hx-swap="innerHTML"></div>
|
||||
```
|
||||
|
||||
* `outerHTML`
|
||||
* `innerHTML`
|
||||
* `beforebegin`, `afterbegin`, etc.
|
||||
- `outerHTML`
|
||||
- `innerHTML`
|
||||
- `beforebegin`, `afterbegin`, etc.
|
||||
|
||||
### `hx-swap-oob`
|
||||
|
||||
@@ -92,7 +80,7 @@ plugins:
|
||||
<div hx-swap-oob="true" id="msg"></div>
|
||||
```
|
||||
|
||||
*Useful for global updates from partials.*
|
||||
_Useful for global updates from partials._
|
||||
|
||||
### Swap Modifiers
|
||||
|
||||
@@ -100,8 +88,6 @@ plugins:
|
||||
hx-swap="outerHTML transition:true swap:1s"
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Forms & Events {.cols-3}
|
||||
|
||||
### Auto POST on Submit
|
||||
@@ -118,35 +104,21 @@ hx-swap="outerHTML transition:true swap:1s"
|
||||
|
||||
```html
|
||||
<input id="user-id" name="id" />
|
||||
<button
|
||||
hx-post="/update"
|
||||
hx-include="#user-id">
|
||||
Update
|
||||
</button>
|
||||
<button hx-post="/update" hx-include="#user-id">Update</button>
|
||||
```
|
||||
|
||||
### `hx-vals`
|
||||
|
||||
```html
|
||||
<button
|
||||
hx-post="/save"
|
||||
hx-vals='{"id": 42, "active": true}'>
|
||||
Save
|
||||
</button>
|
||||
<button hx-post="/save" hx-vals='{"id": 42, "active": true}'>Save</button>
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Advanced Features {.cols-3}
|
||||
|
||||
### Loading Indicator
|
||||
|
||||
```html
|
||||
<button
|
||||
hx-get="/load"
|
||||
hx-indicator="#spinner">
|
||||
Load
|
||||
</button>
|
||||
<button hx-get="/load" hx-indicator="#spinner">Load</button>
|
||||
<div id="spinner" class="htmx-indicator">Loading...</div>
|
||||
```
|
||||
|
||||
@@ -162,23 +134,21 @@ hx-swap="outerHTML transition:true swap:1s"
|
||||
<div hx-get="/time" hx-trigger="every 5s"></div>
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Events & Extensions {.cols-3}
|
||||
|
||||
### Listen to Events
|
||||
|
||||
```js
|
||||
document.body.addEventListener('htmx:afterSwap', e => {
|
||||
console.log("Swap complete");
|
||||
document.body.addEventListener('htmx:afterSwap', (e) => {
|
||||
console.log('Swap complete');
|
||||
});
|
||||
```
|
||||
|
||||
### Event Hooks
|
||||
|
||||
* `htmx:beforeRequest`
|
||||
* `htmx:afterSwap`
|
||||
* `htmx:responseError`
|
||||
- `htmx:beforeRequest`
|
||||
- `htmx:afterSwap`
|
||||
- `htmx:responseError`
|
||||
|
||||
### Extensions
|
||||
|
||||
@@ -187,8 +157,6 @@ document.body.addEventListener('htmx:afterSwap', e => {
|
||||
<form hx-post="/api" hx-ext="json-enc"></form>
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Example Use Case {.cols-2}
|
||||
|
||||
### Python Backend (Flask)
|
||||
@@ -202,11 +170,6 @@ def hello():
|
||||
### HTML Client
|
||||
|
||||
```html
|
||||
<button
|
||||
hx-get="/hello"
|
||||
hx-target="#msg">
|
||||
Click
|
||||
</button>
|
||||
<button hx-get="/hello" hx-target="#msg">Click</button>
|
||||
<div id="msg"></div>
|
||||
```
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
---
|
||||
title: IntelliJ IDEA
|
||||
date: 2020-12-17 21:51:44
|
||||
background:
|
||||
bg-gradient-to-r from-pink-500 via-violet-400 to-blue-400 hover:from-pink-700 hover:via-violet-600 hover:to-blue-500
|
||||
background: bg-gradient-to-r from-pink-500 via-violet-400 to-blue-400 hover:from-pink-700 hover:via-violet-600 hover:to-blue-500
|
||||
tags:
|
||||
- jetbrains
|
||||
- java
|
||||
|
||||
@@ -27,13 +27,13 @@ JavaScript is a lightweight, interpreted programming language.
|
||||
|
||||
```javascript
|
||||
// => Hello world!
|
||||
console.log("Hello world!");
|
||||
console.log('Hello world!');
|
||||
|
||||
// => Hello CheatSheets.zip
|
||||
console.warn("hello %s", "CheatSheets.zip");
|
||||
console.warn('hello %s', 'CheatSheets.zip');
|
||||
|
||||
// Prints error message to stderr
|
||||
console.error(new Error("Oops!"));
|
||||
console.error(new Error('Oops!'));
|
||||
```
|
||||
|
||||
### Numbers
|
||||
@@ -47,7 +47,7 @@ let price = 4.99;
|
||||
|
||||
```javascript
|
||||
let x = null;
|
||||
let name = "Tammy";
|
||||
let name = 'Tammy';
|
||||
const found = false;
|
||||
|
||||
// => Tammy, false, null
|
||||
@@ -60,8 +60,8 @@ console.log(a); // => undefined
|
||||
### Strings
|
||||
|
||||
```javascript
|
||||
let single = "Wheres my bandit hat?";
|
||||
let double = "Wheres my bandit hat?";
|
||||
let single = 'Wheres my bandit hat?';
|
||||
let double = 'Wheres my bandit hat?';
|
||||
|
||||
// => 21
|
||||
console.log(single.length);
|
||||
@@ -107,7 +107,7 @@ console.log(number);
|
||||
let age = 7;
|
||||
|
||||
// String concatenation
|
||||
"Tommy is " + age + " years old.";
|
||||
'Tommy is ' + age + ' years old.';
|
||||
|
||||
// String interpolation
|
||||
`Tommy is ${age} years old.`;
|
||||
@@ -139,7 +139,7 @@ numberOfColumns = 8;
|
||||
const isMailSent = true;
|
||||
|
||||
if (isMailSent) {
|
||||
console.log("Mail sent to recipient");
|
||||
console.log('Mail sent to recipient');
|
||||
}
|
||||
```
|
||||
|
||||
@@ -178,7 +178,7 @@ true && false; // false
|
||||
250 >= 250; // true
|
||||
1 === 1; // true
|
||||
1 === 2; // false
|
||||
1 === "1"; // false
|
||||
1 === '1'; // false
|
||||
```
|
||||
|
||||
#### Logical Operator !
|
||||
@@ -194,12 +194,12 @@ console.log(oppositeValue);
|
||||
#### Nullish coalescing operator ??
|
||||
|
||||
```javascript
|
||||
null ?? "I win"; // 'I win'
|
||||
undefined ?? "Me too"; // 'Me too'
|
||||
null ?? 'I win'; // 'I win'
|
||||
undefined ?? 'Me too'; // 'Me too'
|
||||
|
||||
false ?? "I lose"; // false
|
||||
0 ?? "I lose again"; // 0
|
||||
"" ?? "Damn it"; // ''
|
||||
false ?? 'I lose'; // false
|
||||
0 ?? 'I lose again'; // 0
|
||||
'' ?? 'Damn it'; // ''
|
||||
```
|
||||
|
||||
### else if
|
||||
@@ -208,13 +208,13 @@ false ?? "I lose"; // false
|
||||
const size = 10;
|
||||
|
||||
if (size > 100) {
|
||||
console.log("Big");
|
||||
console.log('Big');
|
||||
} else if (size > 20) {
|
||||
console.log("Medium");
|
||||
console.log('Medium');
|
||||
} else if (size > 4) {
|
||||
console.log("Small");
|
||||
console.log('Small');
|
||||
} else {
|
||||
console.log("Tiny");
|
||||
console.log('Tiny');
|
||||
}
|
||||
// Print: Small
|
||||
```
|
||||
@@ -222,17 +222,17 @@ if (size > 100) {
|
||||
### switch Statement
|
||||
|
||||
```javascript
|
||||
const food = "salad";
|
||||
const food = 'salad';
|
||||
|
||||
switch (food) {
|
||||
case "oyster":
|
||||
console.log("The taste of the sea");
|
||||
case 'oyster':
|
||||
console.log('The taste of the sea');
|
||||
break;
|
||||
case "pizza":
|
||||
console.log("A delicious pie");
|
||||
case 'pizza':
|
||||
console.log('A delicious pie');
|
||||
break;
|
||||
default:
|
||||
console.log("Enjoy your meal");
|
||||
console.log('Enjoy your meal');
|
||||
}
|
||||
```
|
||||
|
||||
@@ -241,12 +241,12 @@ switch (food) {
|
||||
```javascript
|
||||
0 == false; // true
|
||||
0 === false; // false, different type
|
||||
1 == "1"; // true, automatic type conversion
|
||||
1 === "1"; // false, different type
|
||||
1 == '1'; // true, automatic type conversion
|
||||
1 === '1'; // false, different type
|
||||
null == undefined; // true
|
||||
null === undefined; // false
|
||||
"0" == false; // true
|
||||
"0" === false; // false
|
||||
'0' == false; // true
|
||||
'0' === false; // false
|
||||
```
|
||||
|
||||
The `==` just check the value, `===` check both the value and the type.
|
||||
@@ -270,12 +270,12 @@ sum(3, 6); // 9
|
||||
```javascript
|
||||
// Named function
|
||||
function rocketToMars() {
|
||||
return "BOOM!";
|
||||
return 'BOOM!';
|
||||
}
|
||||
|
||||
// Anonymous function
|
||||
const rocketToMars = function () {
|
||||
return "BOOM!";
|
||||
return 'BOOM!';
|
||||
};
|
||||
```
|
||||
|
||||
@@ -294,7 +294,7 @@ console.log(sum(2, 5)); // => 7
|
||||
|
||||
```javascript
|
||||
const printHello = () => {
|
||||
console.log("hello");
|
||||
console.log('hello');
|
||||
};
|
||||
printHello(); // => hello
|
||||
```
|
||||
@@ -349,7 +349,7 @@ sum(2, 4); // 6
|
||||
|
||||
```javascript
|
||||
const dog = function () {
|
||||
return "Woof!";
|
||||
return 'Woof!';
|
||||
};
|
||||
```
|
||||
|
||||
@@ -376,7 +376,7 @@ function add(num1, num2) {
|
||||
|
||||
```javascript
|
||||
function myFunction() {
|
||||
var pizzaName = "Margarita";
|
||||
var pizzaName = 'Margarita';
|
||||
// Code here can use pizzaName
|
||||
}
|
||||
|
||||
@@ -389,7 +389,7 @@ function myFunction() {
|
||||
const isLoggedIn = true;
|
||||
|
||||
if (isLoggedIn == true) {
|
||||
const statusMessage = "Logged in.";
|
||||
const statusMessage = 'Logged in.';
|
||||
}
|
||||
|
||||
// Uncaught ReferenceError...
|
||||
@@ -400,7 +400,7 @@ console.log(statusMessage);
|
||||
|
||||
```javascript
|
||||
// Variable declared globally
|
||||
const color = "blue";
|
||||
const color = 'blue';
|
||||
|
||||
function printColor() {
|
||||
console.log(color);
|
||||
@@ -455,10 +455,10 @@ The variable has its own copy using `let`, and the variable has shared copy usin
|
||||
### Arrays
|
||||
|
||||
```javascript
|
||||
const fruits = ["apple", "orange", "banana"];
|
||||
const fruits = ['apple', 'orange', 'banana'];
|
||||
|
||||
// Different data types
|
||||
const data = [1, "chicken", false];
|
||||
const data = [1, 'chicken', false];
|
||||
```
|
||||
|
||||
### Property .length
|
||||
@@ -494,8 +494,8 @@ console.log(myArray[1]); // 200
|
||||
|
||||
```javascript
|
||||
// Adding a single element:
|
||||
const cart = ["apple", "orange"];
|
||||
cart.push("pear");
|
||||
const cart = ['apple', 'orange'];
|
||||
cart.push('pear');
|
||||
|
||||
// Adding multiple elements:
|
||||
const numbers = [1, 2];
|
||||
@@ -507,7 +507,7 @@ Add items to the end and returns the new array length.
|
||||
### Array.pop()
|
||||
|
||||
```javascript
|
||||
const fruits = ["apple", "orange", "banana"];
|
||||
const fruits = ['apple', 'orange', 'banana'];
|
||||
|
||||
const fruit = fruits.pop(); // 'banana'
|
||||
console.log(fruits); // ["apple", "orange"]
|
||||
@@ -518,7 +518,7 @@ Remove an item from the end and returns the removed item.
|
||||
### Array.shift()
|
||||
|
||||
```javascript
|
||||
let cats = ["Bob", "Willy", "Mini"];
|
||||
let cats = ['Bob', 'Willy', 'Mini'];
|
||||
|
||||
cats.shift(); // ['Willy', 'Mini']
|
||||
```
|
||||
@@ -528,13 +528,13 @@ Remove an item from the beginning and returns the removed item.
|
||||
### Array.unshift()
|
||||
|
||||
```javascript
|
||||
let cats = ["Bob"];
|
||||
let cats = ['Bob'];
|
||||
|
||||
// => ['Willy', 'Bob']
|
||||
cats.unshift("Willy");
|
||||
cats.unshift('Willy');
|
||||
|
||||
// => ['Puff', 'George', 'Willy', 'Bob']
|
||||
cats.unshift("Puff", "George");
|
||||
cats.unshift('Puff', 'George');
|
||||
```
|
||||
|
||||
Add items to the beginning and returns the new array length.
|
||||
@@ -563,7 +563,7 @@ If you want to avoid mutating your original array, you can use concat.
|
||||
const emptySet = new Set();
|
||||
|
||||
// Set Object with values
|
||||
const setObj = new Set([1, true, "hi"]);
|
||||
const setObj = new Set([1, true, 'hi']);
|
||||
```
|
||||
|
||||
### Add
|
||||
@@ -572,19 +572,19 @@ const setObj = new Set([1, true, "hi"]);
|
||||
const emptySet = new Set();
|
||||
|
||||
// add values
|
||||
emptySet.add("a"); // 'a'
|
||||
emptySet.add('a'); // 'a'
|
||||
emptySet.add(1); // 'a', 1
|
||||
emptySet.add(true); // 'a', 1, true
|
||||
emptySet.add("a"); // 'a', 1, true
|
||||
emptySet.add('a'); // 'a', 1, true
|
||||
```
|
||||
|
||||
### Delete
|
||||
|
||||
```javascript
|
||||
const emptySet = new Set([1, true, "a"]);
|
||||
const emptySet = new Set([1, true, 'a']);
|
||||
|
||||
// delete values
|
||||
emptySet.delete("a"); // 1, true
|
||||
emptySet.delete('a'); // 1, true
|
||||
emptySet.delete(true); // 1
|
||||
emptySet.delete(1); //
|
||||
```
|
||||
@@ -592,10 +592,10 @@ emptySet.delete(1); //
|
||||
### Has
|
||||
|
||||
```javascript
|
||||
const setObj = new Set([1, true, "a"]);
|
||||
const setObj = new Set([1, true, 'a']);
|
||||
|
||||
// returns true or false
|
||||
setObj.has("a"); // true
|
||||
setObj.has('a'); // true
|
||||
setObj.has(1); // true
|
||||
setObj.has(false); // false
|
||||
```
|
||||
@@ -603,7 +603,7 @@ setObj.has(false); // false
|
||||
### Clear
|
||||
|
||||
```javascript
|
||||
const setObj = new Set([1, true, "a"]);
|
||||
const setObj = new Set([1, true, 'a']);
|
||||
|
||||
// clears the set
|
||||
console.log(setObj); // 1, true, 'a'
|
||||
@@ -613,7 +613,7 @@ setObj.clear(); //
|
||||
### Size
|
||||
|
||||
```javascript
|
||||
const setObj = new Set([1, true, "a"]);
|
||||
const setObj = new Set([1, true, 'a']);
|
||||
|
||||
consoloe.log(setObj.size); // 3
|
||||
```
|
||||
@@ -621,7 +621,7 @@ consoloe.log(setObj.size); // 3
|
||||
### ForEach
|
||||
|
||||
```javascript
|
||||
const setObj = new Set([1, true, "a"]);
|
||||
const setObj = new Set([1, true, 'a']);
|
||||
|
||||
setObj.forEach(function (value) {
|
||||
console.log(value);
|
||||
@@ -651,7 +651,7 @@ while (i < 5) {
|
||||
### Reverse Loop
|
||||
|
||||
```javascript
|
||||
const fruits = ["apple", "orange", "banana"];
|
||||
const fruits = ['apple', 'orange', 'banana'];
|
||||
|
||||
for (let i = fruits.length - 1; i >= 0; i--) {
|
||||
console.log(`${i}. ${fruits[i]}`);
|
||||
@@ -715,7 +715,7 @@ for (i = 0; i < 10; i++) {
|
||||
if (i === 3) {
|
||||
continue;
|
||||
}
|
||||
text += "The number is " + i + "<br>";
|
||||
text += 'The number is ' + i + '<br>';
|
||||
}
|
||||
```
|
||||
|
||||
@@ -732,7 +732,7 @@ for (let i = 0; i < 2; i += 1) {
|
||||
### for...in loop
|
||||
|
||||
```javascript
|
||||
const fruits = ["apple", "orange", "banana"];
|
||||
const fruits = ['apple', 'orange', 'banana'];
|
||||
|
||||
for (let index in fruits) {
|
||||
console.log(index);
|
||||
@@ -745,7 +745,7 @@ for (let index in fruits) {
|
||||
### for...of loop
|
||||
|
||||
```javascript
|
||||
const fruits = ["apple", "orange", "banana"];
|
||||
const fruits = ['apple', 'orange', 'banana'];
|
||||
|
||||
for (let fruit of fruits) {
|
||||
console.log(fruit);
|
||||
@@ -803,10 +803,10 @@ console.log(sum); // 10
|
||||
### Array.map()
|
||||
|
||||
```javascript
|
||||
const members = ["Taylor", "Donald", "Don", "Natasha", "Bobby"];
|
||||
const members = ['Taylor', 'Donald', 'Don', 'Natasha', 'Bobby'];
|
||||
|
||||
const announcements = members.map((member) => {
|
||||
return member + " joined the contest.";
|
||||
return member + ' joined the contest.';
|
||||
});
|
||||
|
||||
console.log(announcements);
|
||||
@@ -837,8 +837,8 @@ const filteredArray = randomNumbers.filter((n) => {
|
||||
|
||||
```javascript
|
||||
const apple = {
|
||||
color: "Green",
|
||||
price: { bulk: "$3/kg", smallQty: "$4/kg" },
|
||||
color: 'Green',
|
||||
price: { bulk: '$3/kg', smallQty: '$4/kg' }
|
||||
};
|
||||
console.log(apple.color); // => Green
|
||||
console.log(apple.price.bulk); // => $3/kg
|
||||
@@ -862,7 +862,7 @@ const trainSchedule = {
|
||||
|
||||
```javascript
|
||||
const classElection = {
|
||||
date: "January 12",
|
||||
date: 'January 12'
|
||||
};
|
||||
|
||||
console.log(classElection.place); // undefined
|
||||
@@ -872,16 +872,16 @@ console.log(classElection.place); // undefined
|
||||
|
||||
```javascript
|
||||
const student = {
|
||||
name: "Sheldon",
|
||||
name: 'Sheldon',
|
||||
score: 100,
|
||||
grade: "A",
|
||||
grade: 'A'
|
||||
};
|
||||
|
||||
console.log(student);
|
||||
// { name: 'Sheldon', score: 100, grade: 'A' }
|
||||
|
||||
delete student.score;
|
||||
student.grade = "F";
|
||||
student.grade = 'F';
|
||||
console.log(student);
|
||||
// { name: 'Sheldon', grade: 'F' }
|
||||
|
||||
@@ -893,8 +893,8 @@ student = {};
|
||||
|
||||
```javascript
|
||||
const person = {
|
||||
name: "Tom",
|
||||
age: "22",
|
||||
name: 'Tom',
|
||||
age: '22'
|
||||
};
|
||||
const { name, age } = person;
|
||||
console.log(name); // 'Tom'
|
||||
@@ -905,10 +905,10 @@ console.log(age); // '22'
|
||||
|
||||
```javascript
|
||||
const person = {
|
||||
firstName: "Matilda",
|
||||
firstName: 'Matilda',
|
||||
age: 27,
|
||||
hobby: "knitting",
|
||||
goal: "learning JavaScript",
|
||||
hobby: 'knitting',
|
||||
goal: 'learning JavaScript'
|
||||
};
|
||||
|
||||
delete person.hobby; // or delete person[hobby];
|
||||
@@ -927,11 +927,11 @@ console.log(person);
|
||||
|
||||
```javascript
|
||||
const origNum = 8;
|
||||
const origObj = { color: "blue" };
|
||||
const origObj = { color: 'blue' };
|
||||
|
||||
const changeItUp = (num, obj) => {
|
||||
num = 7;
|
||||
obj.color = "red";
|
||||
obj.color = 'red';
|
||||
};
|
||||
|
||||
changeItUp(origNum, origObj);
|
||||
@@ -947,7 +947,7 @@ console.log(origObj.color);
|
||||
### Shorthand object creation
|
||||
|
||||
```javascript
|
||||
const activity = "Surfing";
|
||||
const activity = 'Surfing';
|
||||
const beach = { activity };
|
||||
console.log(beach); // { activity: 'Surfing' }
|
||||
```
|
||||
@@ -956,11 +956,11 @@ console.log(beach); // { activity: 'Surfing' }
|
||||
|
||||
```javascript
|
||||
const cat = {
|
||||
name: "Pipey",
|
||||
name: 'Pipey',
|
||||
age: 8,
|
||||
whatName() {
|
||||
return this.name;
|
||||
},
|
||||
}
|
||||
};
|
||||
console.log(cat.whatName()); // => Pipey
|
||||
```
|
||||
@@ -977,8 +977,8 @@ const dogFactory = (name, age, breed) => {
|
||||
age: age,
|
||||
breed: breed,
|
||||
bark() {
|
||||
console.log("Woof!");
|
||||
},
|
||||
console.log('Woof!');
|
||||
}
|
||||
};
|
||||
};
|
||||
```
|
||||
@@ -993,11 +993,11 @@ const engine = {
|
||||
},
|
||||
// anonymous arrow function expression with no arguments
|
||||
sputter: () => {
|
||||
console.log("The engine sputters...");
|
||||
},
|
||||
console.log('The engine sputters...');
|
||||
}
|
||||
};
|
||||
|
||||
engine.start("noisily");
|
||||
engine.start('noisily');
|
||||
engine.sputter();
|
||||
```
|
||||
|
||||
@@ -1005,20 +1005,20 @@ engine.sputter();
|
||||
|
||||
```javascript
|
||||
const myCat = {
|
||||
_name: "Dottie",
|
||||
_name: 'Dottie',
|
||||
get name() {
|
||||
return this._name;
|
||||
},
|
||||
set name(newName) {
|
||||
this._name = newName;
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// Reference invokes the getter
|
||||
console.log(myCat.name);
|
||||
|
||||
// Assignment invokes the setter
|
||||
myCat.name = "Yankee";
|
||||
myCat.name = 'Yankee';
|
||||
```
|
||||
|
||||
## JavaScript Classes
|
||||
@@ -1032,16 +1032,16 @@ class Dog {
|
||||
}
|
||||
|
||||
introduce() {
|
||||
console.log("This is " + this._name + " !");
|
||||
console.log('This is ' + this._name + ' !');
|
||||
}
|
||||
|
||||
// A static method
|
||||
static bark() {
|
||||
console.log("Woof!");
|
||||
console.log('Woof!');
|
||||
}
|
||||
}
|
||||
|
||||
const myDog = new Dog("Buster");
|
||||
const myDog = new Dog('Buster');
|
||||
myDog.introduce();
|
||||
|
||||
// Calling the static method
|
||||
@@ -1058,7 +1058,7 @@ class Song {
|
||||
}
|
||||
|
||||
play() {
|
||||
console.log("Song playing!");
|
||||
console.log('Song playing!');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1076,7 +1076,7 @@ class Song {
|
||||
}
|
||||
}
|
||||
|
||||
const mySong = new Song("Bohemian Rhapsody", "Queen");
|
||||
const mySong = new Song('Bohemian Rhapsody', 'Queen');
|
||||
console.log(mySong.title);
|
||||
```
|
||||
|
||||
@@ -1085,11 +1085,11 @@ console.log(mySong.title);
|
||||
```javascript
|
||||
class Song {
|
||||
play() {
|
||||
console.log("Playing!");
|
||||
console.log('Playing!');
|
||||
}
|
||||
|
||||
stop() {
|
||||
console.log("Stopping!");
|
||||
console.log('Stopping!');
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -1114,9 +1114,9 @@ class Song extends Media {
|
||||
}
|
||||
|
||||
const mySong = new Song({
|
||||
artist: "Queen",
|
||||
name: "Bohemian Rhapsody",
|
||||
publishDate: 1975,
|
||||
artist: 'Queen',
|
||||
name: 'Bohemian Rhapsody',
|
||||
publishDate: 1975
|
||||
});
|
||||
```
|
||||
|
||||
@@ -1185,7 +1185,7 @@ module.exports = {
|
||||
add,
|
||||
subtract,
|
||||
multiply,
|
||||
duplicate,
|
||||
duplicate
|
||||
};
|
||||
```
|
||||
|
||||
@@ -1193,7 +1193,7 @@ module.exports = {
|
||||
|
||||
```javascript
|
||||
// main.js
|
||||
const myMath = require("./myMath.js");
|
||||
const myMath = require('./myMath.js');
|
||||
|
||||
console.log(myMath.add(6, 2)); // 8
|
||||
console.log(myMath.subtract(6, 2)); // 4
|
||||
@@ -1210,15 +1210,15 @@ const promise = new Promise((resolve, reject) => {
|
||||
const res = true;
|
||||
// An asynchronous operation.
|
||||
if (res) {
|
||||
resolve("Resolved!");
|
||||
resolve('Resolved!');
|
||||
} else {
|
||||
reject(Error("Error"));
|
||||
reject(Error('Error'));
|
||||
}
|
||||
});
|
||||
|
||||
promise.then(
|
||||
(res) => console.log(res),
|
||||
(err) => console.error(err),
|
||||
(err) => console.error(err)
|
||||
);
|
||||
```
|
||||
|
||||
@@ -1226,7 +1226,7 @@ promise.then(
|
||||
|
||||
```javascript
|
||||
const executorFn = (resolve, reject) => {
|
||||
resolve("Resolved!");
|
||||
resolve('Resolved!');
|
||||
};
|
||||
|
||||
const promise = new Promise(executorFn);
|
||||
@@ -1236,7 +1236,7 @@ const promise = new Promise(executorFn);
|
||||
|
||||
```javascript
|
||||
const loginAlert = () => {
|
||||
console.log("Login");
|
||||
console.log('Login');
|
||||
};
|
||||
|
||||
setTimeout(loginAlert, 6000);
|
||||
@@ -1247,7 +1247,7 @@ setTimeout(loginAlert, 6000);
|
||||
```javascript
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
resolve("Result");
|
||||
resolve('Result');
|
||||
}, 200);
|
||||
});
|
||||
|
||||
@@ -1257,7 +1257,7 @@ promise.then(
|
||||
},
|
||||
(err) => {
|
||||
console.error(err);
|
||||
},
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
@@ -1266,7 +1266,7 @@ promise.then(
|
||||
```javascript
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
reject(Error("Promise Rejected Unconditionally."));
|
||||
reject(Error('Promise Rejected Unconditionally.'));
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
@@ -1299,12 +1299,28 @@ Promise.all([promise1, promise2]).then((res) => {
|
||||
});
|
||||
```
|
||||
|
||||
### Promise.allSettled()
|
||||
|
||||
```javascript
|
||||
const promise1 = Promise.resolve(3);
|
||||
const promise2 = new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
reject(2);
|
||||
}, 100);
|
||||
});
|
||||
|
||||
Promise.allSettled([promise1, promise2]).then((res) => {
|
||||
console.log(res[0].status);
|
||||
console.log(res[1].status);
|
||||
});
|
||||
```
|
||||
|
||||
### Avoiding nested Promise and .then()
|
||||
|
||||
```javascript
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
resolve("*");
|
||||
resolve('*');
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
@@ -1313,7 +1329,7 @@ const twoStars = (star) => {
|
||||
};
|
||||
|
||||
const oneDot = (star) => {
|
||||
return star + ".";
|
||||
return star + '.';
|
||||
};
|
||||
|
||||
const print = (val) => {
|
||||
@@ -1328,7 +1344,7 @@ promise.then(twoStars).then(oneDot).then(print);
|
||||
|
||||
```javascript
|
||||
const executorFn = (resolve, reject) => {
|
||||
console.log("The executor function of the promise!");
|
||||
console.log('The executor function of the promise!');
|
||||
};
|
||||
|
||||
const promise = new Promise(executorFn);
|
||||
@@ -1337,11 +1353,15 @@ const promise = new Promise(executorFn);
|
||||
### Chaining multiple .then()
|
||||
|
||||
```javascript
|
||||
const promise = new Promise((resolve) => setTimeout(() => resolve("dAlan"), 100));
|
||||
const promise = new Promise((resolve) =>
|
||||
setTimeout(() => resolve('dAlan'), 100)
|
||||
);
|
||||
|
||||
promise
|
||||
.then((res) => {
|
||||
return res === "Alan" ? Promise.resolve("Hey Alan!") : Promise.reject("Who are you?");
|
||||
return res === 'Alan'
|
||||
? Promise.resolve('Hey Alan!')
|
||||
: Promise.reject('Who are you?');
|
||||
})
|
||||
.then(
|
||||
(res) => {
|
||||
@@ -1349,7 +1369,7 @@ promise
|
||||
},
|
||||
(err) => {
|
||||
console.error(err);
|
||||
},
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
@@ -1362,7 +1382,7 @@ const mock = (success, timeout = 1000) => {
|
||||
if (success) {
|
||||
resolve({ status: 200, data: {} });
|
||||
} else {
|
||||
reject({ message: "Error" });
|
||||
reject({ message: 'Error' });
|
||||
}
|
||||
}, timeout);
|
||||
});
|
||||
@@ -1384,7 +1404,7 @@ const someEvent = async () => {
|
||||
function helloWorld() {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve("Hello World!");
|
||||
resolve('Hello World!');
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
@@ -1392,13 +1412,13 @@ function helloWorld() {
|
||||
const msg = async function () {
|
||||
//Async Function Expression
|
||||
const msg = await helloWorld();
|
||||
console.log("Message:", msg);
|
||||
console.log('Message:', msg);
|
||||
};
|
||||
|
||||
const msg1 = async () => {
|
||||
//Async Arrow Function
|
||||
const msg = await helloWorld();
|
||||
console.log("Message:", msg);
|
||||
console.log('Message:', msg);
|
||||
};
|
||||
|
||||
msg(); // Message: Hello World! <-- after 2 seconds
|
||||
@@ -1411,7 +1431,7 @@ msg1(); // Message: Hello World! <-- after 2 seconds
|
||||
let pro1 = Promise.resolve(5);
|
||||
let pro2 = 44;
|
||||
let pro3 = new Promise(function (resolve, reject) {
|
||||
setTimeout(resolve, 100, "foo");
|
||||
setTimeout(resolve, 100, 'foo');
|
||||
});
|
||||
|
||||
Promise.all([pro1, pro2, pro3]).then(function (values) {
|
||||
@@ -1426,14 +1446,14 @@ Promise.all([pro1, pro2, pro3]).then(function (values) {
|
||||
function helloWorld() {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve("Hello World!");
|
||||
resolve('Hello World!');
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
|
||||
async function msg() {
|
||||
const msg = await helloWorld();
|
||||
console.log("Message:", msg);
|
||||
console.log('Message:', msg);
|
||||
}
|
||||
|
||||
msg(); // Message: Hello World! <-- after 2 seconds
|
||||
@@ -1448,7 +1468,7 @@ try {
|
||||
let user = JSON.parse(json); // <-- no errors
|
||||
console.log(user.name); // no name!
|
||||
} catch (e) {
|
||||
console.error("Invalid JSON data!");
|
||||
console.error('Invalid JSON data!');
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1458,14 +1478,14 @@ try {
|
||||
function helloWorld() {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve("Hello World!");
|
||||
resolve('Hello World!');
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
|
||||
async function msg() {
|
||||
const msg = await helloWorld();
|
||||
console.log("Message:", msg);
|
||||
console.log('Message:', msg);
|
||||
}
|
||||
|
||||
msg(); // Message: Hello World! <-- after 2 seconds
|
||||
@@ -1489,7 +1509,7 @@ Also see: [JSON cheatsheet](/json)
|
||||
|
||||
```javascript
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "mysite.com/getjson");
|
||||
xhr.open('GET', 'mysite.com/getjson');
|
||||
```
|
||||
|
||||
`XMLHttpRequest` is a browser-level API that enables the client to script data transfers via JavaScript, NOT part of the
|
||||
@@ -1499,8 +1519,8 @@ JavaScript language.
|
||||
|
||||
```javascript
|
||||
const req = new XMLHttpRequest();
|
||||
req.responseType = "json";
|
||||
req.open("GET", "/getdata?id=65");
|
||||
req.responseType = 'json';
|
||||
req.open('GET', '/getdata?id=65');
|
||||
req.onload = () => {
|
||||
console.log(xhr.response);
|
||||
};
|
||||
@@ -1512,13 +1532,13 @@ req.send();
|
||||
|
||||
```javascript
|
||||
const data = {
|
||||
fish: "Salmon",
|
||||
weight: "1.5 KG",
|
||||
units: 5,
|
||||
fish: 'Salmon',
|
||||
weight: '1.5 KG',
|
||||
units: 5
|
||||
};
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "/inventory/add");
|
||||
xhr.responseType = "json";
|
||||
xhr.open('POST', '/inventory/add');
|
||||
xhr.responseType = 'json';
|
||||
xhr.send(JSON.stringify(data));
|
||||
|
||||
xhr.onload = () => {
|
||||
@@ -1550,7 +1570,7 @@ fetch(url, {
|
||||
### JSON Formatted
|
||||
|
||||
```javascript
|
||||
fetch("url-that-returns-JSON")
|
||||
fetch('url-that-returns-JSON')
|
||||
.then((response) => response.json())
|
||||
.then((jsonResponse) => {
|
||||
console.log(jsonResponse);
|
||||
@@ -1573,20 +1593,20 @@ fetch('url')
|
||||
### Fetch API Function
|
||||
|
||||
```javascript
|
||||
fetch("https://api-xxx.com/endpoint", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ id: "200" }),
|
||||
fetch('https://api-xxx.com/endpoint', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ id: '200' })
|
||||
})
|
||||
.then(
|
||||
(response) => {
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
}
|
||||
throw new Error("Request failed!");
|
||||
throw new Error('Request failed!');
|
||||
},
|
||||
(networkError) => {
|
||||
console.log(networkError.message);
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((jsonResponse) => {
|
||||
console.log(jsonResponse);
|
||||
@@ -1600,7 +1620,7 @@ const getSuggestions = async () => {
|
||||
const wordQuery = inputField.value;
|
||||
const endpoint = `${url}${queryParams}${wordQuery}`;
|
||||
try {
|
||||
const response = await fetch(endpoint, { cache: "no-cache" });
|
||||
const response = await fetch(endpoint, { cache: 'no-cache' });
|
||||
if (response.ok) {
|
||||
const jsonResponse = await response.json();
|
||||
}
|
||||
|
||||
@@ -28,7 +28,10 @@ plugins:
|
||||
#### Official CDN
|
||||
|
||||
```html {.wrap}
|
||||
<script src="https://code.jquery.com/jquery-3.5.1.min.js" crossorigin="anonymous"></script>
|
||||
<script
|
||||
src="https://code.jquery.com/jquery-3.5.1.min.js"
|
||||
crossorigin="anonymous"
|
||||
></script>
|
||||
```
|
||||
|
||||
### jQuery syntax
|
||||
@@ -40,11 +43,11 @@ $(selector).methodOrFunction();
|
||||
#### Example:
|
||||
|
||||
```javascript
|
||||
$("#menu").on("click", function () {
|
||||
$('#menu').on('click', function () {
|
||||
$(this).hide();
|
||||
});
|
||||
|
||||
$("body").css("background", "red");
|
||||
$('body').css('background', 'red');
|
||||
```
|
||||
|
||||
### jQuery document ready
|
||||
@@ -52,14 +55,14 @@ $("body").css("background", "red");
|
||||
```javascript
|
||||
$(document).ready(function () {
|
||||
// Runs after the DOM is loaded.
|
||||
alert("DOM fully loaded!");
|
||||
alert('DOM fully loaded!');
|
||||
});
|
||||
```
|
||||
|
||||
```javascript
|
||||
$(function () {
|
||||
// Runs after the DOM is loaded.
|
||||
alert("DOM fully loaded!");
|
||||
alert('DOM fully loaded!');
|
||||
});
|
||||
```
|
||||
|
||||
@@ -68,15 +71,15 @@ $(function () {
|
||||
### Examples {.secondary}
|
||||
|
||||
```javascript
|
||||
$("button").click(() => {
|
||||
$(":button").css("color", "red");
|
||||
$('button').click(() => {
|
||||
$(':button').css('color', 'red');
|
||||
});
|
||||
```
|
||||
|
||||
#### Combining selectors
|
||||
|
||||
```javascript
|
||||
$("selector1, selector2 ...selectorn");
|
||||
$('selector1, selector2 ...selectorn');
|
||||
```
|
||||
|
||||
### Basics
|
||||
@@ -175,32 +178,32 @@ $("selector1, selector2 ...selectorn");
|
||||
### Examples {.secondary .row-span-2}
|
||||
|
||||
```javascript
|
||||
$("h2").css({
|
||||
color: "blue",
|
||||
backgroundColor: "gray",
|
||||
fontSize: "24px",
|
||||
$('h2').css({
|
||||
color: 'blue',
|
||||
backgroundColor: 'gray',
|
||||
fontSize: '24px'
|
||||
});
|
||||
```
|
||||
|
||||
#### jQuery addClass
|
||||
|
||||
```javascript
|
||||
$(".button").addClass("active");
|
||||
$('.button').addClass('active');
|
||||
```
|
||||
|
||||
#### jQuery removeClass
|
||||
|
||||
```javascript
|
||||
$(".button").on("mouseleave", (evt) => {
|
||||
$('.button').on('mouseleave', (evt) => {
|
||||
let e = evt.currentTarget;
|
||||
$(e).removeClass("active");
|
||||
$(e).removeClass('active');
|
||||
});
|
||||
```
|
||||
|
||||
#### jQuery .toggleClass
|
||||
|
||||
```javascript
|
||||
$(".choice").toggleClass("highlighted");
|
||||
$('.choice').toggleClass('highlighted');
|
||||
```
|
||||
|
||||
### Attributes
|
||||
@@ -268,15 +271,15 @@ $(".choice").toggleClass("highlighted");
|
||||
|
||||
```javascript
|
||||
/*<span>Span.</span>*/
|
||||
$("span").after("<p>Paragraph.</p>");
|
||||
$('span').after('<p>Paragraph.</p>');
|
||||
/*<span>Span.</span><p>Paragraph.</p>*/
|
||||
|
||||
/*<span>Span.</span>*/
|
||||
$("<span>Span.</span>").replaceAll("p");
|
||||
$('<span>Span.</span>').replaceAll('p');
|
||||
/*<p>Span.</p>*/
|
||||
|
||||
/*<span>This is span.</span>*/
|
||||
$("span").wrap("<p></p>");
|
||||
$('span').wrap('<p></p>');
|
||||
/*<p><span>This is span.</span></p>*/
|
||||
```
|
||||
|
||||
@@ -389,25 +392,25 @@ $("span").wrap("<p></p>");
|
||||
|
||||
```javascript
|
||||
// A mouse event 'click'
|
||||
$("#menu-button").on("click", () => {
|
||||
$("#menu").show();
|
||||
$('#menu-button').on('click', () => {
|
||||
$('#menu').show();
|
||||
});
|
||||
|
||||
// A keyboard event 'keyup'
|
||||
$("#textbox").on("keyup", () => {
|
||||
$("#menu").show();
|
||||
$('#textbox').on('keyup', () => {
|
||||
$('#menu').show();
|
||||
});
|
||||
|
||||
// A scroll event 'scroll'
|
||||
$("#menu-button").on("scroll", () => {
|
||||
$("#menu").show();
|
||||
$('#menu-button').on('scroll', () => {
|
||||
$('#menu').show();
|
||||
});
|
||||
```
|
||||
|
||||
#### Event object
|
||||
|
||||
```javascript
|
||||
$("#menu").on("click", (event) => {
|
||||
$('#menu').on('click', (event) => {
|
||||
$(event.currentTarget).hide();
|
||||
});
|
||||
```
|
||||
@@ -415,19 +418,19 @@ $("#menu").on("click", (event) => {
|
||||
#### Method chaining
|
||||
|
||||
```javascript
|
||||
$("#menu-btn")
|
||||
.on("mouseenter", () => {
|
||||
$("#menu").show();
|
||||
$('#menu-btn')
|
||||
.on('mouseenter', () => {
|
||||
$('#menu').show();
|
||||
})
|
||||
.on("mouseleave", () => {
|
||||
$("#menu").hide();
|
||||
.on('mouseleave', () => {
|
||||
$('#menu').hide();
|
||||
});
|
||||
```
|
||||
|
||||
#### Prevents the event
|
||||
|
||||
```javascript
|
||||
$("p").click(function (event) {
|
||||
$('p').click(function (event) {
|
||||
event.stopPropagation();
|
||||
// Do something
|
||||
});
|
||||
@@ -537,18 +540,18 @@ $("p").click(function (event) {
|
||||
### Examples {.secondary .row-span-2}
|
||||
|
||||
```javascript
|
||||
$("#menu-button").on("click", () => {
|
||||
$('#menu-button').on('click', () => {
|
||||
// $('#menu').fadeIn(400, 'swing')
|
||||
$("#menu").fadeIn();
|
||||
$('#menu').fadeIn();
|
||||
});
|
||||
```
|
||||
|
||||
#### fadeOut effect
|
||||
|
||||
```javascript
|
||||
$("#menu-button").on("click", () => {
|
||||
$('#menu-button').on('click', () => {
|
||||
// $('#menu').fadeOut(400, 'swing')
|
||||
$("#menu").fadeOut();
|
||||
$('#menu').fadeOut();
|
||||
});
|
||||
```
|
||||
|
||||
@@ -606,13 +609,13 @@ $("#menu-button").on("click", () => {
|
||||
$.ajax({
|
||||
url: this.action,
|
||||
type: this.method,
|
||||
data: $(this).serialize(),
|
||||
data: $(this).serialize()
|
||||
})
|
||||
.done(function (server_data) {
|
||||
console.log("success" + server_data);
|
||||
console.log('success' + server_data);
|
||||
})
|
||||
.fail(function (jqXHR, status, err) {
|
||||
console.log("fail" + err);
|
||||
console.log('fail' + err);
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
@@ -213,12 +213,12 @@ Begins with `[` and ends with `]`
|
||||
|
||||
```javascript
|
||||
let myObject = {
|
||||
name: "Jason",
|
||||
last: "Doe",
|
||||
name: 'Jason',
|
||||
last: 'Doe',
|
||||
age: 39,
|
||||
gender: "M",
|
||||
gender: 'M',
|
||||
salary: 70000,
|
||||
married: true,
|
||||
married: true
|
||||
};
|
||||
```
|
||||
|
||||
@@ -242,10 +242,10 @@ let myObject = {
|
||||
age: 2,
|
||||
gender: 3,
|
||||
salary: 4,
|
||||
married: 5,
|
||||
married: 5
|
||||
},
|
||||
jdoe: ["Jason", "Doe", 39, "M", 70000, true],
|
||||
jsmith: ["Tom", "Smith", 42, "F", 80000, true],
|
||||
jdoe: ['Jason', 'Doe', 39, 'M', 70000, true],
|
||||
jsmith: ['Tom', 'Smith', 42, 'F', 80000, true]
|
||||
};
|
||||
```
|
||||
|
||||
@@ -264,29 +264,29 @@ let myObject = {
|
||||
```javascript
|
||||
let myArray = [
|
||||
{
|
||||
name: "Jason",
|
||||
last: "Doe",
|
||||
name: 'Jason',
|
||||
last: 'Doe',
|
||||
age: 39,
|
||||
gender: "M",
|
||||
gender: 'M',
|
||||
salary: 70000,
|
||||
married: true,
|
||||
married: true
|
||||
},
|
||||
{
|
||||
name: "Tom",
|
||||
last: "Smith",
|
||||
name: 'Tom',
|
||||
last: 'Smith',
|
||||
age: 42,
|
||||
gender: "F",
|
||||
gender: 'F',
|
||||
salary: 80000,
|
||||
married: true,
|
||||
married: true
|
||||
},
|
||||
{
|
||||
name: "Amy",
|
||||
last: "Burnquist",
|
||||
name: 'Amy',
|
||||
last: 'Burnquist',
|
||||
age: 29,
|
||||
gender: "F",
|
||||
gender: 'F',
|
||||
salary: 60000,
|
||||
married: false,
|
||||
},
|
||||
married: false
|
||||
}
|
||||
];
|
||||
```
|
||||
|
||||
@@ -303,7 +303,7 @@ let myArray = [
|
||||
### Access Array
|
||||
|
||||
```javascript
|
||||
let myArray = ["Jason", "Doe", 39, "M", 70000, true];
|
||||
let myArray = ['Jason', 'Doe', 39, 'M', 70000, true];
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
@@ -200,7 +200,7 @@ Example based on KaTeX showing on one line: `KaTeX:\int_0^\infty x^2 dx`
|
||||
|
||||
### `KaTeX:\LaTeX` math constructs {.col-span-3}
|
||||
|
||||
| 预览 | 方法 | 预览 | 方法 | 预览 | 方法 |
|
||||
| Preview | Method | Preview | Method | Preview | Method |
|
||||
| :---------------------- | :--------------------------- | :---------------------- | :--------------------------- | :--------------------------- | :-------------------------------- |
|
||||
| `KaTeX:\frac{abc}{xyz}` | <pur>`\frac{abc}{xyz}`</pur> | `KaTeX:\overline{abc}` | <pur>`\overline{abc}`</pur> | `KaTeX:\overrightarrow{abc}` | <pur>`\overrightarrow{abc}`</pur> |
|
||||
| `KaTeX:f'` | <pur>`f'`</pur> | `KaTeX:\underline{abc}` | <pur>`\underline{abc}`</pur> | `KaTeX:\overleftarrow{abc}` | <pur>`\overleftarrow{abc}`</pur> |
|
||||
@@ -481,7 +481,7 @@ The pair of expressions `\left` `KaTeX:s_1` and `\right` `KaTeX:s_2` can be used
|
||||
|
||||
{.left-align}
|
||||
|
||||
### 可扩展箭头 {.col-span-3}
|
||||
### Extensible arrows {.col-span-3}
|
||||
|
||||
| :- | :- | :- | :- |
|
||||
| :------------------------------- | :------------------------------------ | :-------------------------------- | :------------------------------------- |
|
||||
@@ -909,7 +909,6 @@ x = \begin{cases}
|
||||
\end{itemize}
|
||||
```
|
||||
|
||||
|
||||
### Ordered List
|
||||
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
@@ -143,7 +143,7 @@ ___
|
||||
|
||||
````markdown
|
||||
```javascript
|
||||
console.log("This is a block code");
|
||||
console.log('This is a block code');
|
||||
```
|
||||
````
|
||||
|
||||
@@ -228,7 +228,7 @@ A markdown table generator: [tableconvert.com](https://tableconvert.com/)
|
||||
```markdown
|
||||
![alt text][logo]
|
||||
|
||||
[logo]: /images/logo.png "Logo Title"
|
||||
[logo]: /images/logo.png 'Logo Title'
|
||||
```
|
||||
|
||||
### Backslash escapes
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
---
|
||||
title: "Matplotlib"
|
||||
title: 'Matplotlib'
|
||||
date: 06-06-2025
|
||||
background: bg-[#1a073e]
|
||||
tags:
|
||||
- "data visualization"
|
||||
- "matplotlib"
|
||||
- "plotting"
|
||||
- 'data visualization'
|
||||
- 'matplotlib'
|
||||
- 'plotting'
|
||||
categories:
|
||||
- "Python"
|
||||
- 'Python'
|
||||
intro: |
|
||||
[Matplotlib](https://matplotlib.org/) is a comprehensive library for creating static, animated, and interactive plots in Python.
|
||||
This cheat sheet provides a quick reference from basic to advanced usage, covering essential features for data science, machine learning, and scientific computing.
|
||||
@@ -15,10 +15,9 @@ plugins:
|
||||
- copyCode
|
||||
---
|
||||
|
||||
|
||||
---
|
||||
|
||||
## Getting Started {.cols-2}
|
||||
## Getting Started {.cols-2}
|
||||
|
||||
### Importing
|
||||
|
||||
@@ -38,7 +37,7 @@ plt.show() # Display the plot
|
||||
|
||||
---
|
||||
|
||||
## Plot Types {.cols-2}
|
||||
## Plot Types {.cols-2}
|
||||
|
||||
### Line Plot
|
||||
|
||||
@@ -98,7 +97,7 @@ plt.show()
|
||||
|
||||
---
|
||||
|
||||
## Customization {.row-span-2}
|
||||
## Customization {.row-span-2}
|
||||
|
||||
| Feature | Code Example | Description |
|
||||
| --------------- | ------------------------------------------------------------------------------------ | ------------------------------------------- |
|
||||
@@ -117,7 +116,7 @@ plt.show()
|
||||
|
||||
---
|
||||
|
||||
## Subplots & Layouts
|
||||
## Subplots & Layouts
|
||||
|
||||
### Multiple Subplots
|
||||
|
||||
@@ -139,7 +138,7 @@ plt.figure(figsize=(10, 5)) # Set figure size (width, height in inches)
|
||||
|
||||
---
|
||||
|
||||
## Advanced Visualizations {.cols-2}
|
||||
## Advanced Visualizations {.cols-2}
|
||||
|
||||
### Heatmap
|
||||
|
||||
@@ -174,7 +173,7 @@ plt.show()
|
||||
|
||||
---
|
||||
|
||||
## Working with Images
|
||||
## Working with Images
|
||||
|
||||
```python
|
||||
import matplotlib.image as mpimg
|
||||
@@ -233,7 +232,7 @@ plt.show()
|
||||
|
||||
---
|
||||
|
||||
## Saving Plots
|
||||
## Saving Plots
|
||||
|
||||
```python
|
||||
plt.savefig("figure.png", dpi=300, bbox_inches='tight') # Save plot to file
|
||||
@@ -241,7 +240,7 @@ plt.savefig("figure.png", dpi=300, bbox_inches='tight') # Save plot to file
|
||||
|
||||
---
|
||||
|
||||
## Show & Clear
|
||||
## Show & Clear
|
||||
|
||||
```python
|
||||
plt.show() # Show plot window
|
||||
@@ -251,7 +250,7 @@ plt.close() # Close figure window (useful in scripts or GUI apps)
|
||||
|
||||
---
|
||||
|
||||
## More Useful Functions
|
||||
## More Useful Functions
|
||||
|
||||
| Function | Use Case |
|
||||
| ------------------------------ | ------------------------------- |
|
||||
@@ -265,4 +264,3 @@ plt.close() # Close figure window (useful in scripts or GUI apps)
|
||||
| `plt.gcf()` | Get current figure |
|
||||
|
||||
---
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
---
|
||||
title: MongoDB
|
||||
date: 2023-04-05
|
||||
background:
|
||||
bg-gradient-to-r from-green-900 via-green-600 to-green-400 hover:from-green-900 hover:via-green-700 hover:to-green-500
|
||||
background: bg-gradient-to-r from-green-900 via-green-600 to-green-400 hover:from-green-900 hover:via-green-700 hover:to-green-500
|
||||
tags:
|
||||
- NoSQL
|
||||
- DB
|
||||
@@ -91,14 +90,14 @@ db.coll.findOneAndDelete({"name": "Max"})
|
||||
|
||||
```mongosh
|
||||
db.coll.updateMany({"_id": 1}, {$set: {"year": 2016}}) // WARNING! Replaces the entire document where "_id" = 1
|
||||
db.coll.updateOne({"_id": 1}, {$set: {"year": 2016, name: "Max"}})
|
||||
db.coll.updateOne({"_id": 1}, {$unset: {"year": 1}})
|
||||
db.coll.updateOne({"_id": 1}, {$rename: {"year": "date"} })
|
||||
db.coll.updateOne({"_id": 1}, {$inc: {"year": 5}})
|
||||
db.coll.updateOne({"_id": 1}, {$mul: {price: 2}})
|
||||
db.coll.updateOne({"_id": 1}, {$set: {"year": 2016, name: "Max"}})
|
||||
db.coll.updateOne({"_id": 1}, {$unset: {"year": 1}})
|
||||
db.coll.updateOne({"_id": 1}, {$rename: {"year": "date"} })
|
||||
db.coll.updateOne({"_id": 1}, {$inc: {"year": 5}})
|
||||
db.coll.updateOne({"_id": 1}, {$mul: {price: 2}})
|
||||
db.coll.updateOne({"_id": 1}, {$min: {"imdb": 5}})
|
||||
db.coll.updateOne({"_id": 1}, {$max: {"imdb": 8}})
|
||||
db.coll.updateMany({"_id": {$lt: 10}}, {$set: {"lastModified": ISODate()}})
|
||||
db.coll.updateOne({"_id": 1}, {$max: {"imdb": 8}})
|
||||
db.coll.updateMany({"_id": {$lt: 10}}, {$set: {"lastModified": ISODate()}})
|
||||
```
|
||||
|
||||
### Array {.row-span-2}
|
||||
|
||||
@@ -0,0 +1,227 @@
|
||||
---
|
||||
title: NetworkPorts
|
||||
date: 2025-06-19 15:00:00
|
||||
background: bg-[#71d1f9]
|
||||
tags:
|
||||
- Network
|
||||
categories:
|
||||
- Other
|
||||
intro: |
|
||||
A network ports cheat sheet with non-exhaustive list of ports used according to their field of application.
|
||||
plugins:
|
||||
---
|
||||
|
||||
|
||||
## Networking and Infrastructure
|
||||
|
||||
### Web Ports
|
||||
|
||||
| **Port** | **Nom** | **Description** |
|
||||
|:-------------| :--------------- |:----------------------------|
|
||||
| `80` | HTTP | HyperText Transfer Protocol |
|
||||
| `443` | HTTPS | HTTP Secure |
|
||||
| `8080` | HTTP-Alt | Alternative HTTP Port |
|
||||
| `8443` | HTTPS-Alt | Alternative HTTPS Port |
|
||||
| `8000` | HTTP-Proxy | For proxy server HTTP |
|
||||
| `8008` | HTTP-Backup | Backup port for HTTP |
|
||||
| `8888` | HTTP-Alternative | Alternative port for HTTP |
|
||||
|
||||
### Network and Infrastructure Service Ports
|
||||
|
||||
| **Port** | **Nom** | **Description** |
|
||||
|:---------| :-------- |:------------------------------------|
|
||||
| `53` | DNS | Domain Name System |
|
||||
| `67`/`68`| DHCP | Dynamic Host Configuration Protocol |
|
||||
| `123` | NTP | Network Time Protocol |
|
||||
| `161` | SNMP | Simple Network Management Protocol |
|
||||
| `162` | SNMP-Trap | SNMP Trap Messages |
|
||||
| `514` | Syslog | Logging system |
|
||||
| `69` | TFTP | Trivial File Transfer Protocol |
|
||||
|
||||
### Virtualization and Containerization Service Ports
|
||||
|
||||
| **Port** | **Nom** | **Description** |
|
||||
|:----------| :------------ |:--------------------------------|
|
||||
| `2375` | Docker | Docker without TLS |
|
||||
| `2376` | Docker | Docker with TLS |
|
||||
| `6443` | Kubernetes | Kubernetes API Server |
|
||||
| `8443` | Kubernetes | Alternative Kubernetes API port |
|
||||
| `9100` | Node Exporter | Prometheus Node Exporter |
|
||||
| `9090` | Prometheus | Prometheus Monitoring |
|
||||
| `5672` | RabbitMQ | Message Broker RabbitMQ |
|
||||
|
||||
### Monitoring and Management Service Ports {.col-span-2}
|
||||
|
||||
| **Port** | **Nom** | **Description** |
|
||||
|:---------| :--------- |:------------------------------------------|
|
||||
| `631` | IPP | Internet Printing Protocol |
|
||||
| `873` | rsync | Remote Sync |
|
||||
| `8086` | InfluxDB | Time Series Database InfluxDB |
|
||||
| `9093` | Prometheus | Prometheus Alertmanager Alert Management |
|
||||
|
||||
|
||||
|
||||
## Data Management
|
||||
|
||||
### Data Base Ports {.col-span-2}
|
||||
|
||||
| **Port** | **Nom** | **Description** |
|
||||
|:----------| :------------------- |:--------------------------------------|
|
||||
| `1433` | Microsoft SQL Server | Microsoft SQL Database Server |
|
||||
| `3306` | MySQL | MySQL Database Management System |
|
||||
| `5432` | PostgreSQL | PostgreSQL Database Management System |
|
||||
| `1521` | Oracle | Oracle Database Management System |
|
||||
| `27017` | MongoDB | MongoDB NoSQL Database |
|
||||
| `11211` | Memcached | Memcached Memory Caching System |
|
||||
| `6379` | Redis | Redis In-Memory Database |
|
||||
|
||||
|
||||
|
||||
|
||||
## Communication Services
|
||||
|
||||
### Remote Ports
|
||||
|
||||
| **Port** | **Nom** | **Description** |
|
||||
|:---------| :------ |:-----------------------------------|
|
||||
| `22` | SSH | Secure Shell |
|
||||
| `23` | Telnet | Unsecure remote terminal protocol |
|
||||
| `3389` | RDP | Remote Desktop Protocol |
|
||||
| `5900` | VNC | Virtual Network Computing |
|
||||
| `69` | TFTP | Trivial File Transfer Protocol |
|
||||
| `179` | BGP | Border Gateway Protocol |
|
||||
| `113` | Ident | Ident Protocol |
|
||||
|
||||
### Messagerie Service Ports
|
||||
|
||||
| **Port** | **Nom** | **Description** |
|
||||
|:---------| :-------------- |:---------------------------------|
|
||||
| `25` | SMTP | Simple Mail Transfer Protocol |
|
||||
| `465` | SMTPS | SMTP Secure |
|
||||
| `587` | SMTP-Submission | Port for email submission |
|
||||
| `110` | POP3 | Post Office Protocol v3 |
|
||||
| `995` | POP3S | POP3 Secure |
|
||||
| `143` | IMAP | Internet Message Access Protocol |
|
||||
| `993` | IMAPS | IMAP Secure |
|
||||
|
||||
|
||||
### Instant Messaging and VoIP Service Ports
|
||||
|
||||
| **Port** | **Nom** | **Description** |
|
||||
|:---------| :---------- |:-------------------------------------------|
|
||||
| `5060` | SIP | Session Initiation Protocol |
|
||||
| `5061` | SIP-Secure | SIP over TLS |
|
||||
| `1720` | H.323 | Communication protocol for VoIP |
|
||||
| `3478` | STUN | Session Traversal Utilities for NAT |
|
||||
| `1234` | Skype | Communication VoIP via Skype |
|
||||
| `5222` | XMPP | Extensible Messaging and Presence Protocol |
|
||||
| `5223` | XMPP-Secure | XMPP over SSL |
|
||||
|
||||
|
||||
### Voice and Video Service Ports {.col-span-2}
|
||||
|
||||
| **Port** | **Nom** | **Description** |
|
||||
|:----------------| :--------- |:--------------------------------------------------------|
|
||||
| `5060` | SIP | Session Initiation Protocol pour VoIP |
|
||||
| `5061` | SIP Secure | SIP sur TLS |
|
||||
| `16384`-`32767` | RTP | Real-time Transport Protocol pour streaming audio/vidéo |
|
||||
| `3478` | STUN | Session Traversal Utilities for NAT |
|
||||
| `5004` | RTP | Real-time Transport Protocol for media |
|
||||
| `5222` | XMPP | Extensible messaging protocol for instant messaging |
|
||||
| `9000` | WebRTC | Protocols for real-time communication via browser |
|
||||
|
||||
|
||||
### P2P Download and Sharing Service Ports
|
||||
|
||||
| **Port** | **Nom** | **Description** |
|
||||
|:--------------| :--------- |:---------------------------------------|
|
||||
| `6881`-`6889` | BitTorrent | Ports used by BitTorrent clients |
|
||||
| `51413` | BitTorrent | Default port for BitTorrent |
|
||||
| `6969` | BitTorrent | Default port for BitTorrent trackers |
|
||||
| `1194` | OpenVPN | Also used for VPNs and some P2P |
|
||||
| `4661` | uTorrent | Port used by uTorrent client |
|
||||
| `37152` | Steam | Used by Steam platform for downloads |
|
||||
|
||||
|
||||
|
||||
|
||||
## Security Services
|
||||
|
||||
### Security Ports {.col-span-2}
|
||||
|
||||
| **Port** | **Nom** | **Description** |
|
||||
|:---------| :---------- | :----------------------------------------- |
|
||||
| `1194` | OpenVPN | Virtual Private Network |
|
||||
| `1701` | L2TP | Layer 2 Tunneling Protocol |
|
||||
| `1723` | PPTP | Point-to-Point Tunneling Protocol |
|
||||
| `4500` | IPsec-NAT-T | IPsec NAT Traversal |
|
||||
| `500` | IKE | Internet Key Exchange |
|
||||
| `1812` | RADIUS | Remote Authentication Dial-In User Service |
|
||||
| `3306` | MySQL SSL | MySQL avec chiffrement SSL |
|
||||
|
||||
|
||||
### Cryptography and Security Service Ports
|
||||
|
||||
| **Port** | **Nom** | **Description** |
|
||||
|:---------| :-------- |:---------------------------------------|
|
||||
| `443` | HTTPS | HTTP Secure avec SSL/TLS |
|
||||
| `993` | IMAPS | IMAP sécurisé avec SSL/TLS |
|
||||
| `995` | POP3S | POP3 sécurisé avec SSL/TLS |
|
||||
| `636` | LDAPS | LDAP sécurisé avec SSL/TLS |
|
||||
| `8443` | HTTPS-Alt | Alternative port for HTTPS |
|
||||
| `8888` | SSL Proxy | Secure proxy using SSL/TLS |
|
||||
| `563` | SNEWS | Secure Network News Transfer Protocol |
|
||||
|
||||
|
||||
## System and Application Services
|
||||
|
||||
### File Service Ports {.col-span-2}
|
||||
|
||||
| **Port** | **Nom** | **Description** |
|
||||
|:---------| :---------- |:----------------------------------------|
|
||||
| `20` | FTP-DATA | FTP data transfer |
|
||||
| `21` | FTP | File Transfer Protocol |
|
||||
| `22` | SFTP | Secure File Transfer Protocol (via SSH) |
|
||||
| `445` | SMB | Server Message Block (Windows Shares) |
|
||||
| `139` | NetBIOS-SSN | NetBIOS Session Service |
|
||||
| `2049` | NFS | Network File System |
|
||||
| `548` | AFP | Apple Filing Protocol |
|
||||
|
||||
|
||||
### Miscellaneous System and App Ports
|
||||
|
||||
| **Port** | **Nom** | **Description** |
|
||||
|:------------| :------ |:----------------------------------------------|
|
||||
| `137`-`139` | NetBIOS | NetBIOS services for naming and file sharing |
|
||||
| `1900` | UPnP | Universal Plug and Play |
|
||||
| `24800` | Vuze | Client BitTorrent Vuze |
|
||||
| `32400` | Plex | Serveur multimédia Plex |
|
||||
|
||||
|
||||
## Miscellaneous Services
|
||||
|
||||
|
||||
### Gaming Service Ports {.col-span-2}
|
||||
|
||||
| **Port** | **Nom** | **Description** |
|
||||
|:----------| :------------ |:---------------------------------|
|
||||
| `27015` | Steam | Steam gaming platform |
|
||||
| `7777` | Unreal Engine | Game servers using Unreal Engine |
|
||||
| `27020` | Source Engine | Game servers using Source Engine |
|
||||
| `28910` | Various Games | Various multiplayer games |
|
||||
| `27000` | Various Games | Additional multiplayer games |
|
||||
|
||||
|
||||
### Miscellaneous Service Ports
|
||||
|
||||
| **Port** | **Nom** | **Description** |
|
||||
|:----------| :------ | :-------------------------------------------------------- |
|
||||
| `500` | ISAKMP | Internet Security Association and Key Management Protocol |
|
||||
| `520` | RIP | Routing Information Protocol |
|
||||
| `1900` | UPnP | Universal Plug and Play |
|
||||
| `3659` | RADIUS | Remote Authentication Dial-In User Service |
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@ categories:
|
||||
- Productivity
|
||||
- Software
|
||||
intro:
|
||||
A comprehensive quick reference guide for Notion keyboard shortcuts on Desktop and Web, designed to boost your productivity.
|
||||
A comprehensive quick reference guide for Notion keyboard shortcuts on Desktop and Web, designed to boost your
|
||||
productivity.
|
||||
plugins:
|
||||
- copyCode
|
||||
---
|
||||
@@ -22,26 +23,30 @@ plugins:
|
||||
## Most Popular / Essential {.col-span-3}
|
||||
|
||||
### Create & Navigate
|
||||
| Action | Mac Shortcut | Windows/Linux Shortcut |
|
||||
| :--------------------------- | :------------------------ | :----------------------- |
|
||||
| Create a new page | `Cmd` `N` | `Ctrl` `N` |
|
||||
| Open new Notion window | `Cmd` `Shift` `N` | `Ctrl` `Shift` `N` |
|
||||
| Quick Find (Search) | `Cmd` `P` | `Ctrl` `P` |
|
||||
| Go back in page history | `Cmd` `[` | `Ctrl` `[` |
|
||||
| Go forward in page history | `Cmd` `]` | `Ctrl` `]` |
|
||||
| Go to parent page | `Cmd` `Shift` `U` | `Ctrl` `Shift` `U` |
|
||||
| Open Page Link in New Tab | `Cmd` `Click` | `Ctrl` `Click` |
|
||||
| Open Page Link in New Window | `Option` `Shift` `Click` | `Alt` `Shift` `Click` |
|
||||
|
||||
| Action | Mac Shortcut | Windows/Linux Shortcut |
|
||||
| :--------------------------- | :----------------------- | :--------------------- |
|
||||
| Create a new page | `Cmd` `N` | `Ctrl` `N` |
|
||||
| Open new Notion window | `Cmd` `Shift` `N` | `Ctrl` `Shift` `N` |
|
||||
| Quick Find (Search) | `Cmd` `P` | `Ctrl` `P` |
|
||||
| Go back in page history | `Cmd` `[` | `Ctrl` `[` |
|
||||
| Go forward in page history | `Cmd` `]` | `Ctrl` `]` |
|
||||
| Go to parent page | `Cmd` `Shift` `U` | `Ctrl` `Shift` `U` |
|
||||
| Open Page Link in New Tab | `Cmd` `Click` | `Ctrl` `Click` |
|
||||
| Open Page Link in New Window | `Option` `Shift` `Click` | `Alt` `Shift` `Click` |
|
||||
|
||||
{.show-header .shortcuts}
|
||||
|
||||
### View & Mode
|
||||
| Action | Mac Shortcut | Windows/Linux Shortcut |
|
||||
| :--------------------------- | :------------------------ | :----------------------- |
|
||||
| Toggle Dark/Light Mode | `Cmd` `Shift` `L` | `Ctrl` `Shift` `L` |
|
||||
| Lock/Unlock current page | `Cmd` `Shift` `L` (Hold) | `Ctrl` `Shift` `L` (Hold)|
|
||||
| Zoom In | `Cmd` `+` | `Ctrl` `+` |
|
||||
| Zoom Out | `Cmd` `-` | `Ctrl` `-` |
|
||||
| Reset Zoom | `Cmd` `0` | `Ctrl` `0` |
|
||||
|
||||
| Action | Mac Shortcut | Windows/Linux Shortcut |
|
||||
| :----------------------- | :----------------------- | :------------------------ |
|
||||
| Toggle Dark/Light Mode | `Cmd` `Shift` `L` | `Ctrl` `Shift` `L` |
|
||||
| Lock/Unlock current page | `Cmd` `Shift` `L` (Hold) | `Ctrl` `Shift` `L` (Hold) |
|
||||
| Zoom In | `Cmd` `+` | `Ctrl` `+` |
|
||||
| Zoom Out | `Cmd` `-` | `Ctrl` `-` |
|
||||
| Reset Zoom | `Cmd` `0` | `Ctrl` `0` |
|
||||
|
||||
{.show-header .shortcuts}
|
||||
|
||||
---
|
||||
@@ -49,64 +54,58 @@ plugins:
|
||||
# Markdown Style Formatting {.cols-1}
|
||||
|
||||
### On New Lines
|
||||
|
||||
Type the following at the beginning of an empty line, then press `Space`:
|
||||
|
||||
* `*`, `-`, or `+` : Bulleted list
|
||||
* `[]` : To-do checkbox (Note: just the characters, no `Cmd`/`Ctrl`)
|
||||
* `1.` : Numbered list
|
||||
* `#` : H1 heading
|
||||
* `##` : H2 heading
|
||||
* `###` : H3 heading
|
||||
* `>` : Toggle list
|
||||
* `"` : Quote block
|
||||
* `---` : Divider (three hyphens)
|
||||
* ```` ```` : Code block (three backticks)
|
||||
- `*`, `-`, or `+` : Bulleted list
|
||||
- `[]` : To-do checkbox (Note: just the characters, no `Cmd`/`Ctrl`)
|
||||
- `1.` : Numbered list
|
||||
- `#` : H1 heading
|
||||
- `##` : H2 heading
|
||||
- `###` : H3 heading
|
||||
- `>` : Toggle list
|
||||
- `"` : Quote block
|
||||
- `---` : Divider (three hyphens)
|
||||
- ` ` : Code block (three backticks)
|
||||
|
||||
### Inline
|
||||
* Wrap text with `**` or `__` for **Bold**.
|
||||
* Wrap text with `*` or `_` for *Italics*.
|
||||
* Wrap text with `~` for ~~Strikethrough~~.
|
||||
* Wrap text with `` ` `` for `inline code`.
|
||||
|
||||
- Wrap text with `**` or `__` for **Bold**.
|
||||
- Wrap text with `*` or `_` for _Italics_.
|
||||
- Wrap text with `~` for ~~Strikethrough~~.
|
||||
- Wrap text with `` ` `` for `inline code`.
|
||||
|
||||
---
|
||||
|
||||
# Text Formatting & Editing {.cols-2}
|
||||
|
||||
### Basic Formatting
|
||||
Select text first, then use the shortcut:
|
||||
| Action | Mac Shortcut | Windows/Linux Shortcut |
|
||||
| :------------------------- | :------------------------ | :----------------------- |
|
||||
| Bold | `Cmd` `B` | `Ctrl` `B` |
|
||||
| Italic | `Cmd` `I` | `Ctrl` `I` |
|
||||
| Underline | `Cmd` `U` | `Ctrl` `U` |
|
||||
| Strikethrough | `Cmd` `Shift` `S` | `Ctrl` `Shift` `S` |
|
||||
| Inline Code | `Cmd` `E` | `Ctrl` `E` |
|
||||
| Create Link | `Cmd` `K` | `Ctrl` `K` |
|
||||
| Change Color / Highlight | `Cmd` `Shift` `H` | `Ctrl` `Shift` `H` |
|
||||
| Clear Formatting | `Cmd` `\` | `Ctrl` `\` |
|
||||
{.show-header .shortcuts}
|
||||
|
||||
Select text first, then use the shortcut: | Action | Mac Shortcut | Windows/Linux Shortcut | |
|
||||
:------------------------- | :------------------------ | :----------------------- | | Bold | `Cmd` `B` | `Ctrl` `B` | |
|
||||
Italic | `Cmd` `I` | `Ctrl` `I` | | Underline | `Cmd` `U` | `Ctrl` `U` | | Strikethrough | `Cmd` `Shift` `S` | `Ctrl`
|
||||
`Shift` `S` | | Inline Code | `Cmd` `E` | `Ctrl` `E` | | Create Link | `Cmd` `K` | `Ctrl` `K` | | Change Color /
|
||||
Highlight | `Cmd` `Shift` `H` | `Ctrl` `Shift` `H` | | Clear Formatting | `Cmd` `\` | `Ctrl` `\` | {.show-header
|
||||
.shortcuts}
|
||||
|
||||
### Block Type Conversion
|
||||
Select the block(s) first, then use the shortcut:
|
||||
| Action | Mac Shortcut | Windows/Linux Shortcut |
|
||||
| :------------------------- | :------------------------ | :----------------------- |
|
||||
| Turn into Text block | `Cmd` `Option` `0` | `Ctrl` `Alt` `0` |
|
||||
| Turn into H1 Heading | `Cmd` `Option` `1` | `Ctrl` `Alt` `1` |
|
||||
| Turn into H2 Heading | `Cmd` `Option` `2` | `Ctrl` `Alt` `2` |
|
||||
| Turn into H3 Heading | `Cmd` `Option` `3` | `Ctrl` `Alt` `3` |
|
||||
| Turn into To-do list | `Cmd` `Option` `4` | `Ctrl` `Alt` `4` |
|
||||
| Turn into Bulleted list | `Cmd` `Option` `5` | `Ctrl` `Alt` `5` |
|
||||
| Turn into Numbered list | `Cmd` `Option` `6` | `Ctrl` `Alt` `6` |
|
||||
| Turn into Toggle list | `Cmd` `Option` `7` | `Ctrl` `Alt` `7` |
|
||||
| Turn into Code block | `Cmd` `Option` `8` | `Ctrl` `Alt` `8` |
|
||||
| Turn into Page | `Cmd` `Option` `9` | `Ctrl` `Alt` `9` |
|
||||
| Turn into Callout | `Cmd` `Option` `C` | `Ctrl` `Alt` `C` |
|
||||
{.show-header .shortcuts}
|
||||
|
||||
Select the block(s) first, then use the shortcut: | Action | Mac Shortcut | Windows/Linux Shortcut | |
|
||||
:------------------------- | :------------------------ | :----------------------- | | Turn into Text block | `Cmd`
|
||||
`Option` `0` | `Ctrl` `Alt` `0` | | Turn into H1 Heading | `Cmd` `Option` `1` | `Ctrl` `Alt` `1` | | Turn into H2
|
||||
Heading | `Cmd` `Option` `2` | `Ctrl` `Alt` `2` | | Turn into H3 Heading | `Cmd` `Option` `3` | `Ctrl` `Alt` `3` | |
|
||||
Turn into To-do list | `Cmd` `Option` `4` | `Ctrl` `Alt` `4` | | Turn into Bulleted list | `Cmd` `Option` `5` | `Ctrl`
|
||||
`Alt` `5` | | Turn into Numbered list | `Cmd` `Option` `6` | `Ctrl` `Alt` `6` | | Turn into Toggle list | `Cmd` `Option`
|
||||
`7` | `Ctrl` `Alt` `7` | | Turn into Code block | `Cmd` `Option` `8` | `Ctrl` `Alt` `8` | | Turn into Page | `Cmd`
|
||||
`Option` `9` | `Ctrl` `Alt` `9` | | Turn into Callout | `Cmd` `Option` `C` | `Ctrl` `Alt` `C` | {.show-header
|
||||
.shortcuts}
|
||||
|
||||
### Editing
|
||||
| Action | Mac Shortcut | Windows/Linux Shortcut |
|
||||
| :------------------------- | :------------------------ | :----------------------- |
|
||||
| New Line within same block | `Shift` `Enter` | `Shift` `Enter` |
|
||||
|
||||
| Action | Mac Shortcut | Windows/Linux Shortcut |
|
||||
| :------------------------- | :-------------- | :--------------------- |
|
||||
| New Line within same block | `Shift` `Enter` | `Shift` `Enter` |
|
||||
|
||||
{.show-header .shortcuts}
|
||||
|
||||
---
|
||||
@@ -114,32 +113,35 @@ Select the block(s) first, then use the shortcut:
|
||||
# Creating & Modifying Blocks {.cols-2}
|
||||
|
||||
### Creation & Selection
|
||||
| Action | Mac Shortcut | Windows/Linux Shortcut |
|
||||
| :------------------------------------------ | :------------------------------- | :------------------------------ |
|
||||
| Create new text block below | `Enter` | `Enter` |
|
||||
| Open the `/` command menu | `/` | `/` |
|
||||
| Select current block | `Esc` | `Esc` |
|
||||
| Select parent block | `Shift` `Esc` | `Shift` `Esc` |
|
||||
| Select block above/below | `Up` / `Down` | `Up` / `Down` |
|
||||
| Select multiple blocks | `Shift` `Up`/`Down` | `Shift` `Up`/`Down` |
|
||||
| Select all blocks | `Cmd` `A` | `Ctrl` `A` |
|
||||
| Edit selected block (or text within block) | `Enter` | `Enter` |
|
||||
|
||||
| Action | Mac Shortcut | Windows/Linux Shortcut |
|
||||
| :----------------------------------------- | :------------------ | :--------------------- |
|
||||
| Create new text block below | `Enter` | `Enter` |
|
||||
| Open the `/` command menu | `/` | `/` |
|
||||
| Select current block | `Esc` | `Esc` |
|
||||
| Select parent block | `Shift` `Esc` | `Shift` `Esc` |
|
||||
| Select block above/below | `Up` / `Down` | `Up` / `Down` |
|
||||
| Select multiple blocks | `Shift` `Up`/`Down` | `Shift` `Up`/`Down` |
|
||||
| Select all blocks | `Cmd` `A` | `Ctrl` `A` |
|
||||
| Edit selected block (or text within block) | `Enter` | `Enter` |
|
||||
|
||||
{.show-header .shortcuts}
|
||||
|
||||
|
||||
### Moving & Structuring
|
||||
| Action | Mac Shortcut | Windows/Linux Shortcut |
|
||||
| :------------------------------------------ | :------------------------------- | :------------------------------ |
|
||||
| Duplicate selected block(s) | `Cmd` `D` | `Ctrl` `D` |
|
||||
| Move selected block(s) up/down | `Cmd` `Shift` `Up`/`Down` | `Ctrl` `Shift` `Up`/`Down` |
|
||||
| Indent block (nest) | `Tab` | `Tab` |
|
||||
| Un-indent block | `Shift` `Tab` | `Shift` `Tab` |
|
||||
| Expand/Collapse toggle list | `Cmd` `Option` `T` | `Ctrl` `Alt` `T` |
|
||||
| Expand/Collapse all toggles | `Cmd` `Option` `Shift` `T` | `Ctrl` `Alt` `Shift` `T` |
|
||||
| Open page from selected link/page block | `Cmd` `Enter` | `Ctrl` `Enter` |
|
||||
| Delete selected block(s) | `Delete` or `Backspace` | `Delete` or `Backspace` |
|
||||
| Turn block into a page | `Cmd` `Option` `9` | `Ctrl` `Alt` `9` |
|
||||
| Move block(s) to another page | `Cmd` `Option` `Shift` `M` | `Ctrl` `Alt` `Shift` `M` |
|
||||
|
||||
| Action | Mac Shortcut | Windows/Linux Shortcut |
|
||||
| :-------------------------------------- | :------------------------- | :------------------------- |
|
||||
| Duplicate selected block(s) | `Cmd` `D` | `Ctrl` `D` |
|
||||
| Move selected block(s) up/down | `Cmd` `Shift` `Up`/`Down` | `Ctrl` `Shift` `Up`/`Down` |
|
||||
| Indent block (nest) | `Tab` | `Tab` |
|
||||
| Un-indent block | `Shift` `Tab` | `Shift` `Tab` |
|
||||
| Expand/Collapse toggle list | `Cmd` `Option` `T` | `Ctrl` `Alt` `T` |
|
||||
| Expand/Collapse all toggles | `Cmd` `Option` `Shift` `T` | `Ctrl` `Alt` `Shift` `T` |
|
||||
| Open page from selected link/page block | `Cmd` `Enter` | `Ctrl` `Enter` |
|
||||
| Delete selected block(s) | `Delete` or `Backspace` | `Delete` or `Backspace` |
|
||||
| Turn block into a page | `Cmd` `Option` `9` | `Ctrl` `Alt` `9` |
|
||||
| Move block(s) to another page | `Cmd` `Option` `Shift` `M` | `Ctrl` `Alt` `Shift` `M` |
|
||||
|
||||
{.show-header .shortcuts}
|
||||
|
||||
---
|
||||
@@ -147,24 +149,29 @@ Select the block(s) first, then use the shortcut:
|
||||
# Comments & Mentions {.cols-2}
|
||||
|
||||
### Comments
|
||||
| Action | Mac Shortcut | Windows/Linux Shortcut |
|
||||
| :------------------------- | :------------------------ | :----------------------- |
|
||||
| Add comment to selection | `Cmd` `Shift` `M` | `Ctrl` `Shift` `M` |
|
||||
|
||||
| Action | Mac Shortcut | Windows/Linux Shortcut |
|
||||
| :----------------------- | :---------------- | :--------------------- |
|
||||
| Add comment to selection | `Cmd` `Shift` `M` | `Ctrl` `Shift` `M` |
|
||||
|
||||
{.show-header .shortcuts}
|
||||
|
||||
### Mentions & Links (Type in block)
|
||||
* `@` + person's name: Mention a person
|
||||
* `@` + page title: Mention/link a page
|
||||
* `[[` + page title: Link another page
|
||||
* `+` + page title: Link another page (alternative)
|
||||
* `@` + date (e.g., `@today`, `@next tuesday`, `@1/15`): Add a date mention
|
||||
* `@remind` + date + time (optional): Set a reminder
|
||||
|
||||
- `@` + person's name: Mention a person
|
||||
- `@` + page title: Mention/link a page
|
||||
- `[[` + page title: Link another page
|
||||
- `+` + page title: Link another page (alternative)
|
||||
- `@` + date (e.g., `@today`, `@next tuesday`, `@1/15`): Add a date mention
|
||||
- `@remind` + date + time (optional): Set a reminder
|
||||
|
||||
### Emoji
|
||||
| Action | Mac Shortcut | Windows/Linux Shortcut |
|
||||
| :------------------------- | :------------------------ | :----------------------- |
|
||||
| Emoji Picker (System) | `Cmd` `Ctrl` `Space` | `Win` `.` or `Win` `;` |
|
||||
| Emoji Picker (Notion) | `:` + emoji name + `:` | `:` + emoji name + `:` |
|
||||
|
||||
| Action | Mac Shortcut | Windows/Linux Shortcut |
|
||||
| :-------------------- | :--------------------- | :--------------------- |
|
||||
| Emoji Picker (System) | `Cmd` `Ctrl` `Space` | `Win` `.` or `Win` `;` |
|
||||
| Emoji Picker (Notion) | `:` + emoji name + `:` | `:` + emoji name + `:` |
|
||||
|
||||
{.show-header .shortcuts}
|
||||
|
||||
---
|
||||
@@ -172,26 +179,29 @@ Select the block(s) first, then use the shortcut:
|
||||
# Database Shortcuts {.cols-2}
|
||||
|
||||
### Navigation & Selection
|
||||
| Action | Mac Shortcut | Windows/Linux Shortcut |
|
||||
| :---------------------------------------- | :--------------------- | :---------------------- |
|
||||
| Select row above/below | `Shift` `Up`/`Down` | `Shift` `Up`/`Down` |
|
||||
| Open selected page(s) | `Cmd` `Enter` | `Ctrl` `Enter` |
|
||||
| Edit property | `Enter` | `Enter` |
|
||||
| Move to cell above/below | `Shift` `Enter` | `Shift` `Enter` |
|
||||
| Move to cell left/right | `Tab` / `Shift` `Tab` | `Tab` / `Shift` `Tab` |
|
||||
| Select column | `Cmd` `Shift` `K` | `Ctrl` `Shift` `K` |
|
||||
| Select multiple cards/rows | `Shift` `Click` | `Shift` `Click` |
|
||||
|
||||
| Action | Mac Shortcut | Windows/Linux Shortcut |
|
||||
| :------------------------- | :-------------------- | :--------------------- |
|
||||
| Select row above/below | `Shift` `Up`/`Down` | `Shift` `Up`/`Down` |
|
||||
| Open selected page(s) | `Cmd` `Enter` | `Ctrl` `Enter` |
|
||||
| Edit property | `Enter` | `Enter` |
|
||||
| Move to cell above/below | `Shift` `Enter` | `Shift` `Enter` |
|
||||
| Move to cell left/right | `Tab` / `Shift` `Tab` | `Tab` / `Shift` `Tab` |
|
||||
| Select column | `Cmd` `Shift` `K` | `Ctrl` `Shift` `K` |
|
||||
| Select multiple cards/rows | `Shift` `Click` | `Shift` `Click` |
|
||||
|
||||
{.show-header .shortcuts}
|
||||
|
||||
### Other
|
||||
| Action | Mac Shortcut | Windows/Linux Shortcut |
|
||||
| :---------------------------------------- | :--------------------- | :---------------------- |
|
||||
| Quick Find within Database | `Cmd` `Shift` `P` | `Ctrl` `Shift` `P` |
|
||||
|
||||
| Action | Mac Shortcut | Windows/Linux Shortcut |
|
||||
| :------------------------- | :---------------- | :--------------------- |
|
||||
| Quick Find within Database | `Cmd` `Shift` `P` | `Ctrl` `Shift` `P` |
|
||||
|
||||
{.show-header .shortcuts}
|
||||
|
||||
---
|
||||
|
||||
## Also see
|
||||
|
||||
- [Official Notion Keyboard Shortcuts](https://www.notion.so/help/keyboard-shortcuts)
|
||||
_(notion.so)_
|
||||
- [Official Notion Keyboard Shortcuts](https://www.notion.so/help/keyboard-shortcuts) _(notion.so)_
|
||||
@@ -53,7 +53,7 @@ $ opam install hex
|
||||
#### Global Open
|
||||
|
||||
```ml
|
||||
open Hex
|
||||
open Hex
|
||||
```
|
||||
|
||||
#### Local Open
|
||||
@@ -61,7 +61,7 @@ open Hex
|
||||
```ml
|
||||
Hex.of_string "hex string"
|
||||
|
||||
let open Hex in
|
||||
let open Hex in
|
||||
of_string "to hex"
|
||||
```
|
||||
|
||||
@@ -73,7 +73,7 @@ let open Hex in
|
||||
(* A single line comment *)
|
||||
|
||||
(* A multi-line comment
|
||||
* where we want to explain
|
||||
* where we want to explain
|
||||
* something complex *)
|
||||
|
||||
(* Outer comment
|
||||
@@ -201,7 +201,7 @@ Lists are immutable
|
||||
Bundle related data
|
||||
|
||||
```ml
|
||||
type person = {
|
||||
type person = {
|
||||
name: string;
|
||||
age: int
|
||||
}
|
||||
@@ -215,7 +215,7 @@ val zeno : person = {name = "Zeno"; age = 30}
|
||||
Several different, but related types
|
||||
|
||||
```ml
|
||||
type shape =
|
||||
type shape =
|
||||
| Circle of float
|
||||
| Rectangle of float * float
|
||||
|
||||
@@ -225,8 +225,7 @@ type shape =
|
||||
|
||||
#### Aliases
|
||||
|
||||
Provide meaningful name
|
||||
to complex or commonly used types
|
||||
Provide meaningful name to complex or commonly used types
|
||||
|
||||
```ml
|
||||
type point = float * float
|
||||
@@ -242,7 +241,7 @@ val origin : point = (0., 0.)
|
||||
#### Single parameter
|
||||
|
||||
```ml
|
||||
let add_one x =
|
||||
let add_one x =
|
||||
let result = x + 1 in
|
||||
result
|
||||
|
||||
@@ -265,10 +264,10 @@ let sum x y =
|
||||
|
||||
```ml
|
||||
let str_concat (x, y) =
|
||||
x ^ " " ^ y
|
||||
x ^ " " ^ y
|
||||
|
||||
# str_concat ("Hello", "OCaml") ;;
|
||||
- : string = "Hello Ocaml"
|
||||
- : string = "Hello Ocaml"
|
||||
```
|
||||
|
||||
### Recursive Functions
|
||||
@@ -278,7 +277,7 @@ let str_concat (x, y) =
|
||||
All recusive functions use the rec keyword
|
||||
|
||||
```ml
|
||||
let rec factorial n =
|
||||
let rec factorial n =
|
||||
if n < 1 then 1 else n * factorial (n - 1)
|
||||
```
|
||||
|
||||
@@ -289,7 +288,7 @@ The above can cause stackoverflow.
|
||||
Makes use of a helper function and the acc argument.
|
||||
|
||||
```ml
|
||||
let rec factorial_helper n acc =
|
||||
let rec factorial_helper n acc =
|
||||
if n = 0 then acc
|
||||
else factorial_helper (n - 1) (n * acc)
|
||||
```
|
||||
@@ -316,7 +315,7 @@ Read from right to left, the first operation is `sum 2 3`
|
||||
|
||||
```ml
|
||||
(* find log((x + y)!) *)
|
||||
# sum 2 3
|
||||
# sum 2 3
|
||||
|> factorial
|
||||
|> float_of_int
|
||||
|> log ;;
|
||||
@@ -332,26 +331,26 @@ Read from right to left, the first operation is `sum 2 3`
|
||||
#### If Statement
|
||||
|
||||
```ml
|
||||
let is_pos x =
|
||||
let is_pos x =
|
||||
if x > 0 then "positive" else "negative"
|
||||
```
|
||||
|
||||
#### If else if
|
||||
|
||||
```ml
|
||||
let f x =
|
||||
let f x =
|
||||
if x > 3 then "gt 3"
|
||||
else if x < 3 then "lt 3"
|
||||
else "eq 3"
|
||||
else "eq 3"
|
||||
```
|
||||
|
||||
#### Pattern Matching
|
||||
|
||||
```ml
|
||||
let is_pos x =
|
||||
match x > 0 with
|
||||
let is_pos x =
|
||||
match x > 0 with
|
||||
| true -> "positive"
|
||||
| false -> "negative"
|
||||
| false -> "negative"
|
||||
```
|
||||
|
||||
### Loops
|
||||
@@ -360,7 +359,7 @@ let is_pos x =
|
||||
|
||||
```ml
|
||||
for i = 1 to 5 do
|
||||
print_int i
|
||||
print_int i
|
||||
done
|
||||
```
|
||||
|
||||
@@ -369,7 +368,7 @@ done
|
||||
Notice the `ref` is needed to have the while condition eventually become false.
|
||||
|
||||
```ml
|
||||
let i = ref 0 in
|
||||
let i = ref 0 in
|
||||
while !i < 5 do
|
||||
print_int !i;
|
||||
i := !i + 1
|
||||
@@ -393,7 +392,7 @@ let i = ref 0 in
|
||||
|
||||
```ml
|
||||
(* int operator float operator *)
|
||||
+ +. (* addition *)
|
||||
+ +. (* addition *)
|
||||
- -. (* subtraction *)
|
||||
* *. (* multiplication *)
|
||||
/ /. (* division *)
|
||||
@@ -440,7 +439,7 @@ List.fold_left (+) 0 lst
|
||||
#### Definition and Access
|
||||
|
||||
```ml
|
||||
let scores =
|
||||
let scores =
|
||||
[("math", 91); ("phil", 89); ("stats", 94)]
|
||||
|
||||
# List.assoc "stats" scores;;
|
||||
@@ -499,7 +498,7 @@ Maps are immutable key-value association tables.
|
||||
(* the Map.Make functor creates the custom map module *)
|
||||
# module StringMap = Map.Make(String);;
|
||||
|
||||
let books =
|
||||
let books =
|
||||
StringMap.empty
|
||||
|> StringMap.add "Dune" ("Herbet", 1965)
|
||||
|> StringMap.add "Neuromancer" ("Gibson", 1984)
|
||||
@@ -522,17 +521,17 @@ let books =
|
||||
Creates a new map since maps are immutable
|
||||
|
||||
```ml
|
||||
let more_books = books
|
||||
let more_books = books
|
||||
|> StringMap.add "Foundation" ("Isaac Asimov", 1951)
|
||||
|
||||
let less_books =
|
||||
let less_books =
|
||||
|> StringMap.remove "Dune"
|
||||
```
|
||||
|
||||
Filtering
|
||||
|
||||
```ml
|
||||
let eighties_books =
|
||||
let eighties_books =
|
||||
StringMap.filter
|
||||
(fun _ (_, year) -> year > 1980 & number < 1990) books
|
||||
```
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
title: OpenSSL
|
||||
date: 2020-11-25 18:28:43
|
||||
icon: icon-style
|
||||
background: bg-emerald-600
|
||||
background: bg-indigo-600
|
||||
tags:
|
||||
categories:
|
||||
- Linux Command
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
---
|
||||
|
||||
title: Pandas
|
||||
date: 2024-07-04
|
||||
background: bg-[#110750]
|
||||
@@ -12,7 +11,6 @@ intro: |
|
||||
[Pandas](https://pandas.pydata.org/) is a powerful data analysis and manipulation library for Python. This cheat sheet is a quick reference for Pandas beginners.
|
||||
plugins:
|
||||
- copyCode
|
||||
|
||||
---
|
||||
|
||||
## Getting Started {.cols-2}
|
||||
@@ -27,112 +25,112 @@ import pandas as pd
|
||||
|
||||
### Creating DataFrames
|
||||
|
||||
| - | - |
|
||||
| -------------------------------------------------------------- | --------------------------------------------------- |
|
||||
| `pd.DataFrame(data={'col1': [1, 2], 'col2': [3, 4]})` | From a dictionary |
|
||||
| `pd.DataFrame(data=[{'a': 1, 'b': 2}, {'a': 3, 'b': 4}])` | From a list of dictionaries |
|
||||
| `pd.read_csv('file.csv')` | From a CSV file |
|
||||
| `pd.read_excel('file.xlsx')` | From an Excel file |
|
||||
| - | - |
|
||||
| --------------------------------------------------------- | --------------------------- |
|
||||
| `pd.DataFrame(data={'col1': [1, 2], 'col2': [3, 4]})` | From a dictionary |
|
||||
| `pd.DataFrame(data=[{'a': 1, 'b': 2}, {'a': 3, 'b': 4}])` | From a list of dictionaries |
|
||||
| `pd.read_csv('file.csv')` | From a CSV file |
|
||||
| `pd.read_excel('file.xlsx')` | From an Excel file |
|
||||
|
||||
### Inspecting Data {.row-span-2}
|
||||
|
||||
| - | - |
|
||||
| ----------------------- | ------------------------------- |
|
||||
| `df.head()` | First 5 rows |
|
||||
| `df.tail()` | Last 5 rows |
|
||||
| `df.shape` | Number of rows and columns |
|
||||
| `df.info()` | Info on DataFrame |
|
||||
| `df.describe()` | Summary statistics |
|
||||
| `df.columns` | Column names |
|
||||
| `df.index` | Index |
|
||||
| `df.dtypes` | Data types of columns |
|
||||
| - | - |
|
||||
| --------------- | -------------------------- |
|
||||
| `df.head()` | First 5 rows |
|
||||
| `df.tail()` | Last 5 rows |
|
||||
| `df.shape` | Number of rows and columns |
|
||||
| `df.info()` | Info on DataFrame |
|
||||
| `df.describe()` | Summary statistics |
|
||||
| `df.columns` | Column names |
|
||||
| `df.index` | Index |
|
||||
| `df.dtypes` | Data types of columns |
|
||||
|
||||
### Selecting Data
|
||||
|
||||
| - | - |
|
||||
| ------------------------ | ------------------------------------------------- |
|
||||
| `df['col1']` | Select column |
|
||||
| `df[['col1', 'col2']]` | Select multiple columns |
|
||||
| `df.loc[0]` | Select row by index |
|
||||
| `df.loc[:, 'col1']` | Select all rows for 'col1' |
|
||||
| `df.iloc[0]` | Select row by position |
|
||||
| `df.iloc[0, 1]` | Select specific value |
|
||||
| `df[df['col1'] > 2]` | Select rows based on condition |
|
||||
| - | - |
|
||||
| ---------------------- | ------------------------------ |
|
||||
| `df['col1']` | Select column |
|
||||
| `df[['col1', 'col2']]` | Select multiple columns |
|
||||
| `df.loc[0]` | Select row by index |
|
||||
| `df.loc[:, 'col1']` | Select all rows for 'col1' |
|
||||
| `df.iloc[0]` | Select row by position |
|
||||
| `df.iloc[0, 1]` | Select specific value |
|
||||
| `df[df['col1'] > 2]` | Select rows based on condition |
|
||||
|
||||
### Data Cleaning
|
||||
|
||||
| - | - |
|
||||
| ---------------------------- | -------------------------------------- |
|
||||
| `df.dropna()` | Drop rows with any missing values |
|
||||
| `df.dropna(axis=1)` | Drop columns with any missing values |
|
||||
| `df.fillna(0)` | Replace missing values with 0 |
|
||||
| `df.drop_duplicates()` | Drop duplicate rows |
|
||||
| `df.rename(columns={'old_name': 'new_name'})` | Rename columns |
|
||||
| `df.astype('int')` | Change data type |
|
||||
| - | - |
|
||||
| --------------------------------------------- | ------------------------------------ |
|
||||
| `df.dropna()` | Drop rows with any missing values |
|
||||
| `df.dropna(axis=1)` | Drop columns with any missing values |
|
||||
| `df.fillna(0)` | Replace missing values with 0 |
|
||||
| `df.drop_duplicates()` | Drop duplicate rows |
|
||||
| `df.rename(columns={'old_name': 'new_name'})` | Rename columns |
|
||||
| `df.astype('int')` | Change data type |
|
||||
|
||||
### Adding/Removing Data {.row-span-2}
|
||||
|
||||
| - | - |
|
||||
| ----------------------------------- | ------------------------------ |
|
||||
| `df['col3'] = df['col1'] + df['col2']` | Add new column |
|
||||
| `df.drop('col1', axis=1)` | Drop column |
|
||||
| `df.append(new_row)` | Add new row |
|
||||
| `df.insert(2, 'new_col', new_data)` | Insert new column at position 2|
|
||||
| - | - |
|
||||
| -------------------------------------- | ------------------------------- |
|
||||
| `df['col3'] = df['col1'] + df['col2']` | Add new column |
|
||||
| `df.drop('col1', axis=1)` | Drop column |
|
||||
| `df.append(new_row)` | Add new row |
|
||||
| `df.insert(2, 'new_col', new_data)` | Insert new column at position 2 |
|
||||
|
||||
### Combining Data
|
||||
|
||||
| - | - |
|
||||
| --------------------------------------------- | ------------------------------------------------ |
|
||||
| `pd.concat([df1, df2])` | Concatenate rows |
|
||||
| `pd.concat([df1, df2], axis=1)` | Concatenate columns |
|
||||
| `pd.merge(df1, df2, on='key')` | Merge DataFrames on key |
|
||||
| `pd.merge(df1, df2, left_on='key1', right_on='key2')` | Merge on different keys |
|
||||
| `df1.join(df2, lsuffix='_left', rsuffix='_right')` | Join DataFrames |
|
||||
| - | - |
|
||||
| ----------------------------------------------------- | ----------------------- |
|
||||
| `pd.concat([df1, df2])` | Concatenate rows |
|
||||
| `pd.concat([df1, df2], axis=1)` | Concatenate columns |
|
||||
| `pd.merge(df1, df2, on='key')` | Merge DataFrames on key |
|
||||
| `pd.merge(df1, df2, left_on='key1', right_on='key2')` | Merge on different keys |
|
||||
| `df1.join(df2, lsuffix='_left', rsuffix='_right')` | Join DataFrames |
|
||||
|
||||
### Aggregating Data
|
||||
|
||||
| - | - |
|
||||
| ------------------------------------ | ------------------------------------------------ |
|
||||
| `df['col1'].sum()` | Sum of values in column |
|
||||
| `df['col1'].mean()` | Mean of values in column |
|
||||
| `df['col1'].count()` | Count of values in column |
|
||||
| `df['col1'].min()` | Minimum value in column |
|
||||
| `df['col1'].max()` | Maximum value in column |
|
||||
| `df['col1'].std()` | Standard deviation |
|
||||
| `df['col1'].var()` | Variance |
|
||||
| `df.groupby('col1').sum()` | Group by and sum |
|
||||
| `df.groupby('col1').mean()` | Group by and mean |
|
||||
| `df.groupby(['col1', 'col2']).count()` | Group by multiple columns |
|
||||
| - | - |
|
||||
| -------------------------------------- | ------------------------- |
|
||||
| `df['col1'].sum()` | Sum of values in column |
|
||||
| `df['col1'].mean()` | Mean of values in column |
|
||||
| `df['col1'].count()` | Count of values in column |
|
||||
| `df['col1'].min()` | Minimum value in column |
|
||||
| `df['col1'].max()` | Maximum value in column |
|
||||
| `df['col1'].std()` | Standard deviation |
|
||||
| `df['col1'].var()` | Variance |
|
||||
| `df.groupby('col1').sum()` | Group by and sum |
|
||||
| `df.groupby('col1').mean()` | Group by and mean |
|
||||
| `df.groupby(['col1', 'col2']).count()` | Group by multiple columns |
|
||||
|
||||
### Applying Functions {.row-span-2}
|
||||
|
||||
| - | - |
|
||||
| ---------------------------------- | ------------------------------------ |
|
||||
| `df.apply(np.sqrt)` | Apply function to all values |
|
||||
| `df['col1'].apply(lambda x: x ** 2)`| Apply function to column |
|
||||
| `df.applymap(str)` | Apply function to DataFrame elements |
|
||||
| `df['col1'].map({'a': 1, 'b': 2})` | Map values |
|
||||
| `df['col1'].replace('a', 1)` | Replace values |
|
||||
| - | - |
|
||||
| ------------------------------------ | ------------------------------------ |
|
||||
| `df.apply(np.sqrt)` | Apply function to all values |
|
||||
| `df['col1'].apply(lambda x: x ** 2)` | Apply function to column |
|
||||
| `df.applymap(str)` | Apply function to DataFrame elements |
|
||||
| `df['col1'].map({'a': 1, 'b': 2})` | Map values |
|
||||
| `df['col1'].replace('a', 1)` | Replace values |
|
||||
|
||||
### Handling Dates
|
||||
|
||||
| - | - |
|
||||
| ------------------------------------ | ------------------------------------------ |
|
||||
| `df['date'] = pd.to_datetime(df['date'])` | Convert to datetime |
|
||||
| `df['year'] = df['date'].dt.year` | Extract year |
|
||||
| `df['month'] = df['date'].dt.month` | Extract month |
|
||||
| `df['day'] = df['date'].dt.day` | Extract day |
|
||||
| `df.set_index('date', inplace=True)` | Set date as index |
|
||||
| - | - |
|
||||
| ----------------------------------------- | ------------------- |
|
||||
| `df['date'] = pd.to_datetime(df['date'])` | Convert to datetime |
|
||||
| `df['year'] = df['date'].dt.year` | Extract year |
|
||||
| `df['month'] = df['date'].dt.month` | Extract month |
|
||||
| `df['day'] = df['date'].dt.day` | Extract day |
|
||||
| `df.set_index('date', inplace=True)` | Set date as index |
|
||||
|
||||
### Input/Output
|
||||
|
||||
| - | - |
|
||||
| ------------------------------------ | ------------------------------------------------ |
|
||||
| `df.to_csv('file.csv')` | Save DataFrame to CSV |
|
||||
| `df = pd.read_csv('file.csv')` | Load DataFrame from CSV |
|
||||
| `df.to_excel('file.xlsx')` | Save DataFrame to Excel |
|
||||
| `df = pd.read_excel('file.xlsx')` | Load DataFrame from Excel |
|
||||
| `from sqlalchemy import create_engine`| Import SQLAlchemy for SQL operations |
|
||||
| `engine = create_engine('sqlite:///:memory:')` | Create SQL engine |
|
||||
| `df.to_sql('table_name', engine)` | Save to SQL table |
|
||||
| `df = pd.read_sql('table_name', engine)` | Load from SQL table |
|
||||
| - | - |
|
||||
| ---------------------------------------------- | ------------------------------------ |
|
||||
| `df.to_csv('file.csv')` | Save DataFrame to CSV |
|
||||
| `df = pd.read_csv('file.csv')` | Load DataFrame from CSV |
|
||||
| `df.to_excel('file.xlsx')` | Save DataFrame to Excel |
|
||||
| `df = pd.read_excel('file.xlsx')` | Load DataFrame from Excel |
|
||||
| `from sqlalchemy import create_engine` | Import SQLAlchemy for SQL operations |
|
||||
| `engine = create_engine('sqlite:///:memory:')` | Create SQL engine |
|
||||
| `df.to_sql('table_name', engine)` | Save to SQL table |
|
||||
| `df = pd.read_sql('table_name', engine)` | Load from SQL table |
|
||||
@@ -913,6 +913,166 @@ class Cls implements Foo, Bar
|
||||
}
|
||||
```
|
||||
|
||||
## PHP Trait
|
||||
|
||||
### Trait declaration & Use case {.col-span-3}
|
||||
```php
|
||||
// Declare Trait allows reuse of code
|
||||
// across multiple classes for common characteristics or use cases
|
||||
|
||||
<?php
|
||||
trait Logger {
|
||||
public function log($message) {
|
||||
$date = new DateTime();
|
||||
echo "| ". $date->format('Y-m-d H:i:s') . " | " . $message;
|
||||
}
|
||||
}
|
||||
|
||||
// Use case :
|
||||
// Call trait with "use <trait name> in Class"
|
||||
|
||||
class User {
|
||||
use Logger;
|
||||
|
||||
public function createUser() {
|
||||
// User creation logic
|
||||
$this->log("User created.");
|
||||
}
|
||||
}
|
||||
|
||||
class Product {
|
||||
use Logger;
|
||||
|
||||
public function createProduct() {
|
||||
// Product creation logic
|
||||
$this->log("Product created.");
|
||||
}
|
||||
}
|
||||
|
||||
$user = new User();
|
||||
$user->createUser(); // Output ex: | 2025-06-18 14:06:09 | User created.
|
||||
|
||||
$product = new Product();
|
||||
$product->createProduct(); // Output ex: | 2025-06-18 14:06:09 | Product created.
|
||||
```
|
||||
|
||||
## PHP Enums (PHP 8.1)
|
||||
|
||||
### Enum Declaration & Use case {.col-span-3}
|
||||
|
||||
```php
|
||||
<?php
|
||||
// enum is a data type that allows you to define a set of named constants,
|
||||
// representing a fixed group of related values
|
||||
|
||||
enum Status {
|
||||
case Pending;
|
||||
case Approved;
|
||||
case Rejected;
|
||||
}
|
||||
|
||||
// Use case
|
||||
|
||||
function getStatusMessage(Status $status): string {
|
||||
return match($status) {
|
||||
Status::Pending => "Waiting for approval.",
|
||||
Status::Approved => "Your request has been approved.",
|
||||
Status::Rejected => "Your request has been rejected.",
|
||||
};
|
||||
}
|
||||
|
||||
$currentStatus = Status::Approved;
|
||||
echo getStatusMessage($currentStatus); // Output : Your request has been approved.
|
||||
```
|
||||
|
||||
## PHP Date & Time Handling
|
||||
|
||||
### Current date and time
|
||||
```php
|
||||
// DateTime in PHP handles both date and time
|
||||
|
||||
<?php
|
||||
$now = new DateTime();
|
||||
echo $now->format('Y-m-d H:i:s.u');
|
||||
|
||||
// Output ex: 2024-04-27 14:35:22.123456
|
||||
```
|
||||
|
||||
|
||||
### Creating specific date/time objects
|
||||
```php
|
||||
<?php
|
||||
// Create a date object
|
||||
$d = new DateTime('2024-04-27');
|
||||
echo $d->format('Y-m-d');
|
||||
|
||||
// Output : 2024-04-27
|
||||
|
||||
// Create a time object
|
||||
$t = new DateTime('15:30:45');
|
||||
echo $t->format('H:i:s');
|
||||
|
||||
// Output : 15:30:45
|
||||
|
||||
// Create a datetime object
|
||||
$dt = new DateTime('2024-04-27 15:30:45');
|
||||
echo $dt->format('Y-m-d H:i:s');
|
||||
|
||||
// Output : 2024-04-27 15:30:45
|
||||
```
|
||||
|
||||
### Converting between date formats
|
||||
```php
|
||||
<?php
|
||||
// Convert a string to a DateTime object
|
||||
$date_str = "2024-04-27 14:00";
|
||||
$dt_obj = new DateTime($date_str);
|
||||
echo $dt_obj->format('Y-m-d H:i:s');
|
||||
|
||||
// Output : 2024-04-27 14:00:0027
|
||||
|
||||
// Convert a DateTime object to a string
|
||||
$formatted_str = $dt_obj->format('d/m/Y H:i');
|
||||
echo $formatted_str;
|
||||
|
||||
// Output : 27/04/2024 14:00
|
||||
```
|
||||
### Timestamps and Unix time {.col-span-2}
|
||||
```php
|
||||
<?php
|
||||
// Get current timestamp
|
||||
$timestamp = time();
|
||||
echo $timestamp;
|
||||
|
||||
// Output ex: 1750253583
|
||||
|
||||
// Convert timestamp back to DateTime
|
||||
$dt_from_timestamp = (new DateTime())->setTimestamp($timestamp);
|
||||
echo $dt_from_timestamp->format('Y-m-d H:i:s');
|
||||
|
||||
// Output ex : 2025-06-18 13:33:03
|
||||
```
|
||||
|
||||
|
||||
### Date difference and timedelta {.col-span-1}
|
||||
```php
|
||||
<?php
|
||||
$date1 = new DateTime('2024-04-27');
|
||||
$date2 = new DateTime('2024-05-01');
|
||||
|
||||
$interval = $date1->diff($date2);
|
||||
echo $interval->days;
|
||||
|
||||
// Output : 4
|
||||
|
||||
// Using DateInterval for date arithmetic
|
||||
$new_date = clone $date1;
|
||||
$new_date->add(new DateInterval('P10D'));
|
||||
echo $new_date->format('Y-m-d');
|
||||
|
||||
// Output : 2024-05-07
|
||||
```
|
||||
|
||||
## Miscellaneous
|
||||
|
||||
### Basic error handling
|
||||
@@ -1002,6 +1162,25 @@ See: [Regex in PHP](/regex#regex-in-php)
|
||||
| `a` | Write, append |
|
||||
| `a+` | Read and write, append |
|
||||
|
||||
### Super Global Variables {.col-span-2}
|
||||
|
||||
| Variable | Description |
|
||||
|--------------|:-------------------------------------------------------------|
|
||||
| `$_SERVER` | Holds information about headers, paths, and script locations |
|
||||
| `$_GET` | Contains data sent via URL parameters (query string) |
|
||||
| `$_POST` | Contains data sent via HTTP POST method |
|
||||
| `$_FILES` | Contains information about uploaded files |
|
||||
| `$_COOKIE` | Contains cookie data |
|
||||
| `$_SESSION` | Stores session variables |
|
||||
| `$_REQUEST` | Contains data from `$_GET`, `$_POST`, and `$_COOKIE` |
|
||||
| `$_ENV` | Contains environment variables |
|
||||
| `$GLOBALS` | References all global variables available in the script |
|
||||
|
||||
{.left-text}
|
||||
|
||||
Super Global Variables are built-in variables always available in all scopes.
|
||||
|
||||
|
||||
### Runtime defined Constants
|
||||
|
||||
```php
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
title: PhpStorm
|
||||
date: 2022-11-23 16:23:31.703719
|
||||
background: bg-gradient-to-r from-[#be4fe9] to-[#715bef] hover:from-emerald-400 hover:to-blue-500
|
||||
background: bg-gradient-to-r from-[#be4fe9] to-[#715bef] hover:from-indigo-400 hover:to-blue-500
|
||||
label:
|
||||
tags:
|
||||
- jetbrains
|
||||
|
||||
@@ -957,6 +957,80 @@ else:
|
||||
|
||||
Also see: [Python Tips](https://book.pythontips.com/en/latest/for_-_else.html)
|
||||
|
||||
### Over Dictionary
|
||||
|
||||
```python
|
||||
johndict = {
|
||||
"firstname": "John",
|
||||
"lastname": "Doe",
|
||||
"age": 30
|
||||
}
|
||||
|
||||
x = johndict.items()
|
||||
print(x)
|
||||
|
||||
# Output: dict_items([('firstname', 'John'),
|
||||
# ('lastname', 'Doe'),
|
||||
# ('age', 30)])
|
||||
|
||||
for key, value in johndict.items():
|
||||
print(f"{key} : : {value}")
|
||||
|
||||
# Output: firstname : : John
|
||||
# Output: lastname : : Doe
|
||||
# Output: age : : 30
|
||||
```
|
||||
|
||||
## Python Comprehensions
|
||||
|
||||
### Comprehension List {.col-span-2}
|
||||
|
||||
```python
|
||||
languages = ["html", "go", "rust", "javascript", "python"]
|
||||
|
||||
newlist = [x for x in languages if "l" not in x]
|
||||
# add language for language in languages if "l" not in language
|
||||
|
||||
print(newlist) #Output : [ 'go', 'rust', 'javascript', 'python']
|
||||
|
||||
# List comprehension avoid this :
|
||||
oldlist = []
|
||||
for x in languages:
|
||||
if "l" not in x:
|
||||
oldlist.append(x)
|
||||
print(oldlist) #Output : [ 'go', 'rust', 'javascript', 'python']
|
||||
|
||||
|
||||
```
|
||||
|
||||
### Comprehension Dictionary {.col-span-2}
|
||||
|
||||
```python
|
||||
languages = ["html", "go", "rust", "javascript", "python"]
|
||||
|
||||
language_dict = {lang: ('l' not in lang) for lang in languages}
|
||||
# Key is the language & bool is Value (no offense for html..)
|
||||
|
||||
print(language_dict)
|
||||
# Output: {'html': False, 'go': True, 'rust': True,
|
||||
# 'javascript': True, 'python': True}
|
||||
|
||||
|
||||
# Dictionary comprehension avoid this :
|
||||
|
||||
language_dict2 = {}
|
||||
|
||||
for e in languages:
|
||||
if "l" not in e:
|
||||
language_dict2[e] = True
|
||||
else:
|
||||
language_dict2[e] = False
|
||||
|
||||
print(language_dict2)
|
||||
# Output: {'html': False, 'go': True, 'rust': True,
|
||||
# 'javascript': True, 'python': True}
|
||||
```
|
||||
|
||||
## Python Functions
|
||||
|
||||
### Basic
|
||||
@@ -1030,6 +1104,29 @@ add(5, 20) # => 25
|
||||
(lambda x, y: x ** 2 + y ** 2)(2, 1)
|
||||
```
|
||||
|
||||
### @decorator {.col-span-2}
|
||||
|
||||
```python
|
||||
# Modify or extend behavior of function or class method,
|
||||
# without changing their actual code.
|
||||
|
||||
# Define decorator that will wrap function or method
|
||||
def handle_errors(func):
|
||||
def wrapper(*args, **kwargs):
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except Exception as e:
|
||||
return print(f"Error : {e}")
|
||||
return wrapper
|
||||
|
||||
# Decorate function or method
|
||||
@handle_errors
|
||||
def divide(a, b):
|
||||
return a / b
|
||||
|
||||
divide(10, 0) # Output : Error : division by zero
|
||||
```
|
||||
|
||||
## Python Modules
|
||||
|
||||
### Import modules
|
||||
@@ -1298,6 +1395,24 @@ print(Yoki.legs) # => 4
|
||||
Yoki.sound() # => Woof!
|
||||
```
|
||||
|
||||
### @staticmethod {.col-span-2}
|
||||
|
||||
```python
|
||||
class MyClass:
|
||||
@staticmethod
|
||||
def greet(name):
|
||||
return f"Hello, {name}!"
|
||||
|
||||
# No instantiation nedded
|
||||
|
||||
# Call via class
|
||||
print(MyClass.greet("Alice")) # => Hello, Alice!
|
||||
|
||||
# Can still call via instance
|
||||
obj = MyClass()
|
||||
print(obj.greet("Bob")) # => Hello, Bob!
|
||||
```
|
||||
|
||||
## Python Type Hints (Since Python 3.5)
|
||||
|
||||
### Variable & Parameter
|
||||
@@ -1525,6 +1640,80 @@ while (data := values[i]):
|
||||
# Expected result: 1, "text", True
|
||||
```
|
||||
|
||||
## Date & Time Handling
|
||||
|
||||
### Current date and time
|
||||
|
||||
```python
|
||||
import datetime
|
||||
|
||||
now = datetime.datetime.now()
|
||||
print(now) # e.g., 2024-04-27 14:35:22.123456
|
||||
```
|
||||
|
||||
### Creating specific date/time objects
|
||||
|
||||
```python
|
||||
import datetime
|
||||
|
||||
# Create a date object
|
||||
d = datetime.date(2024, 4, 27)
|
||||
print(d) # 2024-04-27
|
||||
|
||||
# Create a time object
|
||||
t = datetime.time(15, 30, 45)
|
||||
print(t) # 15:30:45
|
||||
|
||||
# Create a datetime object
|
||||
dt = datetime.datetime(2024, 4, 27, 15, 30, 45)
|
||||
print(dt) # 2024-04-27 15:30:45
|
||||
```
|
||||
|
||||
### Converting between date formats
|
||||
|
||||
```python
|
||||
import datetime
|
||||
|
||||
# Convert a string to a datetime object
|
||||
date_str = "2024-04-27 14:00"
|
||||
dt_obj = datetime.datetime.strptime(date_str, "%Y-%m-%d %H:%M")
|
||||
print(dt_obj) # 2024-04-27 14:00:00
|
||||
|
||||
# Convert a datetime object to a string
|
||||
formatted_str = dt_obj.strftime("%d/%m/%Y %H:%M")
|
||||
print(formatted_str) # 27/04/2024 14:00
|
||||
```
|
||||
|
||||
### Timestamps and Unix time
|
||||
|
||||
```python
|
||||
import datetime
|
||||
|
||||
# Get current timestamp
|
||||
timestamp = datetime.datetime.now().timestamp()
|
||||
print(timestamp) # e.g., 1714188922.123456
|
||||
|
||||
# Convert timestamp back to datetime
|
||||
dt_from_timestamp = datetime.datetime.fromtimestamp(timestamp)
|
||||
print(dt_from_timestamp)
|
||||
```
|
||||
|
||||
### Date difference and timedelta {.col-span-2}
|
||||
|
||||
```python
|
||||
import datetime
|
||||
|
||||
date1 = datetime.date(2024, 4, 27)
|
||||
date2 = datetime.date(2024, 5, 1)
|
||||
|
||||
delta = date2 - date1
|
||||
print(delta.days) # 4
|
||||
|
||||
# Using timedelta for date arithmetic
|
||||
new_date = date1 + datetime.timedelta(days=10)
|
||||
print(new_date) # 2024-05-07
|
||||
```
|
||||
|
||||
## Miscellaneous
|
||||
|
||||
### Comments
|
||||
@@ -1582,3 +1771,46 @@ else: # Optional clause to the try/except block. Must follow
|
||||
finally: # Execute under all circumstances
|
||||
print("We can clean up resources here")
|
||||
```
|
||||
|
||||
### Dispatcher Pattern {.col-span-3}
|
||||
|
||||
```python
|
||||
# Dispatcher allows dynamic selection and execution of functions based on user input or other runtime conditions
|
||||
|
||||
def add(x, y):
|
||||
return x + y
|
||||
|
||||
def subtract(x, y):
|
||||
return x - y
|
||||
|
||||
def multiply(x, y):
|
||||
return x * y
|
||||
|
||||
def divide(x, y):
|
||||
if y == 0:
|
||||
return 'Error: Division by zero'
|
||||
return x / y
|
||||
|
||||
# Dispatcher dictionary: maps operation names to their corresponding functions
|
||||
operations = {
|
||||
'add': add,
|
||||
'subtract': subtract,
|
||||
'multiply': multiply,
|
||||
'divide': divide
|
||||
}
|
||||
|
||||
# Function to dispatch operation based on operation name
|
||||
# Common use cases include executing different functions dynamically, such as in calculators, command interpreters, or event handling
|
||||
def dispatcher(operation_name, x, y):
|
||||
func = operations.get(operation_name)
|
||||
if func:
|
||||
return func(x, y)
|
||||
else:
|
||||
return f"Unknown operation: {operation_name}"
|
||||
|
||||
# Usage examples
|
||||
print(dispatcher('add', 5, 3)) # Output: 8
|
||||
print(dispatcher('multiply', 4, 2)) # Output: 8
|
||||
print(dispatcher('divide', 10, 0)) # Output: Error: Division by zero
|
||||
print(dispatcher('mod', 10, 3)) # Output: Unknown operation: mod
|
||||
```
|
||||
@@ -7,8 +7,7 @@ tags:
|
||||
- reference
|
||||
categories:
|
||||
- Other
|
||||
intro:
|
||||
This is the magic syntax variant manual that you can use on CheatSheets.zip, It's a good practice for contributors.
|
||||
intro: This is the magic syntax variant manual that you can use on CheatSheets.zip, It's a good practice for contributors.
|
||||
plugins:
|
||||
- copyCode
|
||||
---
|
||||
|
||||
@@ -29,13 +29,13 @@ let emptyHeading = <h1 />;
|
||||
### JSX Expressions
|
||||
|
||||
```javascript
|
||||
let name = "Josh Perez";
|
||||
let name = 'Josh Perez';
|
||||
let element = <h1>Hello, {name}</h1>;
|
||||
|
||||
function fullName(firstName, lastName) {
|
||||
return firstName + " " + lastName;
|
||||
return firstName + ' ' + lastName;
|
||||
}
|
||||
let element = <h1>Hello, {fullName("Julie", "Johnson")}</h1>;
|
||||
let element = <h1>Hello, {fullName('Julie', 'Johnson')}</h1>;
|
||||
```
|
||||
|
||||
### JSX Attributes
|
||||
@@ -62,7 +62,7 @@ return (
|
||||
### JSX Conditional Rendering {.col-span-2}
|
||||
|
||||
```javascript
|
||||
import React from "react";
|
||||
import React from 'react';
|
||||
function Weather(props) {
|
||||
if (props.temperature >= 20) {
|
||||
return (
|
||||
@@ -89,7 +89,7 @@ Note: A component must always return something.
|
||||
### Functional Component
|
||||
|
||||
```javascript
|
||||
import React from "react";
|
||||
import React from 'react';
|
||||
|
||||
export default function UserProfile() {
|
||||
return (
|
||||
@@ -106,8 +106,8 @@ Note: Every component needs one root element
|
||||
### Embed an internal Component
|
||||
|
||||
```javascript
|
||||
import React from "react";
|
||||
import UserAvatar from "./UserAvatar";
|
||||
import React from 'react';
|
||||
import UserAvatar from './UserAvatar';
|
||||
|
||||
export default function UserProfile() {
|
||||
return (
|
||||
@@ -124,8 +124,8 @@ Note: Assuming UserAvatar is declared in UserAvatar.js
|
||||
### Embed an external Component
|
||||
|
||||
```javascript
|
||||
import React from "react";
|
||||
import ComponentName from "component-name";
|
||||
import React from 'react';
|
||||
import ComponentName from 'component-name';
|
||||
|
||||
export default function UserProfile() {
|
||||
return (
|
||||
@@ -141,7 +141,7 @@ Note: External components are found on npmjs.com and need to be imported first.
|
||||
### Advanced Functional Components
|
||||
|
||||
```javascript
|
||||
import React from "react";
|
||||
import React from 'react';
|
||||
|
||||
function Hello(props) {
|
||||
function fullName() {
|
||||
@@ -170,7 +170,7 @@ export default () => <Hello firstName="Matt" lastName="Delac" />;
|
||||
### Assigning the Properties from a Component
|
||||
|
||||
```javascript
|
||||
import React from "react";
|
||||
import React from 'react';
|
||||
|
||||
export default function Student(props) {
|
||||
return (
|
||||
@@ -186,12 +186,12 @@ export default function Student(props) {
|
||||
### React State
|
||||
|
||||
```javascript
|
||||
import React, { useState } from "react";
|
||||
import React, { useState } from 'react';
|
||||
|
||||
export default function Hello(props) {
|
||||
let [name, setName] = useState("Julie");
|
||||
let [name, setName] = useState('Julie');
|
||||
function updateName() {
|
||||
let newName = prompt("What is your name?");
|
||||
let newName = prompt('What is your name?');
|
||||
setName(newName);
|
||||
}
|
||||
|
||||
@@ -209,12 +209,12 @@ export default function Hello(props) {
|
||||
### Event Listener
|
||||
|
||||
```javascript
|
||||
import React from "react";
|
||||
import React from 'react';
|
||||
|
||||
export default function Hello() {
|
||||
function handleClick(event) {
|
||||
event.preventDefault();
|
||||
alert("Hello World");
|
||||
alert('Hello World');
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -232,7 +232,7 @@ Note: The most common event listeners are onClick for links/buttons and onSubmit
|
||||
### Looping through an Array
|
||||
|
||||
```javascript
|
||||
let elements = ["one", "two", "three"];
|
||||
let elements = ['one', 'two', 'three'];
|
||||
|
||||
return (
|
||||
<ul>
|
||||
@@ -250,17 +250,17 @@ Note: Each list item inside a map loop needs a key attribute with a unique value
|
||||
```javascript
|
||||
let elements = [
|
||||
{
|
||||
name: "one",
|
||||
value: 1,
|
||||
name: 'one',
|
||||
value: 1
|
||||
},
|
||||
{
|
||||
name: "two",
|
||||
value: 2,
|
||||
name: 'two',
|
||||
value: 2
|
||||
},
|
||||
{
|
||||
name: "three",
|
||||
value: 3,
|
||||
},
|
||||
name: 'three',
|
||||
value: 3
|
||||
}
|
||||
];
|
||||
return (
|
||||
<ul>
|
||||
@@ -282,11 +282,11 @@ Note: Each list item inside a map loop needs a key attribute with a unique value
|
||||
### React Forms
|
||||
|
||||
```javascript
|
||||
import React, { useState } from "react";
|
||||
import React, { useState } from 'react';
|
||||
|
||||
export default function LoginForm() {
|
||||
let [username, setUsername] = useState("");
|
||||
let [password, setPassword] = useState("");
|
||||
let [username, setUsername] = useState('');
|
||||
let [password, setPassword] = useState('');
|
||||
|
||||
function handleSubmit(event) {
|
||||
event.preventDefault();
|
||||
@@ -316,8 +316,8 @@ export default function LoginForm() {
|
||||
### CSS in a React Component
|
||||
|
||||
```javascript
|
||||
import React from "react";
|
||||
import "./Student.css";
|
||||
import React from 'react';
|
||||
import './Student.css';
|
||||
|
||||
export default function Student() {
|
||||
return <div className="Student">Julie Johnson</div>;
|
||||
@@ -331,8 +331,8 @@ Note: You'll then have to crate a css file called Student.css
|
||||
### AJAX Request with Axios
|
||||
|
||||
```javascript
|
||||
import React from "react";
|
||||
import axios from "axios";
|
||||
import React from 'react';
|
||||
import axios from 'axios';
|
||||
|
||||
export default function Weather(props) {
|
||||
function handleResponse(response) {
|
||||
@@ -356,7 +356,7 @@ Note: Make sure to import Axios first to your project.
|
||||
### useState Hook
|
||||
|
||||
```javascript
|
||||
import React, { useState } from "react";
|
||||
import React, { useState } from 'react';
|
||||
|
||||
function Counter() {
|
||||
const [count, setCount] = useState(0);
|
||||
@@ -378,11 +378,11 @@ way to declare state variables and update them within a functional component. Ex
|
||||
### Multiple State Variable Declaration
|
||||
|
||||
```javascript
|
||||
import React, { useState } from "react";
|
||||
import React, { useState } from 'react';
|
||||
|
||||
function Counter() {
|
||||
const [count, setCount] = useState(0);
|
||||
const [name, setName] = useState("");
|
||||
const [name, setName] = useState('');
|
||||
const [isCompleted, setIsCompleted] = useState(false);
|
||||
|
||||
const handleIncrement = () => {
|
||||
@@ -402,10 +402,19 @@ function Counter() {
|
||||
<p>Count: {count}</p>
|
||||
<button onClick={handleIncrement}>Increment</button>
|
||||
|
||||
<input type="text" value={name} onChange={handleNameChange} placeholder="Enter your name" />
|
||||
<input
|
||||
type="text"
|
||||
value={name}
|
||||
onChange={handleNameChange}
|
||||
placeholder="Enter your name"
|
||||
/>
|
||||
|
||||
<label>
|
||||
<input type="checkbox" checked={isCompleted} onChange={toggleCompletion} />
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={isCompleted}
|
||||
onChange={toggleCompletion}
|
||||
/>
|
||||
Completed
|
||||
</label>
|
||||
</div>
|
||||
@@ -421,10 +430,14 @@ component. Each call to useState manages a separate piece of state.
|
||||
### Input State Management
|
||||
|
||||
```javascript
|
||||
import { useState } from "react";
|
||||
import { useState } from 'react';
|
||||
|
||||
function FormExample() {
|
||||
const [formData, setFormData] = useState({ name: "", email: "", message: "" });
|
||||
const [formData, setFormData] = useState({
|
||||
name: '',
|
||||
email: '',
|
||||
message: ''
|
||||
});
|
||||
|
||||
const handleChange = (event) => {
|
||||
const { name, value } = event.target;
|
||||
@@ -433,19 +446,38 @@ function FormExample() {
|
||||
|
||||
const handleSubmit = (event) => {
|
||||
event.preventDefault();
|
||||
alert(`Name: ${formData.name}, Email: ${formData.email}, Message: ${formData.message}`);
|
||||
alert(
|
||||
`Name: ${formData.name}, Email: ${formData.email}, Message: ${formData.message}`
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit}>
|
||||
<label htmlFor="name">Name:</label>
|
||||
<input type="text" id="name" name="name" value={formData.name} onChange={handleChange} />
|
||||
<input
|
||||
type="text"
|
||||
id="name"
|
||||
name="name"
|
||||
value={formData.name}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
|
||||
<label htmlFor="email">Email:</label>
|
||||
<input type="email" id="email" name="email" value={formData.email} onChange={handleChange} />
|
||||
<input
|
||||
type="email"
|
||||
id="email"
|
||||
name="email"
|
||||
value={formData.email}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
|
||||
<label htmlFor="message">Message:</label>
|
||||
<textarea id="message" name="message" value={formData.message} onChange={handleChange} />
|
||||
<textarea
|
||||
id="message"
|
||||
name="message"
|
||||
value={formData.message}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
|
||||
<button type="submit">Submit</button>
|
||||
</form>
|
||||
@@ -458,7 +490,7 @@ export default FormExample;
|
||||
### useEffect Hook
|
||||
|
||||
```javascript
|
||||
import React, { useState, useEffect } from "react";
|
||||
import React, { useState, useEffect } from 'react';
|
||||
|
||||
function Timer() {
|
||||
const [seconds, setSeconds] = useState(0);
|
||||
@@ -483,20 +515,20 @@ code based on component lifecycle events like mounting, updating, and unmounting
|
||||
### Fetch API using useEffect
|
||||
|
||||
```javascript
|
||||
import React, { useState, useEffect } from "react";
|
||||
import axios from "axios";
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import axios from 'axios';
|
||||
|
||||
function UserList() {
|
||||
const [users, setUsers] = useState([]);
|
||||
|
||||
useEffect(() => {
|
||||
axios
|
||||
.get("https://jsonplaceholder.typicode.com/users")
|
||||
.get('https://jsonplaceholder.typicode.com/users')
|
||||
.then((response) => {
|
||||
setUsers(response.data);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error fetching users:", error);
|
||||
console.error('Error fetching users:', error);
|
||||
});
|
||||
}, []);
|
||||
|
||||
@@ -520,7 +552,7 @@ Note: Make sure to import Axios first to your project.
|
||||
### Custom Hook creation useLocalStorage
|
||||
|
||||
```javascript
|
||||
import { useState, useEffect } from "react";
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
function useLocalStorage(key, initialValue) {
|
||||
const [value, setValue] = useState(() => {
|
||||
@@ -544,7 +576,7 @@ to extract stateful logic from components into standalone functions.
|
||||
### Creating Refs in Class Components
|
||||
|
||||
```javascript
|
||||
import React, { Component } from "react";
|
||||
import React, { Component } from 'react';
|
||||
|
||||
class MyComponent extends Component {
|
||||
constructor(props) {
|
||||
@@ -567,7 +599,7 @@ export default MyComponent;
|
||||
### Using Refs in Functional Components
|
||||
|
||||
```javascript
|
||||
import React, { useRef, useEffect } from "react";
|
||||
import React, { useRef, useEffect } from 'react';
|
||||
|
||||
function MyComponent() {
|
||||
const myRef = useRef(null);
|
||||
@@ -585,7 +617,7 @@ export default MyComponent;
|
||||
### Callback Refs
|
||||
|
||||
```javascript
|
||||
import React, { Component } from "react";
|
||||
import React, { Component } from 'react';
|
||||
|
||||
class MyComponent extends Component {
|
||||
constructor(props) {
|
||||
@@ -628,7 +660,7 @@ const ref = React.createRef();
|
||||
### Accessing DOM Elements with Refs
|
||||
|
||||
```javascript
|
||||
import React, { useRef, useEffect } from "react";
|
||||
import React, { useRef, useEffect } from 'react';
|
||||
|
||||
function FocusInput() {
|
||||
const inputRef = useRef(null);
|
||||
@@ -643,19 +675,21 @@ function FocusInput() {
|
||||
|
||||
export default FocusInput;
|
||||
```
|
||||
Note: Refs are often used to access and interact with DOM elements directly. Here's an example where we focus an input element using a ref.
|
||||
|
||||
Note: Refs are often used to access and interact with DOM elements directly. Here's an example where we focus an input
|
||||
element using a ref.
|
||||
|
||||
### Managing Focus with Refs
|
||||
|
||||
```javascript
|
||||
import React, { useRef } from "react";
|
||||
import React, { useRef } from 'react';
|
||||
|
||||
function Form() {
|
||||
const firstInputRef = useRef(null);
|
||||
const secondInputRef = useRef(null);
|
||||
|
||||
const handleKeyDown = (e) => {
|
||||
if (e.key === "Enter") {
|
||||
if (e.key === 'Enter') {
|
||||
secondInputRef.current.focus();
|
||||
}
|
||||
};
|
||||
@@ -670,4 +704,5 @@ function Form() {
|
||||
|
||||
export default Form;
|
||||
```
|
||||
|
||||
Note: You can also manage focus between multiple elements using refs.
|
||||
@@ -64,23 +64,23 @@ This is a quick cheat sheet to getting started with regular expressions.
|
||||
| `a*+` | Possessive quantifier |
|
||||
|
||||
### Common Metacharacters
|
||||
| Pattern | Description |
|
||||
| -------- | :----------------------------------------- |
|
||||
| `^` | Matches the start of a string. |
|
||||
| `{` | Starts a quantifier for the number of occurrences. |
|
||||
| `+` | Matches one or more of the preceding element. |
|
||||
| `<` | Not a standard regex meta character (commonly used in HTML). |
|
||||
| `[` | Starts a character class. |
|
||||
| `*` | Matches zero or more of the preceding element. |
|
||||
| `)` | Ends a capturing group. |
|
||||
| `>` | Not a standard regex meta character (commonly used in HTML). |
|
||||
| `.` | Matches any character except a newline. |
|
||||
| `(` | Starts a capturing group. |
|
||||
| `|` | Acts as a logical OR within a regex pattern. |
|
||||
| `$` | Matches the end of a string. |
|
||||
| `\` | Escapes a meta character, giving it literal meaning. |
|
||||
| `?` | Matches zero or one of the preceding element. |
|
||||
|
||||
| Pattern | Description |
|
||||
| ------- | :----------------------------------------------------------- | -------------------------------------------- |
|
||||
| `^` | Matches the start of a string. |
|
||||
| `{` | Starts a quantifier for the number of occurrences. |
|
||||
| `+` | Matches one or more of the preceding element. |
|
||||
| `<` | Not a standard regex meta character (commonly used in HTML). |
|
||||
| `[` | Starts a character class. |
|
||||
| `*` | Matches zero or more of the preceding element. |
|
||||
| `)` | Ends a capturing group. |
|
||||
| `>` | Not a standard regex meta character (commonly used in HTML). |
|
||||
| `.` | Matches any character except a newline. |
|
||||
| `(` | Starts a capturing group. |
|
||||
| ` | ` | Acts as a logical OR within a regex pattern. |
|
||||
| `$` | Matches the end of a string. |
|
||||
| `\` | Escapes a meta character, giving it literal meaning. |
|
||||
| `?` | Matches zero or one of the preceding element. |
|
||||
|
||||
{.cols-3 .marker-none}
|
||||
|
||||
@@ -530,8 +530,8 @@ False
|
||||
### test()
|
||||
|
||||
```javascript
|
||||
let textA = "I like APPles very much";
|
||||
let textB = "I like APPles";
|
||||
let textA = 'I like APPles very much';
|
||||
let textB = 'I like APPles';
|
||||
let regex = /apples$/i;
|
||||
|
||||
// Output: false
|
||||
@@ -544,7 +544,7 @@ console.log(regex.test(textB));
|
||||
### search()
|
||||
|
||||
```javascript
|
||||
let text = "I like APPles very much";
|
||||
let text = 'I like APPles very much';
|
||||
let regexA = /apples/;
|
||||
let regexB = /apples/i;
|
||||
|
||||
@@ -558,7 +558,7 @@ console.log(text.search(regexB));
|
||||
### exec()
|
||||
|
||||
```javascript
|
||||
let text = "Do you like apples?";
|
||||
let text = 'Do you like apples?';
|
||||
let regex = /apples/;
|
||||
|
||||
// Output: apples
|
||||
@@ -571,7 +571,7 @@ console.log(regex.exec(text).input);
|
||||
### match()
|
||||
|
||||
```javascript
|
||||
let text = "Here are apples and apPleS";
|
||||
let text = 'Here are apples and apPleS';
|
||||
let regex = /apples/gi;
|
||||
|
||||
// Output: [ "apples", "apPleS" ]
|
||||
@@ -581,7 +581,7 @@ console.log(text.match(regex));
|
||||
### split() {.col-span-2}
|
||||
|
||||
```javascript
|
||||
let text = "This 593 string will be brok294en at places where d1gits are.";
|
||||
let text = 'This 593 string will be brok294en at places where d1gits are.';
|
||||
let regex = /\d+/g;
|
||||
|
||||
// Output: [ "This ", " string will be brok", "en at places where d", "gits are." ]
|
||||
@@ -592,7 +592,7 @@ console.log(text.split(regex));
|
||||
|
||||
```javascript
|
||||
let regex = /t(e)(st(\d?))/g;
|
||||
let text = "test1test2";
|
||||
let text = 'test1test2';
|
||||
let array = [...text.matchAll(regex)];
|
||||
|
||||
// Output: ["test1", "e", "st1", "1"]
|
||||
@@ -605,11 +605,11 @@ console.log(array[1]);
|
||||
### replace()
|
||||
|
||||
```javascript {.wrap}
|
||||
let text = "Do you like aPPles?";
|
||||
let text = 'Do you like aPPles?';
|
||||
let regex = /apples/i;
|
||||
|
||||
// Output: Do you like mangoes?
|
||||
let result = text.replace(regex, "mangoes");
|
||||
let result = text.replace(regex, 'mangoes');
|
||||
console.log(result);
|
||||
```
|
||||
|
||||
@@ -617,10 +617,10 @@ console.log(result);
|
||||
|
||||
```javascript
|
||||
let regex = /apples/gi;
|
||||
let text = "Here are apples and apPleS";
|
||||
let text = 'Here are apples and apPleS';
|
||||
|
||||
// Output: Here are mangoes and mangoes
|
||||
let result = text.replaceAll(regex, "mangoes");
|
||||
let result = text.replaceAll(regex, 'mangoes');
|
||||
console.log(result);
|
||||
```
|
||||
|
||||
|
||||
@@ -449,7 +449,7 @@ case input
|
||||
# Check for an integer, 19
|
||||
when 19
|
||||
puts "It's 19"
|
||||
# 检查一个确切的字符串,“Zaman”
|
||||
# Check for an exact string,“Zaman”
|
||||
when "Zaman"
|
||||
puts "Hi Zaman"
|
||||
when 7..11
|
||||
|
||||
@@ -108,11 +108,11 @@ text: {
|
||||
### @import
|
||||
|
||||
```scss
|
||||
@import "./other_sass_file";
|
||||
@import "/code", "lists";
|
||||
@import './other_sass_file';
|
||||
@import '/code', 'lists';
|
||||
|
||||
// Plain CSS @imports
|
||||
@import "theme.css";
|
||||
@import 'theme.css';
|
||||
@import url(theme);
|
||||
```
|
||||
|
||||
@@ -349,7 +349,7 @@ $menu-items: home about contact;
|
||||
|
||||
@each $item in $menu-items {
|
||||
.photo-#{$item} {
|
||||
background: url("#{$item}.jpg");
|
||||
background: url('#{$item}.jpg');
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -357,7 +357,7 @@ $menu-items: home about contact;
|
||||
### Each loops (nested)
|
||||
|
||||
```scss
|
||||
$backgrounds: (home, "home.jpg"), (about, "about.jpg");
|
||||
$backgrounds: (home, 'home.jpg'), (about, 'about.jpg');
|
||||
|
||||
@each $id, $image in $backgrounds {
|
||||
.photo-#{$id} {
|
||||
@@ -383,10 +383,10 @@ $i: 6;
|
||||
### Conditionals {.row-span-2}
|
||||
|
||||
```scss
|
||||
@if $position == "left" {
|
||||
@if $position == 'left' {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
} @else if $position == "right" {
|
||||
} @else if $position == 'right' {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
} @else {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
title: Screen
|
||||
date: 2021-01-02 20:03:55
|
||||
background: bg-emerald-500
|
||||
background: bg-indigo-500
|
||||
tags:
|
||||
- terminal
|
||||
- session
|
||||
|
||||
@@ -249,7 +249,66 @@ $ ssh-keygen -R <ip/hostname>
|
||||
- PEM
|
||||
- PKCS8
|
||||
|
||||
## SSH Tunneling
|
||||
|
||||
### SSH Tunnel Options {.row-span-2}
|
||||
|
||||
| Option | Description |
|
||||
| ------ | :----------------------------------------------------- |
|
||||
| `-L` | Local port forwarding |
|
||||
| `-R` | Remote port forwarding |
|
||||
| `-D` | Dynamic port forwarding |
|
||||
| `-f` | Run in background |
|
||||
| `-N` | Do not execute a remote command |
|
||||
| `-g` | Allow remote hosts to connect to local forwarded ports |
|
||||
|
||||
{.left-text}
|
||||
|
||||
more details on flag above with `man ssh`
|
||||
|
||||
### Local Port Forwarding {.col-span-2}
|
||||
|
||||
```bash
|
||||
# Forward a local port to a remote server
|
||||
ssh -L local_port:remote_host:remote_port user@ssh_server
|
||||
|
||||
# Example: Forward local port 8080 to remote port 80 on example.com
|
||||
ssh -L 8080:example.com:80 user@ssh_server
|
||||
```
|
||||
|
||||
### Dynamic Port Forwarding {.col-span-2}
|
||||
|
||||
```bash
|
||||
# Create a SOCKS proxy on a local port
|
||||
ssh -D local_port user@ssh_server
|
||||
|
||||
# Create a SOCKS proxy on local port 1080 in the background
|
||||
ssh -f -N -D 1080 user@ssh_server
|
||||
```
|
||||
|
||||
### Background Tunnel {.col-span-3}
|
||||
|
||||
```bash
|
||||
# Create a local port forwarding tunnel in the background
|
||||
ssh -f -N -L local_port:remote_host:remote_port user@ssh_server
|
||||
```
|
||||
|
||||
### Multiple Tunnels {.col-span-3}
|
||||
|
||||
```bash
|
||||
# Create multiple tunnels in a single SSH command
|
||||
ssh -L 8080:example.com:80 -L 3306:db.example.com:3306 user@ssh_server
|
||||
```
|
||||
|
||||
### Combining Options {.col-span-3}
|
||||
|
||||
```bash
|
||||
# In background, no command, allow remote host, local port forward, identity_file
|
||||
ssh -f -N -g -L 8080:example.com:80 -i ~/.ssh/custom_key user@ssh_server
|
||||
```
|
||||
|
||||
## Also see
|
||||
|
||||
- [OpenSSH Config File Examples](https://www.cyberciti.biz/faq/create-ssh-config-file-on-linux-unix/) _(cyberciti.biz)_
|
||||
- [ssh_config](https://linux.die.net/man/5/ssh_config) _(linux.die.net)_
|
||||
- [man-ssh](https://man7.org/linux/man-pages/man1/ssh.1.html)
|
||||
@@ -143,12 +143,7 @@ Note: External components should be installed via npm first.
|
||||
### Passing Properties to a Component
|
||||
|
||||
```js
|
||||
<Student
|
||||
firstName="Zehan"
|
||||
lastName="Khan"
|
||||
age={23}
|
||||
pro={true}
|
||||
/>
|
||||
<Student firstName="Zehan" lastName="Khan" age={23} pro={true} />
|
||||
```
|
||||
|
||||
### Assigning the Properties from a Component
|
||||
@@ -304,6 +299,7 @@ Note: Use `onMount` for side effects like API calls.
|
||||
## Lifecycle Hooks {.cols-1}
|
||||
|
||||
### onMount
|
||||
|
||||
```js
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
@@ -315,6 +311,7 @@ Note: Use `onMount` for side effects like API calls.
|
||||
```
|
||||
|
||||
### beforeUpdate
|
||||
|
||||
```js
|
||||
<script>
|
||||
import { beforeUpdate } from 'svelte';
|
||||
@@ -326,6 +323,7 @@ Note: Use `onMount` for side effects like API calls.
|
||||
```
|
||||
|
||||
### afterUpdate
|
||||
|
||||
```js
|
||||
<script>
|
||||
import { afterUpdate } from 'svelte';
|
||||
@@ -337,6 +335,7 @@ Note: Use `onMount` for side effects like API calls.
|
||||
```
|
||||
|
||||
### onDestroy
|
||||
|
||||
```js
|
||||
<script>
|
||||
import { onDestroy } from 'svelte';
|
||||
@@ -346,8 +345,9 @@ Note: Use `onMount` for side effects like API calls.
|
||||
});
|
||||
</script>
|
||||
```
|
||||
Note: Svelte lifecycle functions are similar to React Hooks, but they are imported individually and used directly in the `<script>` block.
|
||||
|
||||
Note: Svelte lifecycle functions are similar to React Hooks, but they are imported individually and used directly in the
|
||||
`<script>` block.
|
||||
|
||||
## More Svelte Features {.cols-1}
|
||||
|
||||
@@ -358,7 +358,7 @@ Note: Svelte lifecycle functions are similar to React Hooks, but they are import
|
||||
import { writable, derived } from 'svelte/store';
|
||||
|
||||
export const count = writable(0);
|
||||
export const double = derived(count, $count => $count * 2);
|
||||
export const double = derived(count, ($count) => $count * 2);
|
||||
```
|
||||
|
||||
```js
|
||||
@@ -402,11 +402,7 @@ export const time = readable(new Date(), function start(set) {
|
||||
### Reactive Statements with Side Effects
|
||||
|
||||
```js
|
||||
<script>
|
||||
let name = 'Zehan';
|
||||
|
||||
$: console.log('Name changed to', name);
|
||||
</script>
|
||||
<script>let name = 'Zehan'; $: console.log('Name changed to', name);</script>
|
||||
```
|
||||
|
||||
### Bind to DOM Properties
|
||||
@@ -488,4 +484,3 @@ export async function load({ fetch }) {
|
||||
```
|
||||
|
||||
Note: Requires SvelteKit setup for SSR routes.
|
||||
|
||||
@@ -1571,11 +1571,13 @@ enum ShirtSize: String {
|
||||
|
||||
### What are extensions?
|
||||
|
||||
Extensions is a way to add new add new functionality to existing classes, structures, enumerations, or protocol types. This includes adding new methods, properties, initializers, and more.
|
||||
Extensions is a way to add new add new functionality to existing classes, structures, enumerations, or protocol types.
|
||||
This includes adding new methods, properties, initializers, and more.
|
||||
|
||||
### Why use extensions?
|
||||
|
||||
Extensions are particularly useful for organizing and modularizing our code without needing to modify the original type, especially when we don't have access to the original source code.
|
||||
Extensions are particularly useful for organizing and modularizing our code without needing to modify the original type,
|
||||
especially when we don't have access to the original source code.
|
||||
|
||||
### Extension syntax
|
||||
|
||||
@@ -1657,7 +1659,8 @@ print("Swift"[4]) // Output: t
|
||||
|
||||
### Protocol extensions {.row-span-2}
|
||||
|
||||
It works pretty much like abstract classes when regarding a functionality we want to be available in all the classes that implements some protocol (without having to inherit from a base common class).
|
||||
It works pretty much like abstract classes when regarding a functionality we want to be available in all the classes
|
||||
that implements some protocol (without having to inherit from a base common class).
|
||||
|
||||
```swift
|
||||
// Define a protocol
|
||||
@@ -1701,7 +1704,8 @@ print(employee.describe()) // Output: This is a generic description
|
||||
|
||||
### Constraints for extensions
|
||||
|
||||
This is especially useful when we want to add functionality to a type that conforms to a specific protocol or has certain conditions.
|
||||
This is especially useful when we want to add functionality to a type that conforms to a specific protocol or has
|
||||
certain conditions.
|
||||
|
||||
```swift
|
||||
extension Array where Element: Numeric {
|
||||
@@ -1723,7 +1727,8 @@ print(doubles.sum()) // Output: 7.5
|
||||
|
||||
### Organizing code with extensions
|
||||
|
||||
Extensions are not limited to adding functionality; they are also handy for code organization. We can group related methods, properties or views in separate extensions.
|
||||
Extensions are not limited to adding functionality; they are also handy for code organization. We can group related
|
||||
methods, properties or views in separate extensions.
|
||||
|
||||
```swift
|
||||
import SwiftUI
|
||||
@@ -1752,11 +1757,13 @@ extension HomeView {
|
||||
|
||||
### What are generics?
|
||||
|
||||
Generics in Swift are a feature that allows us to create functions, classes, structures, and protocols that can work with any data type.
|
||||
Generics in Swift are a feature that allows us to create functions, classes, structures, and protocols that can work
|
||||
with any data type.
|
||||
|
||||
### Why use generics?
|
||||
|
||||
Generics enable us to write clear and concise code that works with any data type. By using placeholders (like `T`), this reduces the risk of introducing bugs.
|
||||
Generics enable us to write clear and concise code that works with any data type. By using placeholders (like `T`), this
|
||||
reduces the risk of introducing bugs.
|
||||
|
||||
### Type parameters {.row-span-2}
|
||||
|
||||
@@ -1831,7 +1838,9 @@ protocol Foo {
|
||||
}
|
||||
```
|
||||
|
||||
Associated types are used in protocols to define a placeholder for a type that will be specified later. They act as a generic placeholder. The exact type isn't defined in the protocol itself; instead, it's determined when a class, struct, or enum conforms to the protocol.
|
||||
Associated types are used in protocols to define a placeholder for a type that will be specified later. They act as a
|
||||
generic placeholder. The exact type isn't defined in the protocol itself; instead, it's determined when a class, struct,
|
||||
or enum conforms to the protocol.
|
||||
|
||||
### Generic Protocols {.row-span-2}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
title: Tmux
|
||||
date: 2021-02-20 14:31:24
|
||||
background: bg-emerald-600
|
||||
background: bg-indigo-600
|
||||
tags:
|
||||
- utility
|
||||
- terminal
|
||||
@@ -100,15 +100,13 @@ $ tmux show-options -g
|
||||
| `q` | Quit copy mode |
|
||||
| `Ctrl+b` `]` | Paste contents of buffer_0 |
|
||||
|
||||
-------------
|
||||
For tmux version 3.5a on MacOS 15.3.1 Sequoia 'Copy Mode' functions lil bit differently
|
||||
Below I've written the differences
|
||||
| Command | Description |
|
||||
| ------------ | -------------------------- |
|
||||
| `Ctrl + <Space>` | Start selection |
|
||||
| `Ctrl + w` | Copy selection |
|
||||
---
|
||||
|
||||
-------------
|
||||
For tmux version 3.5a on MacOS 15.3.1 Sequoia 'Copy Mode' functions lil bit differently Below I've written the
|
||||
differences | Command | Description | | ------------ | -------------------------- | | `Ctrl + <Space>` | Start selection
|
||||
| | `Ctrl + w` | Copy selection |
|
||||
|
||||
---
|
||||
|
||||
{.shortcuts}
|
||||
|
||||
|
||||
@@ -1,327 +1,331 @@
|
||||
---
|
||||
title: TypeScript
|
||||
date: 2024-05-28 22:12:25
|
||||
background: bg-[#4476c0]
|
||||
tags:
|
||||
- ts
|
||||
- web
|
||||
categories:
|
||||
- Programming
|
||||
intro: |
|
||||
A TypeScript cheat sheet with the most important concepts, functions, methods, and more. A complete quick reference for beginners.
|
||||
plugins:
|
||||
- copyCode
|
||||
- runCode
|
||||
---
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Installing the Compiler
|
||||
|
||||
```shell
|
||||
npm install typescript --save-dev
|
||||
npm tsc
|
||||
```
|
||||
|
||||
## Basic DataTypes
|
||||
|
||||
### basic types
|
||||
|
||||
```ts
|
||||
let isDone: boolean = false;
|
||||
let age: number = 30;
|
||||
let userName: string = "John";
|
||||
let list: number[] = [1, 2, 3];
|
||||
let tuple: [string, number] = ["hello", 10];
|
||||
let notSure: any = 4;
|
||||
notSure = "maybe a string instead";
|
||||
```
|
||||
|
||||
### enums
|
||||
|
||||
```ts
|
||||
enum Color {
|
||||
Red,
|
||||
Green,
|
||||
Blue,
|
||||
}
|
||||
let c: Color = Color.Green;
|
||||
```
|
||||
|
||||
### interface
|
||||
|
||||
```ts
|
||||
interface Person {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
age?: number; // Optional property
|
||||
}
|
||||
|
||||
function greet(person: Person) {
|
||||
return "Hello, " + person.firstName + " " + person.lastName;
|
||||
}
|
||||
```
|
||||
|
||||
### Functions
|
||||
|
||||
```ts
|
||||
function add(x: number, y: number): number {
|
||||
return x + y;
|
||||
}
|
||||
|
||||
let myAdd = function (x: number, y: number): number {
|
||||
return x + y;
|
||||
};
|
||||
|
||||
let myArrowAdd = (x: number, y: number): number => x + y;
|
||||
|
||||
function buildName(firstName: string, lastName = "Smith") {
|
||||
return firstName + " " + lastName;
|
||||
}
|
||||
|
||||
function buildFullName(firstName: string, ...restOfName: string[]) {
|
||||
return firstName + " " + restOfName.join(" ");
|
||||
}
|
||||
```
|
||||
|
||||
### Classes
|
||||
|
||||
```ts
|
||||
class Greeter {
|
||||
greeting: string;
|
||||
constructor(message: string) {
|
||||
this.greeting = message;
|
||||
}
|
||||
greet() {
|
||||
return "Hello, " + this.greeting;
|
||||
}
|
||||
}
|
||||
|
||||
let greeter = new Greeter("world");
|
||||
```
|
||||
|
||||
### Inheritance
|
||||
|
||||
```ts
|
||||
class Animal {
|
||||
move(distance: number = 0) {
|
||||
console.log(`Animal moved ${distance} meters.`);
|
||||
}
|
||||
}
|
||||
|
||||
class Dog extends Animal {
|
||||
bark() {
|
||||
console.log("Woof! Woof!");
|
||||
}
|
||||
}
|
||||
|
||||
const dog = new Dog();
|
||||
dog.bark();
|
||||
dog.move(10);
|
||||
dog.bark();
|
||||
```
|
||||
|
||||
### Generics
|
||||
|
||||
```ts
|
||||
function identity<T>(arg: T): T {
|
||||
return arg;
|
||||
}
|
||||
|
||||
let output1 = identity<string>("myString");
|
||||
let output2 = identity<number>(42);
|
||||
```
|
||||
|
||||
### Type Assertions
|
||||
|
||||
```ts
|
||||
let someValue: any = "this is a string";
|
||||
let strLength: number = (<string>someValue).length;
|
||||
// or
|
||||
let strLength2: number = (someValue as string).length;
|
||||
```
|
||||
|
||||
## Modules
|
||||
|
||||
### Export
|
||||
|
||||
```ts
|
||||
export interface StringValidator {
|
||||
isAcceptable(s: string): boolean;
|
||||
}
|
||||
|
||||
export class ZipCodeValidator implements StringValidator {
|
||||
isAcceptable(s: string) {
|
||||
return s.length === 5;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Import
|
||||
|
||||
```ts
|
||||
import { ZipCodeValidator } from "./ZipCodeValidator";
|
||||
|
||||
let myValidator = new ZipCodeValidator();
|
||||
```
|
||||
|
||||
### Namespaces
|
||||
|
||||
```ts
|
||||
namespace Validation {
|
||||
export interface StringValidator {
|
||||
isAcceptable(s: string): boolean;
|
||||
}
|
||||
|
||||
export class LettersOnlyValidator implements StringValidator {
|
||||
isAcceptable(s: string) {
|
||||
return /^[A-Za-z]+$/.test(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let validator = new Validation.LettersOnlyValidator();
|
||||
```
|
||||
|
||||
## Union and Intersection Types
|
||||
|
||||
### Union Types
|
||||
|
||||
```ts
|
||||
function padLeft(value: string, padding: string | number) {
|
||||
if (typeof padding === "number") {
|
||||
return Array(padding + 1).join(" ") + value;
|
||||
}
|
||||
if (typeof padding === "string") {
|
||||
return padding + value;
|
||||
}
|
||||
throw new Error(`Expected string or number, got '${padding}'.`);
|
||||
}
|
||||
```
|
||||
|
||||
### Intersection Types
|
||||
|
||||
```ts
|
||||
interface ErrorHandling {
|
||||
success: boolean;
|
||||
error?: { message: string };
|
||||
}
|
||||
|
||||
interface ArtworksData {
|
||||
artworks: { title: string }[];
|
||||
}
|
||||
|
||||
type ArtworksResponse = ArtworksData & ErrorHandling;
|
||||
|
||||
const response: ArtworksResponse = {
|
||||
success: true,
|
||||
artworks: [{ title: "Mona Lisa" }],
|
||||
};
|
||||
```
|
||||
|
||||
## Utility Types
|
||||
|
||||
### Partial
|
||||
|
||||
```ts
|
||||
interface User {
|
||||
id: number;
|
||||
name: string;
|
||||
age: number;
|
||||
}
|
||||
|
||||
let partialUser: Partial<User> = {
|
||||
name: "Alice",
|
||||
};
|
||||
```
|
||||
|
||||
### Readonly
|
||||
|
||||
```ts
|
||||
let readonlyUser: Readonly<User> = {
|
||||
id: 1,
|
||||
name: "Bob",
|
||||
age: 25,
|
||||
};
|
||||
|
||||
// readonlyUser.age = 26; // Error: cannot reassign a readonly property
|
||||
```
|
||||
|
||||
### Pick
|
||||
|
||||
```ts
|
||||
type UserName = Pick<User, "name">;
|
||||
|
||||
let userName: UserName = {
|
||||
name: "Charlie",
|
||||
};
|
||||
```
|
||||
|
||||
### Omit
|
||||
|
||||
```ts
|
||||
type UserWithoutAge = Omit<User, "age">;
|
||||
|
||||
let userWithoutAge: UserWithoutAge = {
|
||||
id: 2,
|
||||
name: "Dave",
|
||||
};
|
||||
```
|
||||
|
||||
## Decorators
|
||||
|
||||
### Class Decorator
|
||||
|
||||
```ts
|
||||
function sealed(constructor: Function) {
|
||||
Object.seal(constructor);
|
||||
Object.seal(constructor.prototype);
|
||||
}
|
||||
|
||||
@sealed
|
||||
class Greeter {
|
||||
greeting: string;
|
||||
constructor(message: string) {
|
||||
this.greeting = message;
|
||||
}
|
||||
greet() {
|
||||
return "Hello, " + this.greeting;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Method Decorator
|
||||
|
||||
```ts
|
||||
function enumerable(value: boolean) {
|
||||
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
|
||||
descriptor.enumerable = value;
|
||||
};
|
||||
}
|
||||
|
||||
class Greeter {
|
||||
greeting: string;
|
||||
constructor(message: string) {
|
||||
this.greeting = message;
|
||||
}
|
||||
|
||||
@enumerable(false)
|
||||
greet() {
|
||||
return "Hello, " + this.greeting;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Async/Await
|
||||
|
||||
```ts
|
||||
async function fetchData(url: string) {
|
||||
let response = await fetch(url);
|
||||
let data = await response.json();
|
||||
return data;
|
||||
}
|
||||
```
|
||||
|
||||
## Also read
|
||||
|
||||
- [TypeScript](https://www.typescriptlang.org/docs/)
|
||||
---
|
||||
title: TypeScript
|
||||
date: 2024-05-28 22:12:25
|
||||
background: bg-[#4476c0]
|
||||
tags:
|
||||
- ts
|
||||
- web
|
||||
categories:
|
||||
- Programming
|
||||
intro: |
|
||||
A TypeScript cheat sheet with the most important concepts, functions, methods, and more. A complete quick reference for beginners.
|
||||
plugins:
|
||||
- copyCode
|
||||
- runCode
|
||||
---
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Installing the Compiler
|
||||
|
||||
```shell
|
||||
npm install typescript --save-dev
|
||||
npm tsc
|
||||
```
|
||||
|
||||
## Basic DataTypes
|
||||
|
||||
### basic types
|
||||
|
||||
```ts
|
||||
let isDone: boolean = false;
|
||||
let age: number = 30;
|
||||
let userName: string = 'John';
|
||||
let list: number[] = [1, 2, 3];
|
||||
let tuple: [string, number] = ['hello', 10];
|
||||
let notSure: any = 4;
|
||||
notSure = 'maybe a string instead';
|
||||
```
|
||||
|
||||
### enums
|
||||
|
||||
```ts
|
||||
enum Color {
|
||||
Red,
|
||||
Green,
|
||||
Blue
|
||||
}
|
||||
let c: Color = Color.Green;
|
||||
```
|
||||
|
||||
### interface
|
||||
|
||||
```ts
|
||||
interface Person {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
age?: number; // Optional property
|
||||
}
|
||||
|
||||
function greet(person: Person) {
|
||||
return 'Hello, ' + person.firstName + ' ' + person.lastName;
|
||||
}
|
||||
```
|
||||
|
||||
### Functions
|
||||
|
||||
```ts
|
||||
function add(x: number, y: number): number {
|
||||
return x + y;
|
||||
}
|
||||
|
||||
let myAdd = function (x: number, y: number): number {
|
||||
return x + y;
|
||||
};
|
||||
|
||||
let myArrowAdd = (x: number, y: number): number => x + y;
|
||||
|
||||
function buildName(firstName: string, lastName = 'Smith') {
|
||||
return firstName + ' ' + lastName;
|
||||
}
|
||||
|
||||
function buildFullName(firstName: string, ...restOfName: string[]) {
|
||||
return firstName + ' ' + restOfName.join(' ');
|
||||
}
|
||||
```
|
||||
|
||||
### Classes
|
||||
|
||||
```ts
|
||||
class Greeter {
|
||||
greeting: string;
|
||||
constructor(message: string) {
|
||||
this.greeting = message;
|
||||
}
|
||||
greet() {
|
||||
return 'Hello, ' + this.greeting;
|
||||
}
|
||||
}
|
||||
|
||||
let greeter = new Greeter('world');
|
||||
```
|
||||
|
||||
### Inheritance
|
||||
|
||||
```ts
|
||||
class Animal {
|
||||
move(distance: number = 0) {
|
||||
console.log(`Animal moved ${distance} meters.`);
|
||||
}
|
||||
}
|
||||
|
||||
class Dog extends Animal {
|
||||
bark() {
|
||||
console.log('Woof! Woof!');
|
||||
}
|
||||
}
|
||||
|
||||
const dog = new Dog();
|
||||
dog.bark();
|
||||
dog.move(10);
|
||||
dog.bark();
|
||||
```
|
||||
|
||||
### Generics
|
||||
|
||||
```ts
|
||||
function identity<T>(arg: T): T {
|
||||
return arg;
|
||||
}
|
||||
|
||||
let output1 = identity<string>('myString');
|
||||
let output2 = identity<number>(42);
|
||||
```
|
||||
|
||||
### Type Assertions
|
||||
|
||||
```ts
|
||||
let someValue: any = 'this is a string';
|
||||
let strLength: number = (<string>someValue).length;
|
||||
// or
|
||||
let strLength2: number = (someValue as string).length;
|
||||
```
|
||||
|
||||
## Modules
|
||||
|
||||
### Export
|
||||
|
||||
```ts
|
||||
export interface StringValidator {
|
||||
isAcceptable(s: string): boolean;
|
||||
}
|
||||
|
||||
export class ZipCodeValidator implements StringValidator {
|
||||
isAcceptable(s: string) {
|
||||
return s.length === 5;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Import
|
||||
|
||||
```ts
|
||||
import { ZipCodeValidator } from './ZipCodeValidator';
|
||||
|
||||
let myValidator = new ZipCodeValidator();
|
||||
```
|
||||
|
||||
### Namespaces
|
||||
|
||||
```ts
|
||||
namespace Validation {
|
||||
export interface StringValidator {
|
||||
isAcceptable(s: string): boolean;
|
||||
}
|
||||
|
||||
export class LettersOnlyValidator implements StringValidator {
|
||||
isAcceptable(s: string) {
|
||||
return /^[A-Za-z]+$/.test(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let validator = new Validation.LettersOnlyValidator();
|
||||
```
|
||||
|
||||
## Union and Intersection Types
|
||||
|
||||
### Union Types
|
||||
|
||||
```ts
|
||||
function padLeft(value: string, padding: string | number) {
|
||||
if (typeof padding === 'number') {
|
||||
return Array(padding + 1).join(' ') + value;
|
||||
}
|
||||
if (typeof padding === 'string') {
|
||||
return padding + value;
|
||||
}
|
||||
throw new Error(`Expected string or number, got '${padding}'.`);
|
||||
}
|
||||
```
|
||||
|
||||
### Intersection Types
|
||||
|
||||
```ts
|
||||
interface ErrorHandling {
|
||||
success: boolean;
|
||||
error?: { message: string };
|
||||
}
|
||||
|
||||
interface ArtworksData {
|
||||
artworks: { title: string }[];
|
||||
}
|
||||
|
||||
type ArtworksResponse = ArtworksData & ErrorHandling;
|
||||
|
||||
const response: ArtworksResponse = {
|
||||
success: true,
|
||||
artworks: [{ title: 'Mona Lisa' }]
|
||||
};
|
||||
```
|
||||
|
||||
## Utility Types
|
||||
|
||||
### Partial
|
||||
|
||||
```ts
|
||||
interface User {
|
||||
id: number;
|
||||
name: string;
|
||||
age: number;
|
||||
}
|
||||
|
||||
let partialUser: Partial<User> = {
|
||||
name: 'Alice'
|
||||
};
|
||||
```
|
||||
|
||||
### Readonly
|
||||
|
||||
```ts
|
||||
let readonlyUser: Readonly<User> = {
|
||||
id: 1,
|
||||
name: 'Bob',
|
||||
age: 25
|
||||
};
|
||||
|
||||
// readonlyUser.age = 26; // Error: cannot reassign a readonly property
|
||||
```
|
||||
|
||||
### Pick
|
||||
|
||||
```ts
|
||||
type UserName = Pick<User, 'name'>;
|
||||
|
||||
let userName: UserName = {
|
||||
name: 'Charlie'
|
||||
};
|
||||
```
|
||||
|
||||
### Omit
|
||||
|
||||
```ts
|
||||
type UserWithoutAge = Omit<User, 'age'>;
|
||||
|
||||
let userWithoutAge: UserWithoutAge = {
|
||||
id: 2,
|
||||
name: 'Dave'
|
||||
};
|
||||
```
|
||||
|
||||
## Decorators
|
||||
|
||||
### Class Decorator
|
||||
|
||||
```ts
|
||||
function sealed(constructor: Function) {
|
||||
Object.seal(constructor);
|
||||
Object.seal(constructor.prototype);
|
||||
}
|
||||
|
||||
@sealed
|
||||
class Greeter {
|
||||
greeting: string;
|
||||
constructor(message: string) {
|
||||
this.greeting = message;
|
||||
}
|
||||
greet() {
|
||||
return 'Hello, ' + this.greeting;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Method Decorator
|
||||
|
||||
```ts
|
||||
function enumerable(value: boolean) {
|
||||
return function (
|
||||
target: any,
|
||||
propertyKey: string,
|
||||
descriptor: PropertyDescriptor
|
||||
) {
|
||||
descriptor.enumerable = value;
|
||||
};
|
||||
}
|
||||
|
||||
class Greeter {
|
||||
greeting: string;
|
||||
constructor(message: string) {
|
||||
this.greeting = message;
|
||||
}
|
||||
|
||||
@enumerable(false)
|
||||
greet() {
|
||||
return 'Hello, ' + this.greeting;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Async/Await
|
||||
|
||||
```ts
|
||||
async function fetchData(url: string) {
|
||||
let response = await fetch(url);
|
||||
let data = await response.json();
|
||||
return data;
|
||||
}
|
||||
```
|
||||
|
||||
## Also read
|
||||
|
||||
- [TypeScript](https://www.typescriptlang.org/docs/)
|
||||
@@ -5,110 +5,109 @@ tags:
|
||||
- unreal
|
||||
- engine
|
||||
categories:
|
||||
- Keyboard Shortcuts
|
||||
intro:
|
||||
A visual cheat-sheet for many keyboard shortcuts found in Unreal Engine 5
|
||||
- Keyboard Shortcuts
|
||||
intro: A visual cheat-sheet for many keyboard shortcuts found in Unreal Engine 5
|
||||
---
|
||||
|
||||
## Level Editor
|
||||
|
||||
### Viewport Transformation
|
||||
|
||||
| Shortcut | Action |
|
||||
| --------------------- | --------------------------- |
|
||||
| `W` | Translate |
|
||||
| `E` | Rotate |
|
||||
| `R` | Scale |
|
||||
| `Space Bar` | Toggle Transform Mode |
|
||||
| `[` | Decrease Position Grid Size |
|
||||
| `]` | Increase Position Grid Size |
|
||||
| `Shift` `[` | Decrease Rotation Grid Size |
|
||||
| `Shift` `]` | Increase Rotation Grid Size |
|
||||
| Shortcut | Action |
|
||||
| ----------- | --------------------------- |
|
||||
| `W` | Translate |
|
||||
| `E` | Rotate |
|
||||
| `R` | Scale |
|
||||
| `Space Bar` | Toggle Transform Mode |
|
||||
| `[` | Decrease Position Grid Size |
|
||||
| `]` | Increase Position Grid Size |
|
||||
| `Shift` `[` | Decrease Rotation Grid Size |
|
||||
| `Shift` `]` | Increase Rotation Grid Size |
|
||||
|
||||
{.shortcuts}
|
||||
|
||||
### View Modes
|
||||
|
||||
| Shortcut | Action |
|
||||
| --------------------- | --------------------- |
|
||||
| `Alt` `2` | Wireframe |
|
||||
| `Alt` `3` | Unlit |
|
||||
| `Alt` `4` | Lit |
|
||||
| `Alt` `5` | Detail Lighting |
|
||||
| `Alt` `6` | Lighting Only |
|
||||
| `Alt` `7` | Light Complexity |
|
||||
| `Alt` `8` | Shader Complexity |
|
||||
| `Alt` `0` | Lightmap Density |
|
||||
| Shortcut | Action |
|
||||
| --------- | ----------------- |
|
||||
| `Alt` `2` | Wireframe |
|
||||
| `Alt` `3` | Unlit |
|
||||
| `Alt` `4` | Lit |
|
||||
| `Alt` `5` | Detail Lighting |
|
||||
| `Alt` `6` | Lighting Only |
|
||||
| `Alt` `7` | Light Complexity |
|
||||
| `Alt` `8` | Shader Complexity |
|
||||
| `Alt` `0` | Lightmap Density |
|
||||
|
||||
{.shortcuts}
|
||||
|
||||
### Level Editor General {.row-span-2}
|
||||
|
||||
| Shortcut | Action |
|
||||
| --------------------- | ---------------------------- |
|
||||
| `Esc` | Deselect All |
|
||||
| `H` | Hide Selected |
|
||||
| `Ctrl` `H` | Unhide All |
|
||||
| `F` | Focus on Actor |
|
||||
| `F9` | Screenshot |
|
||||
| `F11` | Immersive Mode |
|
||||
| `G` | Game View |
|
||||
| `T` | Toggle Translucent Selection |
|
||||
| `(right click)` | Asset Menu |
|
||||
| `Ctrl` `E` | Edit Selected Asset |
|
||||
| `Ctrl` `P` | Open Asset |
|
||||
| `P` | Toggle Navmesh |
|
||||
| `Ctrl` `Shift` `,` | Profile GPU |
|
||||
| `Ctrl` `Shift` `H` | Toggle FPS |
|
||||
| `~` | Command Console |
|
||||
| Shortcut | Action |
|
||||
| ------------------ | ---------------------------- |
|
||||
| `Esc` | Deselect All |
|
||||
| `H` | Hide Selected |
|
||||
| `Ctrl` `H` | Unhide All |
|
||||
| `F` | Focus on Actor |
|
||||
| `F9` | Screenshot |
|
||||
| `F11` | Immersive Mode |
|
||||
| `G` | Game View |
|
||||
| `T` | Toggle Translucent Selection |
|
||||
| `(right click)` | Asset Menu |
|
||||
| `Ctrl` `E` | Edit Selected Asset |
|
||||
| `Ctrl` `P` | Open Asset |
|
||||
| `P` | Toggle Navmesh |
|
||||
| `Ctrl` `Shift` `,` | Profile GPU |
|
||||
| `Ctrl` `Shift` `H` | Toggle FPS |
|
||||
| `~` | Command Console |
|
||||
|
||||
{.shortcuts}
|
||||
|
||||
### Camera Navigation
|
||||
|
||||
| Shortcut | Action |
|
||||
| --------------------- | --------------------- |
|
||||
| `Alt` `G` | Perspective View |
|
||||
| `Alt` `H` | Front View |
|
||||
| `Alt` `J` | Top View |
|
||||
| `Alt` `K` | Side View |
|
||||
| `Ctrl` `0-9` | Set Bookmark |
|
||||
| `0-9` | Jump to Bookmark |
|
||||
| Shortcut | Action |
|
||||
| ------------ | ---------------- |
|
||||
| `Alt` `G` | Perspective View |
|
||||
| `Alt` `H` | Front View |
|
||||
| `Alt` `J` | Top View |
|
||||
| `Alt` `K` | Side View |
|
||||
| `Ctrl` `0-9` | Set Bookmark |
|
||||
| `0-9` | Jump to Bookmark |
|
||||
|
||||
{.shortcuts}
|
||||
|
||||
### Editing Modes
|
||||
|
||||
| Shortcut | Action |
|
||||
| --------------------- | --------------------- |
|
||||
| `Shift` `1` | Selection Mode |
|
||||
| `Shift` `2` | Landscape Mode |
|
||||
| `Shift` `3` | Foliage Mode |
|
||||
| `Shift` `4` | Modeling Mode |
|
||||
| `Shift` `5` | Brush Editing Mode |
|
||||
| `Shift` `6` | Animation Mode |
|
||||
| Shortcut | Action |
|
||||
| ----------- | ------------------ |
|
||||
| `Shift` `1` | Selection Mode |
|
||||
| `Shift` `2` | Landscape Mode |
|
||||
| `Shift` `3` | Foliage Mode |
|
||||
| `Shift` `4` | Modeling Mode |
|
||||
| `Shift` `5` | Brush Editing Mode |
|
||||
| `Shift` `6` | Animation Mode |
|
||||
|
||||
{.shortcuts}
|
||||
|
||||
### Snapping
|
||||
|
||||
| Shortcut | Action |
|
||||
| --------------------- | --------------------- |
|
||||
| `End` | Snap to Floor |
|
||||
| `Alt` `End` | Snap Pivot to Floor |
|
||||
| `Shift` `End` | Snap Bounds to Floor |
|
||||
| `Ctrl` `End` | Snap to World Grid |
|
||||
| Shortcut | Action |
|
||||
| ------------- | -------------------- |
|
||||
| `End` | Snap to Floor |
|
||||
| `Alt` `End` | Snap Pivot to Floor |
|
||||
| `Shift` `End` | Snap Bounds to Floor |
|
||||
| `Ctrl` `End` | Snap to World Grid |
|
||||
|
||||
{.shortcuts}
|
||||
|
||||
### Play in Editor (PIE)
|
||||
|
||||
| Shortcut | Action |
|
||||
| --------------------- | --------------------- |
|
||||
| `Alt` `P` | Start PIE Session |
|
||||
| `Pause` | Pause |
|
||||
| `F8 ` | Eject from Player |
|
||||
| `Esc` | Stop PIE Session |
|
||||
| Shortcut | Action |
|
||||
| --------- | ----------------- |
|
||||
| `Alt` `P` | Start PIE Session |
|
||||
| `Pause` | Pause |
|
||||
| `F8 ` | Eject from Player |
|
||||
| `Esc` | Stop PIE Session |
|
||||
|
||||
{.shortcuts}
|
||||
|
||||
@@ -116,11 +115,11 @@ intro:
|
||||
|
||||
Note: You need to select assets first for these shortcuts to work
|
||||
|
||||
| Shortcut | Action |
|
||||
| --------------------- | --------------------- |
|
||||
| `Alt` `Shift` `A` | Audit Assets |
|
||||
| `Alt` `Shift` `R` | Reference Viewer |
|
||||
| `Alt` `Shift` `M` | Size Map |
|
||||
| Shortcut | Action |
|
||||
| ----------------- | ---------------- |
|
||||
| `Alt` `Shift` `A` | Audit Assets |
|
||||
| `Alt` `Shift` `R` | Reference Viewer |
|
||||
| `Alt` `Shift` `M` | Size Map |
|
||||
|
||||
{.shortcuts}
|
||||
|
||||
@@ -128,21 +127,21 @@ Note: You need to select assets first for these shortcuts to work
|
||||
|
||||
### Blueprints {.row-span-2}
|
||||
|
||||
| Shortcut | Action |
|
||||
| --------------------- | ------------------------------- |
|
||||
| `B` | Add Branch |
|
||||
| `S` | Add Sequence |
|
||||
| `D` | Add Delay |
|
||||
| `F` | Add For Each Loop |
|
||||
| `G` | Add Gate |
|
||||
| `M` | Add Multi Gate |
|
||||
| `O` | Add Do Once |
|
||||
| `N` | Add Do N |
|
||||
| `C` | Add Comment |
|
||||
| `F7` | Compile Blueprint |
|
||||
| `F9` | Add Breakpoint to selected node |
|
||||
| `Ctrl` `Shift` `F9` | Remove all Breakpoints |
|
||||
| `Home` | Zoom to selected node |
|
||||
| Shortcut | Action |
|
||||
| ------------------- | ------------------------------- |
|
||||
| `B` | Add Branch |
|
||||
| `S` | Add Sequence |
|
||||
| `D` | Add Delay |
|
||||
| `F` | Add For Each Loop |
|
||||
| `G` | Add Gate |
|
||||
| `M` | Add Multi Gate |
|
||||
| `O` | Add Do Once |
|
||||
| `N` | Add Do N |
|
||||
| `C` | Add Comment |
|
||||
| `F7` | Compile Blueprint |
|
||||
| `F9` | Add Breakpoint to selected node |
|
||||
| `Ctrl` `Shift` `F9` | Remove all Breakpoints |
|
||||
| `Home` | Zoom to selected node |
|
||||
|
||||
{.shortcuts}
|
||||
|
||||
@@ -150,21 +149,21 @@ Note: You need to select assets first for these shortcuts to work
|
||||
|
||||
Used in the viewport for the Mesh Editor, Material Editor, Blueprint Editor, etc.
|
||||
|
||||
| Shortcut | Action |
|
||||
| --------------------- | ---------------------- |
|
||||
| `I` | Toggle Environment |
|
||||
| `O` | Toggle Floor |
|
||||
| `P` | Toggle Post Processing |
|
||||
| Shortcut | Action |
|
||||
| -------- | ---------------------- |
|
||||
| `I` | Toggle Environment |
|
||||
| `O` | Toggle Floor |
|
||||
| `P` | Toggle Post Processing |
|
||||
|
||||
{.shortcuts}
|
||||
|
||||
### Static Meshes
|
||||
|
||||
| Shortcut | Action |
|
||||
| --------------------- | ------------------------- |
|
||||
| `Ctrl` `N` | Show Nanite Fallback Mesh |
|
||||
| `Alt` `N` | Toggle Normals |
|
||||
| `Alt` `S` | Toggle Sockets |
|
||||
| Shortcut | Action |
|
||||
| ---------- | ------------------------- |
|
||||
| `Ctrl` `N` | Show Nanite Fallback Mesh |
|
||||
| `Alt` `N` | Toggle Normals |
|
||||
| `Alt` `S` | Toggle Sockets |
|
||||
|
||||
{.shortcuts}
|
||||
|
||||
@@ -189,4 +188,4 @@ Used in the viewport for the Mesh Editor, Material Editor, Blueprint Editor, etc
|
||||
- [Unreal Engine Editor Hotkey Cheat Sheet](https://uecasts.com/resources/unreal-engine-5-editor-hotkeys-cheat-sheet)
|
||||
_(uecasts.com)_
|
||||
- [Unreal Engine Actor Snapping Shortcuts](https://unrealdirective.com/tips/actor-snapping-shortcuts)
|
||||
_(unrealdirective.com)_
|
||||
_(unrealdirective.com)_
|
||||
@@ -383,7 +383,7 @@ See `:help text-objects`
|
||||
| `<C-w>` `-` _/_ `+` | Decrease/Increase height |
|
||||
| `<C-w>` `<` _/_ `>` | Decrease/Increase width |
|
||||
| `<C-w>` <code>\|</code> | Max out the width |
|
||||
| `<C-w>` `_` | Max out the height |
|
||||
| `<C-w>` `_` | Max out the height |
|
||||
| `<C-w>` `=` | Equally high and wide |
|
||||
| `<C-w>` `h` _/_ `l` | Go to the left/right window |
|
||||
| `<C-w>` `j` _/_ `k` | Go to the up/down window |
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
title: WebStorm
|
||||
date: 2020-12-17 21:51:44
|
||||
background: bg-gradient-to-r from-emerald-300 to-blue-400 hover:from-emerald-400 hover:to-blue-500
|
||||
background: bg-gradient-to-r from-indigo-300 to-blue-400 hover:from-indigo-400 hover:to-blue-500
|
||||
tags:
|
||||
- jetbrains
|
||||
- web
|
||||
|
||||
@@ -323,7 +323,7 @@ Jack:
|
||||
hobby:
|
||||
- a
|
||||
- b
|
||||
location: { country: "A", city: "A-A" }
|
||||
location: { country: 'A', city: 'A-A' }
|
||||
```
|
||||
|
||||
#### ↓ Equivalent JSON
|
||||
@@ -349,7 +349,7 @@ Jack:
|
||||
set1: !!set
|
||||
? one
|
||||
? two
|
||||
set2: !!set { "one", "two" }
|
||||
set2: !!set { 'one', 'two' }
|
||||
```
|
||||
|
||||
#### ↓ Equivalent JSON
|
||||
|
||||
@@ -16,97 +16,98 @@ intro: A visual cheat-sheet for the 50 keyboard shortcuts found in the Zed text
|
||||
|
||||
### Zed
|
||||
|
||||
| Shortcut | Action |
|
||||
|------------------------|------------------------|
|
||||
| `Ctrl` `,` | Open settings |
|
||||
| `Ctrl` `Shift` `X` | Open Extensions store |
|
||||
| `Ctrl` `Q` | Quit Zed |
|
||||
| Shortcut | Action |
|
||||
| ------------------ | --------------------- |
|
||||
| `Ctrl` `,` | Open settings |
|
||||
| `Ctrl` `Shift` `X` | Open Extensions store |
|
||||
| `Ctrl` `Q` | Quit Zed |
|
||||
|
||||
{.shortcuts}
|
||||
|
||||
### File
|
||||
|
||||
| Shortcut | Action |
|
||||
|----------------------------|---------------------|
|
||||
| `Ctrl` `N` | New file |
|
||||
| `Ctrl` `Shift` `N` | New Window |
|
||||
| `Ctrl` `O` | Open folder |
|
||||
| `Ctrl` `Alt` `Shift` `O` | Open remote folder |
|
||||
| `Ctrl` `S` | Save |
|
||||
| `Ctrl` `Shift` `S` | Save As... |
|
||||
| `Ctrl` `Alt` `S` | Save All |
|
||||
| `Ctrl` `Shift` `W` | Close Window |
|
||||
| Shortcut | Action |
|
||||
| ------------------------ | ------------------ |
|
||||
| `Ctrl` `N` | New file |
|
||||
| `Ctrl` `Shift` `N` | New Window |
|
||||
| `Ctrl` `O` | Open folder |
|
||||
| `Ctrl` `Alt` `Shift` `O` | Open remote folder |
|
||||
| `Ctrl` `S` | Save |
|
||||
| `Ctrl` `Shift` `S` | Save As... |
|
||||
| `Ctrl` `Alt` `S` | Save All |
|
||||
| `Ctrl` `Shift` `W` | Close Window |
|
||||
|
||||
{.shortcuts}
|
||||
|
||||
### Edit
|
||||
|
||||
| Shortcut | Action |
|
||||
|------------------------|---------------------|
|
||||
| `Ctrl` `Z` | Undo |
|
||||
| `Ctrl` `Shift` `Z` | Redo |
|
||||
| `Ctrl` `X` | Cut |
|
||||
| `Ctrl` `C` | Copy |
|
||||
| `Ctrl` `V` | Paste |
|
||||
| `Ctrl` `Shift` `F` | Find in project |
|
||||
| `Ctrl` `/` | Toggle line comment |
|
||||
| Shortcut | Action |
|
||||
| ------------------ | ------------------- |
|
||||
| `Ctrl` `Z` | Undo |
|
||||
| `Ctrl` `Shift` `Z` | Redo |
|
||||
| `Ctrl` `X` | Cut |
|
||||
| `Ctrl` `C` | Copy |
|
||||
| `Ctrl` `V` | Paste |
|
||||
| `Ctrl` `Shift` `F` | Find in project |
|
||||
| `Ctrl` `/` | Toggle line comment |
|
||||
|
||||
{.shortcuts}
|
||||
|
||||
### Selection
|
||||
|
||||
| Shortcut | Action |
|
||||
|--------------------------|-------------------------|
|
||||
| `Ctrl` `A` | Select all |
|
||||
| `Alt` `Shift` `Right` | Expand selection |
|
||||
| `Alt` `Shift` `Left` | Shrink selection |
|
||||
| `Alt` `Shift` `Up` | Add cursor above |
|
||||
| `Alt` `Shift` `Down` | Add cursor below |
|
||||
| `Ctrl` `Shift` `Down` | Select next Occurrence |
|
||||
| `Alt` `Up` | Move line up |
|
||||
| `Alt` `Down` | Move line down |
|
||||
| `Ctrl` `Shift` `D` | Duplicate selection |
|
||||
| Shortcut | Action |
|
||||
| --------------------- | ---------------------- |
|
||||
| `Ctrl` `A` | Select all |
|
||||
| `Alt` `Shift` `Right` | Expand selection |
|
||||
| `Alt` `Shift` `Left` | Shrink selection |
|
||||
| `Alt` `Shift` `Up` | Add cursor above |
|
||||
| `Alt` `Shift` `Down` | Add cursor below |
|
||||
| `Ctrl` `Shift` `Down` | Select next Occurrence |
|
||||
| `Alt` `Up` | Move line up |
|
||||
| `Alt` `Down` | Move line down |
|
||||
| `Ctrl` `Shift` `D` | Duplicate selection |
|
||||
|
||||
{.shortcuts}
|
||||
|
||||
### View
|
||||
|
||||
| Shortcut | Action |
|
||||
|------------------------|----------------------|
|
||||
| `Ctrl` `B` | Toggle Left Dock |
|
||||
| `Ctrl` `Alt` `B` | Toggle Right Dock |
|
||||
| `Ctrl` `J` | Toggle Bottom Dock |
|
||||
| `Ctrl` `Alt` `Y` | Close All Docks |
|
||||
| `Ctrl` `K` `Up` | Split Up |
|
||||
| `Ctrl` `K` `Down` | Split Down |
|
||||
| `Ctrl` `K` `Left` | Split Left |
|
||||
| `Ctrl` `K` `Right` | Split Right |
|
||||
| `Ctrl` `Shift` `E` | Project Panel |
|
||||
| `Ctrl` `Shift` `B` | Outline Panel |
|
||||
| `Ctrl` `Shift` `C` | Collab Panel |
|
||||
| `Ctrl` ``` ` ``` | Terminal Panel |
|
||||
| `Ctrl` `Shift` `M` | Diagnostics |
|
||||
| Shortcut | Action |
|
||||
| ------------------ | ------------------ |
|
||||
| `Ctrl` `B` | Toggle Left Dock |
|
||||
| `Ctrl` `Alt` `B` | Toggle Right Dock |
|
||||
| `Ctrl` `J` | Toggle Bottom Dock |
|
||||
| `Ctrl` `Alt` `Y` | Close All Docks |
|
||||
| `Ctrl` `K` `Up` | Split Up |
|
||||
| `Ctrl` `K` `Down` | Split Down |
|
||||
| `Ctrl` `K` `Left` | Split Left |
|
||||
| `Ctrl` `K` `Right` | Split Right |
|
||||
| `Ctrl` `Shift` `E` | Project Panel |
|
||||
| `Ctrl` `Shift` `B` | Outline Panel |
|
||||
| `Ctrl` `Shift` `C` | Collab Panel |
|
||||
| `Ctrl` `` ` `` | Terminal Panel |
|
||||
| `Ctrl` `Shift` `M` | Diagnostics |
|
||||
|
||||
{.shortcuts}
|
||||
|
||||
### Go
|
||||
|
||||
| Shortcut | Action |
|
||||
|-----------------------|----------------------------|
|
||||
| `Ctrl` `Alt` `-` | Back |
|
||||
| `Ctrl` `Shift` `P` | Command Palette… |
|
||||
| `Ctrl` `E` | Go to File… |
|
||||
| `Ctrl` `Shift` `O` | Go to Symbol in Editor… |
|
||||
| `Ctrl` `G` | Go to Line/Column… |
|
||||
| `F12` | Go to Definition |
|
||||
| `Ctrl` `F12` | Go to Type Definition |
|
||||
| `Alt` `Shift` `F12` | Find All References |
|
||||
| `F8` | Next Problem |
|
||||
| `Shift` `F8` | Previous Problem |
|
||||
| Shortcut | Action |
|
||||
| ------------------- | ----------------------- |
|
||||
| `Ctrl` `Alt` `-` | Back |
|
||||
| `Ctrl` `Shift` `P` | Command Palette… |
|
||||
| `Ctrl` `E` | Go to File… |
|
||||
| `Ctrl` `Shift` `O` | Go to Symbol in Editor… |
|
||||
| `Ctrl` `G` | Go to Line/Column… |
|
||||
| `F12` | Go to Definition |
|
||||
| `Ctrl` `F12` | Go to Type Definition |
|
||||
| `Alt` `Shift` `F12` | Find All References |
|
||||
| `F8` | Next Problem |
|
||||
| `Shift` `F8` | Previous Problem |
|
||||
|
||||
{.shortcuts}
|
||||
|
||||
## Also see
|
||||
|
||||
- [Zed](https://zed.dev/)
|
||||
- [Zed GitHub](https://github.com/zed-industries/zed)
|
||||
- [Zed Documentation](https://zed.dev/docs)
|
||||
@@ -3,9 +3,9 @@ title: About
|
||||
date: 2020-03-26 20:45:53
|
||||
---
|
||||
|
||||
Welcome to [CheatSheets] – your go-to resource for [describing content]. Designed with [developers/students/professionals]
|
||||
in mind, our quick reference provides a comprehensive collection of [topics/sections] to help you [solve problems/learn
|
||||
efficiently/etc.].
|
||||
Welcome to [CheatSheets] – your go-to resource for [describing content]. Designed with
|
||||
[developers/students/professionals] in mind, our quick reference provides a comprehensive collection of
|
||||
[topics/sections] to help you [solve problems/learn efficiently/etc.].
|
||||
|
||||
Our user-friendly interface ensures rapid access to the information you need. Whether you're [coding/studying/working],
|
||||
you'll find [specific benefits or standout features].
|
||||
@@ -24,8 +24,7 @@ Key Features:
|
||||
- By avoiding the need to seek through lengthy documentation, cheat sheets save users valuable time during tasks or
|
||||
learning.
|
||||
- Digital cheat sheets are easily searchable, and users can quickly find what they need by using keywords or phrases.
|
||||
- Cheat sheets act as a rapid review tool, allowing users to refresh their memory on topics they've previously
|
||||
learned.
|
||||
- Cheat sheets act as a rapid review tool, allowing users to refresh their memory on topics they've previously learned.
|
||||
|
||||
Our team of experts has meticulously crafted this reference to provide instant information. We're committed to evolving
|
||||
our content to meet your needs and bring out fascinating upgrades in the future.
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" fill="currentColor" height="1em" width="1em">
|
||||
<path d="M512 714.666667c-8.533333 0-17.066667-2.133333-23.466667-8.533334l-341.333333-341.333333c-12.8-12.8-12.8-32 0-44.8 12.8-12.8 32-12.8 44.8 0l320 317.866667 317.866667-317.866667c12.8-12.8 32-12.8 44.8 0 12.8 12.8 12.8 32 0 44.8l-341.333334 341.333333c-4.266667 6.4-12.8 8.533333-21.333333 8.533334z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 431 B |
@@ -0,0 +1,5 @@
|
||||
<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" fill="currentColor" height="1em" width="1em">
|
||||
<path d="M744 312h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c53 0 96 43 96 96s-43 96-96 96h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c101.8 0 184-82.2 184-184s-82.2-184-184-184z"/>
|
||||
<path d="M664 128H144c-17.7 0-32 14.3-32 32v32c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8v-24h480v24c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8v-32c0-17.7-14.3-32-32-32z"/>
|
||||
<path d="M144 256h520c17.7 0 32 14.3 32 32v496c0 17.7-14.3 32-32 32H144c-17.7 0-32-14.3-32-32V288c0-17.7 14.3-32 32-32zm464 496V320H176v432h432z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 615 B |
@@ -0,0 +1,3 @@
|
||||
<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" fill="currentColor" height="1em" width="1em">
|
||||
<path d="M832 64H296c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h496v688c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8V96c0-17.7-14.3-32-32-32zM704 192H192c-17.7 0-32 14.3-32 32v530.7c0 8.5 3.4 16.6 9.4 22.6l173.3 173.3c2.2 2.2 4.7 4 7.4 5.5v1.9h4.4c2.4.8 4.9 1.2 7.5 1.2H704c17.7 0 32-14.3 32-32V224c0-17.7-14.3-32-32-32zM350 856.2L263.9 770H350v86.2zM672 888H414V746c0-22.1-17.9-40-40-40H232V256h440v632z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 512 B |
|
After Width: | Height: | Size: 4.5 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
@@ -0,0 +1,3 @@
|
||||
<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" fill="currentColor" height="1em" width="1em">
|
||||
<path d="M853.333333 298.666667c0-117.333333-96-213.333333-213.333333-213.333334H298.666667c-23.466667 0-42.666667 19.2-42.666667 42.666667v554.666667c0 23.466667 19.2 42.666667 42.666667 42.666666h85.333333c23.466667 0 42.666667-19.2 42.666667-42.666666V469.333333h213.333333c117.333333 0 213.333333-96 213.333333-213.333333z m-85.333333 0c0 70.4-57.6 128-128 128H426.666667V213.333333h213.333333c70.4 0 128 57.6 128 128z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 547 B |
|
After Width: | Height: | Size: 2.4 KiB |
@@ -0,0 +1,3 @@
|
||||
<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" fill="currentColor" height="1em" width="1em">
|
||||
<path d="M714.163 519.284L1160.89 0h-105.86L667.137 450.887L357.328 0H0l468.492 681.821L0 1226.37h105.866l409.625-476.152L826.647 1226.37H1183.98L714.137 519.284h.026ZM569.165 687.828l-47.468-67.894L144.011 79.6944h162.604l304.797 435.991 47.468 67.894 396.2 566.721H892.476L569.165 687.854v-.026Z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 422 B |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 5.0 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 101 KiB |
@@ -0,0 +1,4 @@
|
||||
<svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" width="1em" height="1em">
|
||||
<path d="M234.624 932.864a43.52 43.52 0 0 1-58.688-17.024 46.528 46.528 0 0 1-5.248-21.248V584.896c0 30.72 17.28 49.664 62.848 70.912l278.08 138.688-276.992 138.368z" fill="#6ad09d" opacity=".4"></path>
|
||||
<path d="M642.944 85.312c115.584 0 209.28 45.504 210.368 161.92v647.36a44.992 44.992 0 0 1-5.248 20.864 43.328 43.328 0 0 1-59.84 17.408L511.616 794.496l-278.08-138.688c-45.568-21.248-62.848-40.192-62.848-70.912V247.168c0-116.352 93.696-161.856 208.832-161.856z m28.992 257.792H350.912a33.6 33.6 0 0 0-33.472 33.728c0 18.56 14.976 33.728 33.472 33.728H672a33.6 33.6 0 0 0 33.472-33.728A33.6 33.6 0 0 0 672 343.104z" fill="#6ad09d"></path>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 760 B |
@@ -79,7 +79,7 @@
|
||||
}
|
||||
|
||||
.notfound h1 {
|
||||
font-family: "Quicksand", sans-serif;
|
||||
font-family: 'Quicksand', sans-serif;
|
||||
font-size: 86px;
|
||||
text-transform: uppercase;
|
||||
font-weight: 700;
|
||||
@@ -89,7 +89,7 @@
|
||||
}
|
||||
|
||||
.notfound h2 {
|
||||
font-family: "Quicksand", sans-serif;
|
||||
font-family: 'Quicksand', sans-serif;
|
||||
font-size: 26px;
|
||||
margin: 0;
|
||||
font-weight: 700;
|
||||
@@ -97,7 +97,7 @@
|
||||
}
|
||||
|
||||
.notfound a {
|
||||
font-family: "Quicksand", sans-serif;
|
||||
font-family: 'Quicksand', sans-serif;
|
||||
font-size: 14px;
|
||||
text-decoration: none;
|
||||
text-transform: uppercase;
|
||||
|
||||
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 28 KiB |