xtermjs fit addon causes line to overwrite previous line - xtermjs

The fit addon causes a line in xtermjs to overwrite previous lines. Specifically, when the user types, half a line is filled up, and then the characters begin appearing from the left hand side of the line and overwriting the previous characters written there.
const fitAddon = new FitAddon.FitAddon()
term.loadAddon(fitAddon)
fitAddon.fit()

This happens when the columns of xterm and columns of your serverside PTY are not equivalent. You can change the xterm columns and rows like this.
const term = new Terminal({
rows: x,
cols: y,
});
Where x and y are your PTY rows and columns.

Related

Reading a column file of x y z into table in Lua

Been trying to find my way through Lua, so I have a file containing N lines of numbers, 3 per line, it is actually x,y,z coordinates. I could make it a CSV file and use some Lua CSV parser, but I guess it's better if I learn how to do this regardless.
So what would be the best way to deal with this? So far I am able to read each line into a table line by the code snippet below, but 1) I don't know if this is a string or number table, 2) if I print tbllinesx[1], it prints the whole line of three numbers. I would like to be able to have tbllines[1][1], tbllines[1][2] and tbllines[1][3] corresponding to the first 3 number of 1st line of my file.
local file = io.open("locations.txt")
local tbllinesx = {}
local i = 0
if file then
for line in file:lines() do
i = i + 1
tbllinesx[i] = line
end
file:close()
else
error('file not found')
end
From Programming in Lua https://www.lua.org/pil/21.1.html
You can call read with multiple options; for each argument, the
function will return the respective result. Suppose you have a file
with three numbers per line:
6.0 -3.23 15e12
4.3 234 1000001
... Now you want to print the maximum of each line. You can read all three numbers in a single call to read:
while true do
local n1, n2, n3 = io.read("*number", "*number", "*number")
if not n1 then break end
print(math.max(n1, n2, n3))
end
In any case, you should always consider the alternative of reading the
whole file with option "*all" from io.read and then using
gfind to break it up:
local pat = "(%S+)%s+(%S+)%s+(%S+)%s+"
for n1, n2, n3 in string.gfind(io.read("*all"), pat) do
print(math.max(n1, n2, n3))
end
I'm sure you can figure out how to modify this to put the numbers into table fields on your own.
If you're using three captures you can just use table.pack to create your line table with three entries.
Assuming you only have valid lines in your data file (locations.txt) all you need is change the line:
tbllinesx[i] = line
to:
tbllinesx[i] = { line:match '(%d+)%s+(%d+)%s+(%d+)' }
This will put each of the three space-delimited numbers into its own spot in a table for each line separately.
Edit: The repeated %d+ part of the pattern will need to be adjusted according to your actual input. %d+ assumes plain integers, you need something more involved for possible minus sign (%-?%d+) and for possible dot (%-?%d-%.?%d+), and so on. Of course the easy way would be to grab everything that is not space (%S+) as a potential number.

Modify values programmatically SPSS

I have a file with more than 250 variables and more than 100 cases. Some of these variables have an error in decimal dot (20445.12 should be 2.044512).
I want to modify programatically these data, I found a possible way in a Visual Basic editor provided by SPSS (I show you a screen shot below), but I have an absolute lack of knowledge.
How can I select a range of cells in this language?
How can I store the cell once modified its data?
--- EDITED NEW DATA ----
Thank you for your fast reply.
The problem now its the number of digits that number has. For example, error data could have the following format:
Case A) 43998 (five digits) ---> 4.3998 as correct value.
Case B) 4399 (four digits) ---> 4.3990 as correct value, but parsed as 0.4399 because 0 has been removed when file was created.
Is there any way, like:
IF (NUM < 10000) THEN NUM = NUM / 1000 ELSE NUM = NUM / 10000
Or something like IF (Number_of_digits(NUM)) THEN ...
Thank you.
there's no need for VB script, go this way:
open a syntax window, paste the following code:
do repeat vr=var1 var2 var3 var4.
compute vr=vr/10000.
end repeat.
save outfile="filepath\My corrected data.sav".
exe.
Replace var1 var2 var3 var4 with the names of the actual variables you need to change. For variables that are contiguous in the file you may use var1 to var4.
Replace vr=vr/10000 with whatever mathematical calculation you would like to use to correct the data.
Replace "filepath\My corrected data.sav" with your path and file name.
WARNING: this syntax will change the data in your file. You should make sure to create a backup of your original in addition to saving the corrected data to a new file.

How to modify the data in a column using Wolfram Mathematica?

