问:
Sum the value of some hash keys inside an array
I try to search but any solution doesn't work.

I have this array of hashes

```<code>[{:smartphone=>"Galaxy Note 8 - Samsung", :votes=>0}, {:smartphone=>"ZenFone 4 Pro - Asus", :votes=>0}, {:smartphone=>"Xperia XZ1 - Sony", :votes=>0}, {:smartphone=>"Mate 10 Pro - Huawei", :votes=>0}, {:smartphone=>"V30 - LG", :votes=>0}, {:smartphone=>"One Plus 5T", :votes=>0}, {:smartphone=>"Pixel 2 XL - Google", :votes=>1}, {:smartphone=>"Nokia 8", :votes=>0}, {:smartphone=>"Z2 Force - Moto", :votes=>0}, {:smartphone=>"U11 - HTC", :votes=>0}, {:smartphone=>"iPhone X - Apple", :votes=>0}, {:smartphone=>"iPhone X - Apple", :votes=>1}, {:smartphone=>"iPhone X - Apple", :votes=>1}, {:smartphone=>"Galaxy Note 8 - Samsung", :votes=>0}, {:smartphone=>"ZenFone 4 Pro - Asus", :votes=>0}, {:smartphone=>"Xperia XZ1 - Sony", :votes=>0}, {:smartphone=>"Mate 10 Pro - Huawei", :votes=>0}, {:smartphone=>"V30 - LG", :votes=>0}, {:smartphone=>"One Plus 5T", :votes=>0}, {:smartphone=>"Pixel 2 XL - Google", :votes=>0}, {:smartphone=>"Nokia 8", :votes=>0}, {:smartphone=>"Z2 Force - Moto", :votes=>0}, {:smartphone=>"U11 - HTC", :votes=>0}, {:smartphone=>"Galaxy Note 8 - Samsung", :votes=>0}, {:smartphone=>"ZenFone 4 Pro - Asus", :votes=>0}, {:smartphone=>"Xperia XZ1 - Sony", :votes=>0}, {:smartphone=>"Mate 10 Pro - Huawei", :votes=>0}, {:smartphone=>"V30 - LG", :votes=>0}, {:smartphone=>"One Plus 5T", :votes=>0}, {:smartphone=>"Pixel 2 XL - Google", :votes=>0}, {:smartphone=>"Nokia 8", :votes=>0}, {:smartphone=>"Z2 Force - Moto", :votes=>0}, {:smartphone=>"U11 - HTC", :votes=>0}, {:smartphone=>"Galaxy Note 8 - Samsung", :votes=>0}, {:smartphone=>"ZenFone 4 Pro - Asus", :votes=>0}, {:smartphone=>"Xperia XZ1 - Sony", :votes=>0}, {:smartphone=>"Mate 10 Pro - Huawei", :votes=>0}, {:smartphone=>"V30 - LG", :votes=>0}, {:smartphone=>"One Plus 5T", :votes=>0}, {:smartphone=>"Pixel 2 XL - Google", :votes=>0}, {:smartphone=>"Nokia 8", :votes=>0}, {:smartphone=>"Z2 Force - Moto", :votes=>0}, {:smartphone=>"U11 - HTC", :votes=>1}, {:smartphone=>"iPhone X - Apple", :votes=>0}, {:smartphone=>"Galaxy Note 8 - Samsung", :votes=>0}, {:smartphone=>"ZenFone 4 Pro - Asus", :votes=>1}, {:smartphone=>"Xperia XZ1 - Sony", :votes=>0}, {:smartphone=>"Mate 10 Pro - Huawei", :votes=>0}, {:smartphone=>"V30 - LG", :votes=>0}, {:smartphone=>"One Plus 5T", :votes=>0}, {:smartphone=>"Pixel 2 XL - Google", :votes=>0}, {:smartphone=>"Nokia 8", :votes=>0}, {:smartphone=>"Z2 Force - Moto", :votes=>0}, {:smartphone=>"U11 - HTC", :votes=>0}, {:smartphone=>"iPhone X - Apple", :votes=>0}, {:smartphone=>"Galaxy Note 8 - Samsung", :votes=>1}, {:smartphone=>"ZenFone 4 Pro - Asus", :votes=>0}, {:smartphone=>"One Plus 5T", :votes=>0}, {:smartphone=>"Pixel 2 XL - Google", :votes=>0}, {:smartphone=>"U11 - HTC", :votes=>0}, {:smartphone=>"Z2 Force - Moto", :votes=>0}, {:smartphone=>"Nokia 8", :votes=>0}, {:smartphone=>"Pixel 2 XL - Google", :votes=>0}, {:smartphone=>"One Plus 5T", :votes=>0}, {:smartphone=>"V30 - LG", :votes=>0}, {:smartphone=>"Galaxy Note 8 - Samsung", :votes=>0}, {:smartphone=>"Xperia XZ1 - Sony", :votes=>0}, {:smartphone=>"V30 - LG", :votes=>1}, {:smartphone=>"Z2 Force - Moto", :votes=>0}, {:smartphone=>"iPhone X - Apple", :votes=>0}, {:smartphone=>"iPhone X - Apple", :votes=>0}, {:smartphone=>"ZenFone 4 Pro - Asus", :votes=>0}, {:smartphone=>"Mate 10 Pro - Huawei", :votes=>0}, {:smartphone=>"Nokia 8", :votes=>0}, {:smartphone=>"U11 - HTC", :votes=>0}, {:smartphone=>"Mate 10 Pro - Huawei", :votes=>0}, {:smartphone=>"Xperia XZ1 - Sony", :votes=>0}]
</code>```

And I want to sum the votes for every smartphone

I try with

```<code>results.group_by { |hash1| hash1[:smartphone] }.map do |_,v|
  v.inject do |ele_hash2,ele_hash1|
      puts ele_hash2
      puts ele_hash1
     ele_hash2.merge(ele_hash1) {|k,o,n| k == :vote ? o+n : o }
  end
end
</code>```

But it returns me

```<code>[{:smartphone=>"Galaxy Note 8 - Samsung", :votes=>0}, {:smartphone=>"ZenFone 4 Pro - Asus", :votes=>0}, {:smartphone=>"Xperia XZ1 - Sony", :votes=>0}, {:smartphone=>"Mate 10 Pro - Huawei", :votes=>0}, {:smartphone=>"V30 - LG", :votes=>0}, {:smartphone=>"One Plus 5T", :votes=>0}, {:smartphone=>"Pixel 2 XL - Google", :votes=>1}, {:smartphone=>"Nokia 8", :votes=>0}, {:smartphone=>"Z2 Force - Moto", :votes=>0}, {:smartphone=>"U11 - HTC", :votes=>0}, {:smartphone=>"iPhone X - Apple", :votes=>0}]
</code>```

And it's not correct, Apple iPhone X has 1 vote for example.
Why?

答:
If arr is your array of hashes, you can do the following.

```<code>arr.each_with_object(Hash.new(0)) { |g,h| h[g[:smartphone]] += g[:votes] }
  #=> {"Galaxy Note 8 - Samsung"=>1, "ZenFone 4 Pro - Asus"=>1,
  #    "Xperia XZ1 - Sony"=>0, "Mate 10 Pro - Huawei"=>0, "V30 - LG"=>1,
  #    "One Plus 5T"=>0, "Pixel 2 XL - Google"=>1, "Nokia 8"=>0,
  #    "Z2 Force - Moto"=>0, "U11 - HTC"=>1, "iPhone X - Apple"=>2}
</code>```

Hash.new(0) creates a hash with a default value of zero (sometimes called a counting hash). See Hash::new. This mean if a hash h so defined has no key k, h[k] returns the default value, here zero. (The hash is not changed.) The expression h[g[:smartphone]] += g[:votes] expands to

```<code>h[g[:smartphone]] = h[g[:smartphone]] + g[:votes]
</code>```

When a hash g in the array has a value "iPhone X - Apple" for the key :smartphone, the above expression becomes

```<code>h["iPhone X - Apple"] = h["iPhone X - Apple"] + g[:votes]
</code>```

The first time the value "iPhone X - Apple" for :smartphone in g is encountered the hash h being constructed does not have a key "iPhone X - Apple". h["iPhone X - Apple"] on the right side of the equality above is therefore set equal to the default value, zero, so we have

```<code>h["iPhone X - Apple"] = g[:votes]
</code>```

The next time g[:smartphone] is found to equal "iPhone X - Apple", h["iPhone X - Apple"] on the right side of the equality will equal g[:votes], so the default value will not apply.

Body:
I try to search but any solution doesn't work.

I have this array of hashes

[{:smartphone=>"Galaxy Note 8 - Samsung", :votes=>0}, {:smartphone=>"ZenFone 4 Pro - Asus", :votes=>0}, {:smartphone=>"Xperia XZ1 - Sony", :votes=>0}, {:smartphone=>"Mate 10 Pro - Huawei", :votes=>0}, {:smartphone=>"V30 - LG", :votes=>0}, {:smartphone=>"One Plus 5T", :votes=>0}, {:smartphone=>"Pixel 2 XL - Google", :votes=>1}, {:smartphone=>"Nokia 8", :votes=>0}, {:smartphone=>"Z2 Force - Moto", :votes=>0}, {:smartphone=>"U11 - HTC", :votes=>0}, {:smartphone=>"iPhone X - Apple", :votes=>0}, {:smartphone=>"iPhone X - Apple", :votes=>1}, {:smartphone=>"iPhone X - Apple", :votes=>1}, {:smartphone=>"Galaxy Note 8 - Samsung", :votes=>0}, {:smartphone=>"ZenFone 4 Pro - Asus", :votes=>0}, {:smartphone=>"Xperia XZ1 - Sony", :votes=>0}, {:smartphone=>"Mate 10 Pro - Huawei", :votes=>0}, {:smartphone=>"V30 - LG", :votes=>0}, {:smartphone=>"One Plus 5T", :votes=>0}, {:smartphone=>"Pixel 2 XL - Google", :votes=>0}, {:smartphone=>"Nokia 8", :votes=>0}, {:smartphone=>"Z2 Force - Moto", :votes=>0}, {:smartphone=>"U11 - HTC", :votes=>0}, {:smartphone=>"Galaxy Note 8 - Samsung", :votes=>0}, {:smartphone=>"ZenFone 4 Pro - Asus", :votes=>0}, {:smartphone=>"Xperia XZ1 - Sony", :votes=>0}, {:smartphone=>"Mate 10 Pro - Huawei", :votes=>0}, {:smartphone=>"V30 - LG", :votes=>0}, {:smartphone=>"One Plus 5T", :votes=>0}, {:smartphone=>"Pixel 2 XL - Google", :votes=>0}, {:smartphone=>"Nokia 8", :votes=>0}, {:smartphone=>"Z2 Force - Moto", :votes=>0}, {:smartphone=>"U11 - HTC", :votes=>0}, {:smartphone=>"Galaxy Note 8 - Samsung", :votes=>0}, {:smartphone=>"ZenFone 4 Pro - Asus", :votes=>0}, {:smartphone=>"Xperia XZ1 - Sony", :votes=>0}, {:smartphone=>"Mate 10 Pro - Huawei", :votes=>0}, {:smartphone=>"V30 - LG", :votes=>0}, {:smartphone=>"One Plus 5T", :votes=>0}, {:smartphone=>"Pixel 2 XL - Google", :votes=>0}, {:smartphone=>"Nokia 8", :votes=>0}, {:smartphone=>"Z2 Force - Moto", :votes=>0}, {:smartphone=>"U11 - HTC", :votes=>1}, {:smartphone=>"iPhone X - Apple", :votes=>0}, {:smartphone=>"Galaxy Note 8 - Samsung", :votes=>0}, {:smartphone=>"ZenFone 4 Pro - Asus", :votes=>1}, {:smartphone=>"Xperia XZ1 - Sony", :votes=>0}, {:smartphone=>"Mate 10 Pro - Huawei", :votes=>0}, {:smartphone=>"V30 - LG", :votes=>0}, {:smartphone=>"One Plus 5T", :votes=>0}, {:smartphone=>"Pixel 2 XL - Google", :votes=>0}, {:smartphone=>"Nokia 8", :votes=>0}, {:smartphone=>"Z2 Force - Moto", :votes=>0}, {:smartphone=>"U11 - HTC", :votes=>0}, {:smartphone=>"iPhone X - Apple", :votes=>0}, {:smartphone=>"Galaxy Note 8 - Samsung", :votes=>1}, {:smartphone=>"ZenFone 4 Pro - Asus", :votes=>0}, {:smartphone=>"One Plus 5T", :votes=>0}, {:smartphone=>"Pixel 2 XL - Google", :votes=>0}, {:smartphone=>"U11 - HTC", :votes=>0}, {:smartphone=>"Z2 Force - Moto", :votes=>0}, {:smartphone=>"Nokia 8", :votes=>0}, {:smartphone=>"Pixel 2 XL - Google", :votes=>0}, {:smartphone=>"One Plus 5T", :votes=>0}, {:smartphone=>"V30 - LG", :votes=>0}, {:smartphone=>"Galaxy Note 8 - Samsung", :votes=>0}, {:smartphone=>"Xperia XZ1 - Sony", :votes=>0}, {:smartphone=>"V30 - LG", :votes=>1}, {:smartphone=>"Z2 Force - Moto", :votes=>0}, {:smartphone=>"iPhone X - Apple", :votes=>0}, {:smartphone=>"iPhone X - Apple", :votes=>0}, {:smartphone=>"ZenFone 4 Pro - Asus", :votes=>0}, {:smartphone=>"Mate 10 Pro - Huawei", :votes=>0}, {:smartphone=>"Nokia 8", :votes=>0}, {:smartphone=>"U11 - HTC", :votes=>0}, {:smartphone=>"Mate 10 Pro - Huawei", :votes=>0}, {:smartphone=>"Xperia XZ1 - Sony", :votes=>0}]

