Atom snippet with variable in prefix - atom-editor

Is it possible to create snippets for atom with variables in the prefix?
For example:
if I type: getPosts:: and tab, it should create something like this:
public static function getPosts(){
}
and put my cursor inside the function.
I allready tried
'.text.html.php':
'create public static function':
'prefix': '$1::'
'body': 'public static function $1(){\n\t${2://code...}\n}'
but this does not work.

I do not believe it is possible to have variables in an Atom snippet. Please see more here: Snippet Variables?

Related

Azure functions HttpTrigger, not using HttpMethods class in attribute

Why do functions in AzureFunctions requires to use
[HttpTrigger(AuthorizationLeve.Anonymous, "get")]
Instead of
[HttpTrigger(AuthorizationLeve.Anonymous, HttpMethods.Get)]
Of course I cannot use
HttpMethods.Get.ToString()
becase language does not allow to call functions in Attributes
and creating my own
public static class HttpMethodsStrings
{
public const string Get = "get";
}
seems redundant since .NET already provides HttpMethods.
You can use System.Net.WebRequestMethods.Http.X constants instead of hard coded strings ("get", "post"). I have put together the piece of code and debugged it and it works fine.
The snippet of the same is shown below -
You can modify your second example to use the nameof operator
eg
[HttpTrigger(AuthorizationLeve.Anonymous, HttpMethods.Get)]
becomes
[HttpTrigger(AuthorizationLeve.Anonymous, nameof(HttpMethods.Get))]

Create custom testng html report with browser name against method name

I am working on cross browser testing and each of test methods in multiple classes run on 4 browsers Chrome, Firefox, IE, Safari.
The testng HTML reports & extent reports generated have the test methods in a column but I also need the browser name against each test method.
Even if the testng HTML reports would have the browser name against the test method would be great.
I found this link but I just need the browser column next to method column to custom report in the link
You can do it like here. But it would be better to use reporting features for that e.g. you may pass any test name and description to report see docs.
You can do that by creating a customized TestHTMLReporter . Pass any data in your CustomReport.java class and generate your own report like below. I have also explained it here
With your customReport You'd have to implement IReporter , extend TestListenerAdapter and override generateReport method if you want to implement a custom TestHTMLReporter . For other reporters you may have to do things a bit differently but the concept will remain the same. You'd achieve custom 'TestHTMLReporter' like below .
Create a CustomReport.java file in your project and copy-paste the whole content of TestHTMLReporter.java , change the name of file in getOutputFile method and it would look like below
public class CustomReport extends TestListenerAdapter implements IReporter {
#Override
public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites,
String outputDirectory) {
}
...
//paste the content of TestHTMLReporter.java here
...
...
Make sure all your imports are in place from TestHTMLReporter.java
Now, in this file change as per your requirement . For ex: if you'd like to add the end time of each of the test then at the correct place in generateTable method add the below snippet
// Test class
String testClass = tr.getTestClass().getName();
long testMillis = tr.getEndMillis();
String testMillisString = Long.toString(testMillis);
if (testClass != null) {
pw.append("<br>").append("Test class Name: ").append(testClass);
// this line to add end time in ms
pw.append("<br>").append("End Time(ms): ").append(testMillisString);
// Test name
String testName = tr.getTestName();
if (testName != null) {
pw.append(" (").append(testName).append(")");
}
Then you'll get like below
Now, You'll get two reports one with default and the other with your file name.
The only thing now remains is switching off the default reporting listeners, so you get only one report. For that you can follow this or you may search for solutions. Hope this helps

Twig: How can I manually escape inside a custom function?

I wrote my own Twig function that outputs HTML, so I have is_safe set to html so that Twig knows not to escape the output my function.
However, my function takes arguments. One of the arguments is placed in the output directly. I want to escape this before outputting it. So it seems I just need to be able to manually escape the option value before outputting it.
I can't find how to do this. Anyone know?
The trick is to store the twig enviroment which in turn is passed to twig_escape_filter
class TournExtension extends \Twig_Extension
{
protected $env;
public function initRuntime(\Twig_Environment $env)
{
parent::initRuntime($env);
$this->env = $env;
}
protected function escape($string)
{
return twig_escape_filter($this->env,$string);
}

How can I edit the default TestNG html report

I don't want to create a new one or a custom listener. Is that possible? Where is the html report created in TestNG?
SuiteHTMLReporter [source] is the reporter creating the html report. You can extend and override. Disable default listeners and add your own.
I know this is old , but these reports can be edited and custom reports can be made like below. I have explained here how TestHTMLReporter can be edited
With your customReport You'd have to implement IReporter , extend TestListenerAdapter and override generateReport method if you want to implement a custom TestHTMLReporter . For other reporters you may have to do things a bit differently but the concept will remain the same. You'd achieve custom 'TestHTMLReporter' like below .
Create a CustomReport.java file in your project and copy-paste the whole content of TestHTMLReporter.java , change the name of file in getOutputFile method and it would look like below
public class CustomReport extends TestListenerAdapter implements IReporter {
#Override
public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites,
String outputDirectory) {
}
...
//paste the content of TestHTMLReporter.java here
...
...
Make sure all your imports are in place from TestHTMLReporter.java
Now, in this file change as per your requirement . For ex: if you'd like to add the end time of each of the test then at the correct place in generateTable method add the below snippet
// Test class
String testClass = tr.getTestClass().getName();
long testMillis = tr.getEndMillis();
String testMillisString = Long.toString(testMillis);
if (testClass != null) {
pw.append("<br>").append("Test class Name: ").append(testClass);
// this line to add end time in ms
pw.append("<br>").append("End Time(ms): ").append(testMillisString);
// Test name
String testName = tr.getTestName();
if (testName != null) {
pw.append(" (").append(testName).append(")");
}
Then you'll get like below
Now, You'll get two reports one with default and the other with your file name.
The only thing now remains is switching off the default reporting listeners, so you get only one report. For that you can follow this or you may search for solutions. Hope this helps

Trying to learn Flex function, vars and data flow

So I need to return the location or fname or what ever.... I would like to do this just by changing the pointer variable. I'm just comming from php to flex so I don't know what I'm doing -=) How can I do this?
public var myProfile:Object={
fname:"Deyon",
lname:"Smith",
age:"31",
loc:"New York"};
public var pointer:String="loc";
public function getProfileinfo():void{
trace(myProfile.pointer);
}
Thank you!
Change the following code:
function getProfileinfo(pointer:String):void{
trace(myProfile[pointer]);
}
Plus, you should put this code into a Class.

Resources