Print and update multiple lines in fixed position - ruby

I would like to print an output like the following in a fixed position while the numbers in the block keep updating every couple of seconds. It is similar to what top does.
Jobs monitor:
+-----------------------------------------+
| Waiting | Launched | Running | Finished |
+-----------------------------------------+
| 319 | 364 | 94 | 201 |
+-----------------------------------------+
Elapsed time: 21s
Is there a way to do that?
With only one line, I could do it with STDOUT.flush and "\r", but it does not work for multiple lines since the carriage will put the cursor at the beginning of the new line only.

The curses library is one way to make this work. It allows you to write to locations on a 2-d screen so you're not constrained to the current line. This question has some good resources for learning curses.

Related

How can I split a rule with Lark EBNF?

I'm writing a grammar for parsing PlantUML State diagrams and have the following doubt:
I had:
transition: STATE arrow STATE (":" event? guard? action?)? "\n"
arrow: ("->" | "-->" | "-left->" | "-right->" | "-up->" | "-down->")
But had to change to:
transition: STATE ("->" | "-->" | "-left->" | "-right->" | "-up->" | "-down->") STATE (":" event? GUARD? action?)? "\n"
Because, for my application, I don't need nor care which type of arrow is used; it is sufficient to know that an arrow was there to form the transition.
The question is: Is there a way to split the transition rule in other more manageable rules without the arrow type appearing in the parsed tree?
Full file at https://github.com/thomedes/PlantUML-Lark-EBNF. Feel free to comment / criticize. Trying to learn here 🤓
After RTFM, I've found that terminals whose name begins with underscore are not output to the tree, so I've changed it to:
transition: STATE _ARROW STATE (":" event? GUARD? ACTION?)? "\n"
_ARROW: "->" | "-->" | "-left->" | "-right->" | "-up->" | "-down->"
And now it works fine.
Not marking this as an accepted answer because I'm sure someone with more experience could give a better answer.

Simple event correlation using Elasticsearch and Kibana

I'm doing some optimization work on some database stuff and the system writes down log files. Basically I want to optimize some stuff then restore the original customer db-dump and re-run the whole thing. My log files look something like that:
2016-05-10 15:43:18,135 DEBUG [WorkerThread#0[127.0.0.1:64181]] d.h.h.h.c.d.m... [1517]: doing thing #2081087 took 26831ms
2016-05-10 15:05:18,135 DEBUG [WorkerThread#0[127.0.0.1:64181]] d.h.h.h.c.d.m... [1517]: doing thing #20887 took 4051ms
2016-05-10 15:02:18,135 DEBUG [WorkerThread#0[127.0.0.1:64181]] d.h.h.h.c.d.m... [1517]: doing thing #1087 took 261ms
I want to correlate these events over the different runs now to have some statistical data which change did what. So, what I want is a result like
| run 1 | run 2 | run 3 | ... |
thing #20887 | 261ms | 900ms | 100ms | ... |
thing #1087 | 4051ms | 9000ms | 2000ms | ... |
How can I correlate these events using Elasticsearch and visualize it with Kibana?

Using BASH how can I capture the last 5 lines of a log file without causing file locking

I have a file that is created by an application. The app is perpetually writing large volumes of data to the file.
I need to capture a copy of the last 10 lines of the file periodically and write it to another file without causing any file locking, which could impact the application writing the logFile.
How do I do that without impacting the application writing the logfile? i.e without causing any file locking.
logFile example
1452431219885,546,Item Details Request,200,OK,text,true,12562,91,91,271,ip-172-31-36-138,0,134
1452431219886,1300,Select Item Request,200,OK,text,true,28541,91,91,444,ip-172-31-36-138,0,209
1452431219889,210,Login Success Page Request,200,OK,text,true,29405,91,91,123,ip-172-31-36-137,0,27
1452431219898,217,Item Details Request,200,OK,text,true,10620,91,91,215,ip-172-31-36-135,0,106
1452431219900,1668,Logout and Exit Request,200,OK,text,true,19676,92,92,1133,ip-172-31-36-136,0,266
1452431219902,589,Search Page Request,200,OK,text,true,13392,91,91,296,ip-172-31-36-138,0,147
1452431219903,589,Save Basket Request,200,OK,text,true,17473,91,91,294,ip-172-31-36-138,0,147
1452431219908,1135,Search Results Request,200,OK,text,true,561615,91,91,229,ip-172-31-36-136,0,116
1452431219914,1114,Item Details Request,200,OK,text,true,93243,91,91,282,ip-172-31-36-138,0,138
1452431219921,825,Select Item Request,200,OK,text,true,24354,91,91,339,ip-172-31-36-135,0,161
Under most operating systems (i.e. BSDs, Linux, Mac, essentially anything not Windows), files never get locked unless the program explicitly requests it.
Even then, locks in these operating systems are only advisory, so won't affect programs which don't care about them.
So the answer is: almost anything that can get the last lines of the log, will do so without locking.
Obtain the last 10 lines
If I understand your question correctly, you can simply use:
# tail reads the input file and print out the last 10 lines (default)
tail /path/to/file.log > 10_lines.dump
# Change number of lines from default(10) to 5
tail -n 5 /path/to/file.log > 5_lines.dump
Show last lines every X seconds
If you need to do this periodically without saving the output you can use watch:
# watch show the output of the tail command every 5 seconds (default 2s)
watch -n 5 tail /path/to/file.log
# OR last 5 lines every 5 seconds
watch -n 5 tail -n 5 /path/to/file.log
Extract and save for future reference in background
Create a crontab file (name it file.crontab or as you wish) with an editor of your choice with this content:
# ** Crontab file schema **
# .------------------ [m]inute: [0 - 59] OR */x (every x minutes)
# | .-------------- [h]our: [0 - 23] OR */x (every x hours)
# | | .---------- [d]ay [o]f [m]onth: [1 - 31]
# | | | .------ [mon]th: [1 - 12] OR jan,feb,mar,apr...
# | | | | .-- [d]ay [o]f [w]eek: [0 - 6] (Sunday can be 0 or 7)
# | | | | | (also: sun,mon,tue,wed,thu,fri,sat)
# m h d mon dow
# * * * * * command executed every minute with my user permission
# --
# Execute tail every 5 minutes and append last 10 lines of input to log.extract
*/5 * * * * tail "/path/to/file.log" >> "/path/to/log.extract"
Install it on your system using crontab:
crontab file.crontab

InDesign - how do I know if an image already placed?

I am working on a book with many images, and I want to ensure that I place each picture only once. Is there a way to tell indesign to to check if image exist before placing it? Or a way to define a preflight profile for it?
Thank you,
Omer
You should be able to see a list in the links panel.
It shows the number of times and the page number it appears on.
example:
Name | ! | Pg |
--------------------|---|----|
my-image.psd (2) | | |
my-image.psd | | 1 |
my-image.psd | | 4 |

Octopress: Tables and Definition Lists not showing in rake preview

Hi I dont know if this is the normal behaviour but if possible would like to preview tables and definition lists.
Using latest versions:
I am using the kramdown version of markdown.
I haven't deployed yet which means I only have
a source but no Masters folder.
I use rake generate or rake preview commands only.
I have tried
| First cell|Second cell|Third cell
| First | Second | Third |
First | Second | | Fourth |
size material color
---- ------------ ------------
9 leather brown
10 hemp canvas natural
11 glass transparent
and for definition lists
apples
: Good for making applesauce.
oranges
: Citrus!
tomatoes
: There's no "e" in tomatoe.

Resources