And I want to sum the votes for every smartphone

I try with

results.group_by { |hash1| hash1[:smartphone] }.map do |_,v|
  v.inject do |ele_hash2,ele_hash1|
      puts ele_hash2
      puts ele_hash1
     ele_hash2.merge(ele_hash1) {|k,o,n| k == :vote ? o+n : o }
  end
end

But it returns me

[{:smartphone=>"Galaxy Note 8 - Samsung", :votes=>0}, {:smartphone=>"ZenFone 4 Pro - Asus", :votes=>0}, {:smartphone=>"Xperia XZ1 - Sony", :votes=>0}, {:smartphone=>"Mate 10 Pro - Huawei", :votes=>0}, {:smartphone=>"V30 - LG", :votes=>0}, {:smartphone=>"One Plus 5T", :votes=>0}, {:smartphone=>"Pixel 2 XL - Google", :votes=>1}, {:smartphone=>"Nokia 8", :votes=>0}, {:smartphone=>"Z2 Force - Moto", :votes=>0}, {:smartphone=>"U11 - HTC", :votes=>0}, {:smartphone=>"iPhone X - Apple", :votes=>0}]

And it's not correct, Apple iPhone X has 1 vote for example.
Why?

Body:
If arr is your array of hashes, you can do the following.

arr.each_with_object(Hash.new(0)) { |g,h| h[g[:smartphone]] += g[:votes] }
  #=> {"Galaxy Note 8 - Samsung"=>1, "ZenFone 4 Pro - Asus"=>1,
  #    "Xperia XZ1 - Sony"=>0, "Mate 10 Pro - Huawei"=>0, "V30 - LG"=>1,
  #    "One Plus 5T"=>0, "Pixel 2 XL - Google"=>1, "Nokia 8"=>0,
  #    "Z2 Force - Moto"=>0, "U11 - HTC"=>1, "iPhone X - Apple"=>2}

Hash.new(0) creates a hash with a default value of zero (sometimes called a counting hash). See Hash::new. This mean if a hash h so defined has no key k, h[k] returns the default value, here zero. (The hash is not changed.) The expression h[g[:smartphone]] += g[:votes] expands to

h[g[:smartphone]] = h[g[:smartphone]] + g[:votes]

When a hash g in the array has a value "iPhone X - Apple" for the key :smartphone, the above expression becomes

h["iPhone X - Apple"] = h["iPhone X - Apple"] + g[:votes]

The first time the value "iPhone X - Apple" for :smartphone in g is encountered the hash h being constructed does not have a key "iPhone X - Apple". h["iPhone X - Apple"] on the right side of the equality above is therefore set equal to the default value, zero, so we have

h["iPhone X - Apple"] = g[:votes]

The next time g[:smartphone] is found to equal "iPhone X - Apple", h["iPhone X - Apple"] on the right side of the equality will equal g[:votes], so the default value will not apply.


来源: stackexchange

问:
Using Custom Authentication on Wowza Client Requests
Is it possible to use custom authentication, wherein each request for a stream is authenticated from my database and then a user is allowed to view a stream?

I've configured Wowza IDE for custom authentication using the following:

Integrating Wowza User Authentication with External Authentication

but I do not know exactly where this works? As in how do I make a request for a stream with authentication credentials that are eventually checked by this module's logic?

I am new to Wowza and Video Streaming as well.

Any help is appreciated.

答: Here is a diagram that shows you how this works in a similar module, you can try to mimic this idea in your own plugin.</p>

ContentLicense: CC BY-SA 3.0


问:
Multiple radio buttons rows inside ng-repeat
I have a flow of three div working with each other (and 3 arrays)
The idea is to select some options on the first div (from the first array), those options are passed inside the second one (and the second array).

I have an ng-repeat inside the second div which displays the selected options with, for each one, four radio buttons.

The radio buttons have an ng-click value which will add the option associated to the radio button value to the third array and will allow to sort the options by the different radio buttons checked.

```<code>DIV1            DIV2                          DIV3
|option1|       |option2|                     radio1 : option2
|option2|       oradio1 oradio2 oradio3       radio3 : option4
|option3|  -->  |option4|               -->
|option4|       oradio1 oradio2 oradio3
</code>```

The problem comes from my radio buttons, I've tried to change their name / values / ng-model change values for ng-values and I can't find a way to make it work.
Either I have all my radio buttons changing at the same time or only on radio button line working at a time or all object having the radio value being updated...

I have an idea of what's going on, my scope is updating everything because my ng-model is the same or values are the same but I can't find a way to make it work...

I have spend my day on it... so it's time to get help :)

Here is a plunker of the code I have (I've made a lot of change like I said) but the idea is here...

http://plnkr.co/edit/jElDW1aUAv3k4cqou54y?p=preview

Thank you !

```<code><EDIT>
</code>```

The idea of option may not be very understandable just imagine you have some buttons for people
Mary
Chloe
David
etc.

The radio buttons are team bleu / red / yellow

I select the person I want in the first panel attribute them a team in the second one and display the person per team in the third one :)

答:
I don't know if this can be helpful for you.

I've made a fiddle based on your code.

Please check this.

```<code>$scope.addPerson = function(personName){
    var obj = {};
    obj['name'] = personName;
    $scope.peopleArr.push(obj);
    $scope.personName = '';
};
</code>```

Is this far from your intent?

Body:
I have a flow of three div working with each other (and 3 arrays)
The idea is to select some options on the first div (from the first array), those options are passed inside the second one (and the second array).

I have an ng-repeat inside the second div which displays the selected options with, for each one, four radio buttons.

The radio buttons have an ng-click value which will add the option associated to the radio button value to the third array and will allow to sort the options by the different radio buttons checked.

DIV1            DIV2                          DIV3
|option1|       |option2|                     radio1 : option2
|option2|       oradio1 oradio2 oradio3       radio3 : option4
|option3|  -->  |option4|               -->
|option4|       oradio1 oradio2 oradio3

The problem comes from my radio buttons, I've tried to change their name / values / ng-model change values for ng-values and I can't find a way to make it work.
Either I have all my radio buttons changing at the same time or only on radio button line working at a time or all object having the radio value being updated...

I have an idea of what's going on, my scope is updating everything because my ng-model is the same or values are the same but I can't find a way to make it work...

I have spend my day on it... so it's time to get help :)

Here is a plunker of the code I have (I've made a lot of change like I said) but the idea is here...

http://plnkr.co/edit/jElDW1aUAv3k4cqou54y?p=preview

Thank you !

<EDIT>

The idea of option may not be very understandable just imagine you have some buttons for people
Mary
Chloe
David
etc.

The radio buttons are team bleu / red / yellow

I select the person I want in the first panel attribute them a team in the second one and display the person per team in the third one :)

Body:
I don't know if this can be helpful for you.

I've made a fiddle based on your code.

Please check this.

$scope.addPerson = function(personName){
    var obj = {};
    obj['name'] = personName;
    $scope.peopleArr.push(obj);
    $scope.personName = '';
};

Is this far from your intent?


问:
How to automate basic authentication chrome alert

Have tried several approached to handle it but none worked.

https://user:password@pageaddress.com - doesn't work, chrome launches controlled bu automates test software and authentication pop-up appears anyway.

Adding --disable-blink-features=BlockCredentialedSubresources to Chrome arg and repeat 1'st point - doesn't work, reason the same as in 1'st point.

driver.switchTo().alert.authenticateUsing(new UserAndPassword(user, password)) - here seems like driver doesn't see an alert, have impelented method that checks it and returns false:

private Alert alert;
 public boolean isAlertPresent() {
    try {
        waitForTimeout(10, TimeUnit.SECONDS);
        alert = driver.switchTo().alert();
        return true;
    } catch (NoAlertPresentException e) {
        return false;
    }}

Triggering keyboard or mouse event via selenium Action() doesn't work too.

chromedriver 2.31
Google Chrome Version 61

Any other ideas ? Maybe some js script ?

答:
I had something similar here.
you may not need the full Native Messaging API, though ...
This will all be JavaScript and will work for any browser-generated auth request (at least, it looks that way).

webRequest - chrome and firefox - has an anAuthRequired event.
You can hook into this with a listener then just pass in the credentials you need per some examples.

If you're wanting to just pass in user credentials that won't change, you'll want to use the synchronous method - it's much easier. This question may, indeed, be all you need.

If you're needing to pass in different credentials, you may well want to look into the asynchronous method, that's the one I had to use.
If you're using chrome, forget promises ... but Firefox should work with them.

Hope this helped!


问:
How to completely uninstall VS Code on Windows?
What is the way to totally uninstall Visual Studio Code and its extensions, including all configurations, etc.) on Windows 10?

