Return brackets as string with shortcut - autohotkey

in my autohotkey script i have
:*:eclick:: .addEventListener("click",function(){});
but {} is always ignore, is it possible to return {} as text or is it protected ?!
Thanks,gui

When sending special characters, it's best to use raw mode in order to ensure that the keys won't be misinterpreted:
#Hotstring r
:*:eclick:: .addEventListener("click",function(){});
Alternatively, you could use SendRaw:
:*:eclick::
SendRaw, %A_SPACE%.addEventListener("click",function(){});
return

Related

How to do multiple substitution using perl scripts

I have a bunch of scripts I wanted to replace some texts.
Context : We are using selenium for UI Automation. We used to store the references to the UiElements in a map. But we are now moving to use PageFactory (a class with all the UiElements declared as a string)
So when we used map, we had to call the UIelements as objectMap.getIdentifier("navigate.leftsidebar"). But now with PageFactory (its like instantiating a object, and the UIElements are declared as a string), I can access these UIelements objectPageFactory.navigate_leftsidebar (here navigate_leftsidebar is a String)
So I will need to go modify all my existing scripts. Is there a way I can write a script to get this replaced, than doing it manually ?
Below are the 3 scenarios that I will encounter :
Click(getElement(objectMap.getIdentifier("navigate.leftsidebar").replace("$Page", "Inbox")), "clicking on an element");
objectMap.getIdentifier("navigate.leftsidebar")
Click(objectMap.getIdentifier("navigate.leftsidebar"), "clicking on an element");
This is the expected output:
Click((objectPageFactory.navigate_leftsidebar("Inbox")), "clicking on an element");
objectPageFactory.navigate_leftsidebar
Click(objectPageFactory.navigate_leftsidebar, "clicking on an element");
Changes are :
"objectMap" to be renamed as "objectPageFactory"
There could be different types of map. if objectMap , it should be replaced as objectPageFactory; if loginMap, it should be changed as loginPageFactory
objectMap.getIdentifier("navigate.leftsidebar") >>>> objectFactory.navigate_leftsidebar (the String literal inside the bracket is separated by underscore instead of dots
getElement is not needed now
we used to have some dynamic UiElements (navigate.leftsidebar in this case), for which we used to call String.replace, now we are writing functions which will internally do a String.format
getElement(objectMap.getIdentifier("navigate.leftsidebar").replace("$Page", "Inbox")) >>>>> objectPageFactory.navigate_leftsidebar("Inbox")
I got a perl script from this link, which will do partial job sed command to replace dots.
I just need to add the different scenarios to this, is there a way ? the output should now have a pageFactory text too, based on which map
#! /usr/bin/perl
use strict ;
sub fix { $_ = shift ; s/"//g ; s/\./_/g ; return $_ }
while ( <> ) {
s/getElement\(objectMap\.getIdentifier\(("?[a-z.]+"?)\)/fix($1)/e ;
s/objectMap\.getIdentifier\(("?[a-z.]+"?)\)/fix($1)/e ;
print
}
This seems to provide the output you requested. I don't understand the language you're changing, so there might be corner cases it processes wrong. Make a backup before you change the files!
#!/usr/bin/perl
use warnings;
use strict;
sub fix {
my ($id) = #_;
return $id =~ s/[.]/_/gr
}
while (<>) {
s{getElement\((object|login)Map\.getIdentifier\("([^"]*)"\)\.replace\("\$Page", "([^"]*)"\)\)}
{"$1PageFactory." . fix($2) . qq(("$3"))}ge;
s{(object|login)Map\.getIdentifier\("([^"]*)"\)}
{"$1PageFactory." . fix($2)}ge;
print;
}

What is the most effective way in systemVerilog to know how many words a string has?

I have Strings in the following structure:
cmd, addr, data, data, data, data, ……., \n
For example:
"write,A0001000,00000000, \n"
I have to know how many words the String has.
I know that I can go over the String and search for the number of commas, but is there more effective way to do it?
UVM provides a facility to do regexp matching using the DPI, in case you're already using that. Have a look at the functions in uvm_svcmd_dpi.svh
Verilab also provides svlib, a package containing string matching functions.
A simpler option would be to change the commas(,) to a space, then you can use $sscanf (or $fscanf to skip the intermediate string and read directly from a file), assuming each command has a maximum number of words.
int code; // returns the number of words read
string str,word[5];
code = $sscanf(str,"%s %s %s %s %s", word[0],word[1],word[2],word[3],word[4]);
You can use %h if you know a word is in hex and translate it directly to a numeric value instead of a string.
The first step is to define extremely clearly what a word actually is vis. what constitutes the start of a word and what constitutes the end of the word, once you understand this, if should become obvious how to parse the string correctly.
In Java StringTokenizer is the best way to find the count of words in a string.
String sampleString= "cmd addr data data data data...."
StringTokenizer st = new Tokenizer(sampleString);
st.countTokens();
Hope this will help you :)
In java you can use following code to count words in string
public class WordCounts{
public static void main(String []args){
String text="cmd, addr, data, data, data, data";
String trimmed = text.trim();
int words = trimmed.isEmpty() ? 0 : trimmed.split("\\s+").length;
System.out.println(words);
}
}

How do you write an empty while loop in Coffeescript?

I'm trying to translate some old code to Coffeescript. But there is no direct translation for:
while ( doWork() ) {}
"while doWork()" with nothing after it results in a syntax error.
while doWork() then
Should do the trick
using then is probably the canonical solution since it is explicitly meant for separating the condition from the (in this case empty) body. Alternatively you can write
while doWork()
;#
(the # keeps vim syntax highlighting from flagging it as an error)
I also like the continue while doWork() solution, but I strongly advise against any other form of expression while doWork() mentioned in the comments since when this is the last statement of a function it will become a list constructor:
_results = [];
while (doWork()) {
_results.push(expression);
}
return _results;

Is it possible with Eclipse to only find results in string literals?

Lets assume I have the following Java code:
public String foo()
{
// returns foo()
String log = "foo() : Logging something!"
return log;
}
Can I search in Eclipse for foo() occurring only in a String literal, but not anywhere else in the code? So in the example here Eclipse should only find the third occurrance of foo(), not the first one, which is a function name and not the second one, which is a comment.
Edit: Simple Regular Expressions won't work, because they will find foo() in a line like
String temp = "literal" + foo() + "another literal"
But here foo() is a function name and not a String literal.
You can try it like this:
"[^"\n]*foo\\(\\)[^"\n]*"
You have to escape brackets, plus this regex do not match new lines or additional quotes, which prevent wrong matches.
Maybe you should use regex to find any occurence of foo() between two " ?

Is there a better way to test for an integer in C# than Double.TryParse?

Double.TryParse returns a value, and I don't need a value. I need to be able to tell if a string is numeric and just return a bool.
is there a way to do this?
I would consider exactly what you need to determine. "Is numeric" is vaguer than it sounds at first. Consider the following strings, and whether you'd want to consider them numeric:
"NaN"
"Nan"
"Infinity"
"0.000000000000000000000000000000000000000000000000001"
"1e5"
"1e500"
"1,000"
"+1"
Using Double.TryParse (with an en-GB culture - don't forget about cultural issues!) will give you True, False, True, True (despite it not being representable), True, False. True, True.
If you want to tell whether a later call to Double.TryParse would succeed, calling it here will be the most accurate solution. If you're using some other criteria, a regular expression may well be more appropriate. An example of the criteria you might use:
The can be a + or -, but only in the first character
There can be a single period at any character. You may want to avoid one at the end - should "1." be valid?
Other than the above, all characters must be digits
That would disallow all but the fourth and last examples above.
EDIT: I've now noticed the title of the question includes "integer". That pretty much reduces the specification checks to:
Do you want to allow leading zeroes (e.g. -00012)?
What is the range?
Do you only need decimals (instead of hex etc)?
Do you need to accept thousands separators?
What's your policy on leading/trailing whitespace?
Well, you could use a regular expression, but why not just discard the value from Double.TryParse and move on? I don't think it will be worth the effort trying to duplicate this code.
One way is to add a reference to Microsoft.VisualBasic and then use Information.IsNumeric().
using Microsoft.VisualBasic;
...
if (Information.IsNumeric("1233434.0"))
{
Console.WriteLine("Yes");
}
How about a regular expression?
string s = "13.2";
bool bIsDecimal = Regex.IsMatch("^-?\d+(\.\d+)?$");
should test whether it is a decimal value. What it won't tell you is whether it is a valid decimal, as in, will the number fit in the range of a decimal.
I just fired up Visual Studio Express (both 2005 and 2008). The Intellisense says that the return value of Double.TryParse() is a bool. The following worked for me under limited testing...
double res; // you must be under very resource-constrained
// conditions if you can't just declare a double
// and forget about it
if (Double.TryParse(textBox1.Text, out res)) {
label1.Text = "it's a number";
} else {
label1.Text = "not a number";
}
try this isnumeric:
public static bool IsNumeric(object Expression)
{
bool isNum;
double retNum;
isNum = Double.TryParse(Convert.ToString(Expression), System.Globalization.NumberStyles.Any,System.Globalization.NumberFormatInfo.InvariantInfo, out retNum );
return isNum;
}