how to remove undefined in object - undefined

I have this object and need to remove undefined in typescript. How to do that
myObject = {
0: undefined
1: {label: '129 XENON (RO7492908-001)', genericName: '129 XENON', itemumber: 'RO7492908-001'}
2: {label: '203PB-DOTAM (RO7205834-006)', genericName: '203PB-DOTAM', itemumber: 'RO7205834-006'}
3: {label: '212PB-DOTAM (RO7205834-007)', genericName: '212PB-DOTAM', itemumber: 'RO7205834-007'}
};

Related

$filter ignored by OData when specifying additional parameters

When adding parameters to a call to an OData endpoint in my application like this
https://localhost:12345/TestServer/RequestDto
?$count=true&$orderby=TimeStamp%20desc
&$filter=(Ownername%20eq%20%27Baggins%2C%20Frodo%27)
&$skip=0&$top=26&userID=bt0388&showByAuthor=False
the $filter seems to be getting ignored. userID and showByAuthor are the additional parameters.
The related endpoint looks like this.
public class RequestDtoController : ODataController
{
// ...
[EnableQuery]
public IQueryable<DocumentRequestDTO> Get(string userID, bool showByAuthor)
{
// ...
}
It does get called with proper parameters. The data it returns is correct and complete.
I expect the OData layer to apply the filter, but it doesn't. This is the final result set:
{#odata.context: "https://localhost:44393/DocServer2/$metadata#RequestDto", #odata.count: 4,…}
#odata.context: "https://localhost:44393/DocServer2/$metadata#RequestDto"
#odata.count: 4
value:
[{ID: "dc3a6999", AuthorID: "0388", Authorname: "Wonka, Willy",…},…]
0:
{ID: "dc3a6999", AuthorID: "0388", Authorname: "Wonka, Willy",…}
Ownername: "Wonka, Willy"
...
1:
{ID: "685b7e33", AuthorID: "Test-Owner", Authorname: "Test, Owner",…}
Ownername: "Wonka, Willy"
...
2: {ID: "8192d591", AuthorID: "0003", Authorname: "Hedgehog, Sonic",…}
Ownername: "Baggins, Frodo"
...
3: {ID: "b56b7cfc", AuthorID: "0003", Authorname: "Hedgehog, Sonic",…}
Ownername: "Baggins, Frodo"
...
How would I need to go about fixing it?

monaco registerSignatureHelpProvider() causes error: Cannot read property 'signatures' of undefined

I'm using Monaco 0.22.2 trying to bring up suggestions for function parameters. I've defined a simple example like so:
monaco.languages.registerSignatureHelpProvider('myCustomLang', {
signatureHelpTriggerCharacters: ['(', ','],
provideSignatureHelp: (model, position, token) => {
return {
activeParameter: 0,
activeSignautre: 0,
signatures: [{
label:'string of_string(string $string, int $start)',
parameters: [
{
label: 'string $string',
documentation: 'The input string'
},
{
label: 'int $start',
documentation: "if $start is non-negative...",
}
]
}]
};
}
});
However as soon as I type in "(" or "," to trigger this code, I get the error:
Cannot read property 'signatures' of undefined
TypeError: Cannot read property 'signatures' of undefined
at ParameterHintsModel.eval (parameterHintsModel.js:166)
at Generator.next (<anonymous>)
at fulfilled (parameterHintsModel.js:19)
at eval (errors.js:24)
What am I doing wrong? My regular simple suggestions show up, but I can't get potential function parameter suggestions to show up.
The response should be structured this way:
monaco.languages.registerSignatureHelpProvider("myCustomLang", {
signatureHelpTriggerCharacters: ["(", ","],
provideSignatureHelp: (model, position, token) => {
return {
dispose: () => {},
value: {
activeParameter: 0,
activeSignature: 0,
signatures: [
{
label:
"string substr(string $string, int $start [, int $length])",
parameters: [
{
label: "string $string",
documentation:
"The input string. Must be one character or longer.",
},
{
label: "int $start",
documentation:
"If $start is non-negative, the returned string will start at the $start'th position in string, counting from zero. For instance, in the string 'abcdef', the character at position 0 is 'a', the character at position 2 is 'c', and so forth.\r\nIf $start is negative, the returned string will start at the $start'th character from the end of string. If $string is less than $start characters long, FALSE will be returned.",
},
{
label: "int $length",
documentation:
"If $length is given and is positive, the string returned will contain at most $length characters beginning from $start (depending on the length of $string) If $length is given and is negative, then that many characters will be omitted from the end of $string (after the start position has been calculated when a start is negative). If $start denotes the position of this truncation or beyond, FALSE will be returned. If $length is given and is 0, FALSE or NULL, an empty string will be returned. If $length is omitted, the substring starting from $start until the end of the string will be returned.",
},
],
},
],
},
};
},
});
The response type is SignatureHelpResult, it should have a value and dispose method. The value should be SignatureHelp with activeParameter activeSignature and signatures

delegate.replace() is not working on Array List Grails 2.3.8

Here's my code in order to replace HTML tags:
def str
String.metaClass.removeHtml {
def removeThisHtml = [
[htmlCode: "`", value: "`"],
[htmlCode: "#", value: "#"],
[htmlCode: "&", value: "&"],
[htmlCode: "\", value: "\\"],
[htmlCode: """, value: '"'],
[htmlCode: "'", value: "'"],
[htmlCode: "<", value: "<"],
[htmlCode: ">", value: ">"]
]
removeThisHtml.each { element ->
str = delegate.replace(element.htmlCode, element.value)
}
return str
}
And here is the code form my controller:
def getProjectLists() {
def currentUser = springSecurityService.currentUser
def kups = ([['name':'<b>Sample 1</b>'.removeHtml()],['name':'<b>Sample 2</b>']])
render kups as JSON
}
My expected output is:
< b >Sample1< / b> Sample2
But the output is:
Sample1 Sample2
I think what you really want is to escape HTML - display HTML tags and entities, so the function's name removeHtml is a bit misleading, escapeHtml would fit it better.
Generally I recommend not to do things like this by your self as others have already done that and most likely do it better.
For example Apache Commons has an StringEscapeUtils.escapeHtml method.
String.metaClass.removeHtml {
return org.apache.commons.lang.StringEscapeUtils.escapeHtml(delegate)
}

Export Nested SCSS Map to Json

I am attempting to export my scss to JSON npm package sass-export
I can successfully export variables and maps one level deep, but the problem is I have a colour map(shown is just the first portion there are many colours in it) that is two levels deep. The error that is thrown is about unclosed parenthesis. Everything appears good to me, I have followed the docs to export maps but I can't find much more info on the subject. Thanks for any insight you can provide.
Successfully exported
$z-index: (
"below-base": -1,
"base":0,
"xs": 100,
"sm": 200,
"md": 300,
"lg": 400,
"xl": 500
);
Console Output
mapValue:Array(7)
0: {name: "below-base", value: "-1", compiledValue: "-1"}
1: {name: "base", value: "0", compiledValue: "0"}
2: {name: "xs", value: "100", compiledValue: "100"}
3: {name: "sm", value: "200", compiledValue: "200"}
4: {name: "md", value: "300", compiledValue: "300"}
5: {name: "lg", value: "400", compiledValue: "400"}
6: {name: "xl", value: "500", compiledValue: "500"}
Unsuccessful
$colour-palette: (
gray: (
0: #0D0D0D,
1: #1A1A1A,
2: #262626,
3: #333333,
4: #5C5C5C,
5: #858585,
6: #ADADAD,
7: #D4D6DB
),
);
Terminal Error Output
{ Error: unclosed parenthesis
at Object.module.exports.renderSync (C:\Users\tbilcke\Documents\repos\node_modules\node-sass\lib\index.js:439:16)
status: 1,
file: 'stdin',
line: 193,
column: 34,
message: 'unclosed parenthesis',
formatted: 'Error: unclosed parenthesis\n on line 193 of stdin\n>> #sass-export-id.gray{content:"#{(0: #0D0D0D}";}\n ---------------------------------^\n' }
Console Output
colour-palette: Array(1)
0:
compiledValue:"(gray: (0: #0D0D0D, 1: #1A1A1A, 2: #262626, 3: #333333, 4: #5C5C5C, 5: #858585, 6: #ADADAD, 7: #D4D6DB))"
mapValue: Array(1)
0: {name: "gray", value: "(0: #0D0D0D", compiledValue: ""}
length:1
__proto__: Array(0)
name: "$colour-palette"
value :
"(gray: (0: #0D0D0D,1: #1A1A1A,2: #262626,3: $gray-base,4: #5C5C5C,5: #858585,6: #ADADAD,7: #D4D6DB),)"
Sass Export - Working
let __root = path.join(__dirname, '../')
let __src = path.join(__dirname, '../src')
let exportPath = path.join(__src, 'scss/_test_cars.scss')
let importPath = path.join(__src, 'scss/')
let options = {
inputFiles: [exportPath],
includePaths: [importPath]
}
let asObject = exporter(options).getStructured()
process.env.styles = JSON.stringify(asObject)
I recently encountered the same issue and managed to resolve it with a relatively painless workaround.
If you take your child arrays and separate them out like so;
$colour-palette-gray: (
0: #0D0D0D,
1: #1A1A1A,
2: #262626,
3: #333333,
4: #5C5C5C,
5: #858585,
6: #ADADAD,
7: #D4D6DB
);
and then in a separate scss file (which you dont observe with sass-export) load them into the parent array
$colour-palette: (
'grey': $colour-palette-gray,
'blue': $colour-palette-blue,
'pink': $colour-palette-pink
);
you can also use the special comment syntax above each child array declaration to ensure that the nodes in the JSON are labelled correctly;
/**
* #sass-export-section="brand-colors"
*/
I am using the gulp implementation of the module in this way and it works as desired

Parsing complex json in pig?

I have json file in follwoing format:
{ "_id" : "foo.com", "categories" : [], "h1" : { "bar==" : { "first" : 1281916800, "last" : 1316995200 }, "foo==" : { "first" : 1281916800, "last" : 1316995200 } }, "name2" : [ "foobarl.com", "foobar2.com" ], "rep" : null }
So, how do i parse this json in pig..
also, the categories and rep can have some char in it..and might not be always empty.
I made the following attempt.
a = load 'sample_json.json' using JsonLoader('id:chararray,categories:[chararray], hostt:{ (variable_a: {(first:int,last:int)})}, ns:[chararray],rep:chararray ');
But i get this error:
org.codehaus.jackson.JsonParseException: Unexpected character ('D' (code 68)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
at [Source: java.io.ByteArrayInputStream#4795b8e9; line: 1, column: 50]
at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1291)
at org.codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:385)
at org.codehaus.jackson.impl.JsonParserMinimalBase._reportUnexpectedChar(JsonParserMinimalBase.java:306)
at org.codehaus.jackson.impl.Utf8StreamParser._handleUnexpectedValue(Utf8StreamParser.java:1582)
at org.codehaus.jackson.impl.Utf8StreamParser.nextToken(Utf8StreamParser.java:386)
at org.apache.pig.builtin.JsonLoader.readField(JsonLoader.java:173)
at org.apache.pig.builtin.JsonLoader.getNext(JsonLoader.java:157)
at org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.PigRecordReader.nextKeyValue(PigRecordReader.java:211)
at org.apache.hadoop.mapred.MapTask$NewTrackingRecordReader.nextKeyValue(MapTask.java:532)
at org.apache.hadoop.mapreduce.MapContext.nextKeyValue(MapContext.java:67)
at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:143)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:764)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:370)
at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:212)
You can use elephant bird pig jar for parsing json. It can parse all sort of json data.
Here are certain examples for parsing json via elephant bird pig using this jar.
https://github.com/twitter/elephant-bird/tree/master/examples/src/main/pig
It doesn't break even if an expected json tag isn't present.