I tried uninstalling and installing but it remembered its previous settings.

答:
Since, you might already know the drill to uninstall and you are emphasizing on remembered its previous settings, please do the following:

Open Run (Win + R)

Type %appdata%

Press Enter

Delete the folder Code

Voila! Restart Visual Studio Code and it is reset!

Here is a bat script which does the same thing:

explorer.exe %appdata%
del Code
```

P.S: Since, you want to uninstall go to Add or Remove Programs and click on bottom right of the Visual Studio Code tile, where it says Uninstall.

ContentLicense: CC BY-SA 4.0

Body:
Since, you might already know the drill to uninstall and you are emphasizing on remembered its previous settings, please do the following:

Open Run (Win + R)

Type %appdata%

Press Enter

Delete the folder Code

Voila! Restart Visual Studio Code and it is reset!

Here is a bat script which does the same thing:

explorer.exe %appdata%
del Code

P.S: Since, you want to uninstall go to Add or Remove Programs and click on bottom right of the Visual Studio Code tile, where it says Uninstall.


问:
How to open a PDF file included in assets folder in Ionic 2?
Is it possible to add a PDF file in the assets folder and then access it within the Ionic 2 application. </p>

答:
I use this code and it works for me.

Its need a plugin.

```<code>showDocument(){
    const options: DocumentViewerOptions = {
        title: 'My PDF'
    }
    const imgeLocation = `${cordova.file.applicationDirectory}www/assets/imgs/${'Jainbhajan-Jeevan-Saar-By-Nirmal-Gangwal-1-ilovepdf-compressed (1).pdf'}`;
    this.document.viewDocument(imgeLocation, 'application/pdf', options)
}
</code>```

Body:
I use this code and it works for me.

Its need a plugin.

showDocument(){
    const options: DocumentViewerOptions = {
        title: 'My PDF'
    }
    const imgeLocation = `${cordova.file.applicationDirectory}www/assets/imgs/${'Jainbhajan-Jeevan-Saar-By-Nirmal-Gangwal-1-ilovepdf-compressed (1).pdf'}`;
    this.document.viewDocument(imgeLocation, 'application/pdf', options)
}


问:
Why can't I create view table in SQL?
I have query like this:

```<code>SELECT
       generatedTime AS generatedTime,
       tempTable AS tempTable,
       CASE
           WHEN ((generatedTime < maxPelamarmhsdoktor) or (generatedTime < maxAkdmstmayor)
                    or (generatedTime < maxIpbmstdepartemen) or (generatedTime < maxIpbmstfakultas)
                        or (generatedTime < maxIpbrefjeniskelamin) or (generatedTime < maxJenisinstansi)
                            or (generatedTime < maxJenisinstitusi)) THEN
               'Yes'
           ELSE
               'No'
       END AS NeedsToUpdateorNot
FROM generatedtime
JOIN ( SELECT
              MAX( last_update ) AS maxPelamarmhsdoktor
       FROM pelamarmhsdoktor

     ) AS maxPelamarmhsdoktorFinder
JOIN ( SELECT
              MAX( last_update ) AS maxAkdmstmayor
       FROM akdmst_mayor

     ) AS maxAkdmstmayorFinder
JOIN ( SELECT
              MAX( last_update ) AS maxIpbmstdepartemen
       FROM ipbmst_departemen

     ) AS maxIpbmstdepartemenFinder
JOIN ( SELECT
              MAX( last_update ) AS maxIpbmstfakultas
       FROM ipbmst_fakultas

     ) AS maxIpbmstfakultasFinder
JOIN ( SELECT
              MAX( last_update ) AS maxIpbrefjeniskelamin
       FROM ipbref_jeniskelamin

     ) AS maxIpbrefjeniskelaminFinder
JOIN ( SELECT
              MAX( last_update ) AS maxJenisinstansi
       FROM jenisinstansi

     ) AS maxJenisinstansiFinder
JOIN ( SELECT
              MAX( last_update ) AS maxJenisinstitusi
       FROM jenisinstitusi

     ) AS maxJenisinstitusiFinder
</code>```

Then I want to make that query to be a view table. So I added

```<code>CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `updateforpelamarmagisterrinci`  AS
</code>```

at the beginning.

But When I tried to create view, the error comes, and the error message is like this

```<code>#1349 - View's SELECT contains a subquery in the FROM clause
</code>```

What may I do to solve that? Thanks in advance

答:
Move your sub query to view:

```<code>CREATE VIEW v_max_pelamarmhsdoktor AS
    SELECT MAX( last_update ) AS maxPelamarmhsdoktor FROM pelamarmhsdoktor
...

...
</code>```

your query become:

```<code>SELECT
       generatedTime AS generatedTime,
       tempTable AS tempTable,
       CASE
           WHEN ((generatedTime < maxPelamarmhsdoktor) or (generatedTime < maxAkdmstmayor)
                    or (generatedTime < maxIpbmstdepartemen) or (generatedTime < maxIpbmstfakultas)
                        or (generatedTime < maxIpbrefjeniskelamin) or (generatedTime < maxJenisinstansi)
                            or (generatedTime < maxJenisinstitusi)) THEN
               'Yes'
           ELSE
               'No'
       END AS NeedsToUpdateorNot
FROM generatedtime
JOIN v_max_pelamarmhsdoktor AS maxPelamarmhsdoktorFinder
...

...
</code>```

Title: Why can't I create view table in SQL?

Body:
I have query like this:

SELECT
       generatedTime AS generatedTime,
       tempTable AS tempTable,
       CASE
           WHEN ((generatedTime < maxPelamarmhsdoktor) or (generatedTime < maxAkdmstmayor)
                    or (generatedTime < maxIpbmstdepartemen) or (generatedTime < maxIpbmstfakultas)
                        or (generatedTime < maxIpbrefjeniskelamin) or (generatedTime < maxJenisinstansi)
                            or (generatedTime < maxJenisinstitusi)) THEN
               'Yes'
           ELSE
               'No'
       END AS NeedsToUpdateorNot
FROM generatedtime
JOIN ( SELECT
              MAX( last_update ) AS maxPelamarmhsdoktor
       FROM pelamarmhsdoktor

     ) AS maxPelamarmhsdoktorFinder
JOIN ( SELECT
              MAX( last_update ) AS maxAkdmstmayor
       FROM akdmst_mayor

     ) AS maxAkdmstmayorFinder
JOIN ( SELECT
              MAX( last_update ) AS maxIpbmstdepartemen
       FROM ipbmst_departemen

     ) AS maxIpbmstdepartemenFinder
JOIN ( SELECT
              MAX( last_update ) AS maxIpbmstfakultas
       FROM ipbmst_fakultas

     ) AS maxIpbmstfakultasFinder
JOIN ( SELECT
              MAX( last_update ) AS maxIpbrefjeniskelamin
       FROM ipbref_jeniskelamin

     ) AS maxIpbrefjeniskelaminFinder
JOIN ( SELECT
              MAX( last_update ) AS maxJenisinstansi
       FROM jenisinstansi

     ) AS maxJenisinstansiFinder
JOIN ( SELECT
              MAX( last_update ) AS maxJenisinstitusi
       FROM jenisinstitusi

     ) AS maxJenisinstitusiFinder

Then I want to make that query to be a view table. So I added

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `updateforpelamarmagisterrinci`  AS

at the beginning.

But When I tried to create view, the error comes, and the error message is like this

#1349 - View's SELECT contains a subquery in the FROM clause

What may I do to solve that? Thanks in advance

Body:
Move your sub query to view:

CREATE VIEW v_max_pelamarmhsdoktor AS
    SELECT MAX( last_update ) AS maxPelamarmhsdoktor FROM pelamarmhsdoktor
...

...

your query become:

SELECT
       generatedTime AS generatedTime,
       tempTable AS tempTable,
       CASE
           WHEN ((generatedTime < maxPelamarmhsdoktor) or (generatedTime < maxAkdmstmayor)
                    or (generatedTime < maxIpbmstdepartemen) or (generatedTime < maxIpbmstfakultas)
                        or (generatedTime < maxIpbrefjeniskelamin) or (generatedTime < maxJenisinstansi)
                            or (generatedTime < maxJenisinstitusi)) THEN
               'Yes'
           ELSE
               'No'
       END AS NeedsToUpdateorNot
FROM generatedtime
JOIN v_max_pelamarmhsdoktor AS maxPelamarmhsdoktorFinder
...

...


问:
shell script executes as root when it should execute as current logged in user
I was logged in via SSH as the user who was currently logged in.

I enter the remote computer using my admin account.

```<code>ssh admin_a@ipaddress
</code>```

Then proceeded with:

```<code>su username_b (current login user)
</code>```

The result left me in bash-prompt (which I don't understand) as the current user logged in ( tested this by using whoami ).

Q1: When I switch over to the user who is logged in, why does it put me into bash-prompt (i.e. ~bash$ ) - why not ~ username_of_current_user$ ?

After I created the bash script and placed it into the current user's directory - the script is called from launch agents, although it doesn't work.

The error logs showed that one of the variable's output is wrong: whoami = root, when it should = current_user_logged_in.

Q2: Why is the script being called from root?

答:
su - invokes a login shell after switching the user. A login shell resets most environment variables, providing a clean base.

su just switches the user, providing a normal shell with an environment nearly the same as with the old user.

The most obvious example of this is that ~ is root's home directory if you use su -, but your own home directory if you use su.

Depending on your system, it may also mean differences in prompt, PATH, or history file.

For more details:

https://unix.stackexchange.com/questions/7013/why-do-we-use-su-and-not-just-su

Body:
I was logged in via SSH as the user who was currently logged in.

I enter the remote computer using my admin account.

ssh admin_a@ipaddress

Then proceeded with:

su username_b (current login user)

The result left me in bash-prompt (which I don't understand) as the current user logged in ( tested this by using whoami ).

Q1: When I switch over to the user who is logged in, why does it put me into bash-prompt (i.e. ~bash$ ) - why not ~ username_of_current_user$ ?

After I created the bash script and placed it into the current user's directory - the script is called from launch agents, although it doesn't work.

The error logs showed that one of the variable's output is wrong: whoami = root, when it should = current_user_logged_in.

Q2: Why is the script being called from root?


问:
Capslock Shift Modifier
I would like an AHK script that will disable Capslock except when used with arrow keys as a shortcut for Home and End (with and without text selection). I believe it would look something like this, but I can't get figure out how to include the Shift key as a modifier so I may select text as well.</p>

```<code>Capslock::Return
Capslock & Right::End
Capslock & Left::Home
Capslock & Right & Shift::End (with Selection)
Capslock & Left & Shift::Home (with Selection)
</code>```

答:
Copy pasted and trialed and horrored from many, unfortunately forgotten, places is my solution here.

As you can se I have mapped alt-Capslock to normal Capslock

and Capslock by itself to Esc.

Following the same pattern I tried to grab shift-Capslock and alt-Capslock with a +CapsLock & h::Send {Backspace} but AHK complained about bad syntax.

You can also see that ; happens to have a special annotation and that is because I change keyboard and that key is sometimes ; and sometimes ö.

```<code>#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

SetCapsLockState AlwaysOff

; Toggle Capslock with alt-Capslock.
!CapsLock::CapsLock

; Esc.
CapsLock::Send {Esc}

