Merge branch 'master' into feature/update-regexp
This commit is contained in:
commit
46dd46edf1
|
@ -1,2 +1,24 @@
|
||||||
- name: Automatic rebase
|
# https://github.com/cirrus-actions/rebase
|
||||||
uses: cirrus-actions/rebase@1.2
|
on:
|
||||||
|
issue_comment:
|
||||||
|
types: [created]
|
||||||
|
|
||||||
|
name: Automatic rebase
|
||||||
|
jobs:
|
||||||
|
rebase:
|
||||||
|
name: Rebase
|
||||||
|
if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/rebase')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@master
|
||||||
|
- name: Automatic Rebase
|
||||||
|
uses: cirrus-actions/rebase@v1.2.0
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
# https://github.community/t5/GitHub-Actions/Workflow-is-failing-if-no-job-can-be-ran-due-to-condition/m-p/38186#M3250
|
||||||
|
always_job:
|
||||||
|
name: Aways run job
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Always run
|
||||||
|
run: echo "This job is used to prevent the workflow to fail when all other jobs are skipped."
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
image: gitpod/workspace-full
|
||||||
|
|
||||||
|
github:
|
||||||
|
# Prebuild the docker image for gitpod - https://www.gitpod.io/docs/46_prebuilds/
|
||||||
|
prebuilds:
|
||||||
|
# enable for the master/default branch
|
||||||
|
master: true
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
- init: bundle install
|
|
@ -5,3 +5,10 @@ script:
|
||||||
- make -B _site
|
- make -B _site
|
||||||
- if ! make test; then make test-warning; exit 16; fi
|
- if ! make test; then make test-warning; exit 16; fi
|
||||||
cache: bundler
|
cache: bundler
|
||||||
|
notifications:
|
||||||
|
slack:
|
||||||
|
if: branch = master OR branch =~ ^.*slack.*$
|
||||||
|
rooms:
|
||||||
|
- secure: FN4trzyyUdtZ6DXj4G3A7YnhqkPyqi8jN9BIdA6S6D2eJEH1gPbZUfbqAW87LKckKZ9iYB5KDF5IuELhR3vv1DeHRqm3MKRU91JVBDT7EXbF86Z1J/JMJxNOcoWdCilcgpnm9NCkMAPFC9h6Y3txYhaLWLsnDaWlvehBsJg+Ql4=
|
||||||
|
on_success: change
|
||||||
|
on_failure: always
|
||||||
|
|
|
@ -1,5 +1,19 @@
|
||||||
# Developer notes
|
# Developer notes
|
||||||
|
|
||||||
|
## Gitpod
|
||||||
|
This repository supports contribution using [gitpod](https://gitpod.io) which is online IDE using [Theia](https://github.com/eclipse-theia/theia).
|
||||||
|
|
||||||
|
To open-up the environment simple natigate on https://gitpod.io/#https://github.com/rstacruz/cheatsheets
|
||||||
|
|
||||||
|
Or using a button:<br>
|
||||||
|
[](https://gitpod.io/#https://github.com/rstacruz/cheatsheets)
|
||||||
|
|
||||||
|
### Preview built website
|
||||||
|
To preview the website you need to first build it then you can navigate to file that you are trying to contribute and preview directly.
|
||||||
|
|
||||||
|
<img src='_docs/images/gitpod_preview_tut.png' width=828 height=459/>
|
||||||
|
|
||||||
|
|
||||||
## Starting a local instance
|
## Starting a local instance
|
||||||
|
|
||||||
This starts Jekyll and Webpack. This requires recent versions of [Node.js], [Yarn], [Ruby] and [Bundler] installed.
|
This starts Jekyll and Webpack. This requires recent versions of [Node.js], [Yarn], [Ruby] and [Bundler] installed.
|
||||||
|
|
|
@ -17,3 +17,5 @@
|
||||||
---
|
---
|
||||||
|
|
||||||
See [CONTRIBUTING.md](CONTRIBUTING.md) for developer notes.
|
See [CONTRIBUTING.md](CONTRIBUTING.md) for developer notes.
|
||||||
|
|
||||||
|
[](https://gitpod.io/#https://github.com/rstacruz/cheatsheets)
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 504 KiB |
|
@ -33,7 +33,7 @@ Used by [Moment.js](http://momentjs.com/docs/#/displaying/) and [date-fns/format
|
||||||
| `YYYY` | `2013` | |
|
| `YYYY` | `2013` | |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `M` | `1`..`12` _(Jan is 1)_ | **Month** |
|
| `M` | `1`..`12` _(Jan is 1)_ | **Month** |
|
||||||
| `Mo` | `1st`..`31st` | |
|
| `Mo` | `1st`..`12th` | |
|
||||||
| `MM` | `01`..`12` _(Jan is 1)_ | |
|
| `MM` | `01`..`12` _(Jan is 1)_ | |
|
||||||
| `MMM` | `Jan` | |
|
| `MMM` | `Jan` | |
|
||||||
| `MMMM` | `January` | |
|
| `MMMM` | `January` | |
|
||||||
|
|
|
@ -45,7 +45,7 @@ See: [Getting started](http://docs.ansible.com/ansible/latest/intro_getting_star
|
||||||
This is a list of hosts you want to manage, grouped into groups. (Hint: try
|
This is a list of hosts you want to manage, grouped into groups. (Hint: try
|
||||||
using `localhost ansible_connection=local` to deploy to your local machine.)
|
using `localhost ansible_connection=local` to deploy to your local machine.)
|
||||||
|
|
||||||
See: [Intro to Inventory](http://docs.ansible.com/ansible/latest/playbooks_intro.html)
|
See: [Intro to Inventory](http://docs.ansible.com/ansible/latest/intro_inventory.html)
|
||||||
|
|
||||||
### Playbook
|
### Playbook
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ See: [Intro to Inventory](http://docs.ansible.com/ansible/latest/playbooks_intro
|
||||||
gem: name=bundler state=latest
|
gem: name=bundler state=latest
|
||||||
```
|
```
|
||||||
|
|
||||||
See: [Intro to Playbooks](http://docs.ansible.com/ansible/latest/intro_inventory.html)
|
See: [Intro to Playbooks](http://docs.ansible.com/ansible/latest/playbooks_intro.html)
|
||||||
|
|
||||||
## Running
|
## Running
|
||||||
|
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
|
@ -9,6 +9,7 @@ layout: 2017/sheet
|
||||||
```
|
```
|
||||||
aws ec2 describe-instances
|
aws ec2 describe-instances
|
||||||
aws ec2 start-instances --instance-ids i-12345678c
|
aws ec2 start-instances --instance-ids i-12345678c
|
||||||
|
aws ec2 terminate-instances --instance-ids i-12345678c
|
||||||
```
|
```
|
||||||
|
|
||||||
### S3
|
### S3
|
||||||
|
@ -37,6 +38,13 @@ brew install awscli
|
||||||
aws configure
|
aws configure
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Configuration profiles
|
||||||
|
|
||||||
|
```
|
||||||
|
aws configure --profile project1
|
||||||
|
aws configure --profile project2
|
||||||
|
```
|
||||||
|
|
||||||
## Elastic Beanstalk
|
## Elastic Beanstalk
|
||||||
|
|
||||||
### Configuration
|
### Configuration
|
||||||
|
|
43
bash.md
43
bash.md
|
@ -3,7 +3,7 @@ title: Bash scripting
|
||||||
category: CLI
|
category: CLI
|
||||||
layout: 2017/sheet
|
layout: 2017/sheet
|
||||||
tags: [Featured]
|
tags: [Featured]
|
||||||
updated: 2019-03-23
|
updated: 2019-10-02
|
||||||
keywords:
|
keywords:
|
||||||
- Variables
|
- Variables
|
||||||
- Functions
|
- Functions
|
||||||
|
@ -389,18 +389,6 @@ Note that `[[` is actually a command/program that returns either `0` (true) or `
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
```bash
|
|
||||||
if ping -c 1 google.com; then
|
|
||||||
echo "It appears you have a working internet connection"
|
|
||||||
fi
|
|
||||||
````
|
|
||||||
|
|
||||||
```bash
|
|
||||||
if grep -q 'foo' ~/.bash_history; then
|
|
||||||
echo "You appear to have typed 'foo' in the past"
|
|
||||||
fi
|
|
||||||
```
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# String
|
# String
|
||||||
if [[ -z "$string" ]]; then
|
if [[ -z "$string" ]]; then
|
||||||
|
@ -424,7 +412,7 @@ if [[ "$A" == "$B" ]]
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Regex
|
# Regex
|
||||||
if [[ "A" =~ "." ]]
|
if [[ "A" =~ . ]]
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
@ -547,11 +535,11 @@ set -o nounset # Exposes unset variables
|
||||||
### Glob options
|
### Glob options
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
set -o nullglob # Non-matching globs are removed ('*.foo' => '')
|
shopt -s nullglob # Non-matching globs are removed ('*.foo' => '')
|
||||||
set -o failglob # Non-matching globs throw errors
|
shopt -s failglob # Non-matching globs throw errors
|
||||||
set -o nocaseglob # Case insensitive globs
|
shopt -s nocaseglob # Case insensitive globs
|
||||||
set -o globdots # Wildcards match dotfiles ("*.sh" => ".foo.sh")
|
shopt -s dotglob # Wildcards match dotfiles ("*.sh" => ".foo.sh")
|
||||||
set -o globstar # Allow ** for recursive matches ('lib/**/*.rb' => 'lib/a/b/c.rb')
|
shopt -s globstar # Allow ** for recursive matches ('lib/**/*.rb' => 'lib/a/b/c.rb')
|
||||||
```
|
```
|
||||||
|
|
||||||
Set `GLOBIGNORE` as a colon-separated list of patterns to be removed from glob
|
Set `GLOBIGNORE` as a colon-separated list of patterns to be removed from glob
|
||||||
|
@ -735,6 +723,7 @@ read -n 1 ans # Just one character
|
||||||
| `$?` | Exit status of last task |
|
| `$?` | Exit status of last task |
|
||||||
| `$!` | PID of last background task |
|
| `$!` | PID of last background task |
|
||||||
| `$$` | PID of shell |
|
| `$$` | PID of shell |
|
||||||
|
| `$0` | Filename of the shell script |
|
||||||
|
|
||||||
See [Special parameters](http://wiki.bash-hackers.org/syntax/shellvars#special_parameters_and_shell_variables).
|
See [Special parameters](http://wiki.bash-hackers.org/syntax/shellvars#special_parameters_and_shell_variables).
|
||||||
|
|
||||||
|
@ -748,6 +737,22 @@ cd -
|
||||||
pwd # /home/user/foo
|
pwd # /home/user/foo
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Check for command's result
|
||||||
|
|
||||||
|
```bash
|
||||||
|
if ping -c 1 google.com; then
|
||||||
|
echo "It appears you have a working internet connection"
|
||||||
|
fi
|
||||||
|
```
|
||||||
|
|
||||||
|
### Grep check
|
||||||
|
|
||||||
|
```bash
|
||||||
|
if grep -q 'foo' ~/.bash_history; then
|
||||||
|
echo "You appear to have typed 'foo' in the past"
|
||||||
|
fi
|
||||||
|
```
|
||||||
|
|
||||||
## Also see
|
## Also see
|
||||||
{: .-one-column}
|
{: .-one-column}
|
||||||
|
|
||||||
|
|
|
@ -217,7 +217,7 @@ find('#x').fill_in('Street', with: 'Hello')
|
||||||
### Scripting
|
### Scripting
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
execute_script('$("input").trigger('change')')
|
execute_script('$("input").trigger("change")')
|
||||||
evaluate_script('window.ga')
|
evaluate_script('window.ga')
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
10
chef.md
10
chef.md
|
@ -14,26 +14,26 @@ $ sudo apt-get install curl
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ curl -L https://www.opscode.com/chef/install.sh | bash
|
$ curl -L https://omnitruck.chef.io/install.sh | sudo bash
|
||||||
Thank you for installing Chef!
|
Thank you for installing Chef!
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ chef-solo -v
|
$ chef-solo -v
|
||||||
...
|
...
|
||||||
Chef: 11.4.0
|
Chef: 14.5.33
|
||||||
```
|
```
|
||||||
|
|
||||||
### Start the cookbook
|
### Start the cookbook
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
wget http://github.com/opscode/chef-repo/tarball/master -O - | tar xzf - --strip-components=1
|
wget http://github.com/chef-cookbooks/chef-repo/tarball/master -O - | tar xzf - --strip-components=1
|
||||||
```
|
```
|
||||||
|
|
||||||
### Knife
|
### Knife
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ knife cookbook site download mysql
|
$ knife supermarket download mysql
|
||||||
```
|
```
|
||||||
|
|
||||||
### Invoking chef-solo
|
### Invoking chef-solo
|
||||||
|
@ -105,5 +105,5 @@ end
|
||||||
|
|
||||||
## Also see
|
## Also see
|
||||||
|
|
||||||
* [Getting started with Chef](http://gettingstartedwithchef.com/) _(gettingstartedwithchef.com)_
|
* [Learn Chef Rally](https://learn.chef.io) _(learn.chef.io)_
|
||||||
* [install_from_source.rb recipe](https://github.com/mdxp/nodejs-cookbook/blob/master/recipes/install_from_source.rb) _(github.com)_
|
* [install_from_source.rb recipe](https://github.com/mdxp/nodejs-cookbook/blob/master/recipes/install_from_source.rb) _(github.com)_
|
||||||
|
|
24
css.md
24
css.md
|
@ -13,6 +13,7 @@ keywords:
|
||||||
---
|
---
|
||||||
|
|
||||||
## Basics
|
## Basics
|
||||||
|
|
||||||
{: .-three-column}
|
{: .-three-column}
|
||||||
|
|
||||||
### Selectors
|
### Selectors
|
||||||
|
@ -22,10 +23,12 @@ keywords:
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
{: .-setup}
|
{: .-setup}
|
||||||
|
|
||||||
| Selector | Description |
|
| Selector | Description |
|
||||||
| ----------------- | ----------- |
|
| ----------------- | ------------ |
|
||||||
|
| `*` | All elements |
|
||||||
| `div` | Element |
|
| `div` | Element |
|
||||||
| `.class` | Class |
|
| `.class` | Class |
|
||||||
| `#id` | ID |
|
| `#id` | ID |
|
||||||
|
@ -40,6 +43,7 @@ keywords:
|
||||||
| `.parent > .child` | Direct descendant |
|
| `.parent > .child` | Direct descendant |
|
||||||
| `.child + .sibling` | Adjacent sibling |
|
| `.child + .sibling` | Adjacent sibling |
|
||||||
| `.child ~ .sibling` | Far sibling |
|
| `.child ~ .sibling` | Far sibling |
|
||||||
|
| `.class1.class2` | Have both classes |
|
||||||
|
|
||||||
### Attribute selectors
|
### Attribute selectors
|
||||||
|
|
||||||
|
@ -55,7 +59,7 @@ keywords:
|
||||||
### Pseudo-classes
|
### Pseudo-classes
|
||||||
|
|
||||||
| Selector | Description |
|
| Selector | Description |
|
||||||
| -------------------- | ------------------------ |
|
| -------------------- | ------------------------------------------ |
|
||||||
| `:target` | eg, `h2#foo:target` |
|
| `:target` | eg, `h2#foo:target` |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| `:disabled` | |
|
| `:disabled` | |
|
||||||
|
@ -69,6 +73,11 @@ keywords:
|
||||||
| `:nth-last-child(2)` | |
|
| `:nth-last-child(2)` | |
|
||||||
| `:nth-of-type(2)` | |
|
| `:nth-of-type(2)` | |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
|
| `:checked` | Checked inputs |
|
||||||
|
| `:disabled` | Disabled elements |
|
||||||
|
| `:default` | Default element in a group |
|
||||||
|
| --- | --- |
|
||||||
|
| `:empty` | Elements without children |
|
||||||
|
|
||||||
### Pseudo-class variations
|
### Pseudo-class variations
|
||||||
|
|
||||||
|
@ -83,9 +92,11 @@ keywords:
|
||||||
| `:last-child` |
|
| `:last-child` |
|
||||||
| `:nth-child(2)` |
|
| `:nth-child(2)` |
|
||||||
| `:only-child` |
|
| `:only-child` |
|
||||||
|
|
||||||
{: .-left-align}
|
{: .-left-align}
|
||||||
|
|
||||||
## Fonts
|
## Fonts
|
||||||
|
|
||||||
{: .-left-reference}
|
{: .-left-reference}
|
||||||
|
|
||||||
### Properties
|
### Properties
|
||||||
|
@ -103,15 +114,18 @@ keywords:
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| `text-align:` | `left` `right` `center` `justify` |
|
| `text-align:` | `left` `right` `center` `justify` |
|
||||||
| `text-transform:` | `capitalize` `uppercase` `lowercase` |
|
| `text-transform:` | `capitalize` `uppercase` `lowercase` |
|
||||||
|
|
||||||
{: .-key-values}
|
{: .-key-values}
|
||||||
|
|
||||||
### Shorthand
|
### Shorthand
|
||||||
|
|
||||||
{: .-prime}
|
{: .-prime}
|
||||||
|
|
||||||
| | style | weight | size (required) | | line-height | family |
|
| | style | weight | size (required) | | line-height | family |
|
||||||
| ------- | -------- | ------ | --------------- | --- | ----------- | ----------------- |
|
| ------- | -------- | ------ | --------------- | --- | ----------- | ----------------- |
|
||||||
| `font:` | `italic` | `400` | `14px` | `/` | `1.5` | `sans-serif` |
|
| `font:` | `italic` | `400` | `14px` | `/` | `1.5` | `sans-serif` |
|
||||||
| | style | weight | size (required) | | line-height | family (required) |
|
| | style | weight | size (required) | | line-height | family (required) |
|
||||||
|
|
||||||
{: .-css-breakdown}
|
{: .-css-breakdown}
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
@ -133,6 +147,7 @@ text-transform: lowercase; /* hello */
|
||||||
```
|
```
|
||||||
|
|
||||||
## Background
|
## Background
|
||||||
|
|
||||||
{: .-left-reference}
|
{: .-left-reference}
|
||||||
|
|
||||||
### Properties
|
### Properties
|
||||||
|
@ -148,6 +163,7 @@ text-transform: lowercase; /* hello */
|
||||||
| `background-clip:` | `border-box` `padding-box` `content-box` |
|
| `background-clip:` | `border-box` `padding-box` `content-box` |
|
||||||
| `background-repeat:` | `no-repeat` `repeat-x` `repeat-y` |
|
| `background-repeat:` | `no-repeat` `repeat-x` `repeat-y` |
|
||||||
| `background-attachment:` | `scroll` `fixed` `local` |
|
| `background-attachment:` | `scroll` `fixed` `local` |
|
||||||
|
|
||||||
{: .-key-values}
|
{: .-key-values}
|
||||||
|
|
||||||
### Shorthand
|
### Shorthand
|
||||||
|
@ -157,6 +173,7 @@ text-transform: lowercase; /* hello */
|
||||||
| `background:` | `#ff0` | `url(bg.jpg)` | `left` | `top` | `/` | `100px` `auto` | `no-repeat` | `fixed;` |
|
| `background:` | `#ff0` | `url(bg.jpg)` | `left` | `top` | `/` | `100px` `auto` | `no-repeat` | `fixed;` |
|
||||||
| `background:` | `#abc` | `url(bg.png)` | `center` | `center` | `/` | `cover` | `repeat-x` | `local;` |
|
| `background:` | `#abc` | `url(bg.png)` | `center` | `center` | `/` | `cover` | `repeat-x` | `local;` |
|
||||||
| | color | image | positionX | positionY | | size | repeat | attachment |
|
| | color | image | positionX | positionY | | size | repeat | attachment |
|
||||||
|
|
||||||
{: .-css-breakdown}
|
{: .-css-breakdown}
|
||||||
|
|
||||||
### Multiple backgrounds
|
### Multiple backgrounds
|
||||||
|
@ -167,6 +184,7 @@ background: linear-gradient(to bottom, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)),
|
||||||
```
|
```
|
||||||
|
|
||||||
## Animation
|
## Animation
|
||||||
|
|
||||||
{: .-left-reference}
|
{: .-left-reference}
|
||||||
|
|
||||||
### Properties
|
### Properties
|
||||||
|
@ -182,6 +200,7 @@ background: linear-gradient(to bottom, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)),
|
||||||
| `animation-direction:` | `normal` `reverse` `alternate` `alternate-reverse` |
|
| `animation-direction:` | `normal` `reverse` `alternate` `alternate-reverse` |
|
||||||
| `animation-fill-mode:` | `none` `forwards` `backwards` `both` `initial` `inherit` |
|
| `animation-fill-mode:` | `none` `forwards` `backwards` `both` `initial` `inherit` |
|
||||||
| `animation-play-state:` | `normal` `reverse` `alternate` `alternate-reverse` |
|
| `animation-play-state:` | `normal` `reverse` `alternate` `alternate-reverse` |
|
||||||
|
|
||||||
{: .-key-values}
|
{: .-key-values}
|
||||||
|
|
||||||
### Shorthand
|
### Shorthand
|
||||||
|
@ -190,6 +209,7 @@ background: linear-gradient(to bottom, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)),
|
||||||
| ------------ | -------- | -------- | --------------- | ------- | ---------- | ------------------- | --------- | ---------- |
|
| ------------ | -------- | -------- | --------------- | ------- | ---------- | ------------------- | --------- | ---------- |
|
||||||
| `animation:` | `bounce` | `300ms` | `linear` | `100ms` | `infinite` | `alternate-reverse` | `both` | `reverse` |
|
| `animation:` | `bounce` | `300ms` | `linear` | `100ms` | `infinite` | `alternate-reverse` | `both` | `reverse` |
|
||||||
| | name | duration | timing-function | delay | count | direction | fill-mode | play-state |
|
| | name | duration | timing-function | delay | count | direction | fill-mode | play-state |
|
||||||
|
|
||||||
{: .-css-breakdown}
|
{: .-css-breakdown}
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
|
@ -54,6 +54,8 @@ docker-compose down
|
||||||
web:
|
web:
|
||||||
# build from Dockerfile
|
# build from Dockerfile
|
||||||
build: .
|
build: .
|
||||||
|
args: # Add build arguments
|
||||||
|
APP_HOME: app
|
||||||
```
|
```
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -77,7 +79,7 @@ web:
|
||||||
```yaml
|
```yaml
|
||||||
ports:
|
ports:
|
||||||
- "3000"
|
- "3000"
|
||||||
- "8000:80" # guest:host
|
- "8000:80" # host:container
|
||||||
```
|
```
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -214,3 +216,17 @@ networks:
|
||||||
external:
|
external:
|
||||||
name: frontend
|
name: frontend
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Volume
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# Mount host paths or named volumes, specified as sub-options to a service
|
||||||
|
db:
|
||||||
|
image: postgres:latest
|
||||||
|
volumes:
|
||||||
|
- "/var/run/postgres/postgres.sock:/var/run/postgres/postgres.sock"
|
||||||
|
- "dbdata:/var/lib/postgresql/data"
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
dbdata:
|
||||||
|
```
|
||||||
|
|
60
docker.md
60
docker.md
|
@ -12,6 +12,7 @@ Manage images
|
||||||
```yml
|
```yml
|
||||||
docker build [options] .
|
docker build [options] .
|
||||||
-t "app/container_name" # name
|
-t "app/container_name" # name
|
||||||
|
--build-arg APP_HOME=$APP_HOME # Set build-time variables
|
||||||
```
|
```
|
||||||
|
|
||||||
Create an `image` from a Dockerfile.
|
Create an `image` from a Dockerfile.
|
||||||
|
@ -24,6 +25,11 @@ docker run [options] IMAGE
|
||||||
# see `docker create` for options
|
# see `docker create` for options
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
|
||||||
|
```
|
||||||
|
$ docker run -it debian:buster /bin/bash
|
||||||
|
```
|
||||||
Run a command in an `image`.
|
Run a command in an `image`.
|
||||||
|
|
||||||
Manage containers
|
Manage containers
|
||||||
|
@ -97,6 +103,18 @@ $ docker kill $ID
|
||||||
|
|
||||||
Manage `container`s using ps/kill.
|
Manage `container`s using ps/kill.
|
||||||
|
|
||||||
|
|
||||||
|
### `docker logs`
|
||||||
|
|
||||||
|
```
|
||||||
|
$ docker logs $ID
|
||||||
|
$ docker logs $ID 2>&1 | less
|
||||||
|
$ docker logs -f $ID # Follow log output
|
||||||
|
```
|
||||||
|
|
||||||
|
See what's being logged in an `container`.
|
||||||
|
|
||||||
|
|
||||||
Images
|
Images
|
||||||
------
|
------
|
||||||
|
|
||||||
|
@ -123,6 +141,48 @@ docker rmi b750fe78269d
|
||||||
|
|
||||||
Deletes `image`s.
|
Deletes `image`s.
|
||||||
|
|
||||||
|
## Clean up
|
||||||
|
|
||||||
|
### Clean all
|
||||||
|
|
||||||
|
```sh
|
||||||
|
docker system prune
|
||||||
|
```
|
||||||
|
|
||||||
|
Cleans up dangling images, containers, volumes, and networks (ie, not associated with a container)
|
||||||
|
|
||||||
|
```sh
|
||||||
|
docker system prune -a
|
||||||
|
```
|
||||||
|
|
||||||
|
Additionally remove any stopped containers and all unused images (not just dangling images)
|
||||||
|
|
||||||
|
### Containers
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# Stop all running containers
|
||||||
|
docker stop $(docker ps -a -q)
|
||||||
|
|
||||||
|
# Delete stopped containers
|
||||||
|
docker container prune
|
||||||
|
```
|
||||||
|
|
||||||
|
### Images
|
||||||
|
|
||||||
|
```sh
|
||||||
|
docker image prune [-a]
|
||||||
|
```
|
||||||
|
|
||||||
|
Delete all the images
|
||||||
|
|
||||||
|
### Volumes
|
||||||
|
|
||||||
|
```sh
|
||||||
|
docker volume prune
|
||||||
|
```
|
||||||
|
|
||||||
|
Delete all the volumes
|
||||||
|
|
||||||
Also see
|
Also see
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,11 @@ ENV APP_HOME /myapp
|
||||||
RUN mkdir $APP_HOME
|
RUN mkdir $APP_HOME
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```docker
|
||||||
|
ARG APP_HOME=""
|
||||||
|
RUN mkdir $APP_HOME
|
||||||
|
```
|
||||||
|
|
||||||
### Initialization
|
### Initialization
|
||||||
|
|
||||||
```docker
|
```docker
|
||||||
|
|
|
@ -88,7 +88,7 @@ expect(wrap.state('show')).toEqual(true)
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
expect('name' in wrap.props()).toEqual(true)
|
expect('name' in wrap.props()).toEqual('Moe')
|
||||||
expect('show' in wrap.state()).toEqual(true)
|
expect('show' in wrap.state()).toEqual(true)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -219,8 +219,8 @@ wrap.last() // → ReactWrapper
|
||||||
|
|
||||||
```js
|
```js
|
||||||
wrap.get(0) // → ReactElement
|
wrap.get(0) // → ReactElement
|
||||||
wrap.getNode() // → ReactElement
|
wrap.getElement() // → ReactElement
|
||||||
wrap.getNodes() // → Array<ReactElement>
|
wrap.getElements() // → Array<ReactElement>
|
||||||
wrap.getDOMNode() // → DOMComponent
|
wrap.getDOMNode() // → DOMComponent
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
2
es6.md
2
es6.md
|
@ -415,7 +415,7 @@ numbers.map(n => n * 2)
|
||||||
// Same as: numbers.map(function (n) { return n * 2 })
|
// Same as: numbers.map(function (n) { return n * 2 })
|
||||||
numbers.map(n => ({
|
numbers.map(n => ({
|
||||||
result: n * 2
|
result: n * 2
|
||||||
})
|
}))
|
||||||
// Implicitly returning objects requires parentheses around the object
|
// Implicitly returning objects requires parentheses around the object
|
||||||
```
|
```
|
||||||
{: data-line="1,4,5,6"}
|
{: data-line="1,4,5,6"}
|
||||||
|
|
19
find.md
19
find.md
|
@ -2,6 +2,7 @@
|
||||||
title: Find
|
title: Find
|
||||||
category: CLI
|
category: CLI
|
||||||
layout: 2017/sheet
|
layout: 2017/sheet
|
||||||
|
updated: 2019-10-01
|
||||||
---
|
---
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
@ -48,6 +49,20 @@ find <path> <conditions> <actions>
|
||||||
-newerXt "1 hour ago" # [t]imestamp
|
-newerXt "1 hour ago" # [t]imestamp
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Access time conditions
|
||||||
|
|
||||||
|
```bash
|
||||||
|
-atime 0 # Last accessed between now and 24 hours ago
|
||||||
|
-atime +0 # Accessed more than 24 hours ago
|
||||||
|
-atime 1 # Accessed between 24 and 48 hours ago
|
||||||
|
-atime +1 # Accessed more than 48 hours ago
|
||||||
|
-atime -1 # Accessed less than 24 hours ago (same a 0)
|
||||||
|
-ctime -6h30m # File status changed within the last 6 hours and 30 minutes
|
||||||
|
-mtime +1w # Last modified more than 1 week ago
|
||||||
|
```
|
||||||
|
|
||||||
|
These conditions only work in MacOS and BSD-like systems (no GNU/Linux support).
|
||||||
|
|
||||||
### Condition flow
|
### Condition flow
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
@ -73,3 +88,7 @@ find . -name '*.jpg' -exec rm {} \;
|
||||||
```bash
|
```bash
|
||||||
find . -newerBt "24 hours ago"
|
find . -newerBt "24 hours ago"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
find . -type f -mtime +29 # find files modified more than 30 days ago
|
||||||
|
```
|
||||||
|
|
14
go.md
14
go.md
|
@ -422,10 +422,24 @@ func main() {
|
||||||
fmt.Println("Working...")
|
fmt.Println("Working...")
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
{: data-line="2,3,4"}
|
{: data-line="2,3,4"}
|
||||||
|
|
||||||
Lambdas are better suited for defer blocks.
|
Lambdas are better suited for defer blocks.
|
||||||
|
|
||||||
|
```go
|
||||||
|
func main() {
|
||||||
|
var d = int64(0)
|
||||||
|
defer func(d *int64) {
|
||||||
|
fmt.Printf("& %v Unix Sec\n", *d)
|
||||||
|
}(&d)
|
||||||
|
fmt.Print("Done ")
|
||||||
|
d = time.Now().Unix()
|
||||||
|
}
|
||||||
|
```
|
||||||
|
{: data-line="3,4,5"}
|
||||||
|
The defer func uses current value of d, unless we use a pointer to get final value at end of main.
|
||||||
|
|
||||||
## Structs
|
## Structs
|
||||||
{: .-three-column}
|
{: .-three-column}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ category: CLI
|
||||||
| `brew update` | Update brew and cask |
|
| `brew update` | Update brew and cask |
|
||||||
| `brew list` | List installed |
|
| `brew list` | List installed |
|
||||||
| `brew outdated` | What's due for upgrades? |
|
| `brew outdated` | What's due for upgrades? |
|
||||||
|
| `brew doctor` | Diagnose brew issues |
|
||||||
|
|
||||||
### Brew Cask commands
|
### Brew Cask commands
|
||||||
|
|
||||||
|
@ -50,5 +51,4 @@ Cask commands are used for interacting with graphical applications.
|
||||||
|
|
||||||
* [Homebrew homepage](https://brew.sh/) _brew.sh_
|
* [Homebrew homepage](https://brew.sh/) _brew.sh_
|
||||||
* [Homebrew docs](https://docs.brew.sh) _docs.brew.sh_
|
* [Homebrew docs](https://docs.brew.sh) _docs.brew.sh_
|
||||||
* [Homebrew Cask](https://caskroom.github.io/) _caskroom.github.io_
|
|
||||||
{: .-also-see}
|
{: .-also-see}
|
||||||
|
|
23
jsdoc.md
23
jsdoc.md
|
@ -31,7 +31,7 @@ See: <http://usejsdoc.org/index.html>
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| `@param {string=} n` | Optional |
|
| `@param {string=} n` | Optional |
|
||||||
| `@param {string} [n]` | Optional |
|
| `@param {string} [n]` | Optional |
|
||||||
| `@param {(string\|number)} n`| Multiple types |
|
| `@param {(string|number)} n` | Multiple types |
|
||||||
| `@param {*} n` | Any type |
|
| `@param {*} n` | Any type |
|
||||||
| `@param {...string} n` | Repeatable arguments |
|
| `@param {...string} n` | Repeatable arguments |
|
||||||
| `@param {string} [n="hi"]` | Optional with default |
|
| `@param {string} [n="hi"]` | Optional with default |
|
||||||
|
@ -80,6 +80,27 @@ function play (song) {
|
||||||
|
|
||||||
See: <http://usejsdoc.org/tags-typedef.html>
|
See: <http://usejsdoc.org/tags-typedef.html>
|
||||||
|
|
||||||
|
### Typedef Shorthand
|
||||||
|
|
||||||
|
```js
|
||||||
|
/**
|
||||||
|
* A song
|
||||||
|
* @typedef {{title: string, artist: string, year: number}} Song
|
||||||
|
*/
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
/**
|
||||||
|
* Plays a song
|
||||||
|
* @param {Song} song - The {@link Song} to be played
|
||||||
|
*/
|
||||||
|
|
||||||
|
function play (song) {
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
See: <http://usejsdoc.org/tags-typedef.html>
|
||||||
|
|
||||||
### Importing types
|
### Importing types
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|
15
linux.md
15
linux.md
|
@ -12,6 +12,21 @@ title: Linux
|
||||||
|
|
||||||
username ALL=(ALL) NOPASSWD:/sbin/restart whatever
|
username ALL=(ALL) NOPASSWD:/sbin/restart whatever
|
||||||
|
|
||||||
|
### Display the amount of available disk space
|
||||||
|
|
||||||
|
```sh
|
||||||
|
df
|
||||||
|
df -h # human-readable format
|
||||||
|
df -a # all filesystems
|
||||||
|
```
|
||||||
|
|
||||||
|
### Display disk usage
|
||||||
|
|
||||||
|
```sh
|
||||||
|
du
|
||||||
|
du -hsx * | sort -rh | head -10 # largest 10 folders
|
||||||
|
```
|
||||||
|
|
||||||
### Answer yes in a bash script
|
### Answer yes in a bash script
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
2
lua.md
2
lua.md
|
@ -61,7 +61,7 @@ title: Lua
|
||||||
|
|
||||||
if condition then
|
if condition then
|
||||||
print("yes")
|
print("yes")
|
||||||
elsif condition then
|
elseif condition then
|
||||||
print("maybe")
|
print("maybe")
|
||||||
else
|
else
|
||||||
print("no")
|
print("no")
|
||||||
|
|
|
@ -37,7 +37,7 @@ also:
|
||||||
## Command prefixes
|
## Command prefixes
|
||||||
|
|
||||||
| Prefix | Description |
|
| Prefix | Description |
|
||||||
| ------ | ----------- |
|
| ------ | ------------------------------------------- |
|
||||||
| `-` | Ignore errors |
|
| `-` | Ignore errors |
|
||||||
| `@` | Don't print command |
|
| `@` | Don't print command |
|
||||||
| `+` | Run even if Make is in 'don't execute' mode |
|
| `+` | Run even if Make is in 'don't execute' mode |
|
||||||
|
@ -121,4 +121,6 @@ deploy:
|
||||||
|
|
||||||
## Further reading
|
## Further reading
|
||||||
|
|
||||||
* [isaacs's Makefile](https://gist.github.com/isaacs/62a2d1825d04437c6f08)
|
- [isaacs's Makefile](https://gist.github.com/isaacs/62a2d1825d04437c6f08)
|
||||||
|
- [Your Makefiles are wrong](https://tech.davis-hansson.com/p/make/)
|
||||||
|
- [Manual](https://www.gnu.org/software/make/manual/html_node/index.html)
|
||||||
|
|
11
npm.md
11
npm.md
|
@ -12,11 +12,13 @@ updated: 2017-10-27
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| `npm i` | Alias for `npm install` |
|
| `npm i` | Alias for `npm install` |
|
||||||
| `npm install` | Install everything in package.json |
|
| `npm install` | Install everything in package.json |
|
||||||
|
| `npm install --production` | Install everything in package.json, except devDependecies |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| `npm install lodash` | Install a package |
|
| `npm install lodash` | Install a package |
|
||||||
| `npm install --save-dev lodash` | Install as devDependency |
|
| `npm install --save-dev lodash` | Install as devDependency |
|
||||||
| `npm install --save-exact lodash` | Install with exact |
|
| `npm install --save-exact lodash` | Install with exact |
|
||||||
|
|
||||||
|
|
||||||
`--save` is the default as of npm@5. Previously, using `npm install` without `--save` doesn't update package.json.
|
`--save` is the default as of npm@5. Previously, using `npm install` without `--save` doesn't update package.json.
|
||||||
|
|
||||||
### Install names
|
### Install names
|
||||||
|
@ -39,6 +41,15 @@ updated: 2017-10-27
|
||||||
| `npm i ./archive.tgz` | Tarball |
|
| `npm i ./archive.tgz` | Tarball |
|
||||||
| `npm i https://site.com/archive.tgz` | Tarball via HTTP |
|
| `npm i https://site.com/archive.tgz` | Tarball via HTTP |
|
||||||
|
|
||||||
|
### Listing
|
||||||
|
|
||||||
|
| Command | Description |
|
||||||
|
| --- | --- |
|
||||||
|
| `npm list` | Lists the installed versions of all dependencies in this software |
|
||||||
|
| `npm list -g --depth 0` | Lists the installed versions of all globally installed packages |
|
||||||
|
| `npm view` | Lists the latest versions of all dependencies in this software |
|
||||||
|
| `npm outdated` | Lists only the dependencies in this software which are outdated |
|
||||||
|
|
||||||
### Updating
|
### Updating
|
||||||
|
|
||||||
| Command | Description |
|
| Command | Description |
|
||||||
|
|
42
python.md
42
python.md
|
@ -58,6 +58,7 @@ category: Python
|
||||||
string.replace("-", " ")
|
string.replace("-", " ")
|
||||||
",".join(list)
|
",".join(list)
|
||||||
"hi {0}".format('j')
|
"hi {0}".format('j')
|
||||||
|
"hi {name}" # same as "hi {}".format('name')
|
||||||
str.find(",")
|
str.find(",")
|
||||||
str.index(",") # same, but raises IndexError
|
str.index(",") # same, but raises IndexError
|
||||||
str.count(",")
|
str.count(",")
|
||||||
|
@ -101,3 +102,44 @@ category: Python
|
||||||
expr.match(...)
|
expr.match(...)
|
||||||
expr.sub(...)
|
expr.sub(...)
|
||||||
|
|
||||||
|
## File manipulation
|
||||||
|
|
||||||
|
### Reading
|
||||||
|
|
||||||
|
```py
|
||||||
|
file = open("hello.txt", "r") # open in read mode 'r'
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
print(file.read()) # read the file
|
||||||
|
print fh.readline() # Reading line by line
|
||||||
|
```
|
||||||
|
|
||||||
|
### Writing (overwrite)
|
||||||
|
|
||||||
|
```py
|
||||||
|
file = open("hello.txt", "w") # open in write mode 'w'
|
||||||
|
write("Hello World")
|
||||||
|
|
||||||
|
text_lines = ["First line", "Second line", "Last line"]
|
||||||
|
file.writelines(text_lines)
|
||||||
|
|
||||||
|
file.close()
|
||||||
|
```
|
||||||
|
|
||||||
|
### Writing (append)
|
||||||
|
|
||||||
|
```py
|
||||||
|
file = open("Hello.txt", "a") # open in append mode
|
||||||
|
write("Hello World again")
|
||||||
|
file.close()
|
||||||
|
```
|
||||||
|
|
||||||
|
### Context manager
|
||||||
|
|
||||||
|
```py
|
||||||
|
with open("welcome.txt", "r") as file:
|
||||||
|
# 'file' refers directly to the "welcome.txt"
|
||||||
|
data = file.read()
|
||||||
|
```
|
||||||
|
|
||||||
|
It closes the file automatically, no need for `file.close()`.
|
||||||
|
|
|
@ -247,11 +247,11 @@ Associations
|
||||||
belongs_to :parent, :foreign_key => 'parent_id' class_name: 'Folder'
|
belongs_to :parent, :foreign_key => 'parent_id' class_name: 'Folder'
|
||||||
has_many :folders, :foreign_key => 'parent_id', class_name: 'Folder'
|
has_many :folders, :foreign_key => 'parent_id', class_name: 'Folder'
|
||||||
|
|
||||||
has_many :comments, :order => "posted_on"
|
has_many :comments, -> { order('posted_on DESC') }
|
||||||
has_many :comments, :include => :author
|
has_many :comments, :include => :author
|
||||||
has_many :people, :class_name => "Person"
|
has_many :people, :class_name => "Person"
|
||||||
has_many :people, :conditions => "deleted = 0"
|
has_many :people, :conditions => "deleted = 0"
|
||||||
has_many :tracks, :order => "position"
|
has_many :tracks, -> { order(:position) }
|
||||||
has_many :comments, :dependent => :nullify
|
has_many :comments, :dependent => :nullify
|
||||||
has_many :comments, :dependent => :destroy
|
has_many :comments, :dependent => :destroy
|
||||||
has_many :tags, :as => :taggable
|
has_many :tags, :as => :taggable
|
||||||
|
|
145
react.md
145
react.md
|
@ -312,6 +312,151 @@ Called when parents change properties and `.setState()`. These are not called fo
|
||||||
|
|
||||||
See: [Component specs](http://facebook.github.io/react/docs/component-specs.html#updating-componentwillreceiveprops)
|
See: [Component specs](http://facebook.github.io/react/docs/component-specs.html#updating-componentwillreceiveprops)
|
||||||
|
|
||||||
|
Hooks (New)
|
||||||
|
-----------
|
||||||
|
{: .-two-column}
|
||||||
|
|
||||||
|
### State Hook
|
||||||
|
|
||||||
|
```jsx
|
||||||
|
import React, { useState } from 'react';
|
||||||
|
|
||||||
|
function Example() {
|
||||||
|
// Declare a new state variable, which we'll call "count"
|
||||||
|
const [count, setCount] = useState(0);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<p>You clicked {count} times</p>
|
||||||
|
<button onClick={() => setCount(count + 1)}>
|
||||||
|
Click me
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
{: data-line="5,10"}
|
||||||
|
|
||||||
|
Hooks are a new addition in React 16.8.
|
||||||
|
|
||||||
|
See: [Hooks at a Glance](https://reactjs.org/docs/hooks-overview.html)
|
||||||
|
|
||||||
|
### Declaring multiple state variables
|
||||||
|
|
||||||
|
```jsx
|
||||||
|
function ExampleWithManyStates() {
|
||||||
|
// Declare multiple state variables!
|
||||||
|
const [age, setAge] = useState(42);
|
||||||
|
const [fruit, setFruit] = useState('banana');
|
||||||
|
const [todos, setTodos] = useState([{ text: 'Learn Hooks' }]);
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Effect hook
|
||||||
|
|
||||||
|
```jsx
|
||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
|
||||||
|
function Example() {
|
||||||
|
const [count, setCount] = useState(0);
|
||||||
|
|
||||||
|
// Similar to componentDidMount and componentDidUpdate:
|
||||||
|
useEffect(() => {
|
||||||
|
// Update the document title using the browser API
|
||||||
|
document.title = `You clicked ${count} times`;
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<p>You clicked {count} times</p>
|
||||||
|
<button onClick={() => setCount(count + 1)}>
|
||||||
|
Click me
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
{: data-line="6,7,8,9,10"}
|
||||||
|
|
||||||
|
If you’re familiar with React class lifecycle methods, you can think of `useEffect` Hook as `componentDidMount`, `componentDidUpdate`, and `componentWillUnmount` combined.
|
||||||
|
|
||||||
|
By default, React runs the effects after every render — including the first render.
|
||||||
|
|
||||||
|
### Building your own hooks
|
||||||
|
|
||||||
|
#### Define FriendStatus
|
||||||
|
```jsx
|
||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
|
||||||
|
function FriendStatus(props) {
|
||||||
|
const [isOnline, setIsOnline] = useState(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
function handleStatusChange(status) {
|
||||||
|
setIsOnline(status.isOnline);
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatAPI.subscribeToFriendStatus(props.friend.id, handleStatusChange);
|
||||||
|
return () => {
|
||||||
|
ChatAPI.unsubscribeFromFriendStatus(props.friend.id, handleStatusChange);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
if (isOnline === null) {
|
||||||
|
return 'Loading...';
|
||||||
|
}
|
||||||
|
return isOnline ? 'Online' : 'Offline';
|
||||||
|
}
|
||||||
|
```
|
||||||
|
{: data-line="11,12,13,14"}
|
||||||
|
|
||||||
|
Effects may also optionally specify how to “clean up” after them by returning a function.
|
||||||
|
|
||||||
|
#### Use FriendStatus
|
||||||
|
|
||||||
|
```jsx
|
||||||
|
function FriendStatus(props) {
|
||||||
|
const isOnline = useFriendStatus(props.friend.id);
|
||||||
|
|
||||||
|
if (isOnline === null) {
|
||||||
|
return 'Loading...';
|
||||||
|
}
|
||||||
|
return isOnline ? 'Online' : 'Offline';
|
||||||
|
}
|
||||||
|
```
|
||||||
|
{: data-line="2"}
|
||||||
|
|
||||||
|
See: [Building Your Own Hooks](https://reactjs.org/docs/hooks-custom.html)
|
||||||
|
|
||||||
|
### Hooks API Reference
|
||||||
|
|
||||||
|
Also see: [Hooks FAQ](https://reactjs.org/docs/hooks-faq.html)
|
||||||
|
|
||||||
|
#### Basic Hooks
|
||||||
|
|
||||||
|
| Hook | Description |
|
||||||
|
| ---------------------------- | ----------------------------------------- |
|
||||||
|
| `useState`_(initialState)_ | |
|
||||||
|
| `useEffect`_(() => { ... })_ | |
|
||||||
|
| `useContext`_(MyContext)_ | value returned from `React.createContext` |
|
||||||
|
|
||||||
|
Full details: [Basic Hooks](https://reactjs.org/docs/hooks-reference.html#basic-hooks)
|
||||||
|
|
||||||
|
#### Additional Hooks
|
||||||
|
|
||||||
|
| Hook | Description |
|
||||||
|
| -------------------------------------------- | ---------------------------------------------------------------------------- |
|
||||||
|
| `useReducer`_(reducer, initialArg, init)_ | |
|
||||||
|
| `useCallback`_(() => { ... })_ | |
|
||||||
|
| `useMemo`_(() => { ... })_ | |
|
||||||
|
| `useRef`_(initialValue)_ | |
|
||||||
|
| `useImperativeHandle`_(ref, () => { ... })_ | |
|
||||||
|
| `useLayoutEffect` | identical to `useEffect`, but it fires synchronously after all DOM mutations |
|
||||||
|
| `useDebugValue`_(value)_ | display a label for custom hooks in React DevTools |
|
||||||
|
|
||||||
|
Full details: [Additional Hooks](https://reactjs.org/docs/hooks-reference.html#additional-hooks)
|
||||||
|
|
||||||
DOM nodes
|
DOM nodes
|
||||||
---------
|
---------
|
||||||
{: .-two-column}
|
{: .-two-column}
|
||||||
|
|
24
regexp.md
24
regexp.md
|
@ -6,18 +6,20 @@ weight: -1
|
||||||
authors:
|
authors:
|
||||||
- github: rizqyhi
|
- github: rizqyhi
|
||||||
- github: izzergh
|
- github: izzergh
|
||||||
updated: 2019-03-24
|
- github: kolapsys
|
||||||
|
- github: samtrion
|
||||||
|
updated: 2019-11-14
|
||||||
description: |
|
description: |
|
||||||
Basic cheatsheets for regular expression
|
Basic cheatsheets for regular expression
|
||||||
---
|
---
|
||||||
|
|
||||||
##
|
## RegExp
|
||||||
{: .-three-column}
|
{: .-three-column}
|
||||||
|
|
||||||
### Character classes
|
### Character classes
|
||||||
|
|
||||||
| Pattern | Description |
|
| Pattern | Description |
|
||||||
| ------- | ------------------------------ |
|
| -------- | ------------------------------------ |
|
||||||
| `.` | Any character, except newline |
|
| `.` | Any character, except newline |
|
||||||
| `\w` | Word |
|
| `\w` | Word |
|
||||||
| `\d` | Digit |
|
| `\d` | Digit |
|
||||||
|
@ -28,11 +30,20 @@ description: |
|
||||||
| `[abc]` | Any of a, b, or c |
|
| `[abc]` | Any of a, b, or c |
|
||||||
| `[a-e]` | Characters between `a` and `e` |
|
| `[a-e]` | Characters between `a` and `e` |
|
||||||
| `[1-9]` | Digit between `1` and `9` |
|
| `[1-9]` | Digit between `1` and `9` |
|
||||||
|
| `[^abc]` | Any character except `a`, `b` or `c` |
|
||||||
|
|
||||||
### Anchors
|
### Anchors
|
||||||
|
|
||||||
| Pattern | Description |
|
| Pattern | Description |
|
||||||
| ------- | ---------------- |
|
| ------- | ----------------------- |
|
||||||
|
| `\G` | Start of match |
|
||||||
|
| `^` | Start of string |
|
||||||
|
| `$` | End of string |
|
||||||
|
| `\A` | Start of string |
|
||||||
|
| `\Z` | End of string |
|
||||||
|
| `\z` | Absolute end of string |
|
||||||
|
| `\b` | A word boundry |
|
||||||
|
| `\B` | Non-word boundry |
|
||||||
| `^abc` | Start with `abc` |
|
| `^abc` | Start with `abc` |
|
||||||
| `abc$` | End with `abc` |
|
| `abc$` | End with `abc` |
|
||||||
|
|
||||||
|
@ -48,8 +59,11 @@ description: |
|
||||||
### Groups
|
### Groups
|
||||||
|
|
||||||
| Pattern | Description |
|
| Pattern | Description |
|
||||||
| ------- | ------------- |
|
| --------- | ------------------------------ |
|
||||||
| `(abc)` | Capture group |
|
| `(abc)` | Capture group |
|
||||||
|
| `(a|b)` | Match `a` or `b` |
|
||||||
|
| `(?:abc)` | Match `abc`, but don't capture |
|
||||||
|
|
||||||
|
|
||||||
### Quantifiers
|
### Quantifiers
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ Note that suffixed versions (`1.2.3-rc1`) are not matched.
|
||||||
|
|
||||||
| Range | Description |
|
| Range | Description |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| `1.2.3 - 2.3.0` | is `>=1.2.3 <=2.3.4` |
|
| `1.2.3 - 2.3.4` | is `>=1.2.3 <=2.3.4` |
|
||||||
|
|
||||||
#### Partial right
|
#### Partial right
|
||||||
|
|
||||||
|
|
|
@ -125,7 +125,7 @@ this.options = { ...this.options, show: true }
|
||||||
|
|
||||||
Mutable operations such as `push()` won't work. You'll need to assign a new copy.
|
Mutable operations such as `push()` won't work. You'll need to assign a new copy.
|
||||||
|
|
||||||
See: [Updating arrays](https://stenciljs.com/docs/handling-arrays)
|
See: [Updating arrays](https://stenciljs.com/docs/reactive-data/#updating-arrays)
|
||||||
|
|
||||||
## Slots
|
## Slots
|
||||||
|
|
||||||
|
|
|
@ -1,35 +1,61 @@
|
||||||
---
|
---
|
||||||
title: Superagent
|
title: Superagent
|
||||||
category: JavaScript libraries
|
category: JavaScript libraries
|
||||||
|
updated: 2018-04-21
|
||||||
|
prism_languages: [javascript]
|
||||||
|
tags:
|
||||||
|
- WIP
|
||||||
---
|
---
|
||||||
|
|
||||||
### Result
|
### Response object
|
||||||
|
```javascript
|
||||||
|
res: {
|
||||||
|
// The HTTP Status Code (see: httpstatuses.com for definitions on HTTP status codes)
|
||||||
|
status: 202,
|
||||||
|
// True when res.status is 2xx
|
||||||
|
ok: true,
|
||||||
|
// True when res.status is 4xx or 5xx
|
||||||
|
error: false,
|
||||||
|
// True when res.status is 4xx
|
||||||
|
clientError: false,
|
||||||
|
// True when res.status is 5xx
|
||||||
|
serverError: false,
|
||||||
|
|
||||||
result == {
|
// True when res.status == 202
|
||||||
ok: true
|
accepted: true,
|
||||||
error: false
|
// True when res.status == 204 || res.status == 1223
|
||||||
|
noContent: false,
|
||||||
|
// True when res.status == 400
|
||||||
|
badRequest: false,
|
||||||
|
// True when res.status == 401
|
||||||
|
unauthorized: false,
|
||||||
|
// True when res.status == 406
|
||||||
|
notAcceptable: false,
|
||||||
|
// True when res.status == 404
|
||||||
|
notFound: false,
|
||||||
|
// True when res.status == 403
|
||||||
|
forbidden: false,
|
||||||
|
|
||||||
// Response
|
// Unparsed response text
|
||||||
body: null
|
text: '{"user":{"username":"JohnDoe","role":"admin"}}'
|
||||||
text: "<!doctype html>..."
|
|
||||||
|
|
||||||
// Headers
|
// Parsed response text (only if response is 'application/json' or 'application/x-www-form-urlencoded'
|
||||||
status: 200
|
body: {
|
||||||
type: "text/html"
|
// Example of parsed object from res.text
|
||||||
charset: "UTF-8"
|
user: {
|
||||||
|
username: 'JohnDoe',
|
||||||
|
role: 'admin'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The content-type (parsed from headers)
|
||||||
|
type: 'application/json'
|
||||||
|
// The charset (parsed from headers)
|
||||||
|
charset: 'UTF-8'
|
||||||
|
// Header object with each header field as a property
|
||||||
headers: {
|
headers: {
|
||||||
'cache-control': 'public',
|
'content-type': 'application/json; charset=UTF-8',
|
||||||
'content-type': 'text/html; charset=UTF-8'
|
...
|
||||||
}
|
}
|
||||||
|
|
||||||
accepted: false
|
|
||||||
|
|
||||||
// specific errors
|
|
||||||
badRequest: false
|
|
||||||
clientError: false
|
|
||||||
forbidden: false
|
|
||||||
notFound: false
|
|
||||||
noContent: false
|
|
||||||
notAcceptable: false
|
|
||||||
unauthorized: false
|
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
7
tmux.md
7
tmux.md
|
@ -44,8 +44,8 @@ category: CLI
|
||||||
|
|
||||||
### Panes
|
### Panes
|
||||||
|
|
||||||
C-b v # vert
|
C-b % # vert
|
||||||
C-b n # horiz
|
C-b " # horiz
|
||||||
C-b hkjl # navigation
|
C-b hkjl # navigation
|
||||||
C-b HJKL # resize
|
C-b HJKL # resize
|
||||||
C-b o # next window
|
C-b o # next window
|
||||||
|
@ -57,6 +57,9 @@ category: CLI
|
||||||
|
|
||||||
C-b c # New window
|
C-b c # New window
|
||||||
C-b 1 # Go to window 1
|
C-b 1 # Go to window 1
|
||||||
|
C-b n # Go to next window
|
||||||
|
C-b p # Go to previous window
|
||||||
|
C-b w # List all window
|
||||||
|
|
||||||
### Detach/attach
|
### Detach/attach
|
||||||
|
|
||||||
|
|
1
vim.md
1
vim.md
|
@ -78,6 +78,7 @@ Getting started
|
||||||
| Shortcut | Description |
|
| Shortcut | Description |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| `zz` | Center this line |
|
| `zz` | Center this line |
|
||||||
|
| `zt` | Top this line |
|
||||||
| `H` | Move to top of screen |
|
| `H` | Move to top of screen |
|
||||||
| `M` | Move to middle of screen |
|
| `M` | Move to middle of screen |
|
||||||
| `L` | Move to bottom of screen |
|
| `L` | Move to bottom of screen |
|
||||||
|
|
381
vue.md
381
vue.md
|
@ -1,112 +1,363 @@
|
||||||
---
|
---
|
||||||
title: Vue
|
title: Vue.js
|
||||||
category: JavaScript libraries
|
category: JavaScript
|
||||||
|
layout: 2017/sheet
|
||||||
|
updated: 2019-12-26
|
||||||
|
weight: -10
|
||||||
|
intro: |
|
||||||
|
[Vue.js](https://vuejs.org/) is an open-source Model–view–viewmodel JavaScript framework for building user interfaces and single-page applications.
|
||||||
---
|
---
|
||||||
|
|
||||||
{%raw%}
|
{%raw%}
|
||||||
|
|
||||||
### Lists
|
Expressions
|
||||||
|
----------
|
||||||
|
{: .-three-column}
|
||||||
|
|
||||||
|
### Expressions
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<li v-for="todo in todos">
|
<div id="app">
|
||||||
{{ todo.text }}
|
<p>I have a {{ product }}</p>
|
||||||
{{ $index }}
|
<p>{{ product + 's' }}</p>
|
||||||
|
<p>{{ isWorking ? 'YES' : 'NO' }}</p>
|
||||||
|
<p>{{ product.getSalePrice() }}</p>
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
See: [Delimiters](https://vuejs.org/v2/api/#delimiters)
|
||||||
|
|
||||||
|
### Binding
|
||||||
|
|
||||||
|
```html
|
||||||
|
<a v-bind:href="url">...</a>
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Shorthand syntax
|
||||||
|
```html
|
||||||
|
<a :href="url">...</a>
|
||||||
|
```
|
||||||
|
{: data-line="1"}
|
||||||
|
|
||||||
|
#### True or false will add or remove attribute
|
||||||
|
```html
|
||||||
|
<button :disabled="isButtonDisabled">...
|
||||||
|
```
|
||||||
|
|
||||||
|
#### If isActive is truthy, the class ‘active’ will appear
|
||||||
|
```html
|
||||||
|
<div :class="{ active: isActive }">...
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Style color set to value of activeColor
|
||||||
|
```html
|
||||||
|
<div :style="{ color: activeColor }">
|
||||||
|
```
|
||||||
|
|
||||||
|
See: [v-bind](https://vuejs.org/v2/api/#v-bind)
|
||||||
|
|
||||||
|
### Directives
|
||||||
|
|
||||||
|
#### Element inserted/removed based on truthiness
|
||||||
|
```html
|
||||||
|
<p v-if="inStock">{{ product }}</p>
|
||||||
|
```
|
||||||
|
```html
|
||||||
|
<p v-else-if="onSale">...</p>
|
||||||
|
<p v-else>...</p>
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Toggles the display: none CSS property
|
||||||
|
```html
|
||||||
|
<p v-show="showProductDetails">...</p>
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Two-way data binding
|
||||||
|
```html
|
||||||
|
<input v-model="firstName" >
|
||||||
|
```
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
| --- | --- |
|
||||||
|
| `v-model.lazy="..."` | Syncs input after change event |
|
||||||
|
| `v-model.number="..."` | Always returns a number |
|
||||||
|
| `v-model.trim="..."` | Strips whitespace |
|
||||||
|
|
||||||
|
See: [Directives](https://vuejs.org/v2/api/#Directives)
|
||||||
|
|
||||||
|
### Actions/Events
|
||||||
|
|
||||||
|
#### Calls addToCart method on component
|
||||||
|
```html
|
||||||
|
<button v-on:click="addToCart">...
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Shorthand syntax
|
||||||
|
```html
|
||||||
|
<button @click="addToCart">...
|
||||||
|
```
|
||||||
|
{: data-line="1"}
|
||||||
|
|
||||||
|
#### Arguments can be passed
|
||||||
|
```html
|
||||||
|
<button @click="addToCart(product)">...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### To prevent default behavior (e.g. page reload)
|
||||||
|
```html
|
||||||
|
<form @submit.prevent="addProduct">...
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Only trigger once
|
||||||
|
```html
|
||||||
|
<img @mouseover.once="showImage">...
|
||||||
|
```
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
| --- | --- |
|
||||||
|
| `.stop` | Stop all event propagation |
|
||||||
|
| `.self ` | Only trigger if event.target is element itself |
|
||||||
|
|
||||||
|
#### Keyboard entry example
|
||||||
|
```html
|
||||||
|
<input @keyup.enter="submit">
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Call onCopy when control-c is pressed
|
||||||
|
```html
|
||||||
|
<input @keyup.ctrl.c="onCopy">
|
||||||
|
```
|
||||||
|
|
||||||
|
See: [Events](https://vuejs.org/v2/guide/events.html)
|
||||||
|
|
||||||
|
### List rendering
|
||||||
|
|
||||||
|
#### The `:key` is always recommended
|
||||||
|
```html
|
||||||
|
<li v-for="item in items"
|
||||||
|
:key="item.id">
|
||||||
|
{{ item }}
|
||||||
</li>
|
</li>
|
||||||
```
|
```
|
||||||
|
{: data-line="2"}
|
||||||
|
|
||||||
### Events
|
#### To access the position in the array
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<button v-on:click='submit'>Go</button>
|
<li v-for="(item, index) in items">...
|
||||||
```
|
```
|
||||||
|
|
||||||
### Components
|
#### To iterate through objects
|
||||||
|
```html
|
||||||
|
<li v-for="(value, key) in object">...
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Using `v-for` with a component
|
||||||
|
```html
|
||||||
|
<cart-product v-for="item in products"
|
||||||
|
:product="item"
|
||||||
|
:key="item.id">
|
||||||
|
```
|
||||||
|
|
||||||
|
See: [List Rendering](https://vuejs.org/v2/guide/list.html)
|
||||||
|
|
||||||
|
|
||||||
|
Component
|
||||||
|
--------
|
||||||
|
|
||||||
|
### Component anatomy
|
||||||
|
|
||||||
```js
|
```js
|
||||||
new Vue({
|
Vue.component('my-component', {
|
||||||
components: { app: App }
|
components: {
|
||||||
|
// Components that can be used in the template
|
||||||
|
ProductComponent,
|
||||||
|
ReviewComponent
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
// The parameters the component accepts
|
||||||
|
message: String,
|
||||||
|
product: Object,
|
||||||
|
email: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
default: "none"
|
||||||
|
validator: function (value) {
|
||||||
|
// Should return true if value is valid
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data: function() {
|
||||||
|
// `data` must be a function
|
||||||
|
return {
|
||||||
|
firstName: 'Vue',
|
||||||
|
lastName: 'Mastery'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
// Return cached values until dependencies change
|
||||||
|
fullName: function () {
|
||||||
|
return this.firstName + ' ' + this.lastName
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
// Called when firstName changes value
|
||||||
|
firstName: function (value, oldValue) { ... }
|
||||||
|
},
|
||||||
|
methods: { ... },
|
||||||
|
template: '<span>{{ message }}</span>',
|
||||||
|
// Can also use backticks in `template` for multi-line
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
{: data-line="3, 8, 16, 21, 28, 34, 39"}
|
||||||
|
|
||||||
## API
|
See: [Components Basics](https://vuejs.org/v2/guide/components.html)
|
||||||
|
|
||||||
```js
|
### Lifecycle hooks
|
||||||
Vue.extend({ ... }) // creating components
|
|
||||||
Vue.nextTick(() => {...})
|
|
||||||
|
|
||||||
Vue.set(object, key, val) // reactive
|
| Method | Description |
|
||||||
Vue.delete(object, key)
|
| --- | --- |
|
||||||
|
| `beforeCreate` | After the instance has been initialized [#](https://vuejs.org/v2/api/#beforeCreate) |
|
||||||
|
| `created` | After the instance is created [#](https://vuejs.org/v2/api/#created) |
|
||||||
|
| `beforeMount` | Before the first render [#](https://vuejs.org/v2/api/#beforeMount) |
|
||||||
|
| `mounted` | After the instance has been mounted [#](https://vuejs.org/v2/api/#mounted) |
|
||||||
|
| `beforeUpdate` | When data changes, before the DOM is patched [#](https://vuejs.org/v2/api/#beforeUpdate) |
|
||||||
|
| `updated` | After a data change [#](https://vuejs.org/v2/api/#updated) |
|
||||||
|
| `beforeDestroy` | Before the instance is destroyed [#](https://vuejs.org/v2/api/#beforeDestroy) |
|
||||||
|
| `destroyed` | After a Vue instance has been destroyed [#](https://vuejs.org/v2/api/#destroyed) |
|
||||||
|
|
||||||
Vue.directive('my-dir', { bind, update, unbind })
|
See: [Lifecycle Hooks](https://vuejs.org/v2/api/#Options-Lifecycle-Hooks)
|
||||||
// <div v-my-dir='...'></div>
|
|
||||||
|
|
||||||
Vue.elementDirective('my-dir', { bind, update, unbind })
|
### Custom events
|
||||||
// <my-dir>...</my-dir>
|
|
||||||
|
|
||||||
Vue.component('my-component', Vue.extend({ .. }))
|
#### Set listener on component, within its parent
|
||||||
|
```html
|
||||||
Vue.partial('my-partial', '<div>hi {{msg}}</div>')
|
<button-counter v-on:incrementBy="incWithVal">
|
||||||
// <partial name='my-partial'></partial>
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Inside parent component
|
||||||
```js
|
```js
|
||||||
new Vue({
|
methods: {
|
||||||
data: { ... }
|
incWithVal: function (toAdd) { ... }
|
||||||
props: ['size'],
|
}
|
||||||
props: { size: Number },
|
|
||||||
computed: { fullname() { return this.name + ' ' + this.lastName } },
|
|
||||||
methods: { go() { ... } },
|
|
||||||
watch: { a (val, oldVal) { ... } },
|
|
||||||
el: '#foo',
|
|
||||||
template: '...',
|
|
||||||
replace: true, // replace element (default true)
|
|
||||||
|
|
||||||
// lifecycle
|
|
||||||
created () {},
|
|
||||||
beforeCompile () {},
|
|
||||||
compiled () {},
|
|
||||||
ready () {}, // $el is inserted for the first time
|
|
||||||
attached () {},
|
|
||||||
detached () {},
|
|
||||||
beforeDestroy () {},
|
|
||||||
destroyed () {},
|
|
||||||
|
|
||||||
// options
|
|
||||||
directives: {},
|
|
||||||
elementDirectives: {},
|
|
||||||
filters: {},
|
|
||||||
components: {},
|
|
||||||
transitions: {},
|
|
||||||
partials: {}
|
|
||||||
})
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Vue templates
|
#### Inside button-counter template
|
||||||
Via [vueify](https://www.npmjs.com/package/vueify)
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// app.vue
|
this.$emit(
|
||||||
|
'incrementBy', // Custom event name
|
||||||
|
5 // Data sent up to parent
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
Use props to pass data into child components,
|
||||||
|
custom events to pass data to parent elements.
|
||||||
|
|
||||||
|
See: [Custom Events](https://vuejs.org/v2/guide/components-custom-events.html)
|
||||||
|
|
||||||
|
Single file components
|
||||||
|
--------
|
||||||
|
|
||||||
|
### Single file
|
||||||
|
```html
|
||||||
<template>
|
<template>
|
||||||
<h1 class="red">{{msg}}</h1>
|
<p>{{ greeting }} World!</p>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
module.exports = {
|
module.exports = {
|
||||||
data () {
|
data: function () {
|
||||||
return {
|
return {
|
||||||
msg: 'Hello world!'
|
greeting: 'Hello'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
p {
|
||||||
|
font-size: 2em;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
```
|
```
|
||||||
|
|
||||||
Also
|
See: [Single File Components](https://vuejs.org/v2/guide/single-file-components.html)
|
||||||
|
|
||||||
|
### Separation
|
||||||
```html
|
```html
|
||||||
<template lang='jade'>
|
<template>
|
||||||
h1(class='red') {{msg}}
|
<div>This will be pre-compiled</div>
|
||||||
</template>
|
</template>
|
||||||
|
<script src="./my-component.js"></script>
|
||||||
|
<style src="./my-component.css"></style>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
See: [What About Separation of Concerns?](https://vuejs.org/v2/guide/single-file-components.html#What-About-Separation-of-Concerns)
|
||||||
|
|
||||||
|
Slots
|
||||||
|
--------
|
||||||
|
|
||||||
|
### Using a single slot
|
||||||
|
|
||||||
|
#### Component template
|
||||||
|
```html
|
||||||
|
<div>
|
||||||
|
<h2>I'm a title</h2>
|
||||||
|
<slot>
|
||||||
|
Only displayed if no slot content
|
||||||
|
</slot>
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
{: data-line="3,4,5"}
|
||||||
|
|
||||||
|
#### Use of component with data for slot
|
||||||
|
```html
|
||||||
|
<my-component>
|
||||||
|
<p>This will go in the slot</p>
|
||||||
|
</my-component>
|
||||||
|
```
|
||||||
|
{: data-line="2"}
|
||||||
|
|
||||||
|
See: [Slots](https://vuejs.org/v2/guide/components-slots.html)
|
||||||
|
|
||||||
|
### Multiple slots
|
||||||
|
|
||||||
|
#### Component template
|
||||||
|
```html
|
||||||
|
<div class="container">
|
||||||
|
<header>
|
||||||
|
<slot name="header"></slot>
|
||||||
|
</header>
|
||||||
|
<main>
|
||||||
|
<slot>Default content</slot>
|
||||||
|
</main>
|
||||||
|
<footer>
|
||||||
|
<slot name="footer"></slot>
|
||||||
|
</footer>
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
{: data-line="3,6,9"}
|
||||||
|
|
||||||
|
#### Use of component with data for slots
|
||||||
|
```html
|
||||||
|
<app-layout>
|
||||||
|
<h1 slot="header">Page title</h1>
|
||||||
|
<p>the main content.</p>
|
||||||
|
<p slot="footer">Contact info</p>
|
||||||
|
</app-layout>
|
||||||
|
```
|
||||||
|
{: data-line="2,3,4"}
|
||||||
|
|
||||||
|
See: [Slots](https://vuejs.org/v2/guide/components-slots.html)
|
||||||
|
|
||||||
|
Also see
|
||||||
|
--------
|
||||||
|
|
||||||
|
* [Vue CLI](https://cli.vuejs.org/) _(cli.vuejs.org)_
|
||||||
|
* [Vue Router](https://router.vuejs.org/) _(router.vuejs.org)_
|
||||||
|
* [Vue DevTools](https://chrome.google.com/webstore/detail/vuejs-devtools/nhdogjmejiglipccpnnnanhbledajbpd?hl=en) _(chrome.google.com)_
|
||||||
|
* [Nuxt.js](https://nuxtjs.org/) _(nuxtjs.org)_
|
||||||
|
* [Vue.js v1.0.28 cheatsheet](vue@1.0.28/) _Legacy version_
|
||||||
|
|
||||||
{%endraw%}
|
{%endraw%}
|
||||||
|
|
|
@ -0,0 +1,117 @@
|
||||||
|
---
|
||||||
|
title: Vue.js v1.0.28
|
||||||
|
category: JavaScript
|
||||||
|
layout: 2017/sheet
|
||||||
|
deprecated: true
|
||||||
|
weight: -10
|
||||||
|
intro: |
|
||||||
|
**Deprecated:** this guide targets an old version of Vuej.js (v1.0.28). See the [updated Vue.js cheatsheet](vue) for new versions.
|
||||||
|
---
|
||||||
|
|
||||||
|
{% raw %}
|
||||||
|
|
||||||
|
### Lists
|
||||||
|
|
||||||
|
```html
|
||||||
|
<li v-for="todo in todos">
|
||||||
|
{{ todo.text }}
|
||||||
|
{{ $index }}
|
||||||
|
</li>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Events
|
||||||
|
|
||||||
|
```html
|
||||||
|
<button v-on:click='submit'>Go</button>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Components
|
||||||
|
|
||||||
|
```js
|
||||||
|
new Vue({
|
||||||
|
components: { app: App }
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
```js
|
||||||
|
Vue.extend({ ... }) // creating components
|
||||||
|
Vue.nextTick(() => {...})
|
||||||
|
|
||||||
|
Vue.set(object, key, val) // reactive
|
||||||
|
Vue.delete(object, key)
|
||||||
|
|
||||||
|
Vue.directive('my-dir', { bind, update, unbind })
|
||||||
|
// <div v-my-dir='...'></div>
|
||||||
|
|
||||||
|
Vue.elementDirective('my-dir', { bind, update, unbind })
|
||||||
|
// <my-dir>...</my-dir>
|
||||||
|
|
||||||
|
Vue.component('my-component', Vue.extend({ .. }))
|
||||||
|
|
||||||
|
Vue.partial('my-partial', '<div>hi {{msg}}</div>')
|
||||||
|
// <partial name='my-partial'></partial>
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
new Vue({
|
||||||
|
data: { ... }
|
||||||
|
props: ['size'],
|
||||||
|
props: { size: Number },
|
||||||
|
computed: { fullname() { return this.name + ' ' + this.lastName } },
|
||||||
|
methods: { go() { ... } },
|
||||||
|
watch: { a (val, oldVal) { ... } },
|
||||||
|
el: '#foo',
|
||||||
|
template: '...',
|
||||||
|
replace: true, // replace element (default true)
|
||||||
|
|
||||||
|
// lifecycle
|
||||||
|
created () {},
|
||||||
|
beforeCompile () {},
|
||||||
|
compiled () {},
|
||||||
|
ready () {}, // $el is inserted for the first time
|
||||||
|
attached () {},
|
||||||
|
detached () {},
|
||||||
|
beforeDestroy () {},
|
||||||
|
destroyed () {},
|
||||||
|
|
||||||
|
// options
|
||||||
|
directives: {},
|
||||||
|
elementDirectives: {},
|
||||||
|
filters: {},
|
||||||
|
components: {},
|
||||||
|
transitions: {},
|
||||||
|
partials: {}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
## Vue templates
|
||||||
|
Via [vueify](https://www.npmjs.com/package/vueify)
|
||||||
|
|
||||||
|
```js
|
||||||
|
// app.vue
|
||||||
|
<template>
|
||||||
|
<h1 class="red">{{msg}}</h1>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
module.exports = {
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
msg: 'Hello world!'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
|
||||||
|
Also
|
||||||
|
|
||||||
|
```html
|
||||||
|
<template lang='jade'>
|
||||||
|
h1(class='red') {{msg}}
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
|
||||||
|
{% endraw %}
|
2
xpath.md
2
xpath.md
|
@ -18,7 +18,7 @@ Test queries in the Xpath test bed:<br>
|
||||||
### Browser console
|
### Browser console
|
||||||
|
|
||||||
```js
|
```js
|
||||||
$x('//div')
|
$x("//div")
|
||||||
```
|
```
|
||||||
|
|
||||||
Works in Firefox and Chrome.
|
Works in Firefox and Chrome.
|
||||||
|
|
1
yarn.md
1
yarn.md
|
@ -12,6 +12,7 @@ tags: [Featurable]
|
||||||
|
|
||||||
| npm | yarn |
|
| npm | yarn |
|
||||||
| --- | ---- |
|
| --- | ---- |
|
||||||
|
| `npm init` | `yarn init` |
|
||||||
| `npm install` | `yarn` |
|
| `npm install` | `yarn` |
|
||||||
| `npm install gulp --save` | `yarn add gulp` |
|
| `npm install gulp --save` | `yarn add gulp` |
|
||||||
| `npm install gulp --save-dev --save-exact` | `yarn add gulp --dev --exact` |
|
| `npm install gulp --save-dev --save-exact` | `yarn add gulp --dev --exact` |
|
||||||
|
|
Loading…
Reference in New Issue