Cheat sheet for programmers or "we google for you"

Introduction, which can not read


A modern programmer, and even more so a beginner at a level lower than junior, hell, needs the ability to use a search engine. It seems there is nothing difficult in this, but nevertheless questions often pop up on questionnaires, which have long been answered in the first tab of the search engine output. Why is that? Inexperience, laziness - a lot of reasons. We are interested in laziness, let's simplify a little and automate the process of “googling”.


Actually, the essence


So, I present to you the service " cheat.sh ". It is written in Python, so that Pythonists may be interested. There are several implementations of it:


  • Through "curl" on the command line;
  • Through the browser.
  • Through code editors: Emacs, Vim, Sublime Text, VSCode.

How to use


Using "curl"


Here you need to have the utility "curl". On Linux distributions, it already exists; for Windows, it needs to be installed separately. I had no problems with Windows.


Go to the console and send a request of this type:
curl cht.sh/[язык]/[запрос-с-дефисом-вместо-пробела]
Get the answer:


$ curl cht.sh/python/how-to-read-text-file
#  How to read a text file into a list or an array with Python ...##  You will have to split your string into a list of values using split()##  So,
lines = text_file.read().split(',')
#  [Achrome] [so/q/14676265] [cc by-sa 3.0]

Initially, the utility was conceived as a cheat sheet for commands for the Linux terminal, so you can look for help on them:


$  curl cheat.sh/tar
$  curl cht.sh/curl
$  curl https://cheat.sh/rsync
$  curl https://cht.sh/tr

You can also install the console utility:


$   curl https://cht.sh/:cht.sh > ~/bin/cht.sh
$   chmod +x ~/bin/cht.sh

Use example here .
There are no such commands for Windows, so there is an option to use Cygwin, Git bash and so on.
At your peril.


Using a browser


Just go to the desired link in the browser.
For examplewww.cht.sh/python/how-to-read-text-file


image


A link can be sent as a response to Stackoverflow, for example.


Using code editors


What for? In order not to leave the editor get a copy-paste solution code.


Plugin for Emacs ,
Plugin for Sublime Text ,
Plugin for Vim ,
Plugin for VSCode .


Interesting


Tab auto-complement


Installation for bash:


    $ curl https://cheat.sh/:bash_completion > ~/.bash.d/cht.sh
    $ . ~/.bash.d/cht.sh
    $ # and add . ~/.bash.d/cht.sh to ~/.bashrc

Installation for ZSH:


    $ curl https://cheat.sh/:zsh > ~/.zsh.d/_cht
    $ echo'fpath=(~/.zsh.d/ $fpath)' >> ~/.zshrc
    $ # Open a new shell to load the plugin

Response parameters


If you do not need syntax highlighting in the answer:
curl cht.sh/python/open-file?T


If you need only code without comments:
curl cht.sh/python/open-file?Q


You can combine this:
curl cht.sh/python/open-file?QT


Stealth mode


Open the client version with the parameter "--shell" and use:
$ cht.sh --shell [язык программирования]
$ stealth [параметры]
Why? To quickly get an answer. The author proposes to use this in remote interviews. It's just a matter of your own conscience.


One-line solutions


curl cht.sh/[язык]/1line


There is even for Python. Yes, for a language where the separation of blocks of code is a newline.


Oddities of programming languages


curl cht.sh/[язык]/weirdness


View another answer


If you are not satisfied with the current response to your request, you can see another:
curl cht.sh/[язык]/[запрос]/[номер ответа]


And what, with the help of one utility you can learn the basics of the language?


$ curl cht.sh/[язык]/:learn


Conclusion


In general, everything. Maybe someone already knows about “cht.sh” and uses it, but I did not find any normal materials about it in Russian. On GitHub there is a table of completeness “cht.sh” by languages, links to plug-ins for editors, and a complete guide if someone doesn’t like mine. Thanks for reading.


Also popular now: