vim grepformat for node-jslint output - vim

What is the Vim grepformat of the following error output (error output from node-jslint)?
static/js/t.js
#1 Expected 'this' at column 5, not column 3.
this.JSON2 = {}; // Line 44, Pos 3
#2 Expected 'use strict' at column 5, not column 3.
"use strict"; // Line 48, Pos 3

Found answer at https://stackoverflow.com/a/8706966/433662
Used ...
setlocal efm=%-P%f,
\%E%>\ #%n\ %m,%Z%.%#Line\ %l\\,\ Pos\ %c,
\%-G%f\ is\ OK.,%-Q
Plus :make:cw

Related

Pyomo: sending options="threads" to cbc solver causes an error

It is possible to activate multithreading in a command line:
$cbc -threads=6
Welcome to the CBC MILP Solver
Version: 2.9.9
Build Date: Aug 21 2017
$command line - cbc -threads=6 (default strategy 1)
threads was changed from 0 to 6
But when I try to activate this option in pyomo code
opt = SolverFactory('cbc')
result = opt.solve(instance, options="threads=4")
I get an error:
File "/usr/local/lib/python3.9/dist-packages/pyomo/opt/base/solvers.py", line 561, in solve
self.options.update(kwds.pop('options', {}))
File "/usr/local/lib/python3.9/dist-packages/pyutilib/misc/misc.py", line 360, in update
if type(d[k]) is dict:
TypeError: string indices must be integers
Any ideas?
The options keyword argument expects a dictionary. If you want to use the same syntax as the command line, you're after options_string
opt.solve(instance, options_string="threads=4")
opt.solve(instance, options={"threads": 4})

View exported console coloured logs

Is there a way to view exported coloured logs as in console (with colour)?
My program uses colour coding for errors, warnings, etc. If I redirect output of my program to file.log, I get records like:
[32m[1m(INF)[0m /environment/converter: State map: [ 2, 3, 4, 5, 6, 7, 8, 11, 12, 13, 14, 15, 16, 17, 18 ][0m
[32m[1m(INF)[0m /environment/converter: Action map: [ -1, -1, -1, 0, 1, 2, 3, 4, 5 ][0m
[32m[1m(INF)[0m PyEnv: Observation dims: 15[0m
[32m[1m(INF)[0m PyEnv: Action dims: 6[0m
Random seed None
[32m[1m(INF)[0m GRL seed 1428[0m
Now I want to see file.log, but without colour codes or even better with colours preserved.
I have tried nano, vi and gedit but they all do not do what I want.
Here are some ideas if you're still wondering for a good way to do this.
A text editor won't be able to read the color codes, as those are Bash specific. However, cat works because it can interpret the color codes. However, the way you're storing the colors isn't formatted correctly in the first place.
I'm not sure how you are writing into your log file, but I echoed your example and redirected the output into a file. I didn't see colors either. The reason is that you have to escape every square bracket for the codes to be interpreted by Bash.
So the way that I escaped the brackets is by manually adding \e before every square bracket and using echo -e to evaluate the escape characters:
`echo -e "\e[32m\e[1m(INF)\e[0m /environment/converter: State map: [ 2, 3, 4, 5, 6, 7, 8, 11, 12, 13, 14, 15, 16, 17, 18 ]\e[0m`
`\e[32m\e[1m(INF)\e[0m /environment/converter: Action map: [ -1, -1, -1, 0, 1, 2, 3, 4, 5 ]\e[0m`
`\e[32m\e[1m(INF)\e[0m PyEnv: Observation dims: 15\e[0m`
`\e[32m\e[1m(INF)\e[0m PyEnv: Action dims: 6\e[0m`
`Random seed None`
`\e[32m\e[1m(INF)\e[0m GRL seed 1428\e[0m " > example.txt`
Now when I open the file with cat I see correctly colored text:
The color codes are now stored and escaped correctly in the .txt file:
^[[32m[1m(INF)[0m GRL seed 1428^[[0m
vs
[32m[1m(INF)[0m GRL seed 1428[0m
An alternative solution is to use a package like Ansi Html Adapter (Aha).
It will produce HTML instead of plain text. Then you can open the output in your browser, and it would have the right color coding.
However, you would meet with the same problem. If the color codes aren't escaped correctly, the output is not going to be colored.
I ran the following command to convert the correctly formatted text to HTML:
aha -f example.txt > example.html
Here's the result in the browser:
You can find more info on how to use colors in bash in this Bash Tips article.

The way a program executes by line

def main():
result1=cubeVolume(2)
result2=cubeVolume(10)
print("side length 2 equals",result1)
print("side legnth 10 equals",result2)
def cubVolume(sidelength):
volume = sideLength**3
return volume
main()
Would I be correct in saying that this executes in the following sequence line?
9,1,2,6,7,8,3,4,5
Line numbers execute as follows:
1,6,9,
1,2,
6,7,8,
3,
6,7,8,
4,5
6,7,8 is your cubVolume function. This function should be cubeVolume (or more pythonicly cube_volume). Edit: I have put 1, 6, 9 in to state where the functions are being registered as suggested by poke.

Vim errorformat for jshint (with example)

I am trying to write efm for this:
file: app/assets/javascripts/topbar.js
line 17, col 3, Missing semicolon.
line 19, col 19, 'is_mobile' was used before it was defined.
line 21, col 1965, Expected '{' and instead saw 'check'.
line 25, col 18, 'onScroll' was used before it was defined.
file: app/assets/javascripts/trends.js
line 2, col 55, Missing semicolon.
line 6, col 27, 'trendTypeSelected' was used before it was defined.
line 7, col 32, Expected '===' and instead saw '=='.
JSHint check failed
but I think I am missing the concept of file on separate line. Can someone help me out with
this?
This is what I have so far and it does not work:
%-Pfile:\ %f,line\ %l\,\ col\ %c\,\ %m
Thanks!
Solution:
set efm=%-Pfile:\ %f,%*[\ ]line\ %l\\,\ col\ %c\\,\ %m,%-Q,%-GJSHint\ check\ failed
Vim provides %P, which pushes the parsed file (%f) onto the stack, see :help errorformat-separate-filename.
So for your error output, it would be something like %+Pfile: %f,...

Count columns in csv in gnuplot

Is there a function in gnuplot which returns the number of columns in a csv file?
I can't find anything in the docs, maybe someone can propose a custom made function for this?
As of gnuplot4.6, you can make a little hack script to do this. It is certainly not the most efficient, but it is pure gnuplot:
#script col_counter.gp
col_count=1
good_data=1
while (good_data){
stats "$0" u (valid(col_count))
if ( STATS_max ){
col_count = col_count+1
} else {
col_count = col_count-1
good_data = 0
}
}
Now in your main script,
call "col_counter.gp" "my_datafile_name"
print col_count #number of columns is stored in col_count.
This has some limitations -- It will choke if you have a column in the datafile that is completely non-numeric followed by more valid columns for example, but I think that it should work for many typical use cases.
print col_count
As a final note, you can use the environment variable GNUPLOT_LIB and then you don't even need to have col_counter.gp in the current directory.
Assuming this is related to this question, and that the content of infile.csv is:
n,John Smith stats,Sam Williams stats,Joe Jackson stats
1,23.4,44.1,35.1
2,32.1,33.5,38.5
3,42.0,42.1,42.1
You could do it like this:
plot.gp
nc = "`awk -F, 'NR == 1 { print NF; exit }' infile.csv`"
set key autotitle columnhead
set datafile separator ','
plot for [i=2:nc] "< sed -r '1 s/,([^ ]+)[^,]+/,\\1/g' infile.csv" using 1:i with lines
Note that the \1 needs escaping when used within " in Gnuplot.
Output:
Here is an update and an alternative extended retro-workaround: (of course gnuplot-only)
Update: (gnuplot>=5.0.0, Jan 2015)
Since gnuplot 5.0.0, there is the variable STATS_columns which will tell you the number of columns of the first unommented row.
stats FILE u 0 nooutput
print STATS_columns
Extended retro-workaround: (gnuplot>=4.6.0, March 2012)
Some time ago, I learnt that a correct CSV file should have the same number of columns (i.e. commas) in all rows. So it should be sufficient to "count" the commas in the first uncommented row. That's apparently what gnuplot>=5.0.0 is doing more or less.
However, in case you have an "incorrect CSV" with varying columns and you are interested in the minimum and maximum number of columns, you can use the following script, assuming that there are no (doublequoted) strings having a comma inside. Note, row indices are 0-based.
Data: SO13373206.dat
11, 12, 13, 14, 15, 16, 17
21, 22, 23, 24, 25, 26, 27, 28
31, 32, 33, 34, 35, 36, 37, 38, 39
41, 42, 43, 44, 45, 46
Script:
### count number of columns (gnuplot>=4.6.0)
reset
FILE = "SO13373206.dat"
countCommas(s) = sum[i=1:strlen(s)] ( s[i:i] eq ',' ? 1 : 0)
set datafile separator "\t" # in order to read a row as one string
stats FILE u (colCount=countCommas(strcol(1))+1,0) every ::0::0 nooutput
print sprintf("number of columns in first row: %d", colCount)
colMin = colMax = rMin = rMax = NaN
stats FILE u (c=countCommas(strcol(1))+1, \
c<colMin || colMin!=colMin ? (colMin=c,rMin=$0) : 0, \
c>colMax || colMax!=colMax ? (colMax=c,rMax=$0) : 0 ) nooutput
print sprintf("minimum %d columns in row %d",colMin, rMin)
print sprintf("maximum %d columns in row %d",colMax, rMax)
set datafile separator "," # restore separator
# ... plot something
### end of script
Result:
number of columns in first row: 7
minimum 6 columns in row 3
maximum 9 columns in row 2

Resources