; Arrows.
CapsLock & j::Send {Left}
CapsLock & k::Send {Right}
CapsLock & SC027::Send {Down} ; or CapsLock & `;::Send {Down}
CapsLock & l::Send {Up}
CapsLock & u::Send ^{Left}
CapsLock & i::Send ^{Right}

; Backspace and Del.
CapsLock & h::Send {Backspace}

; Home and End.
CapsLock & m::Send {Home}
CapsLock & ,::Send {End}

; Mark word left.
CapsLock & y::Send ^+{Left}
</code>```

Title: Capslock Shift Modifier

Body:
I would like an AHK script that will disable Capslock except when used with arrow keys as a shortcut for Home and End (with and without text selection). I believe it would look something like this, but I can't get figure out how to include the Shift key as a modifier so I may select text as well.

Capslock::Return
Capslock & Right::End
Capslock & Left::Home
Capslock & Right & Shift::End (with Selection)
Capslock & Left & Shift::Home (with Selection)

Body:
Copy pasted and trialed and horrored from many, unfortunately forgotten, places is my solution here.

As you can se I have mapped alt-Capslock to normal Capslock

and Capslock by itself to Esc.

Following the same pattern I tried to grab shift-Capslock and alt-Capslock with a +CapsLock & h::Send {Backspace} but AHK complained about bad syntax.

You can also see that ; happens to have a special annotation and that is because I change keyboard and that key is sometimes ; and sometimes ö.

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

SetCapsLockState AlwaysOff

; Toggle Capslock with alt-Capslock.
!CapsLock::CapsLock

; Esc.
CapsLock::Send {Esc}

; Arrows.
CapsLock & j::Send {Left}
CapsLock & k::Send {Right}
CapsLock & SC027::Send {Down} ; or CapsLock & `;::Send {Down}
CapsLock & l::Send {Up}
CapsLock & u::Send ^{Left}
CapsLock & i::Send ^{Right}

; Backspace and Del.
CapsLock & h::Send {Backspace}

; Home and End.
CapsLock & m::Send {Home}
CapsLock & ,::Send {End}

; Mark word left.
CapsLock & y::Send ^+{Left}


问:
Upload file using HTML  control without file selection dialog
I want upload the file using HTML file control but without selection dialog since i have to upload file which has fixed path "c:\finsts\finstmt.xml".

Scenario 1:

I have tried to upload file using HTML control . In which it shows browse button and on click you have to select file from file chooser dialog box. It works. Its upload file to server fine. Server side code is correct and works fine.

Scenario 2:

But when I hide the file chooser control, with following HTML code:

```<code> <div name="filediv" style="display:none">
  <html type="file" id="uploadfile" value="c:\finsts\finstmt.xml">
 </div>
