Visual Studio Code shortcut equivalent to Webstorm / IntelliJ Extend Selection - intellij-idea

I've grown accustomed to Webstorm's "Extend Selection" shortcut which grows the selection to the next special character.
Example (if the cursor is somewhere in the "someObjectProperty"and the shortcut is activated):
var foo = someObject.someObjectProperty.subProperty;
<-- selection 1 -->
<------ selection 2 --------->
<-------------- selection 3 ------------>
Now that I've switched to Visual Studio Code, the closest to that type of shortcut I've found is 'editor.action.smartSelect.grow' shortcut
However, while it is similar, it's not the same. Using the same example (if the cursor is somewhere in the "someObjectProperty" and the shortcut is activated):
var foo = someObject.someObjectProperty.subProperty;
<---------------- selection 1 -------------->
<------------------- selection 2 ------------------>
Is there anything similar in VS Code as the Extend Selection in WebStorm as described above?

While there is no such shortcut/command that comes with VS Code there is third party extension that can be easily installed:
ext install expand-region
More info on the expand-region command:
https://marketplace.visualstudio.com/items?itemName=letrieu.expand-region

There's still no such thing, the third party plugins are nowhere near what Webstorm/Idea does, here's an incomplete visual gap analysis on how they can't be mentioned on the same page.

The Feature you're looking for is called shrink-expand-selection.
It works by using:
ALT + SHIFT + → to select the next sections
ALT + SHIFT + ← to select the previous sections
It works as follows for your example (imagine the cursor being on the j of someObjectProperty):
var foo = someObject.someObjectProperty.subProperty;
<-S1-> (This section exists because of camelCase)
<- S2 ->
<- S3 ->
<- S4 ->
<- S5 ->
For reference:
https://code.visualstudio.com/docs/getstarted/tips-and-tricks#_shrink-expand-selection

Related

Error in parse(text = x, srcfile = src): <text>:13:6: unexpected symbol 12: 13: This R ^

I am trying to create and run a simple .Rmd (RMarkdown file) on Kaggle.
When I create a new RMarkdown on Kaggle, when I click 'Run All' to run the Rmd code, I see:
Your Kernel is now running in the cloud.
Enter some code at the bottom of this console and press [Enter].
Session is starting...
Session started.
ERROR
Error in parse(text = x, srcfile = src): <text>:13:6: unexpected symbol 12: 13: This R ^
How can I successfully run a sample RMarkdown on Kaggle?
Notes
Similar problem outlined 10 days ago here.
The comment isn't helpful (it's just a shortcut instead of pressing the 'Run All' button)
Problem also seems to be mentioned 2 days ago here
Reproducible example
When creating a new RMarkdown on Kaggle, I do the following.
From the kaggle.com homepage, click on 'Code' on the left hand side, then on 'New Notebook':
When I do this, it is immediately clear that the interpreter doesn't lint the code correctly (look at the colours):
For reference, the language is 'RMarkdown':
And the editor type is 'Script':
And when I click 'Run All':
Click 'Save Version' (top right of screen)
That will run (i.e. 'knit') your RMarkdown code (it may take a moment). A link to the knitted document pop up in the bottom left of screen. It's that easy!

IntelliJ Ultimate Kotlin Script REPL skips first printed lines - Scratch Output cut off

I enjoy using the REPL in intelliJ for coding problems like you would find on codesignal. I currently have the version:
IntelliJ IDEA 2019.1.3 (Ultimate Edition)
Build #IU-191.7479.19, built on May 27, 2019
JRE: 1.8.0_202-release-1483-b58 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.14.4
I have always been really confused by the fact that when running any of these scratch files, the first 5-9 lines I am trying to print output to will just, not exist.
Below is an example program that would print out a pyramid of X's to the console
fun createPyramid(height: Int, drawChar: String = "X") {
// repeat(9) {
// println("blank")
// }
for (i in 1 until height) {
val blank = " ".repeat(height - i)
val row = blank + drawChar.repeat(i * 2 - 1)
println(row)
}
}
createPyramid(11)
If I have the repeat block commented out, my output looks like:
If I uncomment the repeat I will then get output looking like:
The really confusing part about this situation is the number of lines seem to be random, and there is inconsistencies in how it works.
If I do repeat(9) I normally get 1 actually printed out "blank"
If I do repeat(8) most of the time it will actually not put out the first expected "X" from the pyramid.
Output for scratches is printed right in the editor, next to the expression, that provide this output. Scratch Output tool window prints only the output that doesn’t fit into the editor.

Export SQL rows to multiple text files and name them

