Multiline comments in Dockerfiles - docker

Is there a fast way to comment out multiple lines in a Dockerfile?
I know that I can add # at the beginning of each line. But if there are many lines this is too much work. In some languages there are multiline comments such as /* ... */, which makes commenting out large parts of a file very fast.

As of today, no.
According to Dockerfile reference documentation:
Docker treats lines that begin with # as a comment, unless the line is
a valid parser directive. A # marker anywhere else in a line is
treated as an argument.:
There is no further details on how to comment lines.
As said by some comments already, most IDE will allow you to perform multiline comments easily (such as CTRL + / on IntelliJ)

There is no mentioning of multiline comments in Docker documentation
I also paste here the relevant part for simplicity:
Docker treats lines that begin with # as a comment, unless the line is
a valid parser directive.
A # marker anywhere else in a line is treated as an argument.
This allows statements like:
# Comment
RUN echo 'we are running some # of cool things'
Line continuation characters are not supported in comments.
On the other hand you can achieve the requested result easily with any modern IDE / Text Editor.
This is an example using Sublime Text (Select text and then control + /).
You can achieve the same result with VsCode, Notepad++, JetBrains products (IntelliJ, PyCharm, PHPStorm etc.) and almost 100% of the IDEs / Text Editors I know and use.

good solution in VSCode (and many other IDEs) would be:
select all lines that you want to comment out. Hit TAB three times. Now press CTRL+F and search for three TAB spaces (' ') and then replace all with '# '. All lines that had three TAB spaces in front of it now have a '# ' in front of it.

Related

Snippets for Gedit: how to change the text in a placeholder to make the letters uppercase?

I’m trying to improve a snippet for Gedit that helps me write shell scripts.
Currently, the snippet encloses the name of a variable into double quotes surrounding curly brackets preceded with a dollar sign. But to make the letters uppercase, I have to switch to the caps-lock mode or hold down a shift key when entering the words. Here is the code of the snippet:
"\${$1}"
I would like that the snippet makes the letters uppercase for me. To do that, I need to know how to make text uppercase and change the content of a placeholder.
I have carefully read the following articles:
https://wiki.gnome.org/Apps/Gedit/Plugins/Snippets
https://blogs.gnome.org/jessevdk/2009/12/06/about-snippets/
https://www.marxists.org/admin/volunteers/gedit-sed.htm
How do you create a date snippet in gedit?
But I still have no idea how to achieve what I want — to make the letters uppercase. I tried to use the output of shell programs, a Python script, the regular expressions — the initial text in the placeholder is not changed. The last attempt was the following (for clarity, I removed the surrounding double-quotes and the curly brackets with the dollar — working just on the letter case):
${1}$<[1]: return $1.upper()>
But instead of MY_VARIABLE I get my_variableMY_VARIABLE.
Perhaps, the solution is obvious, but I cannot get it.
I did it! The solution found!
Before all, I have to say that I don’t count the solution as correct or corresponding to the ideas of the Gedit editor. It’s a dirty hack, of course. But, strangely, there is no way to change the initial content of placeholders in the snippets — haven’t I just found a standard way to do that?
So. If they don’t allow us to change the text in placeholders, let’s ask the system to do that.
The first thought that stroke me was to print backspace characters. There are two ways to do that: a shell script and a python script. The first approach might look like: $1$(printf '\b') The second one should do the same: $1$<[1]: return '\b'> But both of them don’t work — Gedit prints surrogate squares instead of real backspace characters.
Thus, xdotool is our friend! So is metaprogramming! You will not believe — metaprogramming in a shell script inside a snippet — sed will be writing the scenario for xdotool. Also, I’ve added a feature that changes spaces to underscores for easier typing. Here is the final code of the snippet:
$1$(
eval \
xdotool key \
--delay 5 \
`echo "${1}" | sed "s/./ BackSpace/g;"`
echo "\"\${${1}}\"" \
| tr '[a-z ]' '[A-Z_]'
)$0
Here are some explanations.
Usually, I never use backticks in my scripts because of some troubles and incompatibilities. But now is not the case! It seems Gedit cannot interpret the $(...) constructions correctly when they are nested, so I use the backticks here.
A couple of words about using the xdotool command. The most critical part is the --delay option. By default, it’s 12 milliseconds. If I leave it as is, there will be an error when the length of the text in the placeholder is quite long. Not to mention the snippet processing becomes slow. But if I set the time interval too small, some of the emulated keystrokes sometimes will be swallowed somewhere. So, five milliseconds is the delay that turns out optimal for my system.
At last, as I use backspaces to erase the typed text, I cannot use template parts outside the placeholder. Thus, such transformations must be inside the script. The complex heap after the echo command is what the template parts are.
What the last tr command does is the motivator of all this activity.
It turns out, Gedit snippets may be a power tool. Good luck!

Trix formatting rules

