--- title: Code with comments description: Notes about programming with code snippets and comments. Problem solutions and solution descriptions. sections: [Problem solutions and solution descriptions] tags: [java,javascript,linux,bash,algorithms,implementation,text,fonts,combinations,images,pictures,cryptography] canonical_url: /en/ url_translated: /ru/ title_translated: Код с комментариями lang: en --- {%- assign articles = "" | split: "" %} {%- assign articles = articles | push: "Directory tree with links" %} {%- capture article_brief %} We write a Bash script for building a directory tree for a repository in the Markdown file. We use only the accessories of Bash and the `ls` program. We will use the resulting file in the web interface to navigate over the objects of the repository. We create a recursive function and use it to bypass files and directories of the repository. For each directory, we execute the program `ls` and get a sorted list of files and directories included in it: first there are directories, then files, first uppercase letters, then lowercase, exclude the untracked files that are not in the repository — we get the directory tree in a sorted form. {%- endcapture %} {%- assign articles = articles | push: article_brief %} {%- assign articles = articles | push: "Password generator" %} {%- capture article_brief %} We write a program in JavaScript for the formation of random 20-symbol combinations of latin letters, numbers and special characters. There are 60 variants to choose from — 4 columns of 15 rows. First character — is always a letter, all characters in each combination go without repetitions. We will form passwords for web-sites in the browser. I have been using this algorithm for a long time — I have all passwords for web-sites generated by this scheme, so I recommend it. The first version was written in Java, but for web-sites it turns out easier in JavaScript, so as not to go far. {%- endcapture %} {%- assign articles = articles | push: article_brief %} {%- assign articles = articles | push: "Drawing heart in console" %} {%- capture article_brief %} Let's write two versions of the algorithm in Java to output a heart to the console in the form of a text image — let's congratulate women on the eighth of March. Let's draw a graph of the function in the form of a heart and, in addition, draw the symbol *heart* in the form of a picture, and output the picture as text — console congratulations on the eighth of March. {%- endcapture %} {%- assign articles = articles | push: article_brief %} {%- assign articles = articles | push: "Function graph in console" %} {%- capture article_brief %} Let's write an algorithm to output a graph of a function or a system of equations to the console in the form of text. We will use Java tools. For calculations, we will use the `Math` class, and to bypass the range of coordinates, we will use two nested `for` loops. We draw in the console a graph of a circle and graphs of a rhombus and a square inscribed in it. {%- endcapture %} {%- assign articles = articles | push: article_brief %} {%- assign articles = articles | push: "Drawing simple captcha" %} {%- capture article_brief %} Let's write an algorithm for displaying text as an image using the Java AWT library. Symbols and font can be any, but for this example we will use a combination of uppercase latin letters and digits with the *Comic Sans* font — we will draw a simple captcha for a website or blog. We'll consider special characters, but we won't use them, because it will be difficult for the user to guess them with such a text decoration. For example, the plus `+` is still possible to guess, but the minus `-` or the underscore `_` is already with difficulty, and even if you guess right, then to find these buttons with difficulty, especially on the phone. Therefore, for captcha we'll use a combination of only capital latin letters and digits. {%- endcapture %} {%- assign articles = articles | push: article_brief %} {%- include main_page.html articles = articles -%}