From 868a228ecae45e1394d51ca7a1db2a0df7943242 Mon Sep 17 00:00:00 2001 From: Tero Karvinen Date: Sat, 5 Nov 2022 13:00:05 +0200 Subject: [PATCH] First public release --- LICENSE | 2 +- README.md | 35 +- cheatsheets/Dockerfile | 11 + cheatsheets/ansible.md | 102 +++ cheatsheets/bash.md | 843 +++++++++++++++++++++++ cheatsheets/chef.md | 112 +++ cheatsheets/cron.md | 73 ++ cheatsheets/css.md | 218 ++++++ cheatsheets/dockerfile.md | 115 ++++ cheatsheets/editorconfig.md | 78 +++ cheatsheets/elixir.md | 766 +++++++++++++++++++++ cheatsheets/es6.md | 582 ++++++++++++++++ cheatsheets/go.md | 658 ++++++++++++++++++ cheatsheets/goby.md | 1277 +++++++++++++++++++++++++++++++++++ cheatsheets/graphql.md | 273 ++++++++ cheatsheets/haml.md | 56 ++ cheatsheets/html.md | 110 +++ cheatsheets/javascript.md | 582 ++++++++++++++++ cheatsheets/jinja.md | 104 +++ cheatsheets/jinja2.md | 8 + cheatsheets/kotlin.md | 407 +++++++++++ cheatsheets/ledger.md | 308 +++++++++ cheatsheets/less.md | 45 ++ cheatsheets/lua.md | 303 +++++++++ cheatsheets/makefile.md | 132 ++++ cheatsheets/man.md | 21 + cheatsheets/markdown.md | 167 +++++ cheatsheets/mysql.md | 271 ++++++++ cheatsheets/org-mode.md | 116 ++++ cheatsheets/postgresql.md | 27 + cheatsheets/python.md | 170 +++++ cheatsheets/rake.md | 38 ++ cheatsheets/ruby.md | 34 + cheatsheets/sed.md | 59 ++ cheatsheets/sh.md | 8 + cheatsheets/sql.md | 27 + cheatsheets/typescript.md | 287 ++++++++ cheatsheets/vainglory.md | 147 ++++ cheatsheets/vimscript.md | 720 ++++++++++++++++++++ cheatsheets/vue.md | 365 ++++++++++ cheatsheets/yaml.md | 40 ++ cheatsheets/zsh.md | 45 ++ main.lua | 23 + repo.json | 21 + 44 files changed, 9783 insertions(+), 3 deletions(-) create mode 100644 cheatsheets/Dockerfile create mode 100644 cheatsheets/ansible.md create mode 100644 cheatsheets/bash.md create mode 100644 cheatsheets/chef.md create mode 100644 cheatsheets/cron.md create mode 100644 cheatsheets/css.md create mode 100644 cheatsheets/dockerfile.md create mode 100644 cheatsheets/editorconfig.md create mode 100644 cheatsheets/elixir.md create mode 100644 cheatsheets/es6.md create mode 100644 cheatsheets/go.md create mode 100644 cheatsheets/goby.md create mode 100644 cheatsheets/graphql.md create mode 100644 cheatsheets/haml.md create mode 100644 cheatsheets/html.md create mode 100644 cheatsheets/javascript.md create mode 100644 cheatsheets/jinja.md create mode 100644 cheatsheets/jinja2.md create mode 100644 cheatsheets/kotlin.md create mode 100644 cheatsheets/ledger.md create mode 100644 cheatsheets/less.md create mode 100644 cheatsheets/lua.md create mode 100644 cheatsheets/makefile.md create mode 100644 cheatsheets/man.md create mode 100644 cheatsheets/markdown.md create mode 100644 cheatsheets/mysql.md create mode 100644 cheatsheets/org-mode.md create mode 100644 cheatsheets/postgresql.md create mode 100644 cheatsheets/python.md create mode 100644 cheatsheets/rake.md create mode 100644 cheatsheets/ruby.md create mode 100644 cheatsheets/sed.md create mode 100644 cheatsheets/sh.md create mode 100644 cheatsheets/sql.md create mode 100644 cheatsheets/typescript.md create mode 100644 cheatsheets/vainglory.md create mode 100644 cheatsheets/vimscript.md create mode 100644 cheatsheets/vue.md create mode 100644 cheatsheets/yaml.md create mode 100644 cheatsheets/zsh.md create mode 100644 main.lua create mode 100644 repo.json diff --git a/LICENSE b/LICENSE index 8da2c74..832ef0a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 Tero Karvinen +Copyright (c) 2022 Tero Karvinen https://TeroKarvinen.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index b0348e1..97518d1 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,33 @@ -# micro-cheat -F1 Show cheatsheet for the language you're editing: Lua, Go, Python... +# micro-cheat - F1 cheatsheet for the language you're editing + +**F1** Show cheatsheet for the language you're editing: Lua, Go, Python... + +A plugin for Micro editor. + +## Usage + +Edit a source code file with micro. Press F1. + +A cheatsheet for the language opens. If you're editing Python, it's a Python cheatsheet. If Go, then Go cheatsheet. + +Press Ctrl-Q to close the cheatsheet tab and return to editing. + +For your convenience, micro-cheat also provides a command 'cheat' that you can bind to any key or run with ctrl-E. + +## Installation + +In the future, you will be able to install micro-cheat by + + $ micro --plugin install micro-cheat + +Currently, there is just development install + + $ cd $HOME/.config/micro/plug/ + $ git clone https://github.com/terokarvinen/micro-cheat + +## Adminstrivia + +Cheatsheets are from https://devhints.io project, copyright (c) 2021 Rico Sta. Cruz and contributors, received under MIT license. + +Micro-cheat plugin is Copyright 2022 Tero Karvinen https://TeroKarvinen.com, MIT license. + diff --git a/cheatsheets/Dockerfile b/cheatsheets/Dockerfile new file mode 100644 index 0000000..817e264 --- /dev/null +++ b/cheatsheets/Dockerfile @@ -0,0 +1,11 @@ +FROM ruby:2.7.1 +RUN curl -sL https://deb.nodesource.com/setup_12.x | bash - +RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - +RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list +RUN apt-get update -qq && apt-get install -qq --no-install-recommends \ + nodejs \ + yarn \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* +RUN mkdir -p /app +WORKDIR /app diff --git a/cheatsheets/ansible.md b/cheatsheets/ansible.md new file mode 100644 index 0000000..b2502ee --- /dev/null +++ b/cheatsheets/ansible.md @@ -0,0 +1,102 @@ +--- +title: Ansible +category: Ansible +--- + +{% raw %} + +## Getting started + +### Hosts + + $ sudo mkdir /etc/ansible + $ sudo vim /etc/ansible/hosts + + [example] + 192.0.2.101 + 192.0.2.102 + +### Running a playbook + + $ ansible-playbook playbook.yml + +## Tasks + + - hosts: all + user: root + sudo: no + vars: + aaa: bbb + tasks: + - ... + handlers: + - ... + +### Includes + + tasks: + - include: db.yml + handlers: + - include: db.yml user=timmy + +## Handlers + + handlers: + - name: start apache2 + action: service name=apache2 state=started + + tasks: + - name: install apache + action: apt pkg=apache2 state=latest + notify: + - start apache2 + +## Vars + + - host: lol + vars_files: + - vars.yml + vars: + project_root: /etc/xyz + tasks: + - name: Create the SSH directory. + file: state=directory path=${project_root}/home/.ssh/ + only_if: "$vm == 0" + +## Roles + + - host: xxx + roles: + - db + - { role:ruby, sudo_user:$user } + - web + + # Uses: + # roles/db/tasks/*.yml + # roles/db/handlers/*.yml + +### Task: Failures + + - name: my task + command: ... + register: result + failed_when: "'FAILED' in result.stderr" + + ignore_errors: yes + + changed_when: "result.rc != 2" + +### Env vars + + vars: + local_home: "{{ lookup('env','HOME') }}" + +## References + + * [Intro](http://www.ansibleworks.com/docs/intro_configuration.html) + * [Modules](http://www.ansibleworks.com/docs/modules.html) + +{% endraw %} + +https://devhints.io/ cheatsheets - Copyright (c) 2021 Rico Sta. Cruz and contributors - MIT license +micro-cheat plugin Copyright 2022 Tero Karvinen https://TeroKarvinen.com/micro - MIT license diff --git a/cheatsheets/bash.md b/cheatsheets/bash.md new file mode 100644 index 0000000..89af5d0 --- /dev/null +++ b/cheatsheets/bash.md @@ -0,0 +1,843 @@ +--- +title: Bash scripting +category: CLI +layout: 2017/sheet +tags: [Featured] +updated: 2020-07-05 +keywords: + - Variables + - Functions + - Interpolation + - Brace expansions + - Loops + - Conditional execution + - Command substitution +--- + +Getting started +--------------- +{: .-three-column} + +### Introduction +{: .-intro} + +This is a quick reference to getting started with Bash scripting. + +- [Learn bash in y minutes](https://learnxinyminutes.com/docs/bash/) _(learnxinyminutes.com)_ +- [Bash Guide](http://mywiki.wooledge.org/BashGuide) _(mywiki.wooledge.org)_ +- [Bash Hackers Wiki](https://wiki.bash-hackers.org) _(wiki.bash-hackers.org)_ + +### Example + +```bash +#!/usr/bin/env bash + +name="John" +echo "Hello $name!" +``` + +### Variables + +```bash +name="John" +echo $name # see below +echo "$name" +echo "${name}!" +``` +Generally quote your variables unless they contain wildcards to expand or command fragments. + +```bash +wildcard="*.txt" +option="iv" +cp -$options $wildcard /tmp +``` + +### String quotes + +```bash +name="John" +echo "Hi $name" #=> Hi John +echo 'Hi $name' #=> Hi $name +``` + +### Shell execution + +```bash +echo "I'm in $(pwd)" +echo "I'm in `pwd`" # obsolescent +# Same +``` + +See [Command substitution](http://wiki.bash-hackers.org/syntax/expansion/cmdsubst) + +### Conditional execution + +```bash +git commit && git push +git commit || echo "Commit failed" +``` + +### Functions +{: id='functions-example'} + +```bash +get_name() { + echo "John" +} + +echo "You are $(get_name)" +``` + +See: [Functions](#functions) + +### Conditionals +{: id='conditionals-example'} + +```bash +if [[ -z "$string" ]]; then + echo "String is empty" +elif [[ -n "$string" ]]; then + echo "String is not empty" +fi +``` + +See: [Conditionals](#conditionals) + +### Strict mode + +```bash +set -euo pipefail +IFS=$'\n\t' +``` + +See: [Unofficial bash strict mode](http://redsymbol.net/articles/unofficial-bash-strict-mode/) + +### Brace expansion + +```bash +echo {A,B}.js +``` + +| Expression | Description | +| ---------- | ------------------- | +| `{A,B}` | Same as `A B` | +| `{A,B}.js` | Same as `A.js B.js` | +| `{1..5}` | Same as `1 2 3 4 5` | + +See: [Brace expansion](http://wiki.bash-hackers.org/syntax/expansion/brace) + + +Parameter expansions +-------------------- +{: .-three-column} + +### Basics + +```bash +name="John" +echo "${name}" +echo "${name/J/j}" #=> "john" (substitution) +echo "${name:0:2}" #=> "Jo" (slicing) +echo "${name::2}" #=> "Jo" (slicing) +echo "${name::-1}" #=> "Joh" (slicing) +echo "${name:(-1)}" #=> "n" (slicing from right) +echo "${name:(-2):1}" #=> "h" (slicing from right) +echo "${food:-Cake}" #=> $food or "Cake" +``` + +```bash +length=2 +echo "${name:0:length}" #=> "Jo" +``` + +See: [Parameter expansion](http://wiki.bash-hackers.org/syntax/pe) + +```bash +str="/path/to/foo.cpp" +echo "${str%.cpp}" # /path/to/foo +echo "${str%.cpp}.o" # /path/to/foo.o +echo "${str%/*}" # /path/to + +echo "${str##*.}" # cpp (extension) +echo "${str##*/}" # foo.cpp (basepath) + +echo "${str#*/}" # path/to/foo.cpp +echo "${str##*/}" # foo.cpp + +echo "${str/foo/bar}" # /path/to/bar.cpp +``` + +```bash +str="Hello world" +echo "${str:6:5}" # "world" +echo "${str: -5:5}" # "world" +``` + +```bash +src="/path/to/foo.cpp" +base=${src##*/} #=> "foo.cpp" (basepath) +dir=${src%$base} #=> "/path/to/" (dirpath) +``` + +### Substitution + +| Code | Description | +| ----------------- | ------------------- | +| `${foo%suffix}` | Remove suffix | +| `${foo#prefix}` | Remove prefix | +| --- | --- | +| `${foo%%suffix}` | Remove long suffix | +| `${foo##prefix}` | Remove long prefix | +| --- | --- | +| `${foo/from/to}` | Replace first match | +| `${foo//from/to}` | Replace all | +| --- | --- | +| `${foo/%from/to}` | Replace suffix | +| `${foo/#from/to}` | Replace prefix | + +### Comments + +```bash +# Single line comment +``` + +```bash +: ' +This is a +multi line +comment +' +``` + +### Substrings + +| Expression | Description | +| --------------- | ------------------------------ | +| `${foo:0:3}` | Substring _(position, length)_ | +| `${foo:(-3):3}` | Substring from the right | + +### Length + +| Expression | Description | +| ---------- | ---------------- | +| `${#foo}` | Length of `$foo` | + +### Manipulation + +```bash +str="HELLO WORLD!" +echo "${str,}" #=> "hELLO WORLD!" (lowercase 1st letter) +echo "${str,,}" #=> "hello world!" (all lowercase) + +str="hello world!" +echo "${str^}" #=> "Hello world!" (uppercase 1st letter) +echo "${str^^}" #=> "HELLO WORLD!" (all uppercase) +``` + +### Default values + +| Expression | Description | +| ----------------- | -------------------------------------------------------- | +| `${foo:-val}` | `$foo`, or `val` if unset (or null) | +| `${foo:=val}` | Set `$foo` to `val` if unset (or null) | +| `${foo:+val}` | `val` if `$foo` is set (and not null) | +| `${foo:?message}` | Show error message and exit if `$foo` is unset (or null) | + +Omitting the `:` removes the (non)nullity checks, e.g. `${foo-val}` expands to `val` if unset otherwise `$foo`. + +Loops +----- +{: .-three-column} + +### Basic for loop + +```bash +for i in /etc/rc.*; do + echo "$i" +done +``` + +### C-like for loop + +```bash +for ((i = 0 ; i < 100 ; i++)); do + echo "$i" +done +``` + +### Ranges + +```bash +for i in {1..5}; do + echo "Welcome $i" +done +``` + +#### With step size + +```bash +for i in {5..50..5}; do + echo "Welcome $i" +done +``` + +### Reading lines + +```bash +while read -r line; do + echo "$line" +done 0 bytes | +| `[[ -f FILE ]]` | File | +| `[[ -x FILE ]]` | Executable | +| --- | --- | +| `[[ FILE1 -nt FILE2 ]]` | 1 is more recent than 2 | +| `[[ FILE1 -ot FILE2 ]]` | 2 is more recent than 1 | +| `[[ FILE1 -ef FILE2 ]]` | Same files | + +### Example + +```bash +# String +if [[ -z "$string" ]]; then + echo "String is empty" +elif [[ -n "$string" ]]; then + echo "String is not empty" +else + echo "This never happens" +fi +``` + +```bash +# Combinations +if [[ X && Y ]]; then + ... +fi +``` + +```bash +# Equal +if [[ "$A" == "$B" ]] +``` + +```bash +# Regex +if [[ "A" =~ . ]] +``` + +```bash +if (( $a < $b )); then + echo "$a is smaller than $b" +fi +``` + +```bash +if [[ -e "file.txt" ]]; then + echo "file exists" +fi +``` + +Arrays +------ + +### Defining arrays + +```bash +Fruits=('Apple' 'Banana' 'Orange') +``` + +```bash +Fruits[0]="Apple" +Fruits[1]="Banana" +Fruits[2]="Orange" +``` + +### Working with arrays + +```bash +echo "${Fruits[0]}" # Element #0 +echo "${Fruits[-1]}" # Last element +echo "${Fruits[@]}" # All elements, space-separated +echo "${#Fruits[@]}" # Number of elements +echo "${#Fruits}" # String length of the 1st element +echo "${#Fruits[3]}" # String length of the Nth element +echo "${Fruits[@]:3:2}" # Range (from position 3, length 2) +echo "${!Fruits[@]}" # Keys of all elements, space-separated +``` + +### Operations + +```bash +Fruits=("${Fruits[@]}" "Watermelon") # Push +Fruits+=('Watermelon') # Also Push +Fruits=( "${Fruits[@]/Ap*/}" ) # Remove by regex match +unset Fruits[2] # Remove one item +Fruits=("${Fruits[@]}") # Duplicate +Fruits=("${Fruits[@]}" "${Veggies[@]}") # Concatenate +lines=(`cat "logfile"`) # Read from file +``` + +### Iteration + +```bash +for i in "${arrayName[@]}"; do + echo "$i" +done +``` + +Dictionaries +------------ +{: .-three-column} + +### Defining + +```bash +declare -A sounds +``` + +```bash +sounds[dog]="bark" +sounds[cow]="moo" +sounds[bird]="tweet" +sounds[wolf]="howl" +``` + +Declares `sound` as a Dictionary object (aka associative array). + +### Working with dictionaries + +```bash +echo "${sounds[dog]}" # Dog's sound +echo "${sounds[@]}" # All values +echo "${!sounds[@]}" # All keys +echo "${#sounds[@]}" # Number of elements +unset sounds[dog] # Delete dog +``` + +### Iteration + +#### Iterate over values + +```bash +for val in "${sounds[@]}"; do + echo "$val" +done +``` + +#### Iterate over keys + +```bash +for key in "${!sounds[@]}"; do + echo "$key" +done +``` + +Options +------- + +### Options + +```bash +set -o noclobber # Avoid overlay files (echo "hi" > foo) +set -o errexit # Used to exit upon error, avoiding cascading errors +set -o pipefail # Unveils hidden failures +set -o nounset # Exposes unset variables +``` + +### Glob options + +```bash +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 +matches. + +History +------- + +### Commands + +| Command | Description | +| --------------------- | ----------------------------------------- | +| `history` | Show history | +| `shopt -s histverify` | Don't execute expanded result immediately | + +### Expansions + +| Expression | Description | +| ------------ | ---------------------------------------------------- | +| `!$` | Expand last parameter of most recent command | +| `!*` | Expand all parameters of most recent command | +| `!-n` | Expand `n`th most recent command | +| `!n` | Expand `n`th command in history | +| `!` | Expand most recent invocation of command `` | + +### Operations + +| Code | Description | +| -------------------- | --------------------------------------------------------------------- | +| `!!` | Execute last command again | +| `!!:s///` | Replace first occurrence of `` to `` in most recent command | +| `!!:gs///` | Replace all occurrences of `` to `` in most recent command | +| `!$:t` | Expand only basename from last parameter of most recent command | +| `!$:h` | Expand only directory from last parameter of most recent command | + +`!!` and `!$` can be replaced with any valid expansion. + +### Slices + +| Code | Description | +| -------- | ---------------------------------------------------------------------------------------- | +| `!!:n` | Expand only `n`th token from most recent command (command is `0`; first argument is `1`) | +| `!^` | Expand first argument from most recent command | +| `!$` | Expand last token from most recent command | +| `!!:n-m` | Expand range of tokens from most recent command | +| `!!:n-$` | Expand `n`th token to last from most recent command | + +`!!` can be replaced with any valid expansion i.e. `!cat`, `!-2`, `!42`, etc. + + +Miscellaneous +------------- + +### Numeric calculations + +```bash +$((a + 200)) # Add 200 to $a +``` + +```bash +$(($RANDOM%200)) # Random number 0..199 +``` + +### Subshells + +```bash +(cd somedir; echo "I'm now in $PWD") +pwd # still in first directory +``` + +### Redirection + +```bash +python hello.py > output.txt # stdout to (file) +python hello.py >> output.txt # stdout to (file), append +python hello.py 2> error.log # stderr to (file) +python hello.py 2>&1 # stderr to stdout +python hello.py 2>/dev/null # stderr to (null) +python hello.py >output.txt 2>&1 # stdout and stderr to (file), equivalent to &> +python hello.py &>/dev/null # stdout and stderr to (null) +echo "$0: warning: too many users" >&2 # print diagnostic message to stderr +``` + +```bash +python hello.py < foo.txt # feed foo.txt to stdin for python +diff <(ls -r) <(ls) # Compare two stdout without files +``` + +### Inspecting commands + +```bash +command -V cd +#=> "cd is a function/alias/whatever" +``` + +### Trap errors + +```bash +trap 'echo Error at about $LINENO' ERR +``` + +or + +```bash +traperr() { + echo "ERROR: ${BASH_SOURCE[1]} at about ${BASH_LINENO[0]}" +} + +set -o errtrace +trap traperr ERR +``` + +### Case/switch + +```bash +case "$1" in + start | up) + vagrant up + ;; + + *) + echo "Usage: $0 {start|stop|ssh}" + ;; +esac +``` + +### Source relative + +```bash +source "${0%/*}/../share/foo.sh" +``` + +### printf + +```bash +printf "Hello %s, I'm %s" Sven Olga +#=> "Hello Sven, I'm Olga + +printf "1 + 1 = %d" 2 +#=> "1 + 1 = 2" + +printf "This is how you print a float: %f" 2 +#=> "This is how you print a float: 2.000000" + +printf '%s\n' '#!/bin/bash' 'echo hello' >file +# format string is applied to each group of arguments +printf '%i+%i=%i\n' 1 2 3 4 5 9 +``` + +### Transform strings + +| Command option | Description | +| ------------------ | --------------------------------------------------- | +| `-c` | Operations apply to characters not in the given set | +| `-d` | Delete characters | +| `-s` | Replaces repeated characters with single occurrence | +| `-t` | Truncates | +| `[:upper:]` | All upper case letters | +| `[:lower:]` | All lower case letters | +| `[:digit:]` | All digits | +| `[:space:]` | All whitespace | +| `[:alpha:]` | All letters | +| `[:alnum:]` | All letters and digits | + +#### Example + +```bash +echo "Welcome To Devhints" | tr '[:lower:]' '[:upper:]' +WELCOME TO DEVHINTS +``` + +### Directory of script + +```bash +dir=${0%/*} +``` + +### Getting options + +```bash +while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in + -V | --version ) + echo "$version" + exit + ;; + -s | --string ) + shift; string=$1 + ;; + -f | --flag ) + flag=1 + ;; +esac; shift; done +if [[ "$1" == '--' ]]; then shift; fi +``` + +### Heredoc + +```sh +cat < "..." }) + command "make install" + creates "..." +end +``` + +### Conditions + +```ruby + creates "/usr/local/src/node-v#{version}/node" + not_if { File.exists?('...') } +``` + +## Also see + +* [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)_ + +https://devhints.io/ cheatsheets - Copyright (c) 2021 Rico Sta. Cruz and contributors - MIT license +micro-cheat plugin Copyright 2022 Tero Karvinen https://TeroKarvinen.com/micro - MIT license diff --git a/cheatsheets/cron.md b/cheatsheets/cron.md new file mode 100644 index 0000000..56b4813 --- /dev/null +++ b/cheatsheets/cron.md @@ -0,0 +1,73 @@ +--- +title: Cron +category: CLI +layout: 2017/sheet +updated: 2018-05-03 +weight: -3 +--- + +## Format +{: .-two-column} + +### Format + +``` +Min Hour Day Mon Weekday +``` +{: .-setup} + +``` +* * * * * command to be executed +``` + +``` +┬ ┬ ┬ ┬ ┬ +│ │ │ │ └─ Weekday (0=Sun .. 6=Sat) +│ │ │ └────── Month (1..12) +│ │ └─────────── Day (1..31) +│ └──────────────── Hour (0..23) +└───────────────────── Minute (0..59) +``` +{: .-setup.-box-chars} + +### Operators + +| Operator | Description | +| --- | --- | +| `*` | all values | +| `,` | separate individual values | +| `-` | a range of values | +| `/` | divide a value into steps | + +### Examples + +| Example | Description | +| --- | --- | +| `0 * * * *` | every hour | +| `*/15 * * * *` | every 15 mins | +| `0 */2 * * *` | every 2 hours | +| `0 18 * * 0-6` | every week Mon-Sat at 6pm | +| `10 2 * * 6,7` | every Sat and Sun on 2:10am | +| `0 0 * * 0` | every Sunday midnight | +| --- | --- | +| `@reboot` | every reboot | + +### Crontab + +```bash +# Adding tasks easily +echo "@reboot echo hi" | crontab +``` + +```bash +# Open in editor +crontab -e +``` + +```bash +# List tasks +crontab -l [-u user] +``` + +https://devhints.io/ cheatsheets - Copyright (c) 2021 Rico Sta. Cruz and contributors - MIT license +micro-cheat plugin Copyright 2022 Tero Karvinen https://TeroKarvinen.com/micro - MIT license diff --git a/cheatsheets/css.md b/cheatsheets/css.md new file mode 100644 index 0000000..c8f1156 --- /dev/null +++ b/cheatsheets/css.md @@ -0,0 +1,218 @@ +--- +title: CSS +category: CSS +layout: 2017/sheet +weight: -1 +keywords: + - "margin, padding, border" + - "div, .class, #id, [attr]" + - "font, background" + - "display: block, inline, flex" + - Selectors + - Properties +--- + +## Basics +{: .-three-column} + +### Selectors + +```css +.class { + font-weight: bold; +} +``` +{: .-setup} + +| Selector | Description | +| ----------------- | ------------ | +| `*` | All elements | +| `div` | Element | +| `.class` | Class | +| `#id` | ID | +| `[disabled]` | Attribute | +| `[role="dialog"]` | Attribute | + +### Combinators + +| Selector | Description | +| ------------------- | ----------------- | +| `.parent .child` | Descendant | +| `.parent > .child` | Direct descendant | +| `.child + .sibling` | Adjacent sibling | +| `.child ~ .sibling` | Far sibling | +| `.class1.class2` | Have both classes | + +### Attribute selectors + +| Selector | Description | +| ------------------ | ----------------------------------- | +| `[role="dialog"]` | `=` Exact | +| `[class~="box"]` | `~=` Has word | +| `[class|="box"]` | `|=` Exact or prefix (eg, `value-`) | +| `[href$=".doc"]` | `$=` Ends in | +| `[href^="/index"]` | `^=` Begins with | +| `[class*="-is-"]` | `*=` Contains | + +### 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)` | | +| --- | --- | +| `:checked` | Checked inputs | +| `:disabled` | Disabled elements | +| `:default` | Default element in a group | +| --- | --- | +| `:empty` | Elements without children | + +### Pseudo-class variations + +| Selector | +| ----------------- | +| `:first-of-type` | +| `:last-of-type` | +| `:nth-of-type(2)` | +| `:only-of-type` | +| --- | +| `:first-child` | +| `:last-child` | +| `:nth-child(2)` | +| `:only-child` | +{: .-left-align} + +## Fonts +{: .-left-reference} + +### Properties + +| Property | Description | +| ------------------ | ------------------------------------ | +| `font-family:` | `, ` | +| `font-size:` | `` | +| `letter-spacing:` | `` | +| `line-height:` | `` | +| --- | --- | +| `font-weight:` | `bold` `normal` | +| `font-style:` | `italic` `normal` | +| `text-decoration:` | `underline` `none` | +| --- | --- | +| `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 + +```css +font-family: Arial; +font-size: 12pt; +line-height: 1.5; +letter-spacing: 0.02em; +color: #aa3322; +``` + +### Case + +```css +text-transform: capitalize; /* Hello */ +text-transform: uppercase; /* HELLO */ +text-transform: lowercase; /* hello */ +``` + +## Background +{: .-left-reference} + +### Properties + +| Property | Description | +| ------------------------ | ---------------------------------------- | +| `background:` | _(Shorthand)_ | +| --- | --- | +| `background-color:` | `` | +| `background-image:` | `url(...)` | +| `background-position:` | `left/center/right` `top/center/bottom` | +| `background-size:` | `cover` `X Y` | +| `background-clip:` | `border-box` `padding-box` `content-box` | +| `background-repeat:` | `no-repeat` `repeat-x` `repeat-y` | +| `background-attachment:` | `scroll` `fixed` `local` | +{: .-key-values} + +### Shorthand + +| | color | image | positionX | positionY | | size | repeat | attachment | +| ------------- | ------ | ------------- | --------- | --------- | --- | -------------- | ----------- | ---------- | +| `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 + +```css +background: linear-gradient(to bottom, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), + url('background.jpg') center center / cover, #333; +``` + +## Animation +{: .-left-reference} + +### Properties + +| Property | Value | +| ---------------------------- | -------------------------------------------------------- | +| `animation:` | _(shorthand)_ | +| `animation-name:` | `` | +| `animation-duration:` | `