I want to write a document which includes a part of source code with line numbers.
Example(whitch I expected):
123. int myFunc() {
124. return 100;
125. }
When I use sourcecode/code-block directive, line number is always started from 1.
Currently, I tried following methods, but these are not worked.
Is there any way to control line numbers?
A: use 'linenostart' option.
.. sourcecode:: cpp
:linenos:
:linenostart: 123
int myFunc() {
return 100;
}
=> it was result in error "unknown option: lineno"
B: use literal include.
.. literalinclude:: my_func.cpp
:language: cpp
:linenos:
:lines: 123-125
=> it was result in no error, but line number is start from 1.
Thanks in advance.
Related
I am trying to read data(multiline of key:value pair) from file, which I have written line by line to file, In Jenkinfile
However when I tried to do each line it is read char by char
Example:
echo "1234:34" >> dataList.txt
echo "2341:43" >> dataList.txt
echo "3412:54" >> dataList.txt
echo "4123:38" >> dataList.txt
When I tried to read line by line using commands
def buildData = readFile(file: "dataList.txt")
println buildData
buildData.each { line ->
println line
//def (oldBuildNumber, oldJobId) =line.tokenize(':')
//println oldBuildNumber oldJobId
}
}
displaying as
1
2
3
4
:
3
4
2
3
4
1
:
4
3
...
Any input on this will be very useful.
From the readFile documentation:
readFile: Read file from workspace
Reads a file from a relative path (with root in current directory, usually workspace) and returns its content as a plain string.
This means the the returned value, buildData in your case, is actually a string, and therefore when you iterate over it using the each you are actually iterating over the characters (as a characters array) and that is why you see each character being printed for each iteration.
What you actually want is to iterate over the lines, for that you can split the string using the new line separator (\n) which will give you a list of all lines which you can then iterate over.
Something like the following:
def buildData = readFile(file: "dataList.txt")
println buildData
// split the content into lines and go over each line
buildData.split("\n").each { line ->
println line
}
// or by using the default iterator parameter - it
buildData.split("\n").each {
println it
}
I have this assertion :
cy.get('.myelement').should('have.css', 'background-color','rgb(75, 221, 51)')
I want to replace it with hexadecimal representation as following:
cy.get('.myelement').should('have.css', 'background-color','#4BDD33')
but I get this error from cypress :
expected <.myelement> to have CSS property background-color with the value #4BDD33, but the value was rgb(75, 221, 51)
any help
You can do something like this:
Install the rgb-hex package
npm install rgb-hex
In your test suite file import the package
import rgbHex from 'rgb-hex';
In your test write:
cy.get('.myelement')
.invoke('css', 'background-color')
.then((bgcolor) => {
expect(rgbHex(bgcolor)).to.eq('4bdd33')
})
I'd take the reverse approach of Alapan -- I prefer to modify my expected and leave my actual values alone. To do this, you'd need a way to turn your expected Hex value into the rgb() format.
const hexToRgb = (hex) => {
const rValue = ParseInt(hex.substring(0, 2), 16);
const gValue = ParseInt(hex.substring(2, 4), 16);
const bValue = ParseInt(hex.substring(4), 16);
return `rgb(${rValue}, ${gValue}, ${bValue})`;
}
cy.get('.myelement').should('have.css', 'background-color', hexToRgb('4BDD33'));
If you wanted to include the # in the hex string, you would just need to ignore it in setting the values, most likely by increasing every number in the substring() functions by one.
Overall, I think that Alapan's solution is easier, but this is just something to consider.
My input file:
000000000 vélIstine IOBAN 00000004960
000000000 shankargu kumar 00000000040
TTTTTTTTT 0000000200000000050000000000000000000000
whenever I have non Ascii character in the file like above,
my below code snippet not calculating the sum (d_amt_sum+=substr($0,27,10)) properly sometimes its skiping that row and sometime its giving incorrect value instead of 496 its returning 49 for substr($0,27,10)?
besides I want to know how to add print statement inside AWK, example i need to print the value of "substr($0,27,10)" inside the if block how to do that?
set -A out_result -- `LC_ALL=en_US.UTF-8 awk 'BEGIN{
d_amt_sum=d_rec_count=d_trailer_out_amt_sum=d_trailer_rec_count=0;
}
{
if(substr($0,1,9) != "TTTTTTTTT")
{
d_amt_sum+=substr($0,27,10); d_rec_count+=1
}
else if(substr($0,1,9) == "TTTTTTTTT")
{
d_trailer_out_amt_sum+=substr($0,39,12);
d_trailer_rec_count+=substr($0,31,8);
}
}
END{print d_amt_sum, d_rec_count,d_trailer_out_amt_sum,d_trailer_rec_count}' ${OUTDIR}/${OUT_FILE}
Expected output
500,2,500,2
you have a logic error on the ordering of the if/else statements, another error on checking 1 char length against 9 char length. Fixing both gives...
awk '{k=substr($0,1,9)
if(k=="TTTTTTTTT")
{d_trailer_out_amt_sum+=substr($0,39,12)
d_trailer_rec_count+=substr($0,31,8)}
else if(k!="999999999")
{d_amt_sum+=substr($0,27,10);
d_rec_count+=1}}
END {print d_amt_sum, d_rec_count,d_trailer_out_amt_sum,d_trailer_rec_count}' file
500 2 500 2
I have this code:
function var_leafdrop(var_inc, var_restpos)
If var_y >= var_restpos then
var_y = var_restpos
else
var_y = var_y + var_inc
end
return var_y
end
I get error:
error 18: '=' expected near 'var_y'
18 being the line:
If var_y >= var_restpos then
I've tried:
Changing the variable name
Changing its declaration
Removing the if then block
Moving the entire function to the beginning of the script file
This is using the built in script editor for Watchmaker.
I can't see any error!? I just don't get it. Is this some dumb idiosyncrasy with Watchmaker...?
As mentioned in the comments, Lua is case sensitive.
So use if instead of If.
I have the following code:
term_to_packet(Term) ->
B = term_to_binary(Term),
A = byte_size(B),
<< 1:4/integer-unit:8, B:A/integer-unit:8 >>.
However, when I run:
term_to_packet("Hello").
I get an error:
exception error: bad argument in function term_to_packet line 20
where line 20 corresponds to the last line of the term_to_packet function.
I'm not quite sure what's throwing this error.
B is a binary, but in the binary construction on the last line you specify that it is an integer. This seems to work:
term_to_packet(Term) ->
B = term_to_binary(Term),
A = byte_size(B),
<< 1:4/integer-unit:8, B:A/binary-unit:8 >>.