PHPStorm - Force array() String Declaration With Code Style - phpstorm

In PHPStorm, you can force arrays to be declared as [] in the "Code Style" section of Settings.
Is there anyway to do the opposite and force arrays to be declared with array()? For example, I would like the following:
$myArray = ['one', 'two'];
to become
$myArray = array('one', 'two');
when I reformat a script using the editor.

There's an Intention for this:
Unfortunately there's no way to have it performed automatically on "reformat code".

Related

Perl: HTTP::Tiny delete leaves broken anchor tags

I wrote a script that collects all URLs within a buffer that's read from a database, checks whether that page still exists, and uses HTTP::Tiny to delete the URL from the buffer if it is unreachable or returns invalid.
The problem is that HTTP::Tiny delete left anchor tags like text here that are invalid. The links are highlighted, but there's obviously no way to click them. Is this a deficiency with HTTP::Tiny delete or am I using it wrong?
my $html_full = $ref->{'fulltext'}; # $ref is a pointer to the database
my $dom_buff = Mojo::DOM->new($html_buff);
foreach my $ele ($dom_buff->find('a[href]')->each) {
my $url = $ele->attr('href');
my $response = HTTP::Tiny->new(default_headers => { Accept => '*/*' })->get($url);
if ($response->{success}) {
$success_fulltext_urls{$ref->{'id'}}{$url} = 1;
} else {
delete $ele->attr->{href};
$html_buff = $dom_buff;
$html_buff =~ s{<a>(.*?)</a>}{$1}sg;
my $sql = "not described here";
write_sql($dbh,$sql,$ref->{'id'});
}
}
Here is an example string, after it's been processed by the code above.
This week, perhaps the most interesting articles include "<a>Finding \r\n that Windows is superior to Linux is biased</a>," "How \r\n to set up DNS for Linux VPNs," and "Writing \r\n an Incident Handling and Recovery Plan."
Note the string "Finding \r\n that Windows is superior to Linux is biased" used to be a valid link with an href, but the delete function stripped all that out and left the anchor tags.
Is this the intended effect? Perhaps I should be using a different library or function within HTTP::Tiny?
You're misunderstanding what delete does. All your code does is remove the href attribute from that DOM element in your Mojo::DOM representation. It has nothing to do with HTTP::Tiny.
What you actually want to do is call ->strip on the <a> element, which removes it from the DOM, but keeps its content intact.
Since you are already using Mojo::DOM, you can just as well use Mojo::UserAgent. There is no need to pull in another UA module. You've already got the whole Mojolicious installed anyway.
You can use a HEAD request rather than a GET request to check if a resource is available. There is no need to download the whole thing, the headers are sufficient.
Your code (without the DB part) can be reduced to this.
use strict;
use warnings;
use Mojo::DOM;
use Mojo::UserAgent;
my $ua = Mojo::UserAgent->new;
my $dom = Mojo::DOM->new(<DATA>);
foreach my $element ($dom->find('a[href]')->each) {
$element->strip
unless $ua->head($element->attr('href'))->res->is_success;
}
print $dom;
__DATA__
This link works.
This one does not!
This outputs:
This link works. This one does not!

Angular data binding sending strings?

I'm new to angular, and I would like to know if there's is a way to send a string to the Html file with a variable inside?
test.ts
test: string = "Display this {{testText}}";
testText: string = "Success";
test.html
<p>{{test}}</p>
What I want to achieve is that it displays this: Display this Success.
I'm just curious if this is possible, perhaps I can retrieve from an API chunks of HTML string and display them like that.
**
It is basic Javascript string operation. For this, there is nothing special with Angular at your TypeScript file.
Without handling updates on test
On Typescript file you have two options to merge strings:
First Way:
testText: string = "Success";
test: string = `Display this ${this.testText}`;
Second Way:
testText: string = "Success";
test: string = "Display this " + this.testText;
Of course you can see a problem with both of them. What will happen when you update your test? Based on these ways, the testText just initializing when the component instance is created, so if you want to fetch changes on your test variable you should use the way from one of following
**
First Way:
test.html
<p>Display is {{testText}}</p>
<p>{{'Display is ' + testText}}
Socond Way:
Specifically you can create a custom Pipe. You should check documentation about how are them work. For only this case you don't need to use this way. Pipes are generally for more generic or more complex operations.
Third way:
(more bad than others. Because change detector of Angular will not understand when your content should update the paragraph. You should use others.)
test.ts
getTestText() { return 'Display is ' + this.testText }
test.html
<p>{{ getTestText() }}</p>
**
Binding Dynamic Html Content
For binding any dynamic HTML template you need to use innerHTML attribute like
<div [innerHTML]="htmlVariable"></div>
but this is not a trusted way because there is nothing to check is the html is trusted or is it valid etc. Or if the html contains the selector of any component, it won 't render as expected. You should use more complex ways to do it.