</code>```

As file path is fixed and I don't want to user select file. When I tried with this scenario it doesn't work while first works fine. I don't understood how file control works.

Anyone here knows any work around to work the second scenario?

Thanks.

答:
First of all, there is no <html type="file" at all.

Second, this is not possible, because of security restrictions...

You can't access arbitrary files on users' computer via the browser, you can only ask the user to select a file of their choice.

ContentLicense: CC BY-SA 2.5

Title: Upload file using HTML <html type="file" id="uploadfile"> control without file selection dialog

Body:
I want upload the file using HTML file control but without selection dialog since i have to upload file which has fixed path "c:\finsts\finstmt.xml".

Scenario 1:

I have tried to upload file using HTML control . In which it shows browse button and on click you have to select file from file chooser dialog box. It works. Its upload file to server fine. Server side code is correct and works fine.

Scenario 2:

But when I hide the file chooser control, with following HTML code:

As file path is fixed and I don't want to user select file. When I tried with this scenario it doesn't work while first works fine. I don't understood how file control works.

Anyone here knows any work around to work the second scenario?

Thanks.


问:
ASP.NET Core Sharing Identity Cookie across azure web apps on default domain (*.azurewebsites.net)
Having trouble sharing an Identity Cookie (using ASP.NET Core v2) across multiple web applications

On my development environment, cookies are shared automatically (as it's localhost) - and that works fine!

When dealing with MS Azure, I've tried to set the cookie domain to .azurewebsites.net - to allow two web apps (e.g. app1.azurewebsites.net and app2.azurewebsites.net) to share a cookie.

Using the cookie configuration (abbreviated) like so:

```<code>public IServiceProvider ConfigureServices(IServiceCollection services)
{
    services.ConfigureApplicationCookie(options =>
    {
         options.Cookie.Domain = ".azurewebsites.net";
    }
}
</code>```

However, when I deploy the main site (the one that generates cookies from logins) to Azure, I can't even login. The .AspNetCore.Application.Identity cookie doesn't even get returned after entering username/password (or social logins)

I've also tried the solution here: https://stackoverflow.com/a/44310683/1025394
With no success

Question is: Is there possibly any filtering going on the Azure side of things? Stopping me from setting a cookie for .azurewebsites.net? Maybe for Security purposes?

答:
However, when I deploy the main site (the one that generates cookies from logins) to Azure, I can't even login. The .AspNetCore.Application.Identity cookie doesn't even get returned after entering username/password (or social logins)

I searched the web and found that some domain names do not allowed to create cookies for security concerns. Domains for Azure Cloud are listed as follows:

```<code>azurewebsites.net
azure-mobile.net
cloudapp.net
</code>```

Detailed list of domains you could find here.

Moreover, if you want to share cookie among your multiple web apps, you could map custom domain name for your web apps (e.g. app1.yourwebsite.com, app2.yourwebsite.com) and set options.Cookie.Domain to .yourwebsite.com, details about mapping a custom domain you could follow here. Also, you need to configure data protection to use the same encryption keys for your multiple web apps. In addition, you could follow this similar issue.

Body:
Having trouble sharing an Identity Cookie (using ASP.NET Core v2) across multiple web applications

On my development environment, cookies are shared automatically (as it's localhost) - and that works fine!

When dealing with MS Azure, I've tried to set the cookie domain to .azurewebsites.net - to allow two web apps (e.g. app1.azurewebsites.net and app2.azurewebsites.net) to share a cookie.

Using the cookie configuration (abbreviated) like so:

public IServiceProvider ConfigureServices(IServiceCollection services)
{
    services.ConfigureApplicationCookie(options =>
    {
         options.Cookie.Domain = ".azurewebsites.net";
    }
}

However, when I deploy the main site (the one that generates cookies from logins) to Azure, I can't even login. The .AspNetCore.Application.Identity cookie doesn't even get returned after entering username/password (or social logins)

I've also tried the solution here: https://stackoverflow.com/a/44310683/1025394
With no success

Question is: Is there possibly any filtering going on the Azure side of things? Stopping me from setting a cookie for .azurewebsites.net? Maybe for Security purposes?

Body:
However, when I deploy the main site (the one that generates cookies from logins) to Azure, I can't even login. The .AspNetCore.Application.Identity cookie doesn't even get returned after entering username/password (or social logins)

I searched the web and found that some domain names do not allowed to create cookies for security concerns. Domains for Azure Cloud are listed as follows:

azurewebsites.net
azure-mobile.net
cloudapp.net

Detailed list of domains you could find here.

Moreover, if you want to share cookie among your multiple web apps, you could map custom domain name for your web apps (e.g. app1.yourwebsite.com, app2.yourwebsite.com) and set options.Cookie.Domain to .yourwebsite.com, details about mapping a custom domain you could follow here. Also, you need to configure data protection to use the same encryption keys for your multiple web apps. In addition, you could follow this similar issue.


问:
Get First 2 Characters In a String
I'm trying to get first 2 characters in a string. Here's my code:

```<code>$s = 'hello'; // line 4
printf("[%0.2s]\n", %s); // line 5: Gets first 2 characters [he]
</code>```

It's giving me an error:

Parse error: syntax error, unexpected '%' in
  C:\laragon\www\karakter_tamamlama.php on line 5

Why am I getting error?

答:
Use substring function to get letters from string.

An example:

```<code>substr($s, 0, 2)
</code>```

Title: Get First 2 Characters In a String

Body:
I'm trying to get first 2 characters in a string. Here's my code:

$s = 'hello'; // line 4
printf("[%0.2s]\n", %s); // line 5: Gets first 2 characters [he]

It's giving me an error:

Parse error: syntax error, unexpected '%' in
  C:\laragon\www\karakter_tamamlama.php on line 5

Why am I getting error?

Body:
Use substring function to get letters from string.

An example:

substr($s, 0, 2)


问:
Generate Pdf from Html string with image and css for android using itext
I am using itext-5.3.4.jar and xmlworker-1.2.1.jar library for generate pdf from html string , html contains image logo and inline css.

My html file and image is in Asset folder , using this library my pdf generating successfully but there is no image display and no css style randering. anyone has a suggestion what should i do to fix this issue, if any other library or any other option for generate pdf from html will be helpful.

I am using these function for generate pdf:

```<code>    public static void generatePdfFromHtlm(String fileName, String htmlString){

    try {
        File mediaStorageDir = new File(Environment.getExternalStorageDirectory(), AppConfig.getContext().getPackageName() + "/" + "Pdf");

        if (!mediaStorageDir.exists()) {
            mediaStorageDir.mkdirs();
        }

        File fileWithinMyDir = new File(mediaStorageDir, fileName);

        FontFactory.registerDirectories();
        Document document = new Document(PageSize.A4);
        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream(fileWithinMyDir));
        document.open();
        HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
        htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
        htmlContext.setImageProvider(new AbstractImageProvider() {
            public String getImageRootPath() {

                Uri uri = Uri.parse("file:///android_asset/");

                String newPath = uri.toString();

                return newPath;
            }
        });

        CSSResolver cssResolver =
                XMLWorkerHelper.getInstance().getDefaultCssResolver(false);
        /*Pipeline<?> pipeline =
                new CssResolverPipeline(cssResolver,
                        new HtmlPipeline(htmlContext,
                                new PdfWriterPipeline(document, writer)));*/

        // Pipelines
        PdfWriterPipeline pdf = new PdfWriterPipeline(document, writer);
        HtmlPipeline html = new HtmlPipeline(htmlContext, pdf);
        CssResolverPipeline css = new CssResolverPipeline(cssResolver, html);

        XMLWorker worker = new XMLWorker(css, true);

        XMLParser p = new XMLParser(worker);
        InputStream is = new ByteArrayInputStream(htmlString.getBytes());
        p.parse(is);

        document.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
}
</code>```

my html file is

<!DOCTYPE html>

  <meta charset="utf-8" />

  <title>WeighInsheet</title>

Description

Title Meta

 ##CHANGEHEADER##

  ##CHANGEBODY##

```

My Image file "logo.jpg" is in asset folder .

答:
iText Sharp is not supported all css property.You can load html in webview and generate pdf using this code.

```<code>private void createWebPrintJob(WebView webView) {

        try {
            PrintDocumentAdapter printAdapter;
            String jobName = getString(R.string.app_name) + " Document";
            PrintAttributes attributes = new PrintAttributes.Builder()
                    .setMediaSize(PrintAttributes.MediaSize.ISO_A4)
                    .setResolution(new PrintAttributes.Resolution("pdf", "pdf", 600, 600))
                    .setMinMargins(PrintAttributes.Margins.NO_MARGINS).build();
            File path = new File(Environment.getExternalStorageDirectory()
                    .getAbsolutePath() + "/AamirPDF/");

            path.mkdirs();
            PdfPrint pdfPrint = new PdfPrint(attributes);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                printAdapter = webView.createPrintDocumentAdapter(jobName);
            } else {
                printAdapter = webView.createPrintDocumentAdapter();
            }

            pdfPrint.printNew(printAdapter, path, "output_" + System.currentTimeMillis() + ".pdf", getActivity().getCacheDir().getPath());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
</code>```

PdfPrint class for generate PDF.

```<code>package com.example.nisarg.invoice;

import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.ParcelFileDescriptor;
import android.print.PageRange;
import android.print.PrintAttributes;
import android.print.PrintDocumentAdapter;
import android.util.Log;

import com.example.nisarg.invoice.android.print.ProxyBuilder;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

import static com.example.nisarg.invoice.Database.appglobal.context;

public class PdfPrint {

    public static final String TAG = PdfPrint.class.getSimpleName();
    public static PrintAttributes printAttributes;
    File cacheFolder;

    public PdfPrint(PrintAttributes printAttributes) {
        this.printAttributes = printAttributes;
        cacheFolder = new File(context.getFilesDir() + "/etemp/");
    }

    public static PrintDocumentAdapter.WriteResultCallback getWriteResultCallback(InvocationHandler invocationHandler,
                                                                                File dexCacheDir) throws IOException {
        return ProxyBuilder.forClass(PrintDocumentAdapter.WriteResultCallback.class)
                .dexCache(dexCacheDir)
                .handler(invocationHandler)
                .build();
    }

    public static PrintDocumentAdapter.LayoutResultCallback getLayoutResultCallback(InvocationHandler invocationHandler,
                                                                                File dexCacheDir) throws IOException {
        return ProxyBuilder.forClass(PrintDocumentAdapter.LayoutResultCallback.class)
                .dexCache(dexCacheDir)
                .handler(invocationHandler)
                .build();
    }

  /*  public void print(final PrintDocumentAdapter printAdapter, final File path, final String fileName) {
        printAdapter.onLayout(null, printAttributes, null, new PrintDocumentAdapter.LayoutResultCallback() {
            @Override
            public void onLayoutFinished(PrintDocumentInfo info, boolean changed) {

                try {
                    PrintDocumentAdapter.WriteResultCallback callback = getWriteResultCallback(new InvocationHandler() {
                        @Override
                        public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
                            if (method.getName().equals("onWriteFinished")) {
                                //                            pdfCallback.onPdfCreated();
                            } else {
                                Log.e(TAG, "Layout failed");
                                //                            pdfCallback.onPdfFailed();
                            }
                            return null;
                        }
                    }, null);

                    printAdapter.onWrite(new PageRange[]{PageRange.ALL_PAGES}, getOutputFile(path, fileName), new CancellationSignal(), callback);
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        }, null);
    }*/

    public void printNew(final PrintDocumentAdapter printAdapter, final File path, final String fileName, final String fileNamenew) {

        try {

            printAdapter.onStart();
            printAdapter.onLayout(null, printAttributes, new CancellationSignal(), getLayoutResultCallback(new InvocationHandler() {
                @Override
                public Object invoke(Object o, Method method, Object[] objects) throws Throwable {

                    if (method.getName().equals("onLayoutFinished")) {
                        onLayoutSuccess(printAdapter, path, fileName, fileNamenew);
                    } else {
                        Log.e(TAG, "Layout failed");

                    }
                    return null;
                }
            }, new File(fileNamenew)), new Bundle());

        } catch (Exception e) {
            e.printStackTrace();

        }
    }

    private void onLayoutSuccess(PrintDocumentAdapter printAdapter, File path, String fileName, String filenamenew) throws IOException {
        PrintDocumentAdapter.WriteResultCallback callback = getWriteResultCallback(new InvocationHandler() {
            @Override
            public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
                if (method.getName().equals("onWriteFinished")) {

                    System.out.print("hello");

                } else {
                    Log.e(TAG, "Layout failed");

                }
                return null;
            }
        }, new File(filenamenew));
        printAdapter.onWrite(new PageRange[]{PageRange.ALL_PAGES}, getOutputFile(path, fileName), new CancellationSignal(), callback);
    }

    private ParcelFileDescriptor getOutputFile(File path, String fileName) {
        if (!path.exists()) {
            path.mkdirs();
        }
        File file = new File(path, fileName);
        try {
            file.createNewFile();
            return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_WRITE);
        } catch (Exception e) {
            Log.e(TAG, "Failed to open ParcelFileDescriptor", e);
        }
        return null;
    }
}
</code>```

Generate Proxy of class.[https://gist.github.com/brettwold/838c092329c486b6112c8ebe94c8007e ]

For dependence which is used in proxy builder class add this line in gradle.

```<code> compile 'com.linkedin.dexmaker:dexmaker-mockito:2.2.0'
</code>```

Body:
I am using itext-5.3.4.jar and xmlworker-1.2.1.jar library for generate pdf from html string , html contains image logo and inline css.

My html file and image is in Asset folder , using this library my pdf generating successfully but there is no image display and no css style randering. anyone has a suggestion what should i do to fix this issue, if any other library or any other option for generate pdf from html will be helpful.

I am using these function for generate pdf:

    public static void generatePdfFromHtlm(String fileName, String htmlString){

    try {
        File mediaStorageDir = new File(Environment.getExternalStorageDirectory(), AppConfig.getContext().getPackageName() + "/" + "Pdf");

        if (!mediaStorageDir.exists()) {
            mediaStorageDir.mkdirs();
        }

        File fileWithinMyDir = new File(mediaStorageDir, fileName);

        FontFactory.registerDirectories();
        Document document = new Document(PageSize.A4);
        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream(fileWithinMyDir));
        document.open();
        HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
        htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
        htmlContext.setImageProvider(new AbstractImageProvider() {
            public String getImageRootPath() {

                Uri uri = Uri.parse("file:///android_asset/");

                String newPath = uri.toString();

                return newPath;
            }
        });

        CSSResolver cssResolver =
                XMLWorkerHelper.getInstance().getDefaultCssResolver(false);
        /*Pipeline<?> pipeline =
                new CssResolverPipeline(cssResolver,
                        new HtmlPipeline(htmlContext,
                                new PdfWriterPipeline(document, writer)));*/

        // Pipelines
        PdfWriterPipeline pdf = new PdfWriterPipeline(document, writer);
        HtmlPipeline html = new HtmlPipeline(htmlContext, pdf);
        CssResolverPipeline css = new CssResolverPipeline(cssResolver, html);

        XMLWorker worker = new XMLWorker(css, true);

        XMLParser p = new XMLParser(worker);
        InputStream is = new ByteArrayInputStream(htmlString.getBytes());
        p.parse(is);

        document.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

my html file is

<!DOCTYPE html>

  <meta charset="utf-8" />

  <title>WeighInsheet</title>

Description

Title Meta

 ##CHANGEHEADER##

  ##CHANGEBODY##

My Image file "logo.jpg" is in asset folder .

Body:
iText Sharp is not supported all css property.You can load html in webview and generate pdf using this code.

private void createWebPrintJob(WebView webView) {

        try {
            PrintDocumentAdapter printAdapter;
            String jobName = getString(R.string.app_name) + " Document";
            PrintAttributes attributes = new PrintAttributes.Builder()
                    .setMediaSize(PrintAttributes.MediaSize.ISO_A4)
                    .setResolution(new PrintAttributes.Resolution("pdf", "pdf", 600, 600))
                    .setMinMargins(PrintAttributes.Margins.NO_MARGINS).build();
            File path = new File(Environment.getExternalStorageDirectory()
                    .getAbsolutePath() + "/AamirPDF/");

            path.mkdirs();
            PdfPrint pdfPrint = new PdfPrint(attributes);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                printAdapter = webView.createPrintDocumentAdapter(jobName);
            } else {
                printAdapter = webView.createPrintDocumentAdapter();
            }

            pdfPrint.printNew(printAdapter, path, "output_" + System.currentTimeMillis() + ".pdf", getActivity().getCacheDir().getPath());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

PdfPrint class for generate PDF.

package com.example.nisarg.invoice;

import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.ParcelFileDescriptor;
import android.print.PageRange;
import android.print.PrintAttributes;
import android.print.PrintDocumentAdapter;
import android.util.Log;

import com.example.nisarg.invoice.android.print.ProxyBuilder;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

import static com.example.nisarg.invoice.Database.appglobal.context;

public class PdfPrint {

    public static final String TAG = PdfPrint.class.getSimpleName();
    public static PrintAttributes printAttributes;
    File cacheFolder;

    public PdfPrint(PrintAttributes printAttributes) {
        this.printAttributes = printAttributes;
        cacheFolder = new File(context.getFilesDir() + "/etemp/");
    }

    public static PrintDocumentAdapter.WriteResultCallback getWriteResultCallback(InvocationHandler invocationHandler,
                                                                                File dexCacheDir) throws IOException {
        return ProxyBuilder.forClass(PrintDocumentAdapter.WriteResultCallback.class)
                .dexCache(dexCacheDir)
                .handler(invocationHandler)
                .build();
    }

    public static PrintDocumentAdapter.LayoutResultCallback getLayoutResultCallback(InvocationHandler invocationHandler,
                                                                                File dexCacheDir) throws IOException {
        return ProxyBuilder.forClass(PrintDocumentAdapter.LayoutResultCallback.class)
                .dexCache(dexCacheDir)
                .handler(invocationHandler)
                .build();
    }

  /*  public void print(final PrintDocumentAdapter printAdapter, final File path, final String fileName) {
        printAdapter.onLayout(null, printAttributes, null, new PrintDocumentAdapter.LayoutResultCallback() {
            @Override
            public void onLayoutFinished(PrintDocumentInfo info, boolean changed) {

                try {
                    PrintDocumentAdapter.WriteResultCallback callback = getWriteResultCallback(new InvocationHandler() {
                        @Override
                        public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
                            if (method.getName().equals("onWriteFinished")) {
                                //                            pdfCallback.onPdfCreated();
                            } else {
                                Log.e(TAG, "Layout failed");
                                //                            pdfCallback.onPdfFailed();
                            }
                            return null;
                        }
                    }, null);

                    printAdapter.onWrite(new PageRange[]{PageRange.ALL_PAGES}, getOutputFile(path, fileName), new CancellationSignal(), callback);
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        }, null);
    }*/

    public void printNew(final PrintDocumentAdapter printAdapter, final File path, final String fileName, final String fileNamenew) {

        try {

            printAdapter.onStart();
            printAdapter.onLayout(null, printAttributes, new CancellationSignal(), getLayoutResultCallback(new InvocationHandler() {
                @Override
                public Object invoke(Object o, Method method, Object[] objects) throws Throwable {

                    if (method.getName().equals("onLayoutFinished")) {
                        onLayoutSuccess(printAdapter, path, fileName, fileNamenew);
                    } else {
                        Log.e(TAG, "Layout failed");

                    }
                    return null;
                }
            }, new File(fileNamenew)), new Bundle());

        } catch (Exception e) {
            e.printStackTrace();

        }
    }

    private void onLayoutSuccess(PrintDocumentAdapter printAdapter, File path, String fileName, String filenamenew) throws IOException {
        PrintDocumentAdapter.WriteResultCallback callback = getWriteResultCallback(new InvocationHandler() {
            @Override
            public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
                if (method.getName().equals("onWriteFinished")) {

                    System.out.print("hello");

                } else {
                    Log.e(TAG, "Layout failed");

                }
                return null;
            }
        }, new File(filenamenew));
        printAdapter.onWrite(new PageRange[]{PageRange.ALL_PAGES}, getOutputFile(path, fileName), new CancellationSignal(), callback);
    }

    private ParcelFileDescriptor getOutputFile(File path, String fileName) {
        if (!path.exists()) {
            path.mkdirs();
        }
        File file = new File(path, fileName);
        try {
            file.createNewFile();
            return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_WRITE);
        } catch (Exception e) {
            Log.e(TAG, "Failed to open ParcelFileDescriptor", e);
        }
        return null;
    }
}

Generate Proxy of class.[https://gist.github.com/brettwold/838c092329c486b6112c8ebe94c8007e ]

For dependence which is used in proxy builder class add this line in gradle.

 compile 'com.linkedin.dexmaker:dexmaker-mockito:2.2.0'


问:
Android install apk programmatically
Is it possible to install an apk programmatically in the background or does the user have to accept the installation.

My scenario is that I want my employees to all have the same set of applications installed.

Of course they can install applications by them self, but I want them all to have at least some applications installed.

I'm not talking about installing applications from the market.

答:
```<code>adb install <apk name>
</code>```

using above statement we can install apk into devices.For more information
install apk

Title: Android install apk programmatically

Body:
adb install <apk name>

using above statement we can install apk into devices.For more information
install apk


问:
how to access Rolename from the group by query?
we having two table SiteRoles and SiteRolesModules . In SiteRolesModules we access RoleID in single row based on ModuleID .

```<code>select t1.ModuleID,RoleID=( SELECT RoleID AS [data()]
FROM SiteRoleModules t2
where t2.ModuleID = t1.ModuleID ORDER BY ModuleID  FOR XML PATH(''))
from SiteRoleModules t1 GROUP BY ModuleID
</code>```

In above image we got the output. We required Rolename instead of RoleID. RoleID and Rolename is present in SiteRoles table

In above image we have RoleID 1 - administrator, 2 - superAdmin, 3 - admin

we require output in image 1 Instead of RoleID 1 2 3 we need output as administrator superAdmin admin

```<code>ALTER PROCEDURE [dbo].[MEDEIL_SiteRoleModules_SelectOne]
@ModuleID int
AS
SELECT
   SRM.RoleID,
   SR.RoleName
FROM
   [dbo].[SiteRoleModules]  SRM
   INNER JOIN [dbo].[SiteRoles] SR
   ON SR.RoleID = SRM.RoleID
WHERE ModuleID = 1
</code>```

答:
Just you can use join to perform it;

```<code>select t1.ModuleID,RoleName=(  SELECT s1.RoleName AS [data()]

           FROM SiteRoleModules t2 inner join SiteRoles s1 ON t2.RoleID = s1.RoleID
           where t2.ModuleID = t1.ModuleID group by s1.RoleName FOR XML PATH('')) from SiteRoleModules t1 GROUP BY ModuleID
</code>```

Body:
we having two table SiteRoles and SiteRolesModules . In SiteRolesModules we access RoleID in single row based on ModuleID .

select t1.ModuleID,RoleID=( SELECT RoleID AS [data()]
FROM SiteRoleModules t2
where t2.ModuleID = t1.ModuleID ORDER BY ModuleID  FOR XML PATH(''))
from SiteRoleModules t1 GROUP BY ModuleID

In above image we got the output. We required Rolename instead of RoleID. RoleID and Rolename is present in SiteRoles table

In above image we have RoleID 1 - administrator, 2 - superAdmin, 3 - admin

we require output in image 1 Instead of RoleID 1 2 3 we need output as administrator superAdmin admin

ALTER PROCEDURE [dbo].[MEDEIL_SiteRoleModules_SelectOne]
@ModuleID int
AS
SELECT
   SRM.RoleID,
   SR.RoleName
FROM
   [dbo].[SiteRoleModules]  SRM
   INNER JOIN [dbo].[SiteRoles] SR
   ON SR.RoleID = SRM.RoleID
WHERE ModuleID = 1

Body:
Just you can use join to perform it;

select t1.ModuleID,RoleName=(  SELECT s1.RoleName AS [data()]

           FROM SiteRoleModules t2 inner join SiteRoles s1 ON t2.RoleID = s1.RoleID
           where t2.ModuleID = t1.ModuleID group by s1.RoleName FOR XML PATH('')) from SiteRoleModules t1 GROUP BY ModuleID


问:
How to stop a transparent-fill circle getting mouse events inside it?
I want a Circle to respond to mouse events only when the mouse is on it's 'stroke' , i mean boundary. Of course, the circle has a transparent fill and a colorful stroke. Extending JavaFX Path looks painful to me, is there any way to do that with this Circle class?

答:
This solution doesn't work with Java 9:
Ok, finally I found an excellent way to do that. It may help others in the future:

javafx.scene.shape.Shape class has a Deprecated method

boolean impl_computeContains(double localX, double localY)

which invokes another method  computeShapeContains(localX, localY, impl_configShape())

Now, scene graph decides whether a point is in a shape or not by

boolean contains(double localX, double localY) method from JavaFX.scene.Node which invokes that impl_computeContains method. So I had a look at those method and overrode the impl_computeContains mthod like this:

```<code>@Override
    protected boolean impl_computeContains(double localX, double localY) {
        float miterlimit =
            (float) Utils.clampMin(getStrokeMiterLimit(), 1.0f);
        return Toolkit.getToolkit().strokeContains(impl_configShape(), localX, localY, getStrokeType(),
                Utils.clampMin(getStrokeWidth(), 0.0f), getStrokeLineCap(), getStrokeLineJoin(), miterlimit);
    }
</code>```

and boom!! it works!! All I did was, I removed the part which implemented what to do if the point was on the shape's interior part.

Body:
This solution doesn't work with Java 9:
Ok, finally I found an excellent way to do that. It may help others in the future:

javafx.scene.shape.Shape class has a Deprecated method

boolean impl_computeContains(double localX, double localY)

which invokes another method  computeShapeContains(localX, localY, impl_configShape())

Now, scene graph decides whether a point is in a shape or not by

boolean contains(double localX, double localY) method from JavaFX.scene.Node which invokes that impl_computeContains method. So I had a look at those method and overrode the impl_computeContains mthod like this:

@Override
    protected boolean impl_computeContains(double localX, double localY) {
        float miterlimit =
            (float) Utils.clampMin(getStrokeMiterLimit(), 1.0f);
        return Toolkit.getToolkit().strokeContains(impl_configShape(), localX, localY, getStrokeType(),
                Utils.clampMin(getStrokeWidth(), 0.0f), getStrokeLineCap(), getStrokeLineJoin(), miterlimit);
    }

and boom!! it works!! All I did was, I removed the part which implemented what to do if the point was on the shape's interior part.


问:
opengl tall texture vs wide texture for memory locality
A 2D Texture has two coordinates, x and y. To store a 2D array in 1D memory, the two possible formats are [x + y * width] and [x * height + y]. OpenGL has various confusing row-major/column-major conventions so I am unsure which of the two formats it uses. This is relevant because if a texture is used to store multiple images, such as in a sprite sheet or atlas, it is better to have the parts of an image located close together in memory. For example, if the format is [x + y * width] and we are using a very wide texture, then the GPU will have to skip through long parts of memory to find the texels it needs.

Thus: is a tall texture atlas superior to a wide texture atlas, or is it the other way around? Or do GPUs have no memory locality benefits?

答:
The most important aspect of a texture atlas is how many images can fit inside it. Even when it comes to texture atlases, you are far more likely to access adjacent texels than distant ones.

Think about it. Say you render 2 32x32 sprites. So that's 2 quads, in a single rendering call. Each quad will take up 32x32 pixels on the screen; that's 1024 pixels.

Locality matters; you're rendering from 1024 locally adjacent texels, then rendering from a different set of 1024 locally adjacent texels.

In any case, OpenGL does not expose you to the details of the GPU's image formats. You can ask for a particular size of texel and a number of channels. But you don't get any more details than that. The data you provide will be appropriately converted by the driver into the actual internal GPU data.

Typically, GPUs will swizzle textures in memory. This means rearranging data so that locality is preserved. That is, instead of storing texels as either x + y * width or x * height + y, they get stored in a more complex arrangement.

For example, the first 4 values would be texels 0,0; 0,1; 1,0; and 1,1. So a 2x2 block of texels is store in a single contiguous array of memory. That's an example of how swizzled texture storage works.

But this is all an implementation detail; there's nothing you can do to influence or affect this, and not even a low-level API like Vulkan allows you to directly load pre-swizzled texel data.


问:
Getting error when run react-native run-android
```<code>A problem occurred configuring project ':app'.
   > Could not resolve all dependencies for configuration ':app:_debugApk'.
     > A problem occurred configuring project ':react-native-fbsdk'.
       > Could not resolve all dependencies for configuration ':react-native-fbsdk:_debugPublishCopy'.
         > Could not find com.android.support:appcompat-v7:27.0.1.
           Searched in the following locations:
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.pom
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.jar
             file:/home/ubuntu/git/mstore-pro/android/sdk-manager/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.jar
           Required by:
             beostore:react-native-fbsdk:unspecified
         > Could not find com.android.support:appcompat-v7:27.0.1.
           Searched in the following locations:
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.pom
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.jar
             file:/home/ubuntu/git/mstore-pro/android/sdk-manager/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.jar
           Required by:
             beostore:react-native-fbsdk:unspecified > com.facebook.react:react-native:0.46.4
         > Could not find com.android.support:support-annotations:27.0.1.
           Searched in the following locations:
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/support-annotations/27.0.1/support-annotations-27.0.1.pom
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/support-annotations/27.0.1/support-annotations-27.0.1.jar
             file:/home/ubuntu/git/mstore-pro/android/sdk-manager/com/android/support/support-annotations/27.0.1/support-annotations-27.0.1.jar
           Required by:
             beostore:react-native-fbsdk:unspecified > com.facebook.android:facebook-android-sdk:4.29.0 > com.facebook.android:facebook-core:4.29.0
         > Could not find com.android.support:support-core-utils:27.0.1.
           Searched in the following locations:
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/support-core-utils/27.0.1/support-core-utils-27.0.1.pom
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/support-core-utils/27.0.1/support-core-utils-27.0.1.jar
             file:/home/ubuntu/git/mstore-pro/android/sdk-manager/com/android/support/support-core-utils/27.0.1/support-core-utils-27.0.1.jar
           Required by:
             beostore:react-native-fbsdk:unspecified > com.facebook.android:facebook-android-sdk:4.29.0 > com.facebook.android:facebook-core:4.29.0
         > Could not find com.android.support:appcompat-v7:27.0.1.
           Searched in the following locations:
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.pom
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.jar
             file:/home/ubuntu/git/mstore-pro/android/sdk-manager/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.jar
           Required by:
             beostore:react-native-fbsdk:unspecified > com.facebook.android:facebook-android-sdk:4.29.0 > com.facebook.android:facebook-common:4.29.0
         > Could not find com.android.support:cardview-v7:27.0.1.
           Searched in the following locations:
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/cardview-v7/27.0.1/cardview-v7-27.0.1.pom
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/cardview-v7/27.0.1/cardview-v7-27.0.1.jar
             file:/home/ubuntu/git/mstore-pro/android/sdk-manager/com/android/support/cardview-v7/27.0.1/cardview-v7-27.0.1.jar
           Required by:
             beostore:react-native-fbsdk:unspecified > com.facebook.android:facebook-android-sdk:4.29.0 > com.facebook.android:facebook-common:4.29.0
         > Could not find com.android.support:customtabs:27.0.1.
           Searched in the following locations:
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/customtabs/27.0.1/customtabs-27.0.1.pom
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/customtabs/27.0.1/customtabs-27.0.1.jar
             file:/home/ubuntu/git/mstore-pro/android/sdk-manager/com/android/support/customtabs/27.0.1/customtabs-27.0.1.jar
           Required by:
             beostore:react-native-fbsdk:unspecified > com.facebook.android:facebook-android-sdk:4.29.0 > com.facebook.android:facebook-common:4.29.0
         > Could not find com.android.support:support-v4:27.0.1.
           Searched in the following locations:
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/support-v4/27.0.1/support-v4-27.0.1.pom
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/support-v4/27.0.1/support-v4-27.0.1.jar
             file:/home/ubuntu/git/mstore-pro/android/sdk-manager/com/android/support/support-v4/27.0.1/support-v4-27.0.1.jar
           Required by:
             beostore:react-native-fbsdk:unspecified > com.facebook.android:facebook-android-sdk:4.29.0 > com.facebook.android:facebook-common:4.29.0
</code>```

compileSdkVersion 25

buildToolsVersion "25.0.0"

targetSdkVersion 25

答:
Follow these Steps and Make your Build Successful

Go to Project build.gradle file adding maven {url"https://maven.google.com"} Will download the missing items .

android/build.gradle file and restrict fbsdk Version to 4.28.0.

OTHER WAY

Go to node_modules/react-native-fbsdk : build.gradle change to compileSdkVersion 26 or 27

```<code>allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            url "https://maven.google.com"
            }
        configurations.all {
            resolutionStrategy {
                force 'com.facebook.android:facebook-android-sdk:4.28.0'
                }
            }
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
                url "$rootDir/../node_modules/react-native/android"
            }

        }
    }
</code>```

Body:
A problem occurred configuring project ':app'.
   > Could not resolve all dependencies for configuration ':app:_debugApk'.
     > A problem occurred configuring project ':react-native-fbsdk'.
       > Could not resolve all dependencies for configuration ':react-native-fbsdk:_debugPublishCopy'.
         > Could not find com.android.support:appcompat-v7:27.0.1.
           Searched in the following locations:
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.pom
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.jar
             file:/home/ubuntu/git/mstore-pro/android/sdk-manager/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.jar
           Required by:
             beostore:react-native-fbsdk:unspecified
         > Could not find com.android.support:appcompat-v7:27.0.1.
           Searched in the following locations:
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.pom
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.jar
             file:/home/ubuntu/git/mstore-pro/android/sdk-manager/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.jar
           Required by:
             beostore:react-native-fbsdk:unspecified > com.facebook.react:react-native:0.46.4
         > Could not find com.android.support:support-annotations:27.0.1.
           Searched in the following locations:
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/support-annotations/27.0.1/support-annotations-27.0.1.pom
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/support-annotations/27.0.1/support-annotations-27.0.1.jar
             file:/home/ubuntu/git/mstore-pro/android/sdk-manager/com/android/support/support-annotations/27.0.1/support-annotations-27.0.1.jar
           Required by:
             beostore:react-native-fbsdk:unspecified > com.facebook.android:facebook-android-sdk:4.29.0 > com.facebook.android:facebook-core:4.29.0
         > Could not find com.android.support:support-core-utils:27.0.1.
           Searched in the following locations:
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/support-core-utils/27.0.1/support-core-utils-27.0.1.pom
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/support-core-utils/27.0.1/support-core-utils-27.0.1.jar
             file:/home/ubuntu/git/mstore-pro/android/sdk-manager/com/android/support/support-core-utils/27.0.1/support-core-utils-27.0.1.jar
           Required by:
             beostore:react-native-fbsdk:unspecified > com.facebook.android:facebook-android-sdk:4.29.0 > com.facebook.android:facebook-core:4.29.0
         > Could not find com.android.support:appcompat-v7:27.0.1.
           Searched in the following locations:
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.pom
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.jar
             file:/home/ubuntu/git/mstore-pro/android/sdk-manager/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.jar
           Required by:
             beostore:react-native-fbsdk:unspecified > com.facebook.android:facebook-android-sdk:4.29.0 > com.facebook.android:facebook-common:4.29.0
         > Could not find com.android.support:cardview-v7:27.0.1.
           Searched in the following locations:
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/cardview-v7/27.0.1/cardview-v7-27.0.1.pom
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/cardview-v7/27.0.1/cardview-v7-27.0.1.jar
             file:/home/ubuntu/git/mstore-pro/android/sdk-manager/com/android/support/cardview-v7/27.0.1/cardview-v7-27.0.1.jar
           Required by:
             beostore:react-native-fbsdk:unspecified > com.facebook.android:facebook-android-sdk:4.29.0 > com.facebook.android:facebook-common:4.29.0
         > Could not find com.android.support:customtabs:27.0.1.
           Searched in the following locations:
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/customtabs/27.0.1/customtabs-27.0.1.pom
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/customtabs/27.0.1/customtabs-27.0.1.jar
             file:/home/ubuntu/git/mstore-pro/android/sdk-manager/com/android/support/customtabs/27.0.1/customtabs-27.0.1.jar
           Required by:
             beostore:react-native-fbsdk:unspecified > com.facebook.android:facebook-android-sdk:4.29.0 > com.facebook.android:facebook-common:4.29.0
         > Could not find com.android.support:support-v4:27.0.1.
           Searched in the following locations:
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/support-v4/27.0.1/support-v4-27.0.1.pom
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/support-v4/27.0.1/support-v4-27.0.1.jar
             file:/home/ubuntu/git/mstore-pro/android/sdk-manager/com/android/support/support-v4/27.0.1/support-v4-27.0.1.jar
           Required by:
             beostore:react-native-fbsdk:unspecified > com.facebook.android:facebook-android-sdk:4.29.0 > com.facebook.android:facebook-common:4.29.0

compileSdkVersion 25

buildToolsVersion "25.0.0"

targetSdkVersion 25

Body:
Follow these Steps and Make your Build Successful

Go to Project build.gradle file adding maven {url"https://maven.google.com"} Will download the missing items .

android/build.gradle file and restrict fbsdk Version to 4.28.0.

OTHER WAY

Go to node_modules/react-native-fbsdk : build.gradle change to compileSdkVersion 26 or 27

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            url "https://maven.google.com"
            }
        configurations.all {
            resolutionStrategy {
                force 'com.facebook.android:facebook-android-sdk:4.28.0'
                }
            }
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
                url "$rootDir/../node_modules/react-native/android"
            }

        }
    }


