In react project, do you think of any possible way of assigning a type to a variable based on .env (or any other file) at the compile time?
I have a type let X: A|B|C|null = null. I assign the A, B, or C to the X based on the variable stored in the .env. The reason I want to do that is so the hover or "on click" on the X shows me/forwards me to the correct class.
I've come up with no solid solution yet
Environment variables are read in run-time
TypeScript doesn't exist anymore in run-time
So it's not possible
Related
I'm using react-chartjs-2 with Typescript.
I'm very confused with the interface of chartjs (perhaps this is due to severe API changes beneath versions and information running around online without clearly stating the version).
What is the difference between the following options:
options.scales.x: {}
options.scales.xAxes: {}
I thought this was equal to the above, but under certain circumstances I could not get options.scales.xAxes.min working. So I resorted to using x.
options.scales.xAxes: [{}]
I see many examples using this syntax (especially here on SO). However, using it myself results in a type error.
options.scales.xAxes: [{}] is V2 syntax, here all the x axes are grouped in a single array, same for all the y axes.
In v3 all the scales are their own object within the scales object where the key of the object is your scale ID.
by default you should use options.scales.x to configure the default x axis. But to make things a bit easyer chart.js looks at the fist letter of the object to determine its type so if you pass options.scales.xAxes it should result in the same if you dont have any other scales configured
I call the function XLoadQueryFont(port->dpy, "8x13"), but it returns a NULL. I'm pretty sure I had this working before. If I type locate 8x13, one of the results is
/usr/share/fonts/misc/8x13.pcf.gz
I don't know what the function dislikes, and was wondering as to how to track the problem down.
Update:
Using "fixed" produced an app that executed.
Based on tofo's comments:
I had to install the xlsfonts binary on Arch to get xlsfonts. It listed adobe, lucida, bitstream and misc fonts. xlsfonts | grep misc returned
-misc-fixed-medium-r-semicondensed--0-0-75-75-c-0-iso8859-1
-misc-fixed-medium-r-semicondensed--13-100-100-100-c-60-iso8859-1
-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso8859-1
Most probably you have deleted or corrupted your fonts.alias file in /etc/X11 (or similar location, depending on your distribution, can be anywhere in the font path).
The "8x13" is typically no name, but rather an alias that is defined in this file.
To ensure your server can use this font name, check that your fonts.alias file contains at least the lines (note your actual font names might vary)
8x13 -Misc-Fixed-Medium-R-SemiExpanded--13-120-75-75-C-80-ISO8859-1
8x13bold -Misc-Fixed-Bold-R-SemiExpanded--13-120-75-75-C-80-ISO8859-1
If those aliases are not present or don't resolve to a valid font, you cannot use the "8x13" name. More aliases can be defined as needed.
I have a class with a port of dimensions [x,y] which is connected to another class having a matching port. Now I want to provide value to these variables [x,y] through external function call in which I basically read a .xml file and obtain values for x and y. But Dymola gives an error for this since during compilation it comes out as a non fixed size array.
Screenshot of error is attached.
The array sizes are structural parameters and they usually cannot depend on external function calls because they should be known at compile time. This is however supported in for example OpenModelica where a dll of the external function is built and called and the results are fetched during model compilation.
The only way to support this in all tools is to generate the model using an external tool which reads the xml and changes the .mo file with the values read.
You could probably have something like Parameters.mo:
package Parameters
constant Integer nTube = <EXTERN_NTUBE>;
constant Integer nSeg = <EXTERN_NSEG>;
end Parameters;
and your external tool will read the XML and bind and in Parameters.mo which you can then use in your models via Parameters.nTube and Parameters.nSeg. Maybe it would be good to give some defaults so that it works to use this file directly:
package Parameters
constant Integer nTube = 1;
constant Integer nSeg = 2;
end Parameters;
and then your external tool will replace 1 and 2 with the needed values before compilation.
This should be improved in Dymola 2017 (without the need for modifying the Modelica code). In earlier versions of Dymola it should work if the you translate the C-functions called to compute nTube and nSeg.
If that does not help your complete code would be needed to analyze the problem.
I have a UserForm with a ListBox for the user to select values. Those values are populated in UserForm_Initialize() via a function call to the base module, which returns an array as variant. This works without problems.
If the user selects some values and presses a button, the buttons Click event calls another function in the base module to pass on the user-entered array and compute things. This does not work at all. The value received in the base module is always nonexistent (not even null, but I don't know the correct VBA term, nothing is there at all).
Things I have tried so far:
Passing all arguments ByVal: Did not make a difference
Using global shared variables: This did work, but I don't want to rely on them if all I do is pass a single array to a single function. This also introduces state into the code which has to be managed, especially when reusing the function
Accessing the functions by full qualifiers: Did not make a difference. The functions are found and executed correctly, but the argument variables are empty, therefore the functions fail later on when doing the calculations.
My question is: How can I pass arrays from UserForms to Modules (not vice versa) without relying on global variables and without losing the array content?
This question may be related to this question about passing a String from Form to Module, but the accepted answer does not help in my case (using global variables).
When adding the code as requested in the comments, I stumbled upon that fact that I could print the content of the array, but it would not show anything in the debugger and the size would be 0.
The size issue was because I used Len(array) instead of Application.CountA(array) and I had a leftover On error resume next from earlier still in the code, which meant that no error was raised and size was always set to zero... This was the reason for the strange behaviour.
I have a Matlab script that calculates a certain terrain-parameter (describing the theoretical shelter from and exposure to wind) based on a digital terrain model. The script works both in Matlab and Octave and yields a matrix.
Now: I am trying to couple this with a GRASS GIS shell script. I can call the script from GRASS, but I have problems getting the output back into GRASS. One way is to use the .mat format. The problem is, however: When I export the result of the calculation (with save -mat4-binary result.mat ans) and try to import the .mat file into GRASS, the error is:
ERROR: No 'map_data' array found in [...file]
Similarly, when I load the file in Octave and try to display it
load result.mat
imagesc(map_data), axis equal, axis tight, colorbar
the error is
error: `map_data' undefined near line 19 column 9
error: evaluating argument list element number 1
When I export from Matlab, it is the same problem.
Where is the bug?
Any help is greatly appreciated.
The "bug" is, your mat-file does not contain any variable named "map_data", I would guess your variable in the mat-file is named "ans". I would use res=load result.mat, then you get a struct with everything which is in the mat file. If you type in res. autocomplete should list all variables inside the struct (not sure about octave), alternatively use fieldnames(res) to list all variable names.
/Update:
I took a short look into the documentation of grass. It expects predefined variable names, all beginning with map_*. Instead of
save -mat4-binary result.mat ans
you should rename your variables to match the documentation and save them using
save -mat4-binary result.mat map_*