VSCode keybinding that inputs large amount of code (Python: Visual Studio Code) - visual-studio

I'm currently trying to add a keybinding in Vscode that inputs multiple lines of code. Below is my current attempt at doing that – but it's not working due to some syntaxical errors. Would anyone know how I'm supposed to format this?
{
"key": "ctrl+y",
"command" : "type",
"args": {
"text": "
leave1 = False
while(leave1 == False):
try:
driver.find_element(By.XPATH, '')
except Exception:
time.sleep(0.5)
else:
leave1 = True
"
}
}

Related

RUBY : Unexpected end of file and command not found?

I start to learn Ruby and i got some problem when i ran the code on the
Terminal. it says :
desktop/RUBY/boucles.rb: line 1: voyages: command not found
desktop/RUBY/boucles.rb: line 14: syntax error: unexpected end of file.
My IDE is sublim text.
How i can solve that ?
voyages = [
{ ville: "Paris", duree: 10 },
{ ville: "New York", duree: 5 },
{ ville: "Berlin", duree: 2 },
{ ville: "Montreal", duree: 15 }
]
voyages.each do |voyage|
if voyage[:duree] <= 5
puts "Voyage à #{voyage[:ville]} de #{voyage[:duree]} jours"
end
end
Your code is correct and works without any syntax errors. If you were editing in Sublime Text, you might want to make sure that you saved the file first.
Those errors look like they might be coming from your shell, not from Ruby!
How are you running this script? You should be running ruby boucles.rb in your terminal.

Error reading project.json, Unterminated string error when performing dotnet restore

Using Visual Studio for Mac to perform a "dotnet restore" but the terminal shows this message:
error : Error reading
'/Users/abc/corefx/src/Microsoft.TargetingPack.Private.CoreCLR/ref/project.json' at line 8 column 1 : Unterminated string. Expected delimiter: ". Path 'frameworks', line 8, position 1.
error:Unterminated string. Expected delimiter: ". Path 'frameworks', line 8, position 1.
project.json:
{
"dependencies": {
"Microsoft.TargetingPack.Private.CoreCLR": "1.2.0-beta-24904-03"
},
"frameworks": {
"netcoreapp1.1.0”: {}
}
}
I have found the file but I cannot identify the cause of the problem. What could cause this error message?
It looks to me like the netcoreapp1.1.0 property name is terminated with a typographic right quote mark ” which is not valid JSON. It should be a standard straight quote " instead.
{
"dependencies": {
"Microsoft.TargetingPack.Private.CoreCLR": "1.2.0-beta-24904-03"
},
"frameworks": {
"netcoreapp1.1.0": {}
}
}

Automatically add spaces around "=>"

On SublimeText 3 I try to automatically add spaces before and after "=>"
I try to add this in User Keybinding:
{ "keys": ["equals,>"], "command": "insert_snippet", "args": { "name": "Packages/User/spacer.sublime-snippet" } }
And this is my snippet:
<snippet>
<content><![CDATA[ => ]]></content>
</snippet>
But it's not working.
Console says Unknown key equals,>
equals is redundant. So correct settings:
{ "keys": [">"], "command": "insert_snippet", "args": { "name": "Packages/User/spacer.sublime-snippet" } }
Next time please look for errors in the console first.
UPDATE
I want it matchs on "=>".
["=",">"] should be used in this case
{ "keys": ["=",">"], "command": "insert_snippet", "args": { "name": "Packages/User/spacer.sublime-snippet" } }
When I read the question I realized that I frequently insert spaces on both sides of something, so I knocked up the Sublime Text plugin below for my own use and, as an afterthought, decided to post it here.
This plugin adds a single space both before and after any selected text, e.g. "Sel" --> " Sel ". Multiple selections are, of course, handled. Single cursors are ignored otherwise you'd just be adding two spaces. It is compatible with both Sublime Text v.2 and v.3.
Save the following code in a file called AddSpacesAroundSelection.py and place the file somewhere in your Sublime Text Packages folder. e.g. ~/.config/sublime-text-3/Packages/User/
# File: AddSpacesAroundSelection.py
# Command: add_spaces_around_selection
# Keys: { "keys": ["ctrl+space"], "command": "add_spaces_around_selection" }
import sublime, sublime_plugin
class AddSpacesAroundSelectionCommand(sublime_plugin.TextCommand):
"""
The AddSpacesAroundSelectionCommand class is a Sublime Text plugin which
adds a single space on both sides of each selection. e.g. "Sel" -> " Sel "
"""
def run(self, edit):
""" run() is called when the command is run. """
space_char = " "
# Loop through all the selections.
for sel in self.view.sel():
# If something is actually selected (i.e. not just a cursor) then
# insert a space on both sides of the selected text.
if sel.size() > 0:
# Insert the space at the end of the selection before the
# beginning of it or the insertion position will be wrong.
self.view.insert(edit, sel.end(), space_char)
self.view.insert(edit, sel.begin(), space_char)
# End of def run()
# End of class AddSpacesAroundSelectionCommand()
Add a key binding to your user .sublime-keymap file. On my system the ctrl+space key bindings were not in use and they seemed appropriate to use.
{ "keys": ["ctrl+space"], "command": "add_spaces_around_selection" },
Hope this helps.

