I'm wondering if it's possible to "name" a sublime completion so that the name shows up in the auto complete box. With snippets, you can do this by adding a description, but I tried adding that (and name) to the completion with no luck.
To show what I'm trying to accomplish:
The first option is from a snippet with <description>console.log snippet</description> set.
The second option is a completion:
{ "trigger" : "cl" , "description" : "console.log", "contents" : "console.log( ${10} );" }
Use \t after the trigger text. However, there is a bug where buffer completions get blocked when using this feature.
{
"scope": "source.php",
"completions": [
{
"trigger": "trigger_text\tdescription_text",
"contents":"contents_text"
}
]
}
Related
How to fill/change particular unknown strings of some sections of a well formated .json file from bash keeping the format intact ?
Details:
Part of settings.json :
"profiles":
{
"defaults":
{
// Put settings here that you want to apply to all profiles.
},
"theme": "dark",
"list":
[
{
// Make changes here to the powershell.exe profile.
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"name": "Windows PowerShell",
"commandline": "powershell.exe",
"hidden": false,
"acrylicOpacity": 0.9,
"colorScheme" : "Material",
"cursorColor" : "#FFFFFD",
"useAcrylic" : true
},
{
// Make changes here to the cmd.exe profile.
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"name": "Command Prompt",
"commandline": "cmd.exe",
"hidden": false,
"acrylicOpacity": 0.2,
"colorScheme" : "Frost",
"cursorColor" : "#000000",
"useAcrylic": true,
},
"schemes": [
{
"name" : "Frost",
"background" : "#ffffff",
"black" : "#3C5712",
"blue" : "#17b2ff",
"brightBlack" : "#749B36",
"brightBlue" : "#27B2F6",
"brightCyan" : "#13A8C0",
"brightGreen" : "#89AF50",
"brightPurple" : "#F2A20A",
"brightRed" : "#F49B36",
"brightWhite" : "#741274",
"brightYellow" : "#991070",
"cyan" : "#3C96A6",
"foreground" : "#000000",
"green" : "#6AAE08",
"purple" : "#991070",
"red" : "#8D0C0C",
"white" : "#6E386E",
"yellow" : "#991070"
},
another file pickcolor.txt:
#FFFAFA
#FFFAFA
#EEE9E9
#FFC1C1
#EEB4B4
#CDC9C9
#F08080
#FF6A6A
#CD9B9B
#EE6363
#BC8F8F
#FF4040
#FF3030
#EE3B3B
#CD5C5C
#CD5555
#EE2C2C
#8B8989
#CD3333
#FF0000
#FF0000
#8B6969
#CD2626
#EE0000
#B22222
#A52A2A
#CD0000
#8B3A3A
#8B2323
Want to create a bash which changes value of fields like "background", "cursorColor" to any random value from pickcolor.txt
Requirements/problems I am facing:
Fields appearing many times gets different values from each other
Value of fields changes from time to time, so simple find and replace do not work
Fields changes there line number every time new contents are added, so line number for fields do not remain same.
Format of .json file should not change
Please note : I do not want anyone to write the complete code ; just hinting/pointing out ways will be sufficient. And thanks in advance !!
I believe what you need is something like this
fields=(background cursorColor)
colors=("#FFFAFA" "#CDC9C9" "#EE3B3B")
size=${#colors[#]}
for f in "${fields[#]}"; do
for line in $(grep -n "\"$f\"" myfile.json | cut -f1 -d:); do
index=$(($RANDOM % $size))
color="${colors[$index]}"
sed -i $line's|\("'"$f"'"\s*:\s*"\).\+"|\1'"$color"'"|' myfile.json
done
done
There is some magic in this solution:
We choose random index from array of colors
For each of fields which should be replaced we create it's own unique sed expression, which
First part (\("'"$f"'"\s*:\s*"\)#.\+" finds anything matching pattern "<field name>"<spaces>:<spaces>"<any color>"
Captures anything until 3rd double quote into group
In second group (\1'"${colors[$index]}"'") replaces matched part with itself, but inserts randomly picked color from array into second double quote group
Weird things with lots of quotes are made to interpolate field name and color into single quotes
NB: this is tested with GNU sed. May need a bit different syntax for BSD
I'm trying to make a resource pack in Minecraft, and I'm replacing it so there's only one sound. When I went to go and edit sounds.json in VSC, I want to set all the locations to just one file. It should look like this :
"sounds" : [
"test/test"
],
to test/test for all the "sounds". But I have no idea of how to do this. The sounds.json file is so big it would take more than a day to do all the work by hand. So I checked to see if VSC had any options to replace the text. There wasn't.
I've tried looking around in VSC and there wasn't anything useful.
I've tried replacing all the sounds by pasting .ogg files and renaming them, it took too long, so I realized I could just set all the locations to point at one sound file.
I've gone on Google to do some research but found nothing of use.
"block.enderchest.open": {
"sounds": [
"test/test"
],
"subtitle": "subtitles.block.chest.open"
},
"block.fence_gate.close": {
"sounds": [
"block/fence_gate/close1",
"block/fence_gate/close2"
],
"subtitle": "subtitles.block.fence_gate.toggle"
},
"block.fence_gate.open": {
"sounds": [
"block/fence_gate/open1",
"block/fence_gate/open2"
],
"subtitle": "subtitles.block.fence_gate.toggle"
},
"block.fire.ambient": {
"sounds": [
"fire/fire"
],
I expect a convenient way in order to edit "sounds" : [] []'s all at once.
The actual result is not really a convenient way and a time waster to edit all of the sounds [] values.
One way to do it is with regex, see regex101 demo.
Search for : ("sounds": \[\n)((\s*)[^\]]*\n)*(\s*\],)
Replace with: $1$3"test/test"\n$4
I created a query for a elastic search watcher setup. The result set looks like this:
"_index": "transaction_broker-2017.09.15",
"_type": "transaction_broker",
"_id": "AV6Fn_UQ9KbnKce40avY",
"_score": 3.8539968,
"_source": {
"tbroker.workitem.sync_check.tbroker_value": 7000,
"source": "/logs/web/tomcat/tbroker.log.json",
"type": "transaction_broker",
"tbroker.job.instance_id": "lixporta-p00.xxxxxxx.15053054001381505305457198",
"tbroker.workitem.sync_check.backend_total_value": 6995,
"tbroker.appversion": "1.1.135-180",
"#version": 1,
"beat": {
"hostname": "lixporta-p00",
"name": "lixporta-p00",
"version": "5.1.1"
In the action section, I can access the fields by using:
"actions": {
"my-logging-action": {
"logging": {
"text": "There are {{ctx.payload.hits.hits.0._source.....
After the source tag, I use for example the "type" field from the list above. Other example is:
"ctx.payload.hits.hits.0._source.beat.hostname"
This works pretty fine...
But it is not possible to use a field like
"tbroker.workitem.sync_check.tbroker_value"
The parser thinks that this fields are nested, but this is only a fieldname with dots in it.
Is there any possiblity to "escape" this fieldname?
Anyone who also have had this problem ?
Many thanks & best regards
Claus
I think the following should work:
{{#ctx.payload.hits.hits.0._source}}{{tbroker.workitem.sync_check.tbroker_value}}{{/ctx.payload.hits.hits.0._source}}
It is a limitation of Mustache and this is a workaround.
Another example may help - when in a context looping through hits (I have added // comments purely for clarity - they aren't valid Mustache syntax & should be removed):
{{#ctx.payload.hits.hits}}
// This works fine
{{_source.foo}}
// Not working if each hit's _source contains "bar.baz", not nested "bar">"baz"
{{_source.bar.baz}}
{{/ctx.payload.hits.hits}}
Applying the same workaround by adding an extra context/section:
{{#ctx.payload.hits.hits}}
// Put us in the context of [the current hit] > _source
{{#_source}}
// Now both of these work...
{{foo}}
// ...including this one containing a dot (yay!)
{{bar.baz}}
{{/_source}}
{{/ctx.payload.hits.hits}}
There is no way to directly access source fields that have dots in them, but if you apply a transform like this:
"transform": {
"script": {
"inline": "return [ 'host' : ctx.payload.hits.hits[0]._source.host, 'tbroker_value' : ctx.payload.hits.hits[0]._source['tbroker.workitem.sync_check.tbroker_value']]",
"lang": "painless"
}
}
and then you can use {{ctx.payload.host}} and {{ctx.payload.tbroker_value}} in your action.
I would like to read a json file where the sutructure is like below. I tried fromJson but it just read the first block. Can you help me on specify the delimiter to read all the file?
Thank you so much
json_data <- fromJSON(paste(readLines("C:C:/Users/aa/Data-test.json"), collapse=""))
Warning message:
In readLines("C:/Users/aa/Data-test.json") :
incomplete final line found on 'C:/Users/jsalim/Desktop/Docapost_20160718/FILES/Extract-Morgane_1307/Data-device2.json'
{
"id" : "aaa",
"dateModification" : "2016-06-04T04:29:30Z",
"active" : true,
.....
}
{
"id" : "bbbb",
"dateModification" : "2016-06-04T04:29:30Z",
"active" : true,
.....
}
{
"id" : "ccc",
"dateModification" : "2016-06-04T04:29:30Z",
"active" : true,
.....
}
I believe that as in the answer suggested in this question, you just need to enter a carriage return at the end of the line (that is, there should be a single empty line at the end of your file). This worked for me in the same scenario.
Ahoy! I'm having a very funny issue with MongoDB and, possibly more in general, with JSON. Basically, I accidentally created some MongoDB documents whose subdocuments contain an empty key, e.g. (I stripped ObjectIDs to make the code look nicer):
{
"_id" : ObjectId("..."),
"stats" :
{
"violations" : 0,
"cost" : 170,
},
"parameters" :
{
"" : "../instances/comp/comp20.ectt",
"repetition" : 29,
"time" : 600000
},
"batch" : ObjectId("..."),
"system" : "Linux 3.5.0-27-generic",
"host" : "host3",
"date_started" : ISODate("2013-05-14T16:46:46.788Z"),
"date_stopped" : ISODate("2013-05-14T16:56:48.483Z"),
"copy" : false
}
Of course the problem is line:
"" : "../instances/comp/comp20.ectt"
since I cannot get back the value of the field. If I query using:
db.experiments.find({"batch": ObjectId("...")}, { "parameters.": 1 })
what I get is the full content of the parameters subdocument. My guess is that . is probably ignored if followed by an empty selector. From the JSON specification (15.12.*) it looks like empty keys are allowed. Do you have any ideas about how to solve that?
Is that a known behavior? Is there a use for that?
Update I tried to $rename the field, but that won't work, for the same reasons. Keys that end with . are not allowed.
Update filed issue on MongoDB issue tracker.
Thanks,
Tommaso
I have this same problem. You can select your sub-documents with something like this:
db.foo.find({"parameters.":{$exists:true}})
The dot at the end of "parameters" tells Mongo to look for an empty key in that sub-document. This works for me with Mongo 2.4.x.
Empty keys are not well supported by Mongo, I don't think they are officially supported, but you can insert data with them. So you shouldn't be using them and should find the place in your system where these keys are inserted and eliminate it.
I just checked the code and this does not currently seem possible for the reasons you mention. Since it is allowed to create documents with zero length field names I would consider this a bug. You can report it here : https://jira.mongodb.org
By the way, ironically you can query on it :
> db.c.save({a:{"":1}})
> db.c.save({a:{"":2}})
> db.c.find({"a.":1})
{ "_id" : ObjectId("519349da6bd8a34a4985520a"), "a" : { "" : 1 } }