Académique Documents
Professionnel Documents
Culture Documents
png)
Unified access to the best community driven cheat sheets repositories of the world.
Let's imagine for a moment that there is such a thing as an ideal cheat sheet.
What should it look like?
What features should it have?
* **Concise** — It should only contain the things you need, and nothing else.
* **Fast** — It should be possible to use it instantly.
* **Comprehensive** — It should contain answers for every possible question.
* **Universal** — It should be available everywhere, anytime, without any
preparations.
* **Unobtrusive** — It should not distract you from your main task.
* **Tutoring** — It should help you to learn the subject.
* **Inconspicuous** — It should be possible to use it completely unnoticed.
[![Build Status](https://travis-ci.org/chubin/cheat.sh.svg?branch=master)]
(https://travis-ci.org/chubin/cheat.sh)
## Features
**cheat.sh**
<p align="center">
<img src='https://cheat.sh/files/demo-curl.gif'/>
</p>
## Contents
* [Features](#features)
* [Usage](#usage)
* [Command line client, cht.sh](#command-line-client-chtsh)
* [Installation](#installation)
* [Client usage](#client-usage)
* [Tab-completion](#tab-completion)
* [Stealth mode](#stealth-mode)
* [Self-Hosting](#self-hosting)
* [Docker](#docker)
* [Editors integration](#editors-integration)
* [Vim](#vim)
* [Emacs](#emacs)
* [Visual Studio Code](#visual-studio-code)
* [Sublime](#sublime)
* [IntelliJ IDEA](#intellij-idea)
* [Special pages](#special-pages)
* [Search](#search)
* [Programming languages cheat sheets](#programming-languages-cheat-sheets)
* [Cheat sheets sources](#cheat-sheets-sources)
* [How to contribute](#how-to-contribute)
* [How to edit a cheat sheet](#how-to-edit-a-cheat-sheet)
* [How to add a cheat sheet](#how-to-add-a-cheat-sheet)
* [How to add a cheat sheet repository](#how-to-add-a-cheat-sheet-repository)
## Usage
To get a cheat sheet for a UNIX/Linux command from a command line, query the
service using `curl` or any other HTTP/HTTPS client
specifying the name of the command in the query:
```
curl cheat.sh/tar
curl cht.sh/curl
curl https://cheat.sh/rsync
curl https://cht.sh/tr
```
As you can see, you can use both HTTPS and HTTP to access the service, and both the
long (cheat.sh) and the short (cht.sh) service names.
Here `tar`, `curl`, `rsync`, and `tr` are names of the UNIX/Linux commands you want
to get cheat sheets for.
If you don't know the name of the command you need, you can search for it using the
`~KEYWORD` notation.
For example, to see how you can make `snapshots` of a filesystem/volume/something
else:
```
curl cht.sh/~snapshot
```
<p align="center">
<img src='https://cheat.sh/files/cht.sh-url-structure.png'/>
</p>
The programming language cheat sheets are located in special namespaces dedicated
to them.
```
curl cht.sh/go/Pointers
curl cht.sh/scala/Functions
curl cht.sh/python/lambda
```
To get the list of available programming language cheat sheets, use the special
query `:list`:
```
curl cht.sh/go/:list
```
Try these (and your own) queries to get the impression of that, what the answers
look like:
```
curl cht.sh/go/reverse+a+list
curl cht.sh/python/random+list+elements
curl cht.sh/js/parse+json
curl cht.sh/lua/merge+tables
curl cht.sh/clojure/variadic+function
```
If you don't like an answer for your queries, you can pick another one. For that,
repeat the query with an additional parameter `/1`, `/2` etc. appended:
```
curl cht.sh/python/random+string
curl cht.sh/python/random+string/1
curl cht.sh/python/random+string/2
```
Cheat sheets are formatted as code of the queried programming language (at least we
are trying our best to do so)
so they can be pasted into a program in this language directly. Text comments, if
there are any, are formatted according to the language syntax.
```lua
$ curl cht.sh/lua/table+keys
-- lua: retrieve list of keys in a table
local keyset={}
local n=0
--[[
[ Note that you cannot guarantee any order in keyset. If you want the
[ keys in sorted order, then sort keyset with table.sort(keyset).
[
[ [lhf] [so/q/12674345] [cc by-sa 3.0]
]]
```
If you don't need text comments in the answer, you can eliminate them
using a special option `?Q`:
```lua
$ curl cht.sh/lua/table+keys?Q
local keyset={}
local n=0
And if you don't need syntax highlighting, switch it off using `?T`.
You can combine the options together:
```
curl cht.sh/go/reverse+a+list?Q
curl cht.sh/python/random+list+elements?Q
curl cht.sh/js/parse+json?Q
curl cht.sh/lua/merge+tables?QT
curl cht.sh/clojure/variadic+function?QT
```
The cheat.sh service has its own command line client (`cht.sh`) that
has several useful features compared to querying the service directly with `curl`:
* Special shell mode with a persistent queries context and readline support.
* Queries history.
* Clipboard integration.
* Tab completion support for shells (bash, fish, zsh).
* Stealth mode.
### Installation
```
mkdir -p ~/bin/
curl https://cht.sh/:cht.sh > ~/bin/cht.sh
chmod +x ~/bin/cht.sh
```
Note: The package "rlwrap" is a required dependency to run in shell mode. Install
this using `sudo apt install rlwrap`
Now, you can use `cht.sh` instead of `curl`, and write your queries in more natural
way,
with spaces instead of `+`:
```
$ cht.sh go reverse a list
$ cht.sh python random list elements
$ cht.sh js parse json
```
If all your queries are about the same language, you can change the context
and spare repeating the programming language name:
```
$ cht.sh --shell
cht.sh> cd go
cht.sh/go> reverse a list
```
or even start the client in this context:
```
$ cht.sh --shell go
cht.sh/go> reverse a list
...
cht.sh/go> join a list
...
```
If you want to change the context, you can do it with the `cd` command,
or if you want do a single query for some other language, just prepend it with `/`:
```
$ cht.sh --shell go
...
cht.sh/go> /python dictionary comprehension
...
```
If you want to copy the last answer into the clipboard, you can
use the `c` (`copy`) command, or `C` (`ccopy`, without comments).
```
cht.sh/python> append file
# python - How do you append to a file?
with open("test.txt", "a") as myfile:
myfile.write("appended text")
cht.sh/python> C
copy: 2 lines copied to the selection
```
```
cht.sh> help
help - show this help
hush - do not show the 'help' string at start anymore
cd LANG - change the language context
copy - copy the last answer in the clipboard (aliases: yank, y, c)
ccopy - copy the last answer w/o comments (cut comments; aliases: cc, Y, C)
exit - exit the cheat shell (aliases: quit, ^D)
id [ID] - set/show an unique session id ("reset" to reset, "remove" to
remove)
stealth - stealth mode (automatic queries for selected text)
update - self update (only if the scriptfile is writeable)
version - show current cht.sh version
/:help - service help
QUERY - space separated query staring (examples are below)
cht.sh> python zip list
cht.sh/python> zip list
cht.sh/go> /python zip list
```
```
CHTSH_QUERY_OPTIONS="T"
```
```
CHTSH_QUERY_OPTIONS="style=native"
```
```
CHTSH_CURL_OPTIONS="-A curl" # curl options used for cht.sh queries
CHTSH_URL=https://cht.sh # URL of the cheat.sh server
```
```
$ curl https://cheat.sh/:bash_completion > ~/.bash.d/cht.sh
$ . ~/.bash.d/cht.sh
$ # and add . ~/.bash.d/cht.sh to ~/.bashrc
```
To activate tab completion support for `cht.sh`, add the `:zsh` script to the
*fpath* in your `~/.zshrc`:
```
$ curl https://cheat.sh/:zsh > ~/.zsh.d/_cht
$ echo 'fpath=(~/.zsh.d/ $fpath)' >> ~/.zshrc
$ # Open a new shell to load the plugin
```
Being used fully unnoticed is one of the most important property of any cheat
sheet.
cheat.sh can be used completely unnoticed too. The cheat.sh client, `cht.sh`, has
a special mode, called **stealth mode**. Using that, you don't even need to touch
your
keyboard to open a cheat sheet.
In this mode, as soon as you select some text with the mouse (and thus adding it
into the selection buffer of X Window System or into the clipboard) it's used
as a query string for cheat.sh, and the correspondent cheat sheet is automatically
shown.
Let's imagine, that you are having an online interview, where your interviewer asks
you
some questions using a shared document (say Google Docs) and you are supposed
to write your coding answers there (it's possible too that you'll type in the
questions
on your own, just to show to the interviewer that you've heard it right).
When using the stealth mode of `cht.sh`, the only thing you need to do in order to
see
a cheat sheet for some question, is to select the question using the mouse.
If you don't want any text in the answers and the only thing you need is code,
use the `Q` option when starting the stealth mode.
<p align="center">
<img src='https://cheat.sh/files/stealth-mode.gif'/>
</p>
```
You: Hi! | $ cht.sh --shell python
She: Hi! | cht.sh/python> stealth Q
She: Are you ready for a small interview? | stealth: you are in the
stealth mode; select any text
She: Just a couple of questions | stealth: selections longer
than 5 words are ignored
She: We will talk about python | stealth: query arguments: ?Q
She: Let's start from something simple. | stealth: use ^C to leave this
mode
She: Do you know how to reverse a list in python? |
You: Sure |
You: (selecting "reverse a list") | stealth: reverse a list
| reverse_lst = lst[::-1]
You: lst[::-1]? |
She: Good. |
She: Do you know how to chain a list of lists? |
You: (selecting "chain a list of lists") | stealth: chain a list of
lists
| import itertools
| a = [["a","b"], ["c"]]
| print
list(itertools.chain.from_iterable(a))
You: May I use external modules? |
She: What module do you want to use? |
You: itertools |
She: Yes, you may use it |
You: Ok, then: |
You: itertools.chain.from_iterable(a) |
She: Good. Let's try something harder. |
She: What about quicksort implementation? |
You: (selecting "quicksort implementation") | stealth: quicksort
implementation
You: Let me think about it. | (some big and clumsy lowlevel
implementation shown)
You: Well...(starting typing it in) | def
sort(array=[12,4,5,6,7,3,1,15]):
| less = []
She: (seeing your ugly pascal style) | equal = []
She: Could you write it more concise? | greater = []
| if len(array) > 1:
You: What do you mean? | pivot = array[0]
| for x in array:
She: I mean, | if x < pivot:
less.append(x)
She: do you really need all these ifs and fors? | if x == pivot:
equal.append(x)
She: Could you maybe just use filter instead? | if x > pivot:
greater.append(x)
| return sort(less)
+equal+sort(greater)
You: quicksort with filter? | else:
| return array
She: Yes |
You: (selecting "quicksort with filter") | stealth: quicksort with
filter
You: Ok, I will try. | return qsort(filter(lt,
L[1:]))+[pivot] \
You: Something like this? | +qsort(filter(ge, L[1:]))
You: qsort(filter(lt, L[1:]))+[pivot] \ |
+ qsort(filter(ge, L[1:])) |
|
She: Yes! Perfect! Exactly what I wanted to see! |
|
```
Of course, this is just for fun, and you should never cheat in your coding
interviews,
because you know what happens when you do.
* output colorization;
* command line options;
* its own configuration file.
## Self-Hosting
### Docker
Currently the easiest way to get a self-hosted instance running is by using the
docker-compose.yml file provided in the extra/docker folder.
This pulls down the latest image with baked in cheatsheets and starts the app and a
Redis instance to back it, making the service available on port 8002 of the local
host. This is currently an early implementation and should probably not be used for
anything outside of internal/dev/personal use right now.
## Editors integration
1. If you have a question while editing a program, you can just type
your question directly in the buffer and press `<leader>KK`. You will get
the answer to your question in pager. (with `<leader>KB` you'll get the answer
in a separate buffer).
2. If you like the answer, you can manually paste it from the buffer or
the pager, or if you are lazy you can use `<leader>KP` to paste it below/under
your question (or replace you question using `<leader>KR`). If you want the
answer without the comments, `<leader>KC` replays the last query
toggling them.
If you use some static analysis plugin such as *syntastic* (for Vim), you can use
its warning and error messages as cheat.sh queries: place the cursor on the problem
line
and press `<leader>KE`: explanation for the warning will be opened in a new buffer.
|Feature |Emacs|Sublime|Vim|VSCode|IDEA|
|-------------------|-----|-------|---|------|----|
|Command queries |✓ |✓ |✓ |✓ |✓ |
|Queries from buffer| | |✓ |✓ | |
|Toggle comments | | |✓ | |✓ |
|Prev/next answer | | |✓ | |✓ |
|Multiple answers | |✓ | | |✓ |
|Warnings as queries| | |✓ | | |
|Queries history | | |✓ |✓ | |
|Session id | | |✓ | | |
|Configurable server|✓ | |✓ |✓ | |
### Vim
```vim
" some configuration above ...
call vundle#begin()
Bundle 'gmarik/vundle'
Bundle 'scrooloose/syntastic'
Bundle 'dbeniamine/cheat.sh-vim'
call vundle#end()
Syntastic shows warnings and errors (found by code analysis tools: `jshint`,
`merlin`, `pylint`, `shellcheckt etc.),
and `cheat.sh-vim` shows you explanations for the errors and warnings
and answers on programming languages queries written in the editor.
Watch a demo, where the most important features of the cheat.sh Vim plugin are
shown (5 Min):
<p align="center">
<img src='https://cheat.sh/files/vim-demo.gif'/>
</p>
<p align="center">
<a href="http://www.youtube.com/watch?feature=player_embedded&v=xyf6MJ0y-z8
" target="_blank"><img src="http://img.youtube.com/vi/xyf6MJ0y-z8/0.jpg"
alt="cheat.sh-vim: Using cheat.sh from vim" width="700" height="490"
border="10" /></a>
</p>
<!-- [![asciicast](https://asciinema.org/a/c6QRIhus7np2OOQzmQ2RNXzRZ.png)]
(https://asciinema.org/a/c6QRIhus7np2OOQzmQ2RNXzRZ) -->
### Emacs
[![asciicast](https://asciinema.org/a/3xvqwrsu9g4taj5w526sb2t35.png)]
(https://asciinema.org/a/3xvqwrsu9g4taj5w526sb2t35)
* [vscode-snippet](https://github.com/mre/vscode-snippet)
* Install it from [VSCode Marketplace](https://marketplace.visualstudio.com/items?
itemName=vscode-snippet.Snippet)
Usage:
[![vscode-snippet](https://cheat.sh/files/vscode-snippet-demo.gif)]
(https://github.com/mre/vscode-snippet)
### Sublime
* [cheat.sh-sublime-plugin](https://github.com/gauravk-in/cheat.sh-sublime-plugin/)
Usage:
[![cheat.sh-sublime-plugin-demo](https://cheat.sh/files/demo-sublime.gif)]
(https://github.com/gauravk-in/cheat.sh-sublime-plugin)
* [idea-cheatsh-plugin](https://github.com/szymonprz/idea-cheatsh-plugin)
* Install from [idea plugins marketplace]
(https://plugins.jetbrains.com/plugin/11942-cheat-sh-code-snippets)
Usage:
[![idea-cheatsh-plugin](https://cheat.sh/files/idea-demo.gif)]
(https://github.com/szymonprz/idea-cheatsh-plugin)
## Special pages
There are several special pages that are not cheat sheets.
Their names start with colon and have special meaning.
Getting started:
```
:help description of all special pages and options
:intro cheat.sh introduction, covering the most important usage
questions
:list list all cheat sheets (can be used in a subsection too:
/go/:list)
```
Editors support:
```
:vim cheat.sh support for Vim
:emacs cheat.sh function for Emacs
:emacs-ivy cheat.sh function for Emacs (uses ivy)
```
Other pages:
```
:post how to post new cheat sheet
:styles list of color styles
:styles-demo show color styles usage examples
```
## Search
```
/~keyword
```
```
/~snapshot look for snapshot in the first level cheat sheets
/scala/~currying look for currying in scala cheat sheets
```
```
/~snapshot/r look for snapshot in all cheat sheets
```
You can use special search options after the closing slash:
```
/~shot/bi case insensitive (i), word boundaries (b)
```
```
i case insensitive search
b word boundaries
r recursive search
```
```
lua
lua/hello
lua/:list
lua/:learn
```
```
perl/1line
```
* `hello` describes how you can start with the language — install it if needed,
build and run its programs, and it shows the "Hello world" program written in the
language;
* `:list` shows all topics related to the language
* `:learn` shows a learn-x-in-minutes language cheat sheet perfect for getting
started with the language.
* `1line` is a collection of one-liners in this language
* `weirdness` is a collection of examples of weird things in this language
![cheat.sh usage](http://cheat.sh/files/supported-languages-c++.png)
Pie diagram reflecting cheat sheets sources distribution (by number of cheat sheets
on cheat.sh originating from a repository):
## How to contribute
If you want to edit a cheat.sh cheat sheet, you should edit it in the upstream
repository.
You will find the name of the source repository in a browser when you open a cheat
sheet.
There are two github buttons at the bottom of the page: the second one is the
button
of the repository, which belongs the current cheat sheet.
You can edit the cheat sheet directly in your browser (you need a github account
for it).
There is an edit button in the top right corner. If you click on it, an editor will
be open.
There you will change the cheat sheet (under the hood: the upstrem repository is
forked, your changes are
committed in the forked repository, a pull request to the upstream repository owner
is sent).
If you want to add a cheat sheet, you have one of the following
ways:
* Add it to one of the external cheat sheets repositories; you should decide on
your own what is the best repository for your cheat sheet;
* Add it to the local cheat.sh repository ([cheat.sheets]
(https://github.com/chubin/cheat.sheets)) on github (fork, commit, pull request);
* Post it on cheat.sh using curl or a web browser ([cheat.sh/:post]
(http://cheat.sh/:post)).
If you want to add a cheat sheet repository to cheat.sh, please open an issue:
Please specify the name of the repository, and give its short description.