When users paste items from MS word, for example numbered list or bullet points Trix leaves the symbols in, but does not use the default stye rules. eg See below. Note the indenting
I am wanting to replace pasted bulletpoints with '<li>' tags since that is how the browser, or just adds the default style rules to the text.
As a workaround I was thinking that using Javascript/coffee script to replace all incidents of '•' to <li> during a paste command using onPaste='' However this is problematic, since the implementation could cause unforeseen effects.
Another way might be to create a regex expression, to remove the sybols and do It JIT while pasting.
Any other suggestions would be welcome in achieving this.
Edit
/\d\.\s+|[a-z]\)\s+|•\s+|[A-Z]\.\s+|[IVX]+\.\s+[•].\s/g
This regex expression can find Numbered list and a simple replace on the pasted string, will allow for the desired results.

Atom editor: indentation adding extra unwanted spaces

When hitting enter in Atom editor for python code the cursor at the new line adds two extra spaces. So it doesn't end up where it should, i.e. two spaces in as in the rest of the code.
I have already followed the suggestions mentioned here, i.e. tablength=2, softtab with auto mode: How to change new line indentation in atom editor?
In vim it seems this is set by the shiftwidth keyword (i.e. =4 means same problem as above, =2 means it works). I couldn't find this keyword for Atom though.

Ruby convention for chaining calls over multiple lines

What are the conventions for this?
I use the folowing style, but not sure it is the preferred one since if I miss a dot at the end I can run into a lot of issue without realising that.
query = reservations_scope.for_company(current_company).joins{property.development}.
group{property.development.id}.
group{property.development.name}.
group{property.number}.
group{created_at}.
group{price}.
group{reservation_path}.
group{company_id}.
group{user_id}.
group{fee_paid_date}.
group{contract_exchanged_date}.
group{deposit_paid_date}.
group{cancelled_date}.
select_with_reserving_agent_name_for(current_company, [
"developments.id as dev_id",
"developments.name as dev_name",
"properties.number as prop_number",
"reservations.created_at",
"reservations.price",
"reservations.fee_paid_date",
"reservations.contract_exchanged_date",
"reservations.deposit_paid_date",
"reservations.cancelled_date"
]).reorder("developments.name")
query.to_a # ....
So what are the conventions for chaining methods over multiple lines and which one should I prefer?
NOTE: I couldn't find a good example from the Ruby coding style guide.
There is actually a section on that in the Ruby style guide:
Adopt a consistent multi-line method chaining style. There are two
popular styles in the Ruby community, both of which are considered
good - leading . (Option A) and trailing . (Option B).
(Option A) When continuing a chained method invocation on
another line keep the . on the second line.
# bad - need to consult first line to understand second line
one.two.three.
four
# good - it's immediately clear what's going on the second line
one.two.three
.four
(Option B) When continuing a chained method invocation on another line,
include the . on the first line to indicate that the
expression continues.
# bad - need to read ahead to the second line to know that the chain continues
one.two.three
.four
# good - it's immediately clear that the expression continues beyond the first line
one.two.three.
four
A discussion on the merits of both alternative styles can be found
here.
In Ruby 1.9+ it's possible to write like this:
query = reservations_scope
.for_company(current_company)
.joins{property.development}
.group{property.development.id}
.group{property.development.name}
.group{property.number}
.group{created_at}
.group{price}
.group{reservation_path}
.group{company_id}
.group{user_id}
Much more readable, I think.
Here is a complete list of pros and cons of four options. Two of the options have not been mentioned in any other answer.
Pros and cons can be broken into unique ones and shared ones. Shared pros are the inverses of a unique con of another option. Similarly, shared cons are the inverses of a unique pro of another option. There are also some points that are pros for two options and cons for the other two.
To avoid repeating explanations, I describe each option’s shared pros and cons with just a summary of that point. Full details about a shared pro or con are available in the description of their inverse con or pro in another option’s unique section. For the points that are pros of two options and cons of the other two, I arbitrarily chose to put the full explanations in the set that starts with “. at line beginning”.
For a shorter list that leaves the shared pros and cons implicit instead of repeating them, see this old version of this answer.
. at line end
items.get.lazy.
take(10).
force
Pros
Shared with only one other option:
Continuing lines can be commented out freely, and comments can be added between lines
Pastable into IRB/Pry
Supported in Ruby 1.8
Shared with two other options:
When you read the initial line, it is clear that the expression continues
Plenty of horizontal space for continuing lines
Doesn’t require manual alignment of characters into columns
Looks fine when viewed in a proportional font
Has a minimum of punctuation, reducing typing and visual noise
Cons
Unique:
Continuing lines look strange on their own. You must read the preceding line to understand that they are a continuation.
Indentation is not a reliable indicator that a line continues from the previous line – it could merely mean the start of a block.
Shared with only one other option:
When editing the code, it is harder to comment out or reorder the last line
. at line beginning
items.get.lazy
.take(10)
.force
Pros
Shared with only one other option:
When editing the code, it is easier to comment out or change the order of the last line – no need to delete and add . or \.
Shared with two other options:
Continuing lines can be understood when seen on their own
Plenty of horizontal space for continuing lines
Doesn’t require manual alignment of characters into columns
Looks fine when viewed in a proportional font
Has a minimum of punctuation, reducing typing and visual noise
Cons
Unique:
When you read the initial line, it’s not immediately clear that the expression continues
If you use this in your codebase, then when you read a line, you must always check the line after to make sure that it doesn’t affect the initial line’s meaning.
Shared with only one other option:
The code silently breaks if you # comment out a continuing line, or add a comment between lines
You can’t paste this code into IRB/Pry without it being misinterpreted
Not supported in Ruby 1.8 and below
. at line beginning, indented to the previous .
items.get.lazy
.take(10)
.force
Pros
Shared with only one other option:
When editing the code, it is easier to comment out or change the order of the last line – no need to delete and add . or \.
Shared with two other options:
When you read the initial line, it is clear that the expression continues
Continuing lines can be understood when seen on their own
Has a minimum of punctuation, reducing typing and visual noise
Cons
Unique:
Each line’s code must fit into less horizontal space
Requires manual alignment of the .s into columns
It is easier if you have an editor plugin for aligning text, but still more work than using default indentation rules.
Even if your editing setup includes a plugin for alignment, your coworkers’ setups may not.
The code will look misaligned when viewed in a proportional font
Shared with only one other option:
The code silently breaks if you # comment out a continuing line, or add a comment between lines
You can’t paste this code into IRB/Pry without it being misinterpreted
Not supported in Ruby 1.8 and below
Shared with two other options:
When editing the code, it is harder to comment out or reorder the last line
\ at line end, . at next line’s beginning
items.get.lazy \
.take(10) \
.force
Pros
Shared with only one other option:
Continuing lines can be commented out freely, and comments can be added between lines
Pastable into IRB/Pry
Supported in Ruby 1.8
Shared with two other options:
When you read the initial line, it is clear that the expression continues
Continuing lines can be understood when seen on their own
Plenty of horizontal space for continuing lines
Doesn’t require manual alignment of characters into columns
Looks fine when viewed in a proportional font
Cons
Unique:
Requires more typing
Creates more visual noise
Shared with only one other option:
When editing the code, it is harder to comment out or reorder the last line
The reason why I choose the dot in the end of the line is that it will allow you to paste code in an IRB session. Also, you can't comment lines in the middle of the multi-line code if you use the dots in the beginning of the lines. Here's a good discussion to read: https://github.com/bbatsov/ruby-style-guide/pull/176

