I am trying to exclude all source map files, i.e files ending with .map from being uploaded to app engine.
Here's a snippet of the config in app.yaml file.
handlers:
- url: /(.*\\..+(?\<!map))$
static_files: \\1
upload: /(.*\\..+(?\<!map))$
secure: always
However, when deploying, this is the error that I get.
content <{
"error": {
"code": 400,
"message": "The request is invalid.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "version.handlers[0].url_regex",
"description": "Value \"/(.*\\..+(?\\\u003c!map))$\" must be a valid regular expression. Details: invalid or unsupported Perl syntax."
},
{
"field": "version.handlers[0].static_files.upload_path_regex",
"description": "Value \"/(.*\\..+(?\\\u003c!map))$\" must be a valid regular expression. Details: invalid or unsupported Perl syntax."
}
]
}
In the app.yaml reference documentation, it implies that it supports POSIX extended regular expression syntax.
Might anyone advice on what should be done to fix this.
You can use
^(.*([^.].{3}|.[^m].{2}|.{2}[^a].|.{3}[^p])|.{0,3})$
See the regex demo. Details:
^ - start of string
(.*([^.].{3}|.[^m].{2}|.{2}[^a].|.{3}[^p])|.{0,3}) - Group 1 matching:
.*([^.].{3}|.[^m].{2}|.{2}[^a].|.{3}[^p]) - any text, and then any of
[^.].{3}| - a char other than a . and then any 3 chars, or
.[^m].{2}| - any char, a char other than m, and then any two chars, or
.{2}[^a].| - any two chars, any char other than a, and then any one char
.{3}[^p] - any three chars, and then a char other than p
| - or
.{0,3} - any zero, one, two or three chars.
$ - end of string.
Related
I have observed a strange behavior of my node application using GraphicsMagick.
I would like to identify the number of pages in a pdf file. Therefore, I use "identify" which returns an object of type gm.ImageInfo. Then I "destructure" the returned object to obtain an array of strings that describe the format of my input file. The length should be the number of pages (which it actually is).
What strikes me is that Format inside the interface gm.ImageInfo is defined as string, however "identify" returns an array of strings (in case the input file consists of multiple pages). Still, I cannot formally define my "Format" variable as "string[]" because TypeScript tells me that a string cannot be assigned to an array of strings (which is obviously correct). How can I solve that conflict an obtain the actual array of strings returned by "identify"?
Here is the relevant extract of my code:
This works but I do not formally get an array of strings:
import gm from 'gm';
gm('test.pdf').identify((err: any, value: gm.ImageInfo) => {
const { Format, ...rest }: gm.ImageInfo = value;
console.log(Format);
console.log(Format.length);
if (err) {
console.log('err');
}
});
This does not work since TypeScript complains:
import gm from 'gm';
gm('test.pdf').identify((err: any, value: gm.ImageInfo) => {
const { Format, ...rest }: { Format: string[] } = value;
console.log(Format);
console.log(Format.length);
if (err) {
console.log('err');
}
});
Format typically contains something like this (for example if the input pdf contains 7 pages):
[
'PDF (Portable Document Format)',
'PDF (Portable Document Format)',
'PDF (Portable Document Format)',
'PDF (Portable Document Format)',
'PDF (Portable Document Format)',
'PDF (Portable Document Format)',
'PDF (Portable Document Format)'
]
This looks very much like an array. Format.length is 7 (= the number of pages). However, the type of Format is not string[]. How can I convert Format to a string[] to obtain an actual array?
I'm really struggling to get a regex working. All I want to do is something that would capture a string and its trailing space and put that as an entry into an array.
For example:
"RegExr #was created by gskinner.com, and is proudly hosted by Media Temple.
Edit the Expression & Text to see matches."
["RegExr ", "#was ", "created ", "by ", gskinner.com " ... "& " ... "matches. " etc...]
I'm trying to do the following in a React App:
console.log("matches are: ", message.match(/(\w+\s|#\w+\s|\s )/));
return message.match(/((\w+ ?))/);
// return message.split(" ");
I found that the split function was created some weird issues for me so I wanted just to have the matches function return an array of the results I specified above.
When I log out some attempts I just get weird results no matter what I try, like this:
e.g.
matches are: (2) ["Hey ", "Hey ", index: 0, input: "Hey Martin Im not sure how to make the font in this box bigger #ZX81", groups: undefined]
Can someone help it is really blocking some progress on my app.
To get all non-whitespace char chunks with any adjoining whitespace, you can use
message.match(/\s*\S+\s*/g)
See the regex demo. The g flag will make it extract all matches of
\s* - zero or more whitespace chars
\S+ - one or more non-whitespace chars
\s* - zero or more whitespace chars.
See a JavaScript demo:
const message = "RegExr #was created by gskinner.com, and is proudly hosted by Media Temple. Edit the Expression & Text to see matches.";
console.log(message.match(/\s*\S+\s*/g));
I have the following JSON object, from which I need to retrieve values of certain keys.
For example, in outer JSON object, I need only "timestamp" and "type", next from a nested "meta" object I need only "version", and from nested "payload" I want fields "reason", "type" and "condition" from its nested object "data"
{
"timestamp": "1568961295627",
"type": "test",
"namespace": "internal",
"meta": {
"version": "2.0-test",
"id": "123"
},
"payload": {
"data": {
"reason": "user_request",
"type": "asd",
"condition": "bad"
},
"contentType": "application/json"
}
}
I wrote a function to retrieve such data:
void log_values(json_t *data) {
json_t *obj = NULL;
json_t *nested = NULL;
syslog(LOG_INFO, "%s: ", json_string_value(json_object_get(data, "timestamp")));
syslog(LOG_INFO, "%s: ", json_string_value(json_object_get(data, "type")));
obj = json_object_get(data, "meta");
syslog(LOG_INFO, "%s: ", json_string_value(json_object_get(obj, "version")));
obj = json_object_get(data, "payload");
nested = json_object_get(obj, "data");
syslog(LOG_INFO, "%s: ", json_string_value(json_object_get(nested, "reson")));
syslog(LOG_INFO, "%s: ", json_string_value(json_object_get(nested, "type")));
syslog(LOG_INFO, "%s: ", json_string_value(json_object_get(nested, "condition")));
}
However, the code looks repetitive and I'm wondering if there is any way to generalize it?
The first thing which came to mind is to create a jagged array of pointers to keys needed for each stage, and then walk through the array and retrieve only certain keys on certain nesting level, for example:
char *nested0 = {"timestamp", "type"};
char *nested1 = {"anomaly", "version"};
char *nested2 = {"reason", "type", "condition"};
char *(*keys[])[] = { &nested0, &nested1, &nested2 }
But, this solution does not solve problem regarding where to store key names, which point to nested JSONs (e.g "meta, payload, data").
So, the question is: How to generalize the aforementioned code and what data structure should I use to store names of keys holding a json object and keys for which I need to get values.
Take a look at jsmn, it should fit your needs : https://github.com/zserge/jsmn
exemple of what you could do with jsmn :
[user#machine ~]$ ./json_parser_with_keys test.json timestamp type meta/version
timestamp=1568961295627
type=test
meta/version=2.0-test
[user#machine ~]$ ./json_parser_full test.json
/timestamp=1568961295627
/type=test
/namespace=internal
/meta/version=2.0-test
/meta/id=123
/payload/data/reason=user_request
/payload/data/type=asd
/payload/data/condition=bad
/payload/contentType=application/json
[user#machine ~]$
I have some translations now that are paragraphs of text which quickly become tedious to manage as single JSON strings:
{
"a": {
"b": "This is a really long translated value I have here..."
}
}
I think ideally I would like to be able to represent the values differently and then transform them. For example as an array of strings that would be concatenated together:
{
"a": {
"b": [
"This is a really long ",
"translated value ",
"I have here..."
]
}
}
Does angular-translate have the appropriate hooks to achieve this?? And if so, what is the best approach?
First off, this is a very broad question, and it might come across as me asking for the community to write my code for me. That is not my intent, but I am so lost, I don't know how to give enough information.
I am attempting to use the cJSON library, written by Dave Gamble,
I found this is very useful to use for my embedded device for JSON parse and composing.
to read in the following JSON array
{
"name": "Jack",
"types":[23,56,78],
"format": {
"type": "rect",
"width": 1920, }
}
.. and parsing the getting the object worked with this method
cJSON *format = cJSON_GetObjectItem(json,"format");
int framerate = cJSON_GetObjectItem(format,"width")->valueint;
but I am not able to parse the key "name" and object simple key value ,
I tried this
cJSON *array = cJSON_GetArrayItem(json,"types");
int value = cJSON_GetArrayItem(format1,1)->valueint;
but did not work, how to parse the array object and simple key value..
Your json is just fine. You can iterate through array of values in cJSON:
cJSON * array = cJSON_GetObjectItem(json, "types");
for (i = 0 ; i < cJSON_GetArraySize(array) ; i++)
{
printf("%d ",cJSON_GetArrayItem(array, i)->valueint);
}
will print
23 56 78
I think JSON element should respect key:value format.
{
"name": "Jack",
"types":[{"type" : 23}, {"type" : 56}, {"type":78}],
"format": {
"type": "rect",
"width": 1920, }
}