How can I make snippet that place a variable in the script in VSCODE? - vscode-snippets

I want my prefix "ffz15" turns into "font-size: var(--fz15)".
So, when I have typed "ffz", everything that goes after this prefix should come as variable and inserts in snippets body.
It should be something like this (pseudocode):
"font-size variable": {
"scope": "css, scss",
"prefix": "fzz{value-of-font-size}",
"body": [
"font-size: var(--fz{value-of-font-size}px)",
],
},
I think it can be made quite simple, but I cannot find any information about that.
Thank you in advance for your help.

I don't think you can use part of the prefix as a variable in the snippet. Can you just do this instead? Use fzz as prefix, then it inserts the snippet, and puts you at the place where you just type the font size:
"font-size variable": {
"scope": "css, scss",
"prefix": "fzz",
"body": [
"var(--fz$0)",
],
},

Related

access object in array with blanc key in json typescript

I am using storage connector in loopback to load files onto the file system. for every loaded file I am receiving a response like:
{
"files": {
"": [
{
"container": "00003",
"name": "mydoc.docx",
"type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"field": "",
"size": 23384
}
]
},
"fields": {}
}
There an issue with the returned array with a key "". The objected containing the above is called loadedFile, say I would like to print the size of the loaded file.
console.log(obj.files.""[0].size);
The above doesn't work as the array doesn't have a name in the response.
Please, can anyone point out to a solution?
Thanks in advance and Regards
T
You can access the property via the Bracket notation, rather than the Dot notation.
In your case:
console.log(obj.files[""][0].size)

Mix of objects and arrays

I am trying to structure the json-schema after a json response I want to send.
I have tried several versions of object->array->object->array, but it does not seem like I can validate an UUID key with a regex using patternProperties
The JSON looks like this:
[{
"54ffe69-b8f6-47c8-9437-ccea8ecc2d77": {
"name": "ORC",
"$description": "Design polar from ORC",
"source": {
"label": "signalk-polar"
},
"polarData": [{
"trueWindSpeed": 3.086666667,
"beatAngles": [
0.738274274
]
}]
}
}]
Not really sure, it might be something wrong with the UUID that you are trying to validate. It is though accepting this pattern:
[0-9a-f]{7}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}
but, according to this post, we should have had:
[0-9a-f]{8}
in the starting part, or I might be wrong.
Demo

ARM template array parameter

I have an ARM template with a web app alerting rule, where I want to be able to configure which e-mails get the alerts.
The snippet for the e-mail alerting action is this:
"action": {
"odata.type": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction",
"sendToServiceOwners": false,
"customEmails": [
"email1#example.com",
"email2#example.com"
]
}
The same template is used for setting up production, test, and dev environments. So I would like to use a parameter for the e-mail alerting.
How can I generate an array to be used as the "customEmails" property based on either a comma separated string, or an array type parameter?
I have tried "customEmails": "[array(parameters('AlertEmailRecipients'))]", and also
"customEmails": [
[array(parameters('AlertEmailRecipients'))]
]
but neither work. I don't know how to tell it that the "customEmails" property value should come from a parameter.
I used the following using an array parameter:
parameter declaration:
"customEmails": {
"type": "array",
"metadata": {
"description": "alert email addressess"
}
}
in the parameters file:
"customEmails": {
"value": [
"email1#domain.com",
"email2#domain.com"
]
}
usage:
"customEmails": "[parameters('customEmails')]"
I found a solution. The main problem was that my comma separated list of e-mail addresses had a space after each comma.
The way I have implemented it now is like this:
Define a string parameter with a comma separated list of e-mail addresses. Don't have spaces in the list.
Define a variable like this:
"customEmails" : "[split(parameters('AlertEmailRecipients'), ',')]"
and then reference that variable in the alerting action:
"action": {
"odata.type": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction",
"sendToServiceOwners": false,
"customEmails": "[variables('customEmails')]"
}
The example actually does this, but doesn't make it clear the the list of e-mails can't contain spaces.

Only getting single word parameters from Alexa Skills Kit