Replace strings in LaTeX

I want LaTeX to automatically replace strings like " a ", " s ", " z " with " a~", " s~", " z~", because they can't be at line end. Any suggestions?
For Czech typographic rules, there is a preprocessor called Vlna" by Petr Olšák - download . The set of (usually prepositions in czech) is customizable - so it might be usable for other languages as well.
You can use \StrSubstitute from xstring package.
e.g.
\StrSubstitute{change ME}{ ME}{d}
will convert change ME into changed.
Although, nesting is not possible, so to make another substitution you must use an intermediate variable in this way
\StrSubstitute{change ME}{ ME}{d}[\mystring]
\StrSubstitute{\mystring}{ed}{ing}
Finally, your solution would be
\usepackage{xstring}
\def\mystring{...source string here...}
\begin{document}
\StrSubstitute{\mystring}{ a }{a~{}}[\mystring]
\StrSubstitute{\mystring}{ s }{s~{}}[\mystring]
\StrSubstitute{\mystring}{ z }{z~{}}[\mystring]
\mystring
\end{document}
Note the use of the empty string {} to avoid the sequence ~}.
I'm afraid (to the best of my knowledge) this is basically impossible with LaTeX. A LuaTeX-based solution might be possible, though.
It's not actually clear to me, however, that " a ", for example, shouldn't appear at the end of a
line. Although I might be used to different typographic rules.
(Is there anything wrong with the line break in the last paragraph? :))
As far as I know there is no way to do this in LaTeX itself. I'd go for automating this with some external tools, as my typical setup involves a Makefile handling the LaTeX run by itself. This makes it rather easy to run tools like sed on the sources and do some replacements using regular expressions, and a simple rule would do this for your case.
If you use some LaTeX editor that does everything for you you should check the editors regular expression search and replace functionality.
Yes, this is the age old argument of data processing vs. data composition. We have always done these things in a pre-processor environment responsible for extracting the information from its source environment, SQL or plain-text, and created the contents of a \input(file.tex).
But yes, it is possible (TeX is after all a programming language) but you will have to become a wizard. Get the 4 volume set TeX in Practice by Stephan von Bechtolsheim.
The approach would be to begin an environment (execute a macro) whose ''argument'' was all text down to the end of the environment. Then just munge though the tokens fixing the ones you want.
Still, I don't think any of us are advocating this approach.
If you are using TeXmaker to write your LaTeX file, then you may click on the Edit button on the toolbar, then click on Replace.
A dialogue box will come up, and you can enter your strings one after the other.
You put the strings to be changed in the Find text input and what you want it to be changed to in the Replace text input.
You can also specify where you want the replacement to start from.
Click Find and Replace (or similiar) in the menu of your text editor and do it.

Resources