What is the difference between "" and nothing - json

Hello I would like to know what is the difference between '' and nothing I mean for instance if I take this example :
"test":[""]
and
"test":[""]

Though you have given identical examples, I think you tried to provide these two:
"test":[""]
and this: "test":[]
For the first case, your test array length is 1. So, accessing test[0] will give you ""
But for the second case, its length is 0. So no element in the later but for the first one you have "".
That's it.

Related

Html selector using Regex

So there is a page that I want to perform some action on with puppeteer. The problem is that there is a text area in which I want to type in something however the id of it is :
id="pin-draft-title-13a10e18-5a1e-49b9-893c-c5e028dc63e1"
As you might have guess for some reason only pin-draft-title remains the same but the whole number part changes for every refresh so puppeteer can't find it. I tried deleting the id and copying the selector itself the whoe #_Root div>div etc but that seems to be changing after sometime as well. So the main question is is there any way i can just select it using the pin-draft-title part and no matter what numbers follow it still selects it ?
You can use [id^=pin-draft-title-]
In case of javascript, if you want to select all the elements whos ID starts with a specified string or pattern, in your case "pin-draft-title", then consider using the following syntax.
document.querySelectorAll('[id^="pin-draft-title"]');

How to add more XPATH in parsefilter.json in stormcrawler

I am using stormcrawler (v 1.16) & Elasticsearch(v 7.5.0) for extracting data from about 5k news websites. I have added some XPATH patterns for extracting author name in parsefilter.json.
Parsefilter.json is as shown below:
{
"com.digitalpebble.stormcrawler.parse.ParseFilters": [
{
"class": "com.digitalpebble.stormcrawler.parse.filter.XPathFilter",
"name": "XPathFilter",
"params": {
"canonical": "//*[#rel=\"canonical\"]/#href",
"parse.description": [
"//*[#name=\"description\"]/#content",
"//*[#name=\"Description\"]/#content"
],
"parse.title": [
"//TITLE",
"//META[#name=\"title\"]/#content"
],
"parse.keywords": "//META[#name=\"keywords\"]/#content",
"parse.datePublished": "//META[#itemprop=\"datePublished\"]/#content",
"parse.author":[
"//META[#itemprop=\"author\"]/#content",
"//input[#id=\"authorname\"]/#value",
"//META[#name=\"article:author\"]/#content",
"//META[#name=\"author\"]/#content",
"//META[#name=\"byline\"]/#content",
"//META[#name=\"dc.creator\"]/#content",
"//META[#name=\"byl\"]/#content",
"//META[#itemprop=\"authorname\"]/#content",
"//META[#itemprop=\"article:author\"]/#content",
"//META[#itemprop=\"byline\"]/#content",
"//META[#itemprop=\"dc.creator\"]/#content",
"//META[#rel=\"authorname\"]/#content",
"//META[#rel=\"article:author\"]/#content",
"//META[#rel=\"byline\"]/#content",
"//META[#rel=\"dc.creator\"]/#content",
"//META[#rel=\"author\"]/#content",
"//META[#id=\"authorname\"]/#content",
"//META[#id=\"byline\"]/#content",
"//META[#id=\"dc.creator\"]/#content",
"//META[#id=\"author\"]/#content",
"//META[#class=\"authorname\"]/#content",
"//META[#class=\"article:author\"]/#content",
"//META[#class=\"byline\"]/#content",
"//META[#class=\"dc.creator\"]/#content",
"//META[#class=\"author\"]/#content"
]
}
},
I have also made change in crawler-conf.yaml and it is as shown below.
indexer.md.mapping:
- parse.author=author
metadata.persist:
- author
The issue i am facing is : I am getting result only for 1st pattern (i.e. "//META[#itemprop="author"]/#content") of "parse.author". What changes I should do so that all patterns can be taken as input.
What changes I should do so that all patterns can be taken as input.
I read this as "How can I make a single XPath expression that tries all different ways an author can appear in the document?"
Simplest approach: Join the all expressions you already have into a single one with the XPath Union operator |:
input[...]|meta[...]|meta[...]|meta[...]
And since this potentially selects more than one node, we could state explicitly that we only care for the first match:
(input[...]|meta[...]|meta[...]|meta[...])[1]
This probably works but it will be very long and hard to read. XPath can do better.
Your expressions are all pretty repetitive, that's a good starting point to reduce the size of the expression. For example, those two are the same, except for the attribute value:
//meta[#class='author']/#content|//meta[#class='authorname']/#content
We could use or and it would get shorter already:
//meta[#class='author' or #class='authorname']/#content
But when you have 5 or 6 potential values, it still is pretty long. Next try, a predicate for the attribute:
//meta[#class[.='author' or .='authorname']]/#content
A little shorter, as we don't need to type #class all the time. But still pretty long with 5 or 6 potential values. How about a value list and a substring search (I'm using / as a delimiter character):
//meta[contains(
'/author/authorname/',
concat('/', #class, '/')
)]/#content
Now we can easily expand the list of valid values, and even look at different attributes, too:
//meta[contains(
'/author/authorname/article:author/',
concat('/', #class|#id , '/')
)]/#content
And since we're looking for almost the same possible strings across multiple possible attributes, we could use a fixed list of values that all possible attributes are checked against:
//meta[
contains(
'/author/article:author/authorname/dc.creator/byline/byl/',
concat('/', #name|#itemprop|#rel|#id|#class, '/')
)
]/#content
Combined with the first two points, we could end up with this:
(
//meta[
contains(
'/author/article:author/authorname/dc.creator/byline/byl/',
concat('/', #name|#itemprop|#rel|#id|#class, '/')
)
]/#content
|
//input[
#id='authorname'
]/#value
)[1]
Caveat: This only works as expected when a <meta> will never have both e.g. #name and #rel, or if, that they at least both have the same value. Otherwise concat('/', #name|#itemprop|#rel|#id|#class, '/') might pick the wrong one. It's a calculated risk, I think it's not usual for this to happen in HTML. But you need to decide, you're the one who knows your input data.