问:
PHP instantiation breaks the script with AJAX call
I called a PHP script with jQuery but it doesn't return any response if i instantiate a class before echo-ing the response. Meaning that it works if i instantiate the object after.

javascript code :

```<code>$.post('libraries/test.php', {action: 'duplicateForm', service: service_name}, function(response)
{
    console.log(response);
});
</code>```

php script:

```<code>$response = '1';
$f = new usvn_form_insert();
$response = '2';
echo $response;
</code>```

I don't use the $_POST variables in this test. With this, the response is empty but if I put the echo before $f = new usvn_form_insert(); it prints 1

答: Put error_reporting(E_ALL) at the top of your php script and see if it returning any error back to the browser. </p>

Body:
I called a PHP script with jQuery but it doesn't return any response if i instantiate a class before echo-ing the response. Meaning that it works if i instantiate the object after.

javascript code :

$.post('libraries/test.php', {action: 'duplicateForm', service: service_name}, function(response)
{
    console.log(response);
});

php script:

$response = '1';
$f = new usvn_form_insert();
$response = '2';
echo $response;

I don't use the $_POST variables in this test. With this, the response is empty but if I put the echo before $f = new usvn_form_insert(); it prints 1


问:
Java and windows?

Possible Duplicates:

  Compiling a java program into an exe

  How can I convert my java program to an .exe file ?

