Inserting code with a keybinding in Visual Studio Code - key-bindings

How can I insert code in Visual Studio Code for MacOS with key bindings? For example in Sublime I can insert a console.log like this:
{
"keys": ["super+shift+l"],
"command": "insert_snippet",
"args": {
"contents": "console.log('test:' + varname);${0}"
}
},
If I press Cmd+Shift+L I get console.log('test:' + varname);

You can specify what the insertSnippet command should insert like this:
{
"key": "cmd+shift+l",
"command": "editor.action.insertSnippet",
"args": {
"snippet": "console.log('test:' + varname);${0}"
}
}

Related

Strapi. Method Not Allowed custom question

Through postman, I'm trying to send a post request to create a post, but I get an error that is described in the question itself (error code - 405).
On top of all that, I've issued ALL permissions. What is the problem?
grade collection -
and schema.json from grade -
{
"kind": "collectionType",
"collectionName": "grades",
"info": {
"singularName": "grade",
"pluralName": "grades",
"displayName": "grade"
},
"options": {
"draftAndPublish": true
},
"pluginOptions": {},
"attributes": {
"id_post": {
"type": "biginteger"
},
"grade": {
"type": "integer"
}
}
}
from comments, it seems the problem is two extra invisible characters after the url:
this line makes them visible:
[2022-12-21 14:38:39.382] http: POST /api/grades/%0A%0A (4 ms) 40
notice the %0A%0A
remove them or copy paste clean url:
http://localhost:1337/api/grades

Why does my browser extension do nothing on page load (except in the toolbox)?

I've been trying to make a Firefox extension. I've had success with doing stuff after a user interaction (like a browser action). But I want my extension to do something without user interaction. But no matter what I do, I can't get anything to happen on page load. Here is my super reduced code:
manifest.json
{
"name": "Test",
"version": "0.1",
"manifest_version": 2,
"background": {
"scripts": ["test.js"]
}
}
test.js
document.addEventListener("DOMContentLoaded", init);
function init() {
document.body.innerHTML = "Hello world!";
}
What am I doing wrong here? It works in the toolbox, just not anywhere else!
I've also tried adding host permissons like this:
"permissions": [
"*://*.facebook.com/*"
],
Try this:
manifest.json
{
"name": "Test",
"version": "0.1",
"manifest_version": 2,
"background": {
"scripts": ["background.js"]
},
"permissions": ["webNavigation", "*://*.facebook.com/*"]
}
background.js
browser.webNavigation.onDOMContentLoaded.addListener(handleOnDOMContentLoaded, {
url: [{ hostEquals: 'www.facebook.com' }],
});
function handleOnDOMContentLoaded({ tabId }) {
browser.tabs.executeScript(tabId, { file: 'test.js' });
}
test.js
document.body.innerHTML = 'Hello world!';

Open custom url from vscode

I'd like to create a shortcut to open a custom link generated using the selected text from the current editor. So far I tried:
{
"key": "ctrl+enter",
"command": "workbench.action.url.openUrl",
"args": {
"text": "https://www.thesaurus.com/browse/${selectedText}"
},
"when": "editorTextFocus"
},
with no success.
Is it possible?

Action on Google - Custom action in german language using action sdk

I am developing a speech recognition for a custom device using Google Assistant SDK. I am using Action SDK to create custom actions.
In my example the Google Assistant doesn't recognize actions in german language in case these actions are marked with "locale": "de" and the assistants language is set to german. I recognized that query patterns are understood clearly, but the event is not triggered. If everything is set to english the events are triggered.
action.json
{
"locale": "de",
"manifest": {
"displayName": "Blink Licht",
"invocationName": "Blink Licht",
"category": "PRODUCTIVITY"
},
"actions": [
{
"name": "com.acme.actions.blink_light",
"availability": {
"deviceClasses": [
{
"assistantSdkDevice": {}
}
]
},
"intent": {
"name": "com.acme.intents.blink_light",
"parameters": [
{
"name": "number",
"type": "SchemaOrg_Number"
},
{
"name": "light_target",
"type": "LightType"
}
],
"trigger": {
"queryPatterns": [
"lasse das $LightType:light_target $SchemaOrg_Number:number mal blinken"
]
}
},
"fulfillment": {
"staticFulfillment": {
"templatedResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Das Licht $light_target.raw blinkt $number mal"
}
},
{
"deviceExecution": {
"command": "com.acme.commands.blink_light",
"params": {
"lightKey": "$light_target",
"number": "$number"
}
}
}
]
}
}
}
}
],
"types": [
{
"name": "$LightType",
"entities": [
{
"key": "LIGHT",
"synonyms": [
"Licht",
"LED",
"Glühbirne"]
}
]
}
]
}
hotword.py - snipped of event processing
def process_event(event, device_id):
"""Pretty prints events.
Prints all events that occur with two spaces between each new
conversation and a single space between turns of a conversation.
Args:
event(event.Event): The current event to process.
device_id(str): The device ID of the new instance.
"""
if event.type == EventType.ON_CONVERSATION_TURN_STARTED:
print()
print(event)
if (event.type == EventType.ON_CONVERSATION_TURN_FINISHED and
event.args and not event.args['with_follow_on_turn']):
print()
if event.type == EventType.ON_DEVICE_ACTION:
for command, params in process_device_actions(event, device_id):
print('Do command', command, 'with params', str(params)) #
if command == "com.acme.commands.blink_light":
number = int(params['number'])
for i in range(int(number)):
print('Device is blinking.')
Project language in action console is German:
enter image description here
To update and make the action available for testing I used "gaction CLI".
The question: Why is the event/command "com.acme.commands.blink_light" in hotword.py not triggered in case using german language?
Thanks in anticipation!
Here's how I solved this problem:
1. Go to your action on google console and pick the project you're having this trouble with.
2. In the 'Overview' section you'll see a window with the languages of your action on top, and at their right a 'Modify languages' in blue. Click it and then delete the langauge you're not using, english in this case.
At least that worked for me.

browser.runtime.connect api not working as expected with Firefox for android?

I am developing an extension for Firefox for Android, but since tabs APIs are not supported on Firefox(Android), I am using the following code. It is working fine on Firefox but when porting it to Firefox Android(52 version), background script messages are not being passed to content script listener.
//Content script code
var myPort = browser.runtime.connect({name:"port-from-cs"});
myPort.postMessage({greeting: "hello from content script"});
myPort.onMessage.addListener(function(m) {
console.log("In content script, received message from background script: ");
console.log(m.greeting);
});
// background script
var portFromCS;
function connected(p) {
portFromCS = p;
portFromCS.postMessage({greeting: "hi there content script!"});
portFromCS.onMessage.addListener(function(m) {
console.log("In background script, received message from content script")
console.log(m.greeting);
portFromCS.postMessage({greeting: "hi there content script!"});
});
}
browser.runtime.onConnect.addListener(connected);
//manifest
{
"version": "0.1.5",
"content_scripts": [
{
"js": [
"js/myContentScript.js",
"js/lib/jquery-1.9.1.min.js"
],
"matches": [
"<all_urls>"
],
"run_at": "document_start"
}
],
"description": "xxx",
"manifest_version": 2,
"name": "xx",
"applications": {
"gecko": {
"id": "vpt#mozilla.org"
}
},
"permissions": [
"webRequest",
"notifications",
"http://*/",
"https://*/",
"storage",
"webRequestBlocking"
],
"background": {
"scripts": [
"js/background.js"
]
},
"web_accessible_resources": [
"xxx.js"
]
}
content script is passing the message to background script, but background script messages are caught by portFromCS.onMessage listener. Is my approach correct?

Resources