Reuse build condition for multiple targets in binding.gyp - node-gyp

Originally my binding file has only one target and that has been fine:
{
'targets': [
{
'target_name': 'target1',
'sources': [ 'source1.cc', 'source2.cc' ],
'cflags_cc!': [ '-fno-rtti', '-fno-exceptions' ],
'cflags!': [ '-fno-exceptions' ],
'conditions': [
#A very, very long condition
]
},
}
Now I need another target which is more or less the same, but build an executable file instead of link object. If I duplicate the original target, that will be OK, however I don't want to repeat the condition which is exactly the same. How could I do that?
E.g. My ideal bindin.gyp would look somewhat like this:
{
'conditions': [
#A very, very long condition
]
'targets': [
{
'target_name': 'target1',
'sources': [ 'source1.cc', 'source2.cc' ],
'cflags_cc!': [ '-fno-rtti', '-fno-exceptions' ],
'cflags!': [ '-fno-exceptions' ],
'conditions' : #Refer to the conditions stated above
},
{
'target_name': 'target2',
'type' : 'executable'
'sources': [ 'source1.cc', 'source3.cc' ],
'cflags_cc!': [ '-fno-rtti', '-fno-exceptions' ],
'cflags!': [ '-fno-exceptions' ],
'conditions' : #Refer to the conditions stated above
},
}
I tried using variables but node-gyp only allows variables of type string or list, while 'conditions' is an associative array

I'm not really sure, but at a guess, you might be able to stick the long condition array in a third target and depend on that condition target from each of the other two. Something like this:
{
'targets': [
{
'target_name': 'conditions_target',
'conditions': [
#A very, very long condition
]
},
{
'target_name': 'target1',
'sources': [ 'source1.cc', 'source2.cc' ],
'cflags_cc!': [ '-fno-rtti', '-fno-exceptions' ],
'cflags!': [ '-fno-exceptions' ],
'dependencies': [
'conditions_target',
],
},
{
'target_name': 'target2',
'type' : 'executable'
'sources': [ 'source1.cc', 'source3.cc' ],
'cflags_cc!': [ '-fno-rtti', '-fno-exceptions' ],
'cflags!': [ '-fno-exceptions' ],
'dependencies': [
'conditions_target',
],
},
}
But I'm not very experienced with node-gyp and that might blow things up.
More on dependencies here: https://gyp.gsrc.io/docs/UserDocumentation.md#Dependencies-between-targets

Thanks for suggestion from Joshua Skrzypek.
By my test, it can create a target with type 'none' for reusing build settings (including conditions, include_dirs, defines, ...) for not only other targets but also their direct or indirect dependents (using all_dependent_settings)! This is an example:
{
'targets': [
{
'target_name': 'all-settings',
'type': 'none',
'all_dependent_settings': {
'defines': [
'FOO',
],
'conditions': [
['OS=="mac"', {
'xcode_settings': {
'OTHER_LDFLAGS': [
'-undefined dynamic_lookup'
],
},
}],
['OS=="win"', {
'defines': [
'WIN32',
],
}, {
'defines': [
'OTHER',
],
}],
],
'include_dirs': [
'include',
],
'cflags': ['-Wall'],
'xcode_settings': {
'OTHER_CFLAGS': ['-Wall']
},
}
},
{
'target_name': 'mylib',
'type': 'shared_library',
'dependencies': [
'all-settings'
],
'sources': [
'foo.cc',
'bar.cc',
],
}
]
}
This method is used in my npm pacakges. See this for reference:
https://github.com/MrMYHuang/libxmljs/blob/ccbbea919e0718f45117481235e67185857c06e1/binding.gyp
and its dependent package:
https://github.com/MrMYHuang/node-libxslt/blob/49810b2269cb3c049a451bd3175eaad4d9de959c/binding.gyp#L10

Related

chart js error in next js site hosted on netlify [duplicate]

This question already has answers here:
Error "RangeError: minimumFractionDigits value is out of range" with ChartJS in Next.js app
(3 answers)
Closed 4 months ago.
everthing is working fine in development on my local machine,
but when I deploy my site to netlify, I get this wierd error in console.
the page data is gotten using getStaticProps function and then passed to the page as props.
here is how the data looks like
[
[ 17671, 19856, 37527 ], [ 4887, 5418, 10305 ],
[ 2803, 2303, 5106 ], [ 8617, 9403, 18020 ],
[ 12664, 15722, 28386 ], [ 4227, 3359, 7586 ],
[ 1371, 1545, 2916 ], [ 17526, 14297, 31823 ],
[ 6883, 4781, 11664 ], [ 9805, 10000, 19805 ],
[ 11068, 12888, 23956 ], [ 4570, 4722, 9292 ],
[ 15428, 17309, 32737 ], [ 3565, 3656, 7221 ],
[ 8750, 10443, 19193 ], [ 1771, 1432, 3203 ],
[ 8495, 9979, 18474 ], [ 288, 265, 553 ],
[ 21130, 19321, 40451 ], [ 6867, 6556, 13423 ],
[ 2656, 2092, 4748 ], [ 967, 656, 1623 ],
[ 4540, 4505, 9045 ], [ 7025, 7108, 14133 ],
[ 53134, 59829, 112963 ], [ 8640, 9028, 17668 ],
[ 6759, 7119, 13878 ], [ 28803, 31362, 60165 ],
[ 7346, 7630, 14976 ], [ 9771, 10963, 20734 ],
[ 15783, 17397, 33180 ], [ 9847, 9706, 19553 ],
[ 15154, 17577, 32731 ], [ 1056, 874, 1930 ],
[ 3260, 2476, 5736 ], [ 1488, 1424, 2912 ],
[ 1656, 1154, 2810 ]
]
it is an array of arrays of 3 numbers.
please how do I solve this?
You need to set swcMinify: false false in your next.confug.js. This is currently a bug in the swcMinifier and you will need to wait until they have fixed it before you can enable it again.

TypeORM - PostGIS use custom feature in query

I have a project where I need to check inside which municipalities a certain road is inside. In order to do so I check this using the ST_Intersects function provided by PostGIS.
The problem that I am facing is that I keep on getting errors when using the roads in the querybuilder of typeorm.
My first attempt gave me the following error QueryFailedError: ST_Intersects: Operation on mixed SRID geometries (MultiPolygon, 4326) != (LineString, 0) at new QueryFailedError:
const municipalities = await getConnection()
.getRepository(Municipality)
.createQueryBuilder('municipality')
.where('ST_Intersects(municipality.polygon, :lineString)', { lineString: feature.geometry })
.getQueryAndParameters()
Then I tried to fix this by setting the CRS of the Linestring using ST_SetSRID function that is also provided by PostGIS. But this gives me the following error QueryFailedError: function st_setsrid(unknown, integer) is not unique:
const municipalities = await getConnection()
.getRepository(Municipality)
.createQueryBuilder('municipality')
.where('ST_Intersects(municipality.polygon, ST_SetSRID(:lineString, 4326))', { lineString: feature.geometry })
.getMany()
I have also tried to transfer the Geojson object using ST_GeomFromGeoJSON function in PostGIS. But this gives me the following error: QueryFailedError: quoted object property name expected (at offset 1):
const municipalities = await getConnection()
.getRepository(Municipality)
.createQueryBuilder('municipality')
.where('ST_Intersects(municipality.polygon, ST_GeomFromGeoJSON(:lineString))', { lineString: feature.geometry.coordinates })
.getMany()
I have tried to see if the problem was when inserting the linestring into the query. I did this by using the getQueryAndParameters return function of typeorm:
[
'SELECT "municipality"."uuid" AS "municipality_uuid", "municipality"."name" AS "municipality_name", ST_AsGeoJSON("municipality"."polygon")::json AS "municipality_polygon" FROM "municipality" "municipality" WHERE ST_Intersects("municipality"."polygon", ST_SetSRID($1, 4326))',
[ { type: 'LineString', coordinates: [Array] } ]
A Linestring object in looks as follows:
{
type: 'LineString',
coordinates: [
[ 3.2188848, 51.1980164 ],
[ 3.2190236, 51.1981144 ],
[ 3.2190737, 51.1981991 ],
[ 3.2191065, 51.1982793 ],
[ 3.2191314, 51.1983772 ],
[ 3.2191128, 51.1984885 ],
[ 3.2192215, 51.1985207 ],
[ 3.2192447, 51.1985056 ],
[ 3.219269, 51.1985136 ],
[ 3.2193766, 51.1985571 ],
[ 3.2194258, 51.1985769 ],
[ 3.2194638, 51.198697 ],
[ 3.2195437, 51.1987221 ],
[ 3.2196618, 51.1987591 ],
[ 3.219529, 51.1989397 ],
[ 3.2195909, 51.1990766 ],
[ 3.2196759, 51.1992964 ],
[ 3.2197817, 51.1993408 ],
[ 3.2199103, 51.1992987 ],
[ 3.2204127, 51.1991677 ],
[ 3.2208458, 51.199056 ],
[ 3.2211454, 51.1989993 ],
[ 3.2217751, 51.1988675 ],
[ 3.2219908, 51.1988136 ],
[ 3.2223186, 51.1987693 ],
[ 3.2223696, 51.1987867 ],
[ 3.2223974, 51.1987845 ],
[ 3.2225339, 51.1987696 ],
[ 3.2230863, 51.1987062 ],
[ 3.2233638, 51.198683 ],
[ 3.2234618, 51.1986505 ],
[ 3.223517, 51.1986535 ],
[ 3.2235298, 51.1986528 ],
[ 3.2236432, 51.198651 ],
[ 3.2243337, 51.1986565 ],
[ 3.2244463, 51.198654 ],
[ 3.2245644, 51.1986568 ],
[ 3.2249334, 51.1986506 ],
[ 3.2249647, 51.1986493 ],
[ 3.2251107, 51.19867 ],
[ 3.225378, 51.1986779 ],
[ 3.2257131, 51.1987153 ],
[ 3.225936, 51.1987341 ]
]
}
I have found an answer. ST_GeomFromGeoJSON was indeed the wright function to use in order to inject a GeoJSON object into the query. But I had accidentally used the coordinates instead of the full GeoJSON object.
So the solution is:
const municipalities = await getConnection()
.getRepository(Municipality)
.createQueryBuilder('municipality')
.where('ST_Intersects(municipality.polygon, ST_GeomFromGeoJSON(:lineString))', { lineString: feature.geometry })
.getMany()

Convert the following array data as Json in react

I need to convert the following array data to Json in react.
I tried map method, but it is not the correct way. I need key value pair, so that i can pass it to server as json
[
[
"channel",
"s1"
],
[
"category",
"Account 1"
],
[
"accountAdministration",
"Partnership 1"
],
[
"partnershipAccounting",
"1 level Performance issues"
],
[
"requestCategory",
"Research"
],
[
"severity",
"Blocker"
],
[
"activationDate",
"2020-10-29T05:54:00.000Z"
],
[
"managerApproved",
true
]
]
Try using reduce and creating an object:
var arr = []; // your array
var data = arr.reduce((map, item) => {
map[item[0]] = item[1];
return map;
}, {});
The data object will be in the following format:
{
"accountAdministration": "Partnership 1",
"activationDate": "2020-10-29T05:54:00.000Z",
"category": "Account 1",
"channel": "s1",
...
}
Worked with
Object.fromEntries([
[
"channel",
"s1"
],
[
"category",
"Account 1"
],
[
"accountAdministration",
"Partnership 1"
],
[
"partnershipAccounting",
"1 level Performance issues"
],
[
"requestCategory",
"Research"
],
[
"severity",
"Blocker"
],
[
"activationDate",
"2020-10-29T05:54:00.000Z"
],
[
"managerApproved",
true
]
])

Reverse Array of coordinates in swift 4

I am trying to reverse an array of coordinates. I have this array:
[
[
9.211615025997162,
44.30419567985762
],
[
9.21164184808731,
44.30412081929745
],
[
9.21165257692337,
44.304053636662175
],
[
9.211606979370117,
44.3038789614507
],
[
9.211572110652924,
44.30381945658962
],
[
9.211539924144745,
44.30378874437967
],
[
9.211507737636566,
44.30376187118276
],
[
9.211564064025879,
44.30377530778277
],
[
9.211574792861937,
44.30374075651943
],
[
9.211574792861937,
44.30371388330059
],
[
9.211574792861937,
44.30369852717
],
[
9.21154797077179,
44.303665895379176
],
[
9.211513102054596,
44.303650539236024
],
[
9.211429953575134,
44.30358911462331
],
[
9.211349487304688,
44.30355840229286
],
[
9.211271703243256,
44.303537287556324
],
[
9.21117514371872,
44.30349505806051
],
[
9.211151003837585,
44.303473943301235
],
[
9.211126863956451,
44.30342979423452
],
[
9.211145639419556,
44.30339908182071
],
[
9.211183190345764,
44.303368369390846
],
[
9.211223423480988,
44.30331846165803
],
[
9.211242198944092,
44.30327623200479
],
[
9.211177825927734,
44.30325895622883
],
[
9.211030304431915,
44.303228243725634
],
[
9.210925698280334,
44.30321096793552
],
[
9.210874736309052,
44.303197531206386
],
[
9.210831820964813,
44.303197531206386
],
[
9.21075403690338,
44.303197531206386
],
[
9.21068161725998,
44.3031994507393
],
[
9.210577011108398,
44.3031994507393
],
[
9.210509955883026,
44.303207128870355
],
[
9.210440218448639,
44.303207128870355
],
[
9.210370481014252,
44.30322632419366
],
[
9.2102712392807,
44.30324743904202
],
[
9.210190773010254,
44.30328199059568
],
[
9.210112988948822,
44.30328391012582
],
[
9.210059344768524,
44.303297346835215
],
[
9.209954738616943,
44.30332422024474
],
[
9.209901094436646,
44.303339576473235
],
[
9.209868907928467,
44.303349174114
],
[
9.209858179092407,
44.30338372560779
],
[
9.209791123867035,
44.30340292087333
],
[
9.209697246551514,
44.30342595518367
],
[
9.209648966789246,
44.3034509090097
],
[
9.209606051445007,
44.30351809233474
],
[
9.209579229354858,
44.30355840229286
],
[
9.209581911563873,
44.3035852755829
],
[
9.209622144699097,
44.30355840229286
],
[
9.20967847108841,
44.30355648277167
],
[
9.209697246551514,
44.30354112659989
]
]
And I would like to reverse the coordinates, which are right now in Long-Lat to Lat-Long thus reversing the whole array or each item in the array would do the job here. I have been stuck trying to make it work, trying things like arrayOfCoords.reversed() and .reverse() to no avail. So how can I do this?
There may be a more elegant/efficient way to do this, but I'd look at using compactMap:
let testArray = [[1.123,2.22], [3.11, 4.0], [5.21, 6.19]]
print(testArray)
[[1.123, 2.22], [3.11, 4.0], [5.21, 6.19]]
let flippedElementArray = testArray.compactMap { $0.count > 1 ? [$0[1], $0[0]] : nil }
print(flippedElementArray)
[[2.22, 1.123], [4.0, 3.11], [6.19, 5.21]]
The $0.count > 1 check just makes sure you have at least 2 elements so you don't get a bounds error. If not, the closure returns nil for that element, which will be filtered out by compactMap. Otherwise, it returns a new array element consisting of the second element followed by the first element. All of those elements are stored in the final mapped array (flippedElementArray).
arrayOfCoords.map{ Array($0.reversed()) }
I'm assuming you want to reverse each coordinate pair, but keep the pairs themselves in the original order. Since you have an array of arrays, you have to do the operation on each sub-array separately. And reversed() returns a ReversedCollection instead of an Array so you have to re-initialize it into an array to use it properly.

XSD Setup for Arrays

I have a nested json array as follows:
When I try to post this I am getting the error messages:
{"RestFaultElement":{"summary":"Translation Failure.\nFailed to translate JSON to XML. java.io.IOException: Array start inside array\nThe incoming data does not conform to the NXSD schema. Please correct the problem.\n","code":null,"detail":null}}
"Options": {
"Co-ordinates": {
"X": "594752",
"Y": "714430"
},
"Language": "English",
"PageSize": "A4",
"Scale": "1,000",
"Orientation": "Landscape",
"GeometryData": {
"type": "polygon",
"rings": [
[
[
716102.6700605,
733105.7692149
],
[
716431.41550966,
733105.7692149
],
[
716431.41550966,
732878.22709315
],
[
716102.6700605,
732878.22709315
],
[
716102.6700605,
733105.7692149
]
]
],
"_ring": 0,
"spatialReference": {
"wkid": 2157,
"latestWkid": 2157
},
"cache": {
"_extent": {
"xmin": 717192,
"ymin": 733058.86,
"xmax": 717424,
"ymax": 733230.86,
"spatialReference": {
"wkid": 2157,
"latestWkid": 2157
}
},
"_partwise": "PARTWISE",
"_centroid": {
"type": "point",
"x": 717308.00000013,
"y": 733144.86000007,
"spatialReference": {
"wkid": 2157,
"latestWkid": 2157
}
}
}
}
The problem part of this seems to be with the "rings" array.
I believe that 1 of 2 things is happening:
1. The JSON syntax is wrong.
2. The xsd file is set up wrong.
The XSD segments which should accept this element is defined as:
<xsd:element type="xsd:decimal" name="rings"/>
Would this set up allow for an array like so to be passed to it?
Thank you.
You are missing brackets at start end end of your string. Try:
{"rings": [
[
[
716102.6700605,
733105.7692149
],
[
716431.41550966,
733105.7692149
],
[
716431.41550966,
732878.22709315
],
[
716102.6700605,
732878.22709315
],
[
716102.6700605,
733105.7692149
]
]
]}

Resources