I'm writing an Alexa Skill, and I can only get single word parameters into my code.
Here is the intent schema:
{
"intents": [
{
"intent": "HeroQuizIntent",
"slots": [
{
"name": "SearchTerm",
"type": "SEARCH_TERMS"
}
]
},
{
"intent": "HeroAnswerIntent",
"slots": [
{
"name": "SearchTerm",
"type": "SEARCH_TERMS"
}
]
},
{
"intent": "AMAZON.HelpIntent"
}
]
}
and my sample utterances are:
HeroQuizIntent quiz me
HeroAnswerIntent is it {SearchTerm}
For the HeroAnswerIntent, I'm checking the SearchTerm slot, and I'm only getting single words in there.
So, "Peter Parker" gives "Parker", "Steve Rogers" gives "Rogers", and "Tony Stark" gives "Stark".
How do I accept multiple words into a slot?
I've had same problem with my skill and that's the only solution which is worked for my skill to use several words, but you need to check are these slots not empty and concatenate them
Intent schema:
{
"intent": "HeroAnswerIntent",
"slots": [
{
"name": "SearchTermFirst",
"type": "SEARCH_TERMS"
},
{
"name": "SearchTermSecond",
"type": "SEARCH_TERMS"
},
{
"name": "SearchTermThird",
"type": "SEARCH_TERMS"
}
]
},
Sample utterance
HeroAnswerIntent is it {SearchTermFirst}
HeroAnswerIntent is it {SearchTermFirst} {SearchTermSecond}
HeroAnswerIntent is it {SearchTermFirst} {SearchTermSecond} {SearchTermThird}
And last one you need to put every of your words in separate line in SEARCH_TERMS slot definition
Also using AMAZON.LITERAL sometimes not pass variable into skill at all even if you test it using service simulator (skill console, test tab)
The solution #Xanxir mentioned works equivalently with the newer custom slots format. In this case, you'd just put multiple length examples in your custom list of values for your slot type.
I had to change the Slot type to AMAZON.LITERAL.
The trick was that in the sample utterances, I also had to provide multiple utterances to demonstrate the minimum and maximum sizes of literals that Alexa should interpret. It's wonky, but works.
Here's the reference for it: https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/alexa-skills-kit-interaction-model-reference
AMAZON.SearchQuery
So you can use this in your utterances, and it will detect all words that the user speaks in between, Its rather accurate
It will solve your problem.
Ref Link: Alexa SearcQuery

Creating context for JSON-LD

As a simple exercise I wanted to take some test-data from a little app I had which produced a user record in JSON and turn it into JSON-LD, testing on JSON-LD.org's playground gives some help, but I don't know if I'm doing it right.
The original is:
[
{
"Id": 1
"Username": "Dave",
"Colour":"green“
}
]
So I have a person, who has a username, an ID and an associated colour.
What I've got so far is:
{
"#context": {
"name": "http://schema.org/name",
"Colour": {
"#id": "http://dbpedia.org/ontology/Colour",
"#type": "http://schema.org/Text",
"#language": "en"
}
},
"#type": "http://schema.org/Person",
"#Id": "http://example.com/player/1",
"sameAs" : "https://www.facebook.com/DaveAlger",
"Id": 1,
"name": "David Alger",
"Username": "Dave",
"Colour": "green"
}
So I'm declaring it's a #type of person, and given a URI #id.
I'm also using the "sameAs" idea, which I saw on a blog-post once, but am unclear if it is just supported right off.
Then I've tried to create a #context. Here that I've added a name and given that a reference. I've tried to create something for "colour" too. I'm not sure if pointing to a DBpedia reference about "colour" and specifying a #type and #language is good, or not.
I suppose the final thing is "username", but that feels so deeply internal to a site that it doesn't make sense to "Link" it at all.
I'm aware this data is perhaps not even worth linking, this is very much a learning exercise for me.
I don’t think that http://dbpedia.org/ontology/Colour should be used like that. It’s a class, not a property. The property that has http://dbpedia.org/ontology/Colour as range is http://dbpedia.org/ontology/colour. (That said, I’m not sure if your really intend that the person should have a colour, instead of something related to this person.)
If you want to provide the language of the colour strings, you should not specify the datatype, #language is sufficient (if a value is typed, it can’t have a language anymore; by using #language, it’s implied that the value is a string).
You are using #Id for specifying the node’s URI, but it must be #id.
The properties sameAs, Id and Username are not defined in your #context.
If you intend to use Schema.org’s sameAs property, you could define it similar to what you did with name, but you should specify that the value is a URI:
"sameAs": {
"#id": "http://schema.org/sameAs",
"#type": "#id"
},
For Username, you could use FOAF’s nick property, or maybe Schema.org’s alternateName property.
No idea which property you could use for Id (depends on your case if this is useful for others at all, or if this is only relevant for your internal system).

Resources