Scala Play template vararg HtmlContent

I have a generic template in play 2.6, that I want to pass in a variable amount of HtmlContents. I've defined the template like this (including the implicit parameter I have in case that changes anything):
#(foo: String)(content: Html*)(implicit bar: Bar)
On the template side, this works fine-- I can dissect content with for and render it as I want. However, I haven't been able to figure out a clean way to invoke the variable arguments from the underlying template.
e.g, I have a view named "Baz":
#(something: String)(implicit bar: Bar)
In it, I try to invoke the template with multiple Html arguments. I've tried the following:
#template("fooString"){{123},{abc}}
and
#template("fooString")({123}, {abc})
and
#template("fooString"){{123}, {abc}})
And various other permutations, but inside of an enclosing bracket it seems to interpret everything literally as a single parameter in the HtmlContent vararg.
However, this ended up working as I intended, passing in multiple HtmlContents:
#template("fooString")(Html("123"), Html("abc"))
So that works, and I can use a triple-quoted interpolated string for a large Html block-- but it seems like there should be a cleaner way to do this, and the string interpolation is dangerous as it doesn't do html escaping.
Is there a way to do this using the { enclosed syntax? I'd like to understand more what is actually happening on an underlying level, and how play parses and generates HtmlContent in brackets.
So consider you have below template
// main.scala.html
#(title: String)(contents: Html*)
There are different ways you can call this template
Option #1
This is what you already posted in the question
#main("This is a title")(Html("abc"), Html("123"))
Options #2
#html1 = {
Hello
}
#html2 = {
<div>Tarun</div>
}
#main("This is a title")(html1, html2)
Option #3
#main("This is a title")(Html(<div>Tarun
</div>.toString), Html(<div>
Lalwani
</div>.toString))
Options #4
This is not exactly same option, but needs change in Template signature itself
#(title: String)(contents: List[String])
And then calling it like below
#main("This is a title")(List(
"""<div>
Tarun
</div>
""", """Hello"""))
Option #5
This requires code files and was already answered on another SO thread
Paul Draper's answer on Why doesn't this pass multiple HTML parameters to template

How to change the nodeType of XML document from DOCUMENT to ELEMENT

I used XMLDOM to create a document (#1). I used Load("string"). With another XML document (#2), I want to append the first XMLDOM, but I get an error stating "This operation can not be performed with a Node of type DOCUMENT." How can I change the node to type ELEMENT (1)?
oDOM2 = Createobject(MSXML2.DOMDocument)
<bunch of code and other things go here...>
oDOM1 = Createobject(MSXML2.DOMDocument)
oDOM1.Load("<SomeXML><MoreXML></MoreXML></SomeXML>")
oDOM2.appendChild(oDOM1) -->Error
If i use the DOM object to create the object with createElement and addChild, with that fix the problem?
I figured out one way to handle this. After I have completed my document #1, then I can select a single node (the root) into a new DOM object. It works for my purpose.
oDOM2 = Createobject(MSXML2.DOMDocument)
<bunch of code and other things go here...>
oDOM1 = Createobject(MSXML2.DOMDocument)
oDOM1.Load("<SomeXML><MoreXML></MoreXML></SomeXML>")
oDOMTemp = oDOM1.selectSingleNode("//SomeXML")
oDOM2.appendChild(oDOMTemp)
Is there a better way?

make wordml readonly

how i caon make a wordml read-only from .
any ideas??
Adding the following to your WordML document will tell Word to treat its contents as read only:
<w:wordDocument>
<w:docPr>
<w:documentProtection w:edit="read-only" w:enforcement="on" w:unprotectPassword="5349CC3D"/>
</w:docPr>
</w:wordDocument>
w:unprotectPassword is "1234" in this example but this attribute is not required. If an unlock password is not included Word will allow the user to just turn the read only state of the document off without challenging them.
Hope that helps and is what you are looking for!
if you are using the Open XML SDK 2.0 you can specify a file as read-only in the second parameter to the open method call:
// false is the read-only property
using (var wordprocessingDocument = WordprocessingDocument.Open(documentFileName, false))
{
// Do work here
}