Selecting some kind of closest child with jQuery seems not to work

I try to implement a nested tab module the following way.
By clicking on a .tabs__menu item I want to get the next .tabs__contents to display the correct entry.
I've prepared a codepen with markup and leave out all unimportant code so don't be irritated that it's not working. I don't understand why the variable debug2 is 0 and debug3 is 1. I expect debug2 to be 1 as well since I expect the following expression should find the element. Can anyone help me with this?:
.find(".tabs__contents").not(".tabs__contents .tabs__contents");
https://codepen.io/anon/pen/JNLWQp
Thanks in advance and best wishes,
duc
ok I have an assumption why it's not working. It seems that the .not method doesn't starts to search relatively from the given collection but globally. With this statement
.not(".tabs__contents .tabs__contents")
debug2 finds itself and exclude it from the collection thats why the length is 0.

Cannot create more then two c3js graphs on a page

We are using the following code (generated by php but finally this is on client side)
c3.generate({'bindto':'#b65d3422__salestaffcommunication_xepan_base_view_chart_chart','data':{'keys':{'x':'name','value':['Email','Call','Meeting']},'groups':[['Email','Call','Meeting']],'json':[],'type':'bar'},'axis':{'x':{'type':'category'},'rotated':true},'onrendered':function(ev,ui){$(".widget-grid").masonry({'itemSelector':'.widget'})}});
c3.generate({'bindto':'#f67e14d8__t_masscommunication_xepan_base_view_chart_chart','data':{'keys':{'x':'name','value':['Newsletter','TeleMarketing']},'groups':[['Newsletter','TeleMarketing']],'json':[],'type':'bar'},'axis':{'x':{'type':'category'},'rotated':true},'onrendered':function(ev,ui){$(".widget-grid").masonry({'itemSelector':'.widget'})}});
c3.generate({'bindto':'#517df254__ableworkforce_xepan_base_view_chart_chart','data':{'columns':[['present',11.111111111111]],'type':'gauge'},'color':{'pattern':['#FF0000','#F97600','#F6C600','#60B044'],'threshold':{'values':[30,60,90,100]}},'onrendered':function(ev,ui){$(".widget-grid").masonry({'itemSelector':'.widget'})}});
And last graph is not drawn. showing
SyntaxError (DOM Exception 12): The string did not match the expected pattern.
However, I can run ANY two and it works fine. that means all code is perfect but once second one is drawn ( no matter in which order). Third one doesn't draws.
Is it any known bug, or any workaround known.
Using v0.4.11 of c3 from c3js.org
Here is my jsfiddle
https://jsfiddle.net/2yy2mjaf/1/
Thank you.
IDs cannot start with a number, which is the case of your third ID.
The simple solution is just adding a letter to it:
'bindto':'#a517df254_ //just put an "a" before the number here
Here is your fiddle: https://jsfiddle.net/7dkLdg32/

When the Switch Input is off, it returns NULL element?

I have array of Krajee SwitchInputs, when everyone of SwitchInput is off, it returns nothing.
SwitchInput::widget([
'name' => 'work_time[]',
'value' => 1,
}
The reason you won't receive the values
This should be expected behavior (empty checkboxes are not considered "successful") and has nothing to do with the actual kartik-widget. In the background the widget uses a regular checkbox.
To save overhead, empty checkboxes won't transmit "0". So when you have more than one and all are off, nothing will be transmitted. However this is no problem as you know when all are missing, all are off!
You can find a lot of similar questions here, like this one for example, explaining the same thing. Don't worry too much, as it is quite simple:
value missing or 0: individual checkbox is off
all values missing: all are off
If you still want a workaround, you can find one here
Checking the right way
The following code will respect the types when comparing. Normally you would use either a boolean value or 1 and 0 as integers. Both work perfectly, but the boolean-way is better, as you are then not only able to use the equal-operator == but also the identical-operator ===.
$myCheckboxVal = isset(Yii::$app->request->post('my_checkbox')) ? true : false;
Thanks, I solved.
$value=isset($_POST['day_check']) ? '1' : '0';