Coffeelint indentation in Web Essentials 2013

I have 4 space indentation in my coffee files and when I am compiling those I am getting errors:
CoffeeLint: YourFile.coffee compilation failed: CoffeeLint: Line contains inconsistent indentation; context: Expected 2 got 4
I found that http://www.coffeelint.org/ actually provides option to configure indentation and in Web Essentials menu there is option to edit Global CofeeLint settings. So I changed that option to be:
"indentation": {
"name": "indentation",
"value": 4,
"level": "error"
}
(changed value from 2 to 4)
But it makes no difference I even tried to change level from error to ignore still no success. I even tried to restart VS and Windows, What I am doing wrong?
Update 1.
As requested in comments here is code I have:
if 1
0
And also screenshot of it with View White Space ON:
If you are using coffeelint and you want to change the indentation value to 2 spaces then you must edit the coffeelint/lib/coffeelint.js file and change the value of the "value" to 2 as follows:
module.exports = Indentation = (function() {
Indentation.prototype.rule = {
name: 'indentation',
value: 2,
level: 'error',
message: 'Line contains inconsistent indentation',
description: "This rule imposes a standard number of spaces to be used for\nindentation. Since whitespace is significant in CoffeeScript, it's\ncritical that a project chooses a standard indentation format and\nstays consistent. Other roads lead to darkness. <pre> <code>#\nEnabling this option will prevent this ugly\n# but otherwise valid CoffeeScript.\ntwoSpaces = () ->\n fourSpaces = () ->\n eightSpaces = () ->\n 'this is valid CoffeeScript'\n\n</code>\n</pre>\nTwo space indentation is enabled by default."
};
The file you edited is probably a generated file that is of no consequence.

how to use `NSScriptCommandDescription initWithSuiteName:commandName:dictionary:`

I want to know how to use
NSScriptCommandDescription initWithSuiteName:commandName:dictionary:, esp. how the dictionary is supposed to look like.
It would be nice to see a simple example for a command with a single parameter of type NSString and a return value of type NSString.
I think the documentation about how the dictionary should look like can be found here, esp in "Table B-8, Command dictionary".
However, I am trying with this example and it doesn't work (returns nil):
cmdDesc = NSScriptCommandDescription.alloc().initWithSuiteName_commandName_dictionary_(
"Standard Suite",
"execPython",
{
"CommandClass": "NSScriptCommand", # default behavior
"AppleEventCode": "expy", # 4-char code
"Type": "text", # return-type
"ResultAppleEventCode": "NSString", # return-type
"Arguments": [{
"Type": "NSString",
"AppleEventCode": "data"
}]
}
)
(Note: I really want to know exactly that here; I don't want to know how to register scripting definitions or do other stuff with this question.)
I know this is a VERY old questions but I have stumble upon this and it seems that the this statckoverflow question is the most common result when doing a google search on how to use the NSScriptCommandDescription with arguments.
The code from the accepted answer is correct EXCEPT on how the arguments value is created. The arguments value must be a dictionary that maps argument names with argument descriptions. Using the accepted answer code as an example, in order to pass arguments, our dictionary should look as follows:
cmdDesc = NSScriptCommandDescription.alloc().initWithSuiteName_commandName_dictionary_(
"Chromium Suite",
"exec Python",
{
"Name": "exec Python",
"CommandClass": "NSScriptCommand", # default behavior
"AppleEventCode": "ExPy", # 4-char code
"AppleEventClassCode": "CrSu",
"Type": "NSString", # return-type
"ResultAppleEventCode": "ctxt", # return-type
"Arguments": {
"firstArg": {
"Type": "NSString",
"AppleEventCode": "comm"
}
}
}
)
The above dictionary works on ObjectC (I don't know if the python code does work).
The only thing I can see there that disagrees with the documentation is your value for "Type"; while the documentation doesn't show an example for "Type" in the context of a command, its value in the documentation's examples for other contexts is "NSString", not "text". So, try the Cocoa class name instead of the AppleScript class name.
The "Arguments" section still doesn't really work correct for me (I got strange crashs) but I can also just omit that and still get an argument passed at runtime.
This is the code:
import objc
NSObject = objc.lookUpClass("NSObject")
sharedScriptSuiteReg = objc.lookUpClass("NSScriptSuiteRegistry").sharedScriptSuiteRegistry()
NSScriptCommandDescription = objc.lookUpClass("NSScriptCommandDescription")
sharedAppleEventMgr = objc.lookUpClass("NSAppleEventManager").sharedAppleEventManager()
NSAppleEventDescriptor = objc.lookUpClass("NSAppleEventDescriptor")
from PyObjCTools.TestSupport import fourcc
def register_scripting():
cmdDesc = NSScriptCommandDescription.alloc().initWithSuiteName_commandName_dictionary_(
"Chromium Suite",
"exec Python",
{
"Name": "exec Python",
"CommandClass": "NSScriptCommand", # default behavior
"AppleEventCode": "ExPy", # 4-char code
"AppleEventClassCode": "CrSu",
"Type": "NSString", # return-type
"ResultAppleEventCode": "ctxt", # return-type
"Arguments": {
#"----": {
# "Type": "NSString",
# "AppleEventCode": "comm"
#}
}
}
)
assert cmdDesc is not None
sharedScriptSuiteReg.registerCommandDescription_(cmdDesc)
sharedAppleEventMgr.setEventHandler_andSelector_forEventClass_andEventID_(
appScriptHandler, appScriptHandler.handleExecPy,
fourcc("CrSu"), fourcc("ExPy"))
def handleExecPy(self, ev, replyEv):
print "execPython called,",
cmd = ev.descriptorForKeyword_(fourcc("comm")).stringValue()
print "cmd:", repr(cmd)
res = eval(cmd)
res = unicode(res)
replyEv.setDescriptor_forKeyword_(NSAppleEventDescriptor.descriptorWithString_(res), fourcc("----"))
return True
try:
class AppScriptHandler(NSObject):
def handleExecPy(self, ev, replyEv):
try: return handleExecPy(self, ev, replyEv)
except: traceback.print_exc()
return
except:
AppScriptHandler = objc.lookUpClass("AppScriptHandler")
appScriptHandler = AppScriptHandler.alloc().init()
This works together with this simple client demo:
#!/usr/bin/python
import aem
fullpath = aem.findapp.byname("Google Chrome")
app = aem.Application(fullpath)
def execPy(cmd):
return app.event("CrSuExPy", {"comm": cmd}).send()
print execPy("app.bundle()")
def simple_shell():
import sys
try: import readline
except: pass # ignore
while True:
try:
s = raw_input("> ")
except:
print "breaked debug shell:", sys.exc_info()[0].__name__
break
s = s.strip()
if s: print execPy(s)
simple_shell()
The full code can be seen here and in action here.

Resources