hi everyone . there are many programs such intellij idea or jedit which they have written in JAVA ,
How they have compiled the code into the exe file ?
How can ,I compile my java code to exe file and run it on windows?
And Why javac give us class file ? what is it ?

答:
how about searching stack overflow:

How do I create an .exe for a Java program?

also, like the answer points out launch4j is the program you want to use. i have used it and it works well.

Title: Java and windows?


问:
ModuleVersionNotFoundException android studio
when i click on run button then i got this error

Error:org.gradle.api.artifacts.ResolveException: Could not resolve all dependencies for configuration ':app:_debugApkCopy'.

Error:org.gradle.internal.resolve.ModuleVersionNotFoundException: Could not find com.android.support:appcompat-v7:27.0.1.

please see below screen shot

and when i try to gradle sync
then i got this problem

please see below screen shot

my build.gradle

```<code>buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }

}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}
android {
    signingConfigs {
        config {
        }
    }
    repositories {
        mavenCentral()
    }
    compileSdkVersion 25
    buildToolsVersion '26.0.0'
    useLibrary 'org.apache.http.legacy'
    defaultConfig {
        applicationId "com.hechat"
        minSdkVersion 18
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true

    }
    dexOptions {
        javaMaxHeapSize "2048M"
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
        exclude 'project.properties'
        exclude 'META-INF/INDEX.LIST'

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

    repositories {
        maven { url "https://dl.bintray.com/hani-momanii/maven" }
    }
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
        exclude group: 'com.google.code.findbugs'
    })
    compile('com.twitter.sdk.android:twitter:2.3.1@aar') { transitive = true; }
    compile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') { transitive = true; }
    compile 'com.facebook.android:facebook-android-sdk:[4,5)'
    compile 'com.theartofdev.edmodo:android-image-cropper:2.3.1'
    compile 'com.android.support:appcompat-v7:25.0.0'
    compile 'com.android.support:cardview-v7:25.0.0'
    compile 'com.android.support:design:25.0.0'
    compile 'net.gotev:uploadservice:2.1'
    compile 'com.android.support:recyclerview-v7:25.0.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'hani.momanii.supernova_emoji_library:supernova-emoji-library:0.0.2'
    compile 'com.google.android.gms:play-services:11.0.4'
    compile 'com.google.firebase:firebase-core:10.2.1'
    compile 'com.google.code.gson:gson:2.3'
    compile 'org.apache.httpcomponents:httpcore:4.3.2'
    compile 'org.apache.httpcomponents:httpmime:4.3.3'
    compile 'com.mcxiaoke.volley:library:1.0.17'
    compile 'com.github.clans:fab:1.6.2'
    compile 'org.jsoup:jsoup:1.8.1'
    compile 'com.parse.bolts:bolts-tasks:1.4.0'
    compile 'com.commit451:PhotoView:1.2.4'
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.splitwise:tokenautocomplete:1.3.3'
    compile 'com.tubb.smrv:swipemenu-recyclerview:5.2.1'
    compile 'com.github.bumptech.glide:glide:3.5.2'
    compile 'se.emilsjolander:stickylistheaders:2.7.0'
    compile 'com.mindorks:placeholderview:0.6.4'
    compile 'org.twitter4j:twitter4j-core:4.0.2'
    compile 'jp.wasabeef:fresco-processors:2.1.0'
    compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.3.0'
    compile 'com.google.firebase:firebase-messaging:10.2.1'
    compile 'com.android.billingclient:billing:1.0'

    testCompile 'junit:junit:4.12'
    compile project(':cometchat_platinum-sdk')

}

apply plugin: 'com.google.gms.google-services'
</code>```