I am working on a Dataset object with one column, named Property.
The data is given as shown in the following picture:
Based on the range, I would like to assign a new value, and eventually replace the whole column in question. For example if the range is 500-5000, I would like to get the value 1, and for 5000-50000, I would like to give the value 2, and so on.
As I understand it, you want to recode one column of a dataset by modifying the dataset. To my knowledge, datasets are not really designed to be mutable types. If you can accept that, here are two ways to proceed.
First, let's get some artifical data.
ds = Dataset[<|"x" -> RandomInteger[10],
"y" -> Interval[{10^#, 10^(# + 1)}]|> & /# Range[5]]
Now suppose we want to recode the second column with a function f:
ds[All, {2 -> f}]
Note that the original dataset is unchanged. (Usually a good thing.)
Here's an example function to try out.
f[x_Interval] := Log[10, x[[1, 1]]]
ds[All, {2 -> f}]
Now a big problem with this is that your new dataset has a column with exactly the same name but entirely different interpretation. If this bothers you, you can instead append to the dataset with a new name.
Append[#, "y2" -> f[#y]] & /# ds
Edit:
What about those dollar signs? Unless you show us the full form of an entry, I'll have to guess. So I'll guess that the following artificial data gets us close enough to be useful:
ds = Dataset[<|"x" -> RandomInteger[10],
"y" -> Quantity[Interval[{10^#, 10^(# + 1)}], "USDollars"]|> & /# Range[5]]
This just means we need to make a small change in f:
f[Quantity[Interval[{x_, _}], _]] := Log[10, x]
Then we can replace or append as before:
ds[All, {2 -> f}]
Append[#, "y2" -> f[#y]] & /# ds
If we have grid stuff with column integer x (starting from 1 as we are in mathematica) named "Property", the code to get the column of transformed ranges in x -- to what I think want you -- is below:
Replace[#1[[1]] & /# stuff, x_ :> IntegerLength[x[[1, 1]]] - 2, {1}]
It takes all the ranges in the specified column, and subtracts 2 from the length of the lower part of the range to give you your result.
For example, if we take your sample ranges:
stuff = {{$Interval[{500, 50000}], things, things},
{$Interval[{5000, 5000000}], things, things}}
And run it through our Replace:
Replace[#1[[1]] & /# stuff, x_ :> IntegerLength[x[[1, 1]]] - 2, {1}]
We get an Out: of:
{1, 2}
You can then easily modify the Replace above to give you the transformed column in situ of stuff.

Remove legend bar in R using Image.Plot

This is the test code im using
x_coord <- c(1,2,3,4)
y_coord <- c(1,2,3,4)
value <- c(12,15,19,30)
foo <- data.frame(x_coord, y_coord, value)
library(MBA)
foo=foo[ order(foo[,1], foo[,2],foo[,3]), ]
mba.int <- mba.surf(foo, 300, 300, extend=T)$xyz.est
library(fields)
fields::image.plot(mba.int,legend.only = FALSE, axes=FALSE)
The axes part deletes the axis, but when i try to remove the legend bar, the vertical bar indicating the color measurements, it will not go away.
i have tried smallplot = 1, but that gives me an error but it gets rid of the vertical legend,
Anyone have any idea of how to get rid of the legend without any errors produced ?
If you don't want the color legend, just use the built-in image function instead. The function you are using is designed specifically for adding a legend easily.
If you want to keep the same color scheme as the fields image.plot function:
image(<your data>, ..., col = tim.colors())
Using this creates the exact same image without a legend.
The image and image.plot functions actually have quite different plotting functionality.
One problem (at least for me, trying to plot regional climate model data) with using the built-in image is that it cannot handle irregular grids. The image.plot function uses the poly.image function internally to create the plot. Both are included in the fields package. The good thing is that the poly.image function also can be used on its own, for example like this:
library("fields")
# create an example of an irregular 3x3 grid by adding random perturbations up to ±0.6
x <- matrix(rep(1:3,each=3) + 0.6*runif(9), ncol=3)
y <- matrix(rep(7:9,times=3) + 0.6*runif(9), ncol=3)
# 9 values, from 1 to 9
z <- matrix(1:9,nrow=3)
# Please avoid the default rainbow colours, see e.g.
# https://www.climate-lab-book.ac.uk/2014/end-of-the-rainbow/
# Other examples of colour schemes: https://colorbrewer2.org/
col <- colorRampPalette(c("#2c7bb6","#abd9e9","#ffffbf","#fdae61","#d7191c"))(9)
par(mfrow=c(1,3), mar=c(4,4,4,1), oma=c(0,0,0,0))
image(x=7:9,y=1:3,z,col=col, main="image()\n Only regular grid. Also note transposition.")
image.plot(x,y,z,col=col, main="image.plot()\n Always with colorbar.")
poly.image(x,y,z,col=col, main="poly.image()\n Does not include colorbar.")

vb6 - Greater/Less Than statements giving incorrect output

I have a VB6 form with a text boxes for minimum and maximum values. The text boxes have a MaxLength of 4, and I have code for the keyPress event to limit it to numeric entry. The code checks to make sure that max > min, however it is behaving very strangely. It seems to be comparing the values in scientific notation or something. For example, it evaluates 30 > 200 = true, and 100 > 20 = false. However if I change the entries to 030 > 200 and 100 > 020, then it gives me the correct answer. Does anyone know why it would be acting this way?
My code is below, I am using control arrays for the minimum and maximum text boxes.
For cnt = 0 To 6
If ParameterMin(cnt) > ParameterMax(cnt) Then
MsgBox ("Default, Min, or Max values out of range. Line not updated.")
Exit Sub
End If
Next cnt
That is how text comparison behaves for numbers represented as variable length text (in general, not just VB6).
Either pad with zeros to a fixed length and continue comparing as text (as you noted)
OR
(preferable) Convert to integers and then compare.
If I understood correctly, you can alter the code to
If Val(ParameterMin(cnt)) > Val(ParameterMax(cnt)) Then
I wish to advise one thing -(IMHO...) if possible, avoid checking data during key_press/key_up/key_down .
Can you change the GUI to contain a "submit" button and check your "form" there ?
Hope I helped...

Resources