diff --git a/.github/workflows/rebase.yml b/.github/workflows/rebase.yml index ee363802b..5a6599841 100644 --- a/.github/workflows/rebase.yml +++ b/.github/workflows/rebase.yml @@ -1,2 +1,24 @@ -- name: Automatic rebase - uses: cirrus-actions/rebase@1.2 +# https://github.com/cirrus-actions/rebase +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." diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 000000000..811551272 --- /dev/null +++ b/.gitpod.yml @@ -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 \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 47c1f4361..3f83d39f1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,14 @@ language: ruby rvm: - - 2.5 +- 2.5 script: - - make -B _site - - if ! make test; then make test-warning; exit 16; fi +- make -B _site +- if ! make test; then make test-warning; exit 16; fi cache: bundler +notifications: + slack: + if: branch = master OR branch =~ ^.*slack.*$ + rooms: + - secure: FN4trzyyUdtZ6DXj4G3A7YnhqkPyqi8jN9BIdA6S6D2eJEH1gPbZUfbqAW87LKckKZ9iYB5KDF5IuELhR3vv1DeHRqm3MKRU91JVBDT7EXbF86Z1J/JMJxNOcoWdCilcgpnm9NCkMAPFC9h6Y3txYhaLWLsnDaWlvehBsJg+Ql4= + on_success: change + on_failure: always diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 48d45207c..a361e05eb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,5 +1,19 @@ # 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:
+[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](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. + + + + ## Starting a local instance This starts Jekyll and Webpack. This requires recent versions of [Node.js], [Yarn], [Ruby] and [Bundler] installed. diff --git a/README.md b/README.md index 1380dbee1..c0b0f90f7 100644 --- a/README.md +++ b/README.md @@ -17,3 +17,5 @@ --- See [CONTRIBUTING.md](CONTRIBUTING.md) for developer notes. + +[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/rstacruz/cheatsheets) diff --git a/_docs/images/gitpod_preview_tut.png b/_docs/images/gitpod_preview_tut.png new file mode 100644 index 000000000..e285e1655 Binary files /dev/null and b/_docs/images/gitpod_preview_tut.png differ diff --git a/_includes/common/moment_format.md b/_includes/common/moment_format.md index 4ef8a5b56..67054cc35 100644 --- a/_includes/common/moment_format.md +++ b/_includes/common/moment_format.md @@ -33,7 +33,7 @@ Used by [Moment.js](http://momentjs.com/docs/#/displaying/) and [date-fns/format | `YYYY` | `2013` | | | --- | --- | --- | | `M` | `1`..`12` _(Jan is 1)_ | **Month** | -| `Mo` | `1st`..`31st` | | +| `Mo` | `1st`..`12th` | | | `MM` | `01`..`12` _(Jan is 1)_ | | | `MMM` | `Jan` | | | `MMMM` | `January` | | diff --git a/assets/favicon.png b/assets/favicon.png new file mode 100644 index 000000000..6fc8b7c9f Binary files /dev/null and b/assets/favicon.png differ diff --git a/awscli.md b/awscli.md index 60b80a7c4..e0ba96d5e 100644 --- a/awscli.md +++ b/awscli.md @@ -37,6 +37,13 @@ brew install awscli aws configure ``` +### Configuration profiles + +``` +aws configure --profile project1 +aws configure --profile project2 +``` + ## Elastic Beanstalk ### Configuration diff --git a/bash.md b/bash.md index 158b6a31f..32e2e7af1 100644 --- a/bash.md +++ b/bash.md @@ -389,18 +389,6 @@ Note that `[[` is actually a command/program that returns either `0` (true) or ` ### 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 # String if [[ -z "$string" ]]; then @@ -547,11 +535,11 @@ set -o nounset # Exposes unset variables ### Glob options ```bash -set -o nullglob # Non-matching globs are removed ('*.foo' => '') -set -o failglob # Non-matching globs throw errors -set -o nocaseglob # Case insensitive globs -set -o globdots # Wildcards match dotfiles ("*.sh" => ".foo.sh") -set -o globstar # Allow ** for recursive matches ('lib/**/*.rb' => 'lib/a/b/c.rb') +shopt -s nullglob # Non-matching globs are removed ('*.foo' => '') +shopt -s failglob # Non-matching globs throw errors +shopt -s nocaseglob # Case insensitive globs +shopt -s dotglob # Wildcards match dotfiles ("*.sh" => ".foo.sh") +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 @@ -749,6 +737,22 @@ cd - 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 {: .-one-column} diff --git a/capybara.md b/capybara.md index 061763ffd..689d4858b 100644 --- a/capybara.md +++ b/capybara.md @@ -217,7 +217,7 @@ find('#x').fill_in('Street', with: 'Hello') ### Scripting ```ruby -execute_script('$("input").trigger('change')') +execute_script('$("input").trigger("change")') evaluate_script('window.ga') ``` diff --git a/css.md b/css.md index 162d28c5a..b13e008ef 100644 --- a/css.md +++ b/css.md @@ -13,6 +13,7 @@ keywords: --- ## Basics + {: .-three-column} ### Selectors @@ -22,15 +23,17 @@ keywords: font-weight: bold; } ``` + {: .-setup} -| Selector | Description | -| ----------------- | ----------- | -| `div` | Element | -| `.class` | Class | -| `#id` | ID | -| `[disabled]` | Attribute | -| `[role="dialog"]` | Attribute | +| Selector | Description | +| ----------------- | ------------ | +| `*` | All elements | +| `div` | Element | +| `.class` | Class | +| `#id` | ID | +| `[disabled]` | Attribute | +| `[role="dialog"]` | Attribute | ### Combinators @@ -40,6 +43,7 @@ keywords: | `.parent > .child` | Direct descendant | | `.child + .sibling` | Adjacent sibling | | `.child ~ .sibling` | Far sibling | +| `.class1.class2` | Have both classes | ### Attribute selectors @@ -54,21 +58,26 @@ keywords: ### Pseudo-classes -| Selector | Description | -| -------------------- | ------------------------ | -| `:target` | eg, `h2#foo:target` | -| --- | --- | -| `:disabled` | | -| `:focus` | | -| `:active` | | -| --- | --- | -| `:nth-child(3)` | 3rd child | -| `:nth-child(3n+2)` | 2nd child in groups of 3 | -| `:nth-child(-n+4)` | | -| --- | --- | -| `:nth-last-child(2)` | | -| `:nth-of-type(2)` | | -| --- | --- | +| Selector | Description | +| -------------------- | ------------------------------------------ | +| `:target` | eg, `h2#foo:target` | +| --- | --- | +| `:disabled` | | +| `:focus` | | +| `:active` | | +| --- | --- | +| `:nth-child(3)` | 3rd child | +| `:nth-child(3n+2)` | 2nd child in groups of 3 | +| `:nth-child(-n+4)` | | +| --- | --- | +| `:nth-last-child(2)` | | +| `:nth-of-type(2)` | | +| --- | --- | +| `:checked` | Checked inputs | +| `:disabled` | Disabled elements | +| `:default` | Default element in a group | +| --- | --- | +| `:empty` | Elements without children | ### Pseudo-class variations @@ -83,9 +92,11 @@ keywords: | `:last-child` | | `:nth-child(2)` | | `:only-child` | + {: .-left-align} ## Fonts + {: .-left-reference} ### Properties @@ -103,15 +114,18 @@ keywords: | --- | --- | | `text-align:` | `left` `right` `center` `justify` | | `text-transform:` | `capitalize` `uppercase` `lowercase` | + {: .-key-values} ### Shorthand + {: .-prime} | | style | weight | size (required) | | line-height | family | | ------- | -------- | ------ | --------------- | --- | ----------- | ----------------- | | `font:` | `italic` | `400` | `14px` | `/` | `1.5` | `sans-serif` | | | style | weight | size (required) | | line-height | family (required) | + {: .-css-breakdown} ### Example @@ -133,6 +147,7 @@ text-transform: lowercase; /* hello */ ``` ## Background + {: .-left-reference} ### Properties @@ -148,6 +163,7 @@ text-transform: lowercase; /* hello */ | `background-clip:` | `border-box` `padding-box` `content-box` | | `background-repeat:` | `no-repeat` `repeat-x` `repeat-y` | | `background-attachment:` | `scroll` `fixed` `local` | + {: .-key-values} ### Shorthand @@ -157,6 +173,7 @@ text-transform: lowercase; /* hello */ | `background:` | `#ff0` | `url(bg.jpg)` | `left` | `top` | `/` | `100px` `auto` | `no-repeat` | `fixed;` | | `background:` | `#abc` | `url(bg.png)` | `center` | `center` | `/` | `cover` | `repeat-x` | `local;` | | | color | image | positionX | positionY | | size | repeat | attachment | + {: .-css-breakdown} ### Multiple backgrounds @@ -167,6 +184,7 @@ background: linear-gradient(to bottom, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), ``` ## Animation + {: .-left-reference} ### 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-fill-mode:` | `none` `forwards` `backwards` `both` `initial` `inherit` | | `animation-play-state:` | `normal` `reverse` `alternate` `alternate-reverse` | + {: .-key-values} ### 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` | | | name | duration | timing-function | delay | count | direction | fill-mode | play-state | + {: .-css-breakdown} ### Example diff --git a/docker-compose.md b/docker-compose.md index f45fdbbc6..84d554c41 100644 --- a/docker-compose.md +++ b/docker-compose.md @@ -54,6 +54,8 @@ docker-compose down web: # build from Dockerfile build: . + args: # Add build arguments + APP_HOME: app ``` ```yaml @@ -77,7 +79,7 @@ web: ```yaml ports: - "3000" - - "8000:80" # guest:host + - "8000:80" # host:container ``` ```yaml diff --git a/docker.md b/docker.md index bc074c7fe..11fc2f2bc 100644 --- a/docker.md +++ b/docker.md @@ -24,6 +24,11 @@ docker run [options] IMAGE # see `docker create` for options ``` +#### Example + +``` +$ docker run -it debian:buster /bin/bash +``` Run a command in an `image`. Manage containers diff --git a/dockerfile.md b/dockerfile.md index 82b5d9f78..660259a1c 100644 --- a/dockerfile.md +++ b/dockerfile.md @@ -22,6 +22,11 @@ ENV APP_HOME /myapp RUN mkdir $APP_HOME ``` +```docker +ARG APP_HOME="" +RUN mkdir $APP_HOME +``` + ### Initialization ```docker diff --git a/enzyme.md b/enzyme.md index b0cf7d207..9a12247a2 100644 --- a/enzyme.md +++ b/enzyme.md @@ -88,7 +88,7 @@ expect(wrap.state('show')).toEqual(true) ``` ```js -expect('name' in wrap.props()).toEqual(true) +expect('name' in wrap.props()).toEqual('Moe') expect('show' in wrap.state()).toEqual(true) ``` @@ -248,7 +248,7 @@ wrap.context() // get full context ```js wrap.state('key') // → any -wrap.prop('key') // → any +wrap.prop('key') // → any wrap.context('key') // → any ``` diff --git a/es6.md b/es6.md index 3354696e4..c74dd5fe1 100644 --- a/es6.md +++ b/es6.md @@ -415,7 +415,7 @@ numbers.map(n => n * 2) // Same as: numbers.map(function (n) { return n * 2 }) numbers.map(n => ({ result: n * 2 -}) +})) // Implicitly returning objects requires parentheses around the object ``` {: data-line="1,4,5,6"} diff --git a/find.md b/find.md index fd39a5c9b..ba85b41f2 100644 --- a/find.md +++ b/find.md @@ -2,6 +2,7 @@ title: Find category: CLI layout: 2017/sheet +updated: 2019-10-01 --- ### Usage @@ -48,6 +49,20 @@ find -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 ```bash @@ -73,3 +88,7 @@ find . -name '*.jpg' -exec rm {} \; ```bash find . -newerBt "24 hours ago" ``` + +```bash +find . -type f -mtime +29 # find files modified more than 30 days ago +``` diff --git a/go.md b/go.md index c6be8bd77..64d78347f 100644 --- a/go.md +++ b/go.md @@ -202,9 +202,9 @@ See: [Switch](https://github.com/golang/go/wiki/Switch) ### For loop ```go - for count := 0; count <= 10; count++ { - fmt.Println("My counter is at", count) - } +for count := 0; count <= 10; count++ { + fmt.Println("My counter is at", count) +} ``` See: [For loops](https://tour.golang.org/flowcontrol/1) @@ -212,10 +212,10 @@ See: [For loops](https://tour.golang.org/flowcontrol/1) ### For-Range loop ```go - entry := []string{"Jack","John","Jones"} - for i, val := range entry { - fmt.Printf("At position %d, the character %s is present\n", i, val) - } +entry := []string{"Jack","John","Jones"} +for i, val := range entry { + fmt.Printf("At position %d, the character %s is present\n", i, val) +} ``` See: [For-Range loops](https://gobyexample.com/range) @@ -422,10 +422,24 @@ func main() { fmt.Println("Working...") } ``` + {: data-line="2,3,4"} 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 {: .-three-column} diff --git a/homebrew.md b/homebrew.md index a26b43ba6..d510af11b 100644 --- a/homebrew.md +++ b/homebrew.md @@ -35,6 +35,7 @@ category: CLI | `brew update` | Update brew and cask | | `brew list` | List installed | | `brew outdated` | What's due for upgrades? | +| `brew doctor` | Diagnose brew issues | ### Brew Cask commands @@ -50,5 +51,4 @@ Cask commands are used for interacting with graphical applications. * [Homebrew homepage](https://brew.sh/) _brew.sh_ * [Homebrew docs](https://docs.brew.sh) _docs.brew.sh_ -* [Homebrew Cask](https://caskroom.github.io/) _caskroom.github.io_ {: .-also-see} diff --git a/jsdoc.md b/jsdoc.md index 6f0ae3528..995a40411 100644 --- a/jsdoc.md +++ b/jsdoc.md @@ -31,7 +31,7 @@ See: | --- | --- | | `@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 {...string} n` | Repeatable arguments | | `@param {string} [n="hi"]` | Optional with default | diff --git a/lua.md b/lua.md index ade10c4df..bf4aea9b4 100644 --- a/lua.md +++ b/lua.md @@ -61,7 +61,7 @@ title: Lua if condition then print("yes") - elsif condition then + elseif condition then print("maybe") else print("no") diff --git a/npm.md b/npm.md index 5055e2475..27f6e9014 100644 --- a/npm.md +++ b/npm.md @@ -8,14 +8,16 @@ updated: 2017-10-27 ### Package management -| Command | Description | -| --- | --- | -| `npm i` | Alias for `npm install` | -| `npm install` | Install everything in package.json | -| --- | --- | -| `npm install lodash` | Install a package | -| `npm install --save-dev lodash` | Install as devDependency | -| `npm install --save-exact lodash` | Install with exact | +| Command | Description | +| --- | --- | +| `npm i` | Alias for `npm install` | +| `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 --save-dev lodash` | Install as devDependency | +| `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. @@ -39,6 +41,15 @@ updated: 2017-10-27 | `npm i ./archive.tgz` | Tarball | | `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 | Command | Description | diff --git a/python.md b/python.md index 26b8c7760..0ef2df680 100644 --- a/python.md +++ b/python.md @@ -58,6 +58,7 @@ category: Python string.replace("-", " ") ",".join(list) "hi {0}".format('j') + "hi {name}" # same as "hi {}".format('name') str.find(",") str.index(",") # same, but raises IndexError str.count(",") @@ -101,3 +102,44 @@ category: Python expr.match(...) 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()`. diff --git a/rails-models.md b/rails-models.md index d215f4583..1f1dc235a 100644 --- a/rails-models.md +++ b/rails-models.md @@ -247,11 +247,11 @@ Associations belongs_to :parent, :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 :people, :class_name => "Person" 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 => :destroy has_many :tags, :as => :taggable diff --git a/react.md b/react.md index 217d40b5d..3aae19340 100644 --- a/react.md +++ b/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) +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 ( +
+

You clicked {count} times

+ +
+ ); +} +``` +{: 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 ( +
+

You clicked {count} times

+ +
+ ); +} +``` +{: 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 --------- {: .-two-column} diff --git a/regexp.md b/regexp.md index 5089c4abc..60e2e7a6b 100644 --- a/regexp.md +++ b/regexp.md @@ -6,27 +6,30 @@ weight: -1 authors: - github: rizqyhi - github: kolapsys -updated: 2019-10-24 + - github: samtrion +updated: 2019-11-14 description: | Basic cheatsheets for regular expression --- +## RegExp {: .-three-column} ### Character classes -| Pattern | Description | -| ------- | ------------------------------ | -| `.` | Any character, except newline | -| `\w` | Word | -| `\d` | Digit | -| `\s` | Whitespace | -| `\W` | Not word | -| `\D` | Not digit | -| `\S` | Not whitespace | -| `[abc]` | Any of a, b, or c | -| `[a-e]` | Characters between `a` and `e` | -| `[1-9]` | Digit between `1` and `9` | +| Pattern | Description | +| -------- | ------------------------------------ | +| `.` | Any character, except newline | +| `\w` | Word | +| `\d` | Digit | +| `\s` | Whitespace | +| `\W` | Not word | +| `\D` | Not digit | +| `\S` | Not whitespace | +| `[abc]` | Any of a, b, or c | +| `[a-e]` | Characters between `a` and `e` | +| `[1-9]` | Digit between `1` and `9` | +| `[^abc]` | Any character except `a`, `b` or `c` | ### Anchors @@ -54,9 +57,12 @@ description: | ### Groups -| Pattern | Description | -| ------- | ------------- | -| `(abc)` | Capture group | +| Pattern | Description | +| --------- | ------------------------------ | +| `(abc)` | Capture group | +| `(a|b)` | Match `a` or `b` | +| `(?:abc)` | Match `abc`, but don't capture | + ### Quantifiers diff --git a/stencil.md b/stencil.md index 44fc8e2ee..32cf617b5 100644 --- a/stencil.md +++ b/stencil.md @@ -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. -See: [Updating arrays](https://stenciljs.com/docs/handling-arrays) +See: [Updating arrays](https://stenciljs.com/docs/reactive-data/#updating-arrays) ## Slots diff --git a/superagent.md b/superagent.md index ef6775d93..89a392d61 100644 --- a/superagent.md +++ b/superagent.md @@ -1,35 +1,61 @@ --- title: Superagent 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 == { - ok: true - error: false + // True when res.status == 202 + accepted: true, + // 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 - body: null - text: "..." + // Unparsed response text + text: '{"user":{"username":"JohnDoe","role":"admin"}}' - // Headers - status: 200 - type: "text/html" - charset: "UTF-8" - headers: { - 'cache-control': 'public', - 'content-type': 'text/html; charset=UTF-8' + // Parsed response text (only if response is 'application/json' or 'application/x-www-form-urlencoded' + body: { + // Example of parsed object from res.text + user: { + username: 'JohnDoe', + role: 'admin' } - - accepted: false - - // specific errors - badRequest: false - clientError: false - forbidden: false - notFound: false - noContent: false - notAcceptable: false - unauthorized: false } + + // 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: { + 'content-type': 'application/json; charset=UTF-8', + ... + } +} +``` diff --git a/tmux.md b/tmux.md index b0875dd07..169dc9fa9 100644 --- a/tmux.md +++ b/tmux.md @@ -44,8 +44,8 @@ category: CLI ### Panes - C-b v # vert - C-b n # horiz + C-b % # vert + C-b " # horiz C-b hkjl # navigation C-b HJKL # resize C-b o # next window diff --git a/vim.md b/vim.md index ba786dcdc..585eb1076 100644 --- a/vim.md +++ b/vim.md @@ -78,6 +78,7 @@ Getting started | Shortcut | Description | | --- | --- | | `zz` | Center this line | +| `zt` | Top this line | | `H` | Move to top of screen | | `M` | Move to middle of screen | | `L` | Move to bottom of screen | diff --git a/vue.md b/vue.md index 9ff24a024..5b3706091 100644 --- a/vue.md +++ b/vue.md @@ -1,6 +1,11 @@ --- -title: Vue -category: JavaScript libraries +title: Vue.js +category: JavaScript +layout: 2017/sheet +updated: 2019-11-22 +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 %} diff --git a/xpath.md b/xpath.md index f9f36c0f7..ddec941d9 100644 --- a/xpath.md +++ b/xpath.md @@ -18,7 +18,7 @@ Test queries in the Xpath test bed:
### Browser console ```js -$x('//div') +$x("//div") ``` Works in Firefox and Chrome.