i have not used v-27 then why i am facing v7 issue
thanks in advance

答:
Add allprojects block in your app level build file

1.

```<code> allprojects {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com'
        }}}
</code>```

2.
New projects created using Android Studio 3.0 and higher also include

```<code>allprojects {
repositories {
    jcenter()
    google()
}}
</code>```

And change your compileSdkVersion to 26 and also buildToolsVersion "26.0.1" then sync your project

Hope this will help you.

Body:
when i click on run button then i got this error

Error:org.gradle.api.artifacts.ResolveException: Could not resolve all dependencies for configuration ':app:_debugApkCopy'.

Error:org.gradle.internal.resolve.ModuleVersionNotFoundException: Could not find com.android.support:appcompat-v7:27.0.1.

please see below screen shot

and when i try to gradle sync
then i got this problem

please see below screen shot

my build.gradle

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }

}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}
android {
    signingConfigs {
        config {
        }
    }
    repositories {
        mavenCentral()
    }
    compileSdkVersion 25
    buildToolsVersion '26.0.0'
    useLibrary 'org.apache.http.legacy'
    defaultConfig {
        applicationId "com.hechat"
        minSdkVersion 18
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true

    }
    dexOptions {
        javaMaxHeapSize "2048M"
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
        exclude 'project.properties'
        exclude 'META-INF/INDEX.LIST'

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

    repositories {
        maven { url "https://dl.bintray.com/hani-momanii/maven" }
    }
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
        exclude group: 'com.google.code.findbugs'
    })
    compile('com.twitter.sdk.android:twitter:2.3.1@aar') { transitive = true; }
    compile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') { transitive = true; }
    compile 'com.facebook.android:facebook-android-sdk:[4,5)'
    compile 'com.theartofdev.edmodo:android-image-cropper:2.3.1'
    compile 'com.android.support:appcompat-v7:25.0.0'
    compile 'com.android.support:cardview-v7:25.0.0'
    compile 'com.android.support:design:25.0.0'
    compile 'net.gotev:uploadservice:2.1'
    compile 'com.android.support:recyclerview-v7:25.0.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'hani.momanii.supernova_emoji_library:supernova-emoji-library:0.0.2'
    compile 'com.google.android.gms:play-services:11.0.4'
    compile 'com.google.firebase:firebase-core:10.2.1'
    compile 'com.google.code.gson:gson:2.3'
    compile 'org.apache.httpcomponents:httpcore:4.3.2'
    compile 'org.apache.httpcomponents:httpmime:4.3.3'
    compile 'com.mcxiaoke.volley:library:1.0.17'
    compile 'com.github.clans:fab:1.6.2'
    compile 'org.jsoup:jsoup:1.8.1'
    compile 'com.parse.bolts:bolts-tasks:1.4.0'
    compile 'com.commit451:PhotoView:1.2.4'
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.splitwise:tokenautocomplete:1.3.3'
    compile 'com.tubb.smrv:swipemenu-recyclerview:5.2.1'
    compile 'com.github.bumptech.glide:glide:3.5.2'
    compile 'se.emilsjolander:stickylistheaders:2.7.0'
    compile 'com.mindorks:placeholderview:0.6.4'
    compile 'org.twitter4j:twitter4j-core:4.0.2'
    compile 'jp.wasabeef:fresco-processors:2.1.0'
    compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.3.0'
    compile 'com.google.firebase:firebase-messaging:10.2.1'
    compile 'com.android.billingclient:billing:1.0'

    testCompile 'junit:junit:4.12'
    compile project(':cometchat_platinum-sdk')

}

apply plugin: 'com.google.gms.google-services'

i have not used v-27 then why i am facing v7 issue
thanks in advance

Body:
Add allprojects block in your app level build file

1.

 allprojects {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com'
        }}}

2.
New projects created using Android Studio 3.0 and higher also include

allprojects {
repositories {
    jcenter()
    google()
}}

And change your compileSdkVersion to 26 and also buildToolsVersion "26.0.1" then sync your project

Hope this will help you.


问:
Laravel collection pluck dropping a value
I have the following Eloquent query in a Laravel 5.2 project:

```<code>$regsByCtryCollection = Organisation::join('countries_currencies', 'countries_currencies.id', '=', 'organisations.country_id')
   ->select(DB::raw('DISTINCT LCASE(countries_currencies.country_code) AS ctry, COUNT(organisations.id) AS val'))
   ->groupBy('ctry')
   ->get();
</code>```

The raw query produces this output:

```<code>ctry val
at   1
au   5
br   1
</code>```

The Eloquent call produces a collection of three rows (matching raw query output) like this:

```<code>Collection {#791 ▼
  #items: array:3 [▼
    0 => Organisation {#777 ▼
      #table: "organisations"
      #hidden: []
      ........
      #attributes: array:2 [▶]
      #original: array:2 [▼
        "ctry" => "at"
        "val" => 1
      ]
      #relations: array:5 [▶]
      ........
    }
    1 => Organisation {#778 ▶}
    2 => Organisation {#779 ▶}
  ]
}
</code>```

I then pluck the values and format for Highmaps like this

```<code>$regsByCtry = $regsByCtryCollection->pluck('ctry', 'val')->map(function($country, $value) {
   return [
       "hc-key" => $country,
        "value"  => $value
   ];
})->values()->toJson();
</code>```

And one of the values is dropped and I get this:

```<code>[
    {"hc-key":"br","value":1},
    {"hc-key":"au","value":5}
]
</code>```

Why is the first entry getting dropped?

```<code>{"hc-key":"at","value":1}
</code>```

I am using this same process with two other Eloquent queries and it works as expected, but just not on this collection.

Additionally, I also sum all the values in the array of objects like this:

```<code>$regsTotal = array_sum($regsByCtryCollection->pluck('val')->toArray());
</code>```

And I get the correct value, including all three records summed:

```<code>$regsTotal = 7;
</code>```

答:
The issue is with pluck('ctry', 'val'). This will return val as key & ctry as value. In your query output at & br has same value 1. So one of it getting replaced by the other one.

Try pluck('val', 'ctry')->map(function($value, $country)

Reference

Body:
I have the following Eloquent query in a Laravel 5.2 project:

$regsByCtryCollection = Organisation::join('countries_currencies', 'countries_currencies.id', '=', 'organisations.country_id')
   ->select(DB::raw('DISTINCT LCASE(countries_currencies.country_code) AS ctry, COUNT(organisations.id) AS val'))
   ->groupBy('ctry')
   ->get();

The raw query produces this output:

ctry val
at   1
au   5
br   1

The Eloquent call produces a collection of three rows (matching raw query output) like this:

Collection {#791 ▼
  #items: array:3 [▼
    0 => Organisation {#777 ▼
      #table: "organisations"
      #hidden: []
      ........
      #attributes: array:2 [▶]
      #original: array:2 [▼
        "ctry" => "at"
        "val" => 1
      ]
      #relations: array:5 [▶]
      ........
    }
    1 => Organisation {#778 ▶}
    2 => Organisation {#779 ▶}
  ]
}

I then pluck the values and format for Highmaps like this

$regsByCtry = $regsByCtryCollection->pluck('ctry', 'val')->map(function($country, $value) {
   return [
       "hc-key" => $country,
        "value"  => $value
   ];
})->values()->toJson();

And one of the values is dropped and I get this:

[
    {"hc-key":"br","value":1},
    {"hc-key":"au","value":5}
]

Why is the first entry getting dropped?

{"hc-key":"at","value":1}

I am using this same process with two other Eloquent queries and it works as expected, but just not on this collection.

Additionally, I also sum all the values in the array of objects like this:

$regsTotal = array_sum($regsByCtryCollection->pluck('val')->toArray());

And I get the correct value, including all three records summed:

$regsTotal = 7;


问:
Scala Existential Types for Multi Parameter F-Bounded Polymorphic Types
I am using a library with a class that has a definition that looks like this:

```<code>abstract class ParentClass[X, Y <: ParentClass[X, Y, M], M <: OtherClass[X, M]]
</code>```

This class has subclasses that extend this class like so:

```<code>abstract class ChildClass[B, C <: ChildClass[B, C, D], D <: OtherChildClass[B, D]] extends ParentClass[B, C, D]
</code>```

And that subclass has subclasses that extend it in this manner:

```<code>class SomeClass extends ChildClass[F, SomeClass, SomeOtherClass]
</code>```

How would I go about handling generics for ParentClass? For example, if I wanted to create an Array of objects that share the same ancestor type ParentClass, I could do this:

```<code>getArrayOfParentClass(): Array[ParentClass[_, _, _]]
</code>```

But this doesn't respect the type bounds proposed in the class definition.

It seems like existential types are one of the main solutions for F-Bounded Polymorphic types, but I can't seem to figure out a solution using existential types that handles this case, nor have I seen any examples with regards to existential types with classes that have more than 1 type parameter.  I imagine it would work something like this, but haven't been able to quite figure it out:

```<code>// Doesn't compile
getArrayOfParentClass(): Array[X forSome {type X <: ParentClass[A, X, M forSome {type M <: OtherClass[A, M]}]
</code>```

答:
The syntax you want is</p>

```<code>Array[X forSome { type X <: ParentClass[A, X, M]; type M <: OtherClass[A, M] }]
</code>```

Body:
I am using a library with a class that has a definition that looks like this:

abstract class ParentClass[X, Y <: ParentClass[X, Y, M], M <: OtherClass[X, M]]

This class has subclasses that extend this class like so:

abstract class ChildClass[B, C <: ChildClass[B, C, D], D <: OtherChildClass[B, D]] extends ParentClass[B, C, D]

And that subclass has subclasses that extend it in this manner:

class SomeClass extends ChildClass[F, SomeClass, SomeOtherClass]

How would I go about handling generics for ParentClass? For example, if I wanted to create an Array of objects that share the same ancestor type ParentClass, I could do this:

getArrayOfParentClass(): Array[ParentClass[_, _, _]]

But this doesn't respect the type bounds proposed in the class definition.

It seems like existential types are one of the main solutions for F-Bounded Polymorphic types, but I can't seem to figure out a solution using existential types that handles this case, nor have I seen any examples with regards to existential types with classes that have more than 1 type parameter.  I imagine it would work something like this, but haven't been able to quite figure it out:

// Doesn't compile
getArrayOfParentClass(): Array[X forSome {type X <: ParentClass[A, X, M forSome {type M <: OtherClass[A, M]}]

Body:
The syntax you want is

Array[X forSome { type X <: ParentClass[A, X, M]; type M <: OtherClass[A, M] }]