I have a database with 6 columns and several thousand rows in which I'd like to export the contents into separate, named text files.
id title text text_2
1 blah lorem ipsem... indigo violet...
2 gunf ipsem lorem... up down left...
3 faff sir I have a... amarillo albuquerque...
I'd like to create the following text files for each row:
filename = id - title.txt;
content = title
filename = id - title.txt;
content = text
filename = id - title.txt;
content = text_2
I've looked and can't think how to do it. I used to use a macro in Excel to convert cells to txt but the text is too big for Excel's cell character limit.
I'm using SQLite but am not wedded to it (though would rather not have to buy a program if I can avoid it).
Any advice on what to do? While not too techy I can follow some basic code.
You can use SQLiteStudio 3.x.x and it's custom SQL functions.
Open "Custom SQL Functions editor" (the one with "fx" icon) and add new function, let's call it saveToFile. Select Tcl as implementation language (it's in the top-right corner), leave "Type" as Scalar. If you want you can define input arguments (it's not mandatory, it's just so the code assistant will help you later on when invoking this function): fileName and contents. It's also okay to keep "Register in all databases" option.
Now the most important thing - enter following implementation code:
if {[catch {
lassign $argv fileName contents
set fd [open "C:/tmp/a/$fileName" a+]
puts $fd $contents
close $fd
} res]} {
return "error: $res"
} else {
return "ok"
}
The code contains C:/tmp/a which is path to directory where your files will be created. Change it to whatever you want. The directory must exist.
Commit your function (commit button is on top of functions editor).
Now open SQL editor window (the one with blank paper and a pencil) and type query like this:
SELECT saveToFile(id || ' - ' || title || '.txt', title || x'0a' || text || x'0a' || text_2) AS result FROM table_name;
This query will create one file per row and will put title, text and text_2 columns as 3 separate lines in the file.
The query will return for each row status ok when there was no problem, or error: ... with error details when there was problem, for example with creating a file.

Update current line with command line tool in Swift

I built a OS X command line tool in Swift (same problem in Objective-C) for downloading certain files. I am trying to update the command line with download progress. Unfortunately, I cannot prevent the print statement to jump to the next line.
According to my research, the carriage return \r should jump to the beginning of the same line (while \n would insert a new line).
All tests have been performed in the OS X Terminal app, not the Xcode console.
let logString = String(format: "%2i%% %.2fM \r", percentage, megaBytes)
print(logString)
Still, the display inserts a new line. How to prevent this?
Note: This won't work in Xcode's debugger window because it's not a real terminal emulator and doesn't fully support escape sequences. So, to test things, you have to compile it and then manually run it in a Terminal window.
\r should work to move to the beginning of the current line in most terminals, but you should also take a look at VT100 Terminal Control Escape Sequences. They work by sending an escape character, \u{1B} in Swift, and then a command. (Warning: they make some pretty ugly string definitions)
One that you'll probably need is \u{1B}[K which clears the line from the current cursor position to the end. If you don't do this and your progress output varies in length at all, you'll get artifacts left over from previous print statements.
Some other useful ones are:
Move to any (x, y) position: \u{1B}[\(y);\(x)H Note: x and y are Ints inserted with string interpolation.
Save cursor state and position: \u{1B}7
Restore cursor state and position: \u{1B}8
Clear screen: \u{1B}[2J
You can also do interesting things like set text foreground and background colors.
If for some reason you can't get \r to work, you could work around it by saving the cursor state/position just before you print your logString and then restoring it after:
let logString = String(format: "\u{1B}7%2i%% %.2fM \u{1B}8", percentage, megaBytes)
print(logString)
Or by moving to a pre-defined (x, y) position, before printing it:
let x = 0
let y = 1 // Rows typically start at 1 not 0, but it depends on the terminal and shell
let logString = String(format: "\u{1B}[\(y);\(x)H%2i%% %.2fM ", percentage, megaBytes)
print(logString)
Here's an example assuming some async task is taking place with callbacks that pass a Progress type.
// Print an empty string first otherwise whichever line is above the printed out progress will be removed
print("")
let someProgressCallback: ExampleAsyncCallbackType = { progress in
let percentage = Int(progress.fractionCompleted * 100)
print("\u{1B}[1A\u{1B}[KDownloaded: \(percentage)%")
}
The key part is \u{1B}[1A\u{1B}[K and then whatever you want to print out to the screen following.
Your example will only work on the actual command line, not in the debugger console. And you also need to flush stdout for every iteration, like this:
var logString = String(format: "%2i%% %.2fM \r", 10, 5)
print(logString)
fflush(__stdoutp)

Selenium IDE - storeval- how to copy and paste

3 security questions appearing on the screen like in random order like 1,3,2 or 2.1 and then 3:
Pets name? 2. City you were born? 3. School you attend?
Lets say that answer is a last word of each question. How to code it in Selenium ide. I guess to use GoToif, GotoLabel and StoreEval? Also, the answer should be stripped to one last word without space and "?"
You can store text or value in Selenium IDE.
The Command : storeText | storeValue (or storeAttribute if you want to stora an attribute of the element)
The Target must be a css or an xpath expression which can localize the appropriate element
The Value is the name of the new local variable in your Selenium IDE script
After using store command you can use your new variable like this: ${yourNewVariable}
For example:
storeAttribute xpath=//div[#id='name-day']#name nameday
echo ${nameday}
You can use while loop and goto function in selenium ide with this addon : https://addons.mozilla.org/en-us/firefox/addon/flow-control/
Some commands:
gotoif
while
gotolabel
Example:
store 1 answers
while storedVars.answers <= 3
echo ${answers}
...
store javascript{storedVars.answers++;}
endWhile