Wesbstorm LiveTemplate trick - intellij-idea

LiveTemplates in Webstorm and all IDEA family products one of those nice features that bring pure awesomeness to your coding. So for the snippet like this:
stylus = require "stylus"
I can set abbreviation (for example rqr) and set the template text like this:
require "$END$"
tell Webstrom that this is applicable for coffeescript and voila, I have to type only that:
stylus = rqr[TAB]
But, I thought: "can I go even further with this?" Can I somehow tell Webstorm to read the word that I typed right before the abbreviation (in this case it's stylus), and Webstorm would automagically put it between quotes and finish on the next line? Wouldn't be that cool?
So you would type: express = rqr[TAB] and it would finish that for you, expanding it into:
express = require "express"

Wow, wow, wow! I actually found a better way to do that...
if I keep the same abbreviation and change template text into:
$module$ = require "$module$"
$END$
it does want I wanted, but in the way cooler way!
So you can use your own variables in a template as long as you don't call them $END$ or $SELECTION$
Awesome!

Related

regex limitations within live template / can use live-template functions as replacement?

I'm removing builder pattern on multiple places. Following example would help me with the task, but mainly I'd like to learn how to use live templates more.
Preexisting code:
Something s = s.builder
.a(...)
.b(bbb)
.build();
and I'd like to remove it to:
Something s = new Something();
s.setA(...);
s.setB(bbb);
part of it can be trivially done using intellij regex, pattern: \.(.*)$ and replacement .set\u$1. Well it could be improved, but lets keep it simple.
I can create surround live template using variable:
regularExpression(SELECTION, "\\.(.*)", "\\u$1")
but \\u will be evaluated as u.
question 1: is it possible to get into here somehow \u functionality?
but I might get around is differently, so why not try to use live temlate variable:
regularExpression(SELECTION, "\\.(.)(.*)", concat(capitalize($1), "$2"))
but this does not seem to work either. .abc is replaced to bc
question 2: why? How would correct template look like? And probably, if it worked, this would behave incorrectly for multiline input. How to make it working and also for multiline inputs?
sorry for questions, I didn't find any harder examples of live templates than trivial replacements.
No, there is no \u functionality in the regularExpression() Live Template macro. It is just a way to call String.replaceAll(), which doesn't support \u.
You can create a Live Template like this:
set$VAR$
And set the following expression for the $VAR$ variable:
capitalize(regularExpression(SELECTION, "\\.(.*)", "$1"))

Drop use of = in parsing arguments in raku

The fact that you can write in raku the following
unit sub MAIN(Int $j = 2);
say $j
is amazing, and the fact that the argument parsing is done for you is beyond
useful. However I find personally extremely unergonomic
that for such arguments you habe to write a = to set the value, i.e.
./script.raku -j=5
I was wondering if there is a way to tell the parser that it should allow options without
the = so that I can write
./script.raku -j 5
I haven't seen this in the docs and this would really be much more intuitive for some people
like me. If it is not currently possible, I think it would be a useful add-on.
You could also use SuperMAIN, a library for CLI processing. This add some new superpowers to MAIN
There has been a lot of discussion of how command line parameters should be parsed. At the moment there are no plans of adding more functionality to what Raku provides out of the box.
If you want more tweakability, you should probably look at the Getopt::Long module by Leon Timmermans

Selenium IDE: Comparing/Verifying a variable's text

I'm new to Selenium IDE. Right now I'm trying to store the filepath/URL of an image on a webpage, and then verify that the filepath/filename follows a set of filename conventions.
The progress so far:
I've installed a user extension that allows me to use a command called "storeImagePath". I can store the filepath/filename of the image and save it as a variable called imagePath.
What I'm stuck on:
I can echo ${imagePath} and it's giving me the correct filepath, but I don't know how to even compare the imagePath variable to the real filepath. I want to do something like a VerifyEval of the variable and compare it to the path that I paste in for testing purposes. I tried "type"-ing the variable into an input element and then doing some sort of VerifyText against that but it didn't work. Am I overlooking a very easy solution?
Keep in mind I'm using Selenium IDE and I'd like to stick with this until I'm proficient at it before moving onto RC. Although if what I'm trying to do isn't possible in IDE, you can tell me that. Thanks in advance.
Edit: I'm not sure how clear I'm making this; for the time being I just want to compare ${imagePath} to the URL that I'll paste in myself. Once I'm done with that I can start figuring out how to define the accepted filepath/filename conventions.
If your ultimate intention is to verify that the stored variable match a specific format, then you can use verifyeval function eg.
verifyEval | storedVars['imagePath'].search("ur reg ex")>0 | true
or any of the javascript string methods to do the comparison

how to highlight variables of c/c++ files in vim

I want to highlight variables in a C/C++ file .
such as:
int num;// Highlighted num
char str;// Highlighted str
struct data
{
int year;
int month;
};
struct data *p,time;// Highlighted p time
..........
How to highlight variables as given above (num ,str, p,time.....)
I know we can modify syntax\c.vim to reach that,but how to write the syntax?
Is there any other solution?
In general, you need to do two things:
Generate tags using ctags;
Generate syntax file using resulting tags file.
Now some details.
There are plugins to help you. Firstly, plugin Indexer automatically generates tags for a whole project and keeps tags up-to-date. (i'm author of this plugin, so, if you have any problems using it, feel free to ask me)
And secondly, there's plugin TagHighlight to extra highlights variables, enums, typedefs, etc.
If you mean how to turn on syntax highligting, then you need to:
:syntax on
If it does not work, determine filetype first:
:set filetype?
Should print "cpp". If not, set it first:
:set filetype=cpp

Source style for Google Code Jam

I plan on doing the Code Jam competition next year. The problem is (something that I can't find anywhere) how do I set up my code to accept input and return an output?
I'm just confused as to how I am supposed to handle everything, say for example that I have to add 1 to the input and make the result the output, how would I handle the input/output?
I plan on using LUA. Thanks if you can. I think a code example would be best!
Go to http://www.go-hero.net/jam/11/solutions and choose the problem and the language. You'll find all the examples you need there. Including Lua ones.
http://www.go-hero.net/jam/
On this page you can see source code for every contestant.
You should be able to answer your question from it.
You can either do I/O on files or on stdin/stdout. It doesn't matter. I've seen examples that used files and examples that used stdin/stdout.
In Python say, you could write
import fileinput
f = fileinput.input()
Then call the script from the shell like this
gorosort.py A-small-practice.in
To save the output to a file
gorosort.py A-small-practice.in > A-small-practice.out