问:
Getting numbers from xml element with regex
I have element that have two numbers, separated by [-], for example 120-125.
Now using xslt I want to get these two numbers and create the xml elements with these value, and finally I want something like this:

```<code><first>120</first>
<second>125</second>
</code>```

How can I achieve this?

EDIT

My xml structure to change looks like this:

```<code><issue>
    <number>3</number>
    <year>2017</year>
    <article>
        <title>Title</title>
        <author>
            <firstname>name</firstname>
        </author>
        <pages>71-72</pages>
        <reference>reference</reference>
    </article>
</issue>
</code>```

XSLT:

```<code><issue>
    <number>
        <xsl:value-of select="number"/>
    </number>
    <year>
        <xsl:value-of select="year"/>
    </year>
    <xsl:for-each select="article">
        <article>
            <title>
                <xsl:value-of select="title"/>
            </title>
            <author>
                <firstname>
                    <xsl:value-of select="firstname"/>
                </firstname>
            </author>
            <xsl:template match="pages">
                <xsl:copy>
                    <first>
                        <xsl:value-of select="substring-before(., '-')" />
                    </first>
                    <second>
                        <xsl:value-of select="substring-after(., '-')" />
                    </second>
                </xsl:copy>
            </xsl:template>
            <reference>
                <xsl:value-of select="reference"/>
            </reference>
        </article>
    </issue>
</code>```

Output XML that I want to have:

```<code><issue>
    <number>3</number>
    <year>2017</year>
    <article>
        <title>Title</title>
        <author>
            <firstname>name</firstname>
        </author>
        <first>71</first>
        <second>71</second>
        <reference>reference</reference>
    </article>
</issue>
</code>```

答:
You cannot have a <xsl:template match="pages"> inside <xsl:for-each>. Considering the XSL that you have shared, you need to modify it as below. I have just modified the code for splitting the value of <pages>. The rest of your code remains unchanged.

```<code><xsl:for-each select="article">
    <article>
        ...
        <first><xsl:value-of select="substring-before(pages, '-')" /></first>
        <second><xsl:value-of select="substring-after(pages, '-')" /></second>
        ...
    </article>
</xsl:for-each>
</code>```

Body:
I have element that have two numbers, separated by [-], for example 120-125.
Now using xslt I want to get these two numbers and create the xml elements with these value, and finally I want something like this:

<first>120</first>
<second>125</second>

How can I achieve this?

EDIT

My xml structure to change looks like this:

<issue>
    <number>3</number>
    <year>2017</year>

        <title>Title</title>
        <author>
            <firstname>name</firstname>
        </author>
        <pages>71-72</pages>
        <reference>reference</reference>

</issue>

XSLT:

<issue>
    <number>
        <xsl:value-of select="number"/>
    </number>
    <year>
        <xsl:value-of select="year"/>
    </year>
    <xsl:for-each select="article">

            <title>
                <xsl:value-of select="title"/>
            </title>
            <author>
                <firstname>
                    <xsl:value-of select="firstname"/>
                </firstname>
            </author>
            <xsl:template match="pages">
                <xsl:copy>
                    <first>
                        <xsl:value-of select="substring-before(., '-')" />
                    </first>
                    <second>
                        <xsl:value-of select="substring-after(., '-')" />
                    </second>
                </xsl:copy>
            </xsl:template>
            <reference>
                <xsl:value-of select="reference"/>
            </reference>

    </issue>

Output XML that I want to have:

<issue>
    <number>3</number>
    <year>2017</year>

        <title>Title</title>
        <author>
            <firstname>name</firstname>
        </author>
        <first>71</first>
        <second>71</second>
        <reference>reference</reference>

</issue>

Body:
You cannot have a <xsl:template match="pages"> inside <xsl:for-each>. Considering the XSL that you have shared, you need to modify it as below. I have just modified the code for splitting the value of <pages>. The rest of your code remains unchanged.

<xsl:for-each select="article">
    <article>
        ...
        <first><xsl:value-of select="substring-before(pages, '-')" /></first>
        <second><xsl:value-of select="substring-after(pages, '-')" /></second>
        ...
    </article>
</xsl:for-each>


来源: stackexchange

问:
css floating and iexplorer
i have two divs, that float correctly in chrome, ff and safari but not iexplorer, the right div appears below the left div floated to the right- the two divs are wrapped by an outer div with a width of 800px;</p>

```<code><div class="b_left">

</div>

<div class="b_right">

</div>

.b_left{
        width:350px;
        margin-left:80px;
        float:left;
        display: block;
    }

    .b_right{
        float:right;
        width:350px;
        height:280px;
        background-color:#c8c8c8;
        display: block;

    }
</code>```

答:
Just put margin: 0; padding: 0; on all three divs and go from there to check. Also reset styles are a MUST for IE, I use Eric Meyer's. (easy to Google).

Also, display: inline; on the one with margin will fix it for IE6 I suspect.

ContentLicense: CC BY-SA 2.5

Title: css floating and iexplorer

Body:
i have two divs, that float correctly in chrome, ff and safari but not iexplorer, the right div appears below the left div floated to the right- the two divs are wrapped by an outer div with a width of 800px;

.b_left{
        width:350px;
        margin-left:80px;
        float:left;
        display: block;
    }

    .b_right{
        float:right;
        width:350px;
        height:280px;
        background-color:#c8c8c8;
        display: block;

    }


问:
Trying to decipher a hexadecimal code
I have been doing a programming challenge and i'm on the final question, which involves deciphering a hexadecimal code to reveal a secret code. the answer must start with 0x so it must be another hexadecimal value but i am unable to figure out how to decipher the following hex value:

0xB105F00D 0x6FA83E1C

Some help on how to decipher this code or the deciphered message would be very helpful.

答:
Can you give the whole content of the task?

Did you try to perform basic bit operations (or, and, nand, etc...) on these values?

Maybe the answer is 0x215231EE because

0xB105F00D XNOR 0x215231EE === 0x6FA83E1C

From the guidelines you provided, it is difficult to guess the answer without knowing the profile and type of tasks you had.

Because the answer is to be the hexadecimal value, I think you should find a correlation between your values, taking into account other forms of writing.

ContentLicense: CC BY-SA 3.0

Title: Trying to decipher a hexadecimal code


问:
How to connect to RMAN in Java?
I don't know how to connect to RMAN in Java. Simple request don't work when I use command non-SQL, like RMAN etc... I'm gonna to make program like "ORACLE Secure BackUP", but how they connected to RMAN??</p>

答:
I don't believe that there is a published API for interacting with RMAN other than the command line.  So if you wanted to create a program like Oracle Secure Backup that used RMAN, you'd probably have to invoke the RMAN executable from Java.  Which means that you'd probably also have to parse the output of the various RMAN commands in order to provide feedback to the user.

If you want to go down this path, you'd want to use the Runtime class in Java.  Here is an example of calling an external program from Java.

Title: How to connect to RMAN in Java?


问:
301 redirect https (old site) to http (new site) in htaccess or otherwise
I must have read every answer here 100 times but I still cannot get this to work (maybe my VPS) but I am also pesting my hosts and they cant crack it either.

Old website https://www.olddomain.co.uk i want to 301 to new website http://newdomain.com.

I have tried every conceivable htaccess code / rules I can find but still no good.

Any ideas these are the 2 I have been working with below but seems like htaccess doesn't recognise the SSL and therefore run the rule to redirect.

```<code>RewriteEngine on

# First rule - if this is an SSL connection, then redirect
# to http://enginecoreplugs.com then stop processing other rules
RewriteCond %{HTTPS} on
RewriteRule (.*) http://enginecoreplugs.com/$1 [R=301,L]

# Second rule - all other requests, redirect to http://enginecoreplugs.com.
RewriteRule (.*) http://enginecoreplugs.com/$1 [R=301,L]
</code>```

OR

```<code>RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</code>```

If it helps at all, old website I am wanting to 301 = https://www.enginecoreplugs.co.uk new website = http://enginecoreplugs.com.

Thanks in advance!!

Will

答:
I had everything correct.

This ended up being some stupid problem at the hosts forwarding the https versions.

Body:
I must have read every answer here 100 times but I still cannot get this to work (maybe my VPS) but I am also pesting my hosts and they cant crack it either.

Old website https://www.olddomain.co.uk i want to 301 to new website http://newdomain.com.

I have tried every conceivable htaccess code / rules I can find but still no good.

Any ideas these are the 2 I have been working with below but seems like htaccess doesn't recognise the SSL and therefore run the rule to redirect.

RewriteEngine on

# First rule - if this is an SSL connection, then redirect
# to http://enginecoreplugs.com then stop processing other rules
RewriteCond %{HTTPS} on
RewriteRule (.*) http://enginecoreplugs.com/$1 [R=301,L]

# Second rule - all other requests, redirect to http://enginecoreplugs.com.
RewriteRule (.*) http://enginecoreplugs.com/$1 [R=301,L]

OR

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

If it helps at all, old website I am wanting to 301 = https://www.enginecoreplugs.co.uk new website = http://enginecoreplugs.com.

Thanks in advance!!

Will


问:
How to rename key of object in an array
How to replace array element value with another

i have array like this, without using jquery

```<code> this.products = [
      {
        text: 'prod1',
        value: 1
      },
      {
        text: 'prod2',
        value: 2
      },
      {
        text: 'prod3',
        value: 3
      }
 ];
</code>```

i want to replace 'text' to  'label'

答:
How about this?

var products = [{
    text: 'prod1',
    value: 1
  },
  {
    text: 'prod2',
    value: 2
  }, {
    text: 'prod3',
    value: 3
  }
];

products.forEach(function(obj) {
  obj.label = obj.text;
  delete obj.text;
});
console.log(products);```

Title: How to rename key of object in an array

Body:
How to replace array element value with another

i have array like this, without using jquery

 this.products = [
      {
        text: 'prod1',
        value: 1
      },
      {
        text: 'prod2',
        value: 2
      },
      {
        text: 'prod3',
        value: 3
      }
 ];

i want to replace 'text' to  'label'


问:
How to hide certain columns (from a table) on mobile?
I am having great problems with using tables - they look perfect on a desktop - but not on mobile.
So here's a break up of what I want to do:

If @media screen is 600px then the number of columns = 3& the number of rows = 3

if @media screen is 460px or less then columnCount = 2, rowCount = 4

and columnCount = 4, rowCount =4 on desktop

How can I achieve this?

答:
You can use this nice solution on mobile from CSS tricks. This solution makes your table accessible on mobile, even is the screen is too narrow. It does NOT hide any columns (thus it makes your table truly responsive).

html,body {
  margin: 20px;
  padding: 0;
  height: 100%;
}

body {
  display: flex;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  font-size: 90%;
  color: #333;
  justify-content: center;
}

.table-wrapper {
  max-width: 700px;
  overflow: scroll;
}

table {
  position: relative;
  border: 1px solid #ddd;
  border-collapse: collapse;
}

td, th {
  white-space: nowrap;
  border: 1px solid #ddd;
  padding: 20px;
  text-align: center;
}

th {
  background-color: #eee;
  position: sticky;
  top: -1px;
  z-index: 2;

  &:first-of-type {
    left: 0;
    z-index: 3;
  }
}

tbody tr td:first-of-type {
  background-color: #eee;
  position: sticky;
  left: -1px;
  text-align: left;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="table-wrapper">
  <table>
  <thead>
    <tr>
      <th></th>
      <th>A</th>
      <th>B</th>
      <th>C</th>
      <th>D</th>
      <th>E</th>
      <th>F</th>
      <th>G</th>
      <th>H</th>
      <th>I</th>
      <th>J</th>
      <th>K</th>
      <th>L</th>
      <th>M</th>
      <th>N</th>
      <th>O</th>
      <th>P</th>
      <th>Q</th>
      <th>R</th>
      <th>S</th>
      <th>T</th>
      <th>U</th>
      <th>V</th>
      <th>W</th>
      <th>X</th>
      <th>Y</th>
      <th>Z</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Anna</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
    </tr>
    <tr>
      <td>James</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
    </tr>
    <tr>
      <td>Jennifer</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
    </tr>
    <tr>
      <td>Jeremiah</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
    </tr>
    <tr>
      <td>Jocelyn</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
    </tr>
    <tr>
      <td>Benjamin</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
    </tr>
    <tr>
      <td>Zed</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
    </tr>
   <tr>
      <td>Frank</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
     <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
    </tr>
   <tr>
      <td>Chris</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
    </tr>
   <tr>
      <td>Sarah</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
    </tr>
   <tr>
      <td>Rob</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
    </tr>
   <tr>
      <td>Danielle</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
    </tr>
   <tr>
      <td>Jessica</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
    </tr>
  </tbody>
</table>
</div></code>```

Note that an a desktop your table should fit normally. On mobile it obvioulsy does not. There you need some CSS tricks to get things to work. This code makes that happen.

Source and documentation: https://css-tricks.com/idea-simple-responsive-spreadsheet/

Body:
You can use this nice solution on mobile from CSS tricks. This solution makes your table accessible on mobile, even is the screen is too narrow. It does NOT hide any columns (thus it makes your table truly responsive).

html,body {
  margin: 20px;
  padding: 0;
  height: 100%;
}

body {
  display: flex;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  font-size: 90%;
  color: #333;
  justify-content: center;
}

.table-wrapper {
  max-width: 700px;
  overflow: scroll;
}

table {
  position: relative;
  border: 1px solid #ddd;
  border-collapse: collapse;
}

td, th {
  white-space: nowrap;
  border: 1px solid #ddd;
  padding: 20px;
  text-align: center;
}

th {
  background-color: #eee;
  position: sticky;
  top: -1px;
  z-index: 2;

  &:first-of-type {
    left: 0;
    z-index: 3;
  }
}

tbody tr td:first-of-type {
  background-color: #eee;
  position: sticky;
  left: -1px;
  text-align: left;
}

<div class="table-wrapper">
  <table>
  <thead>
    <tr>
      <th></th>
      <th>A</th>
      <th>B</th>
      <th>C</th>
      <th>D</th>
      <th>E</th>
      <th>F</th>
      <th>G</th>
      <th>H</th>
      <th>I</th>
      <th>J</th>
      <th>K</th>
      <th>L</th>
      <th>M</th>
      <th>N</th>
      <th>O</th>
      <th>P</th>
      <th>Q</th>
      <th>R</th>
      <th>S</th>
      <th>T</th>
      <th>U</th>
      <th>V</th>
      <th>W</th>
      <th>X</th>
      <th>Y</th>
      <th>Z</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Anna</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
    </tr>
    <tr>
      <td>James</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
    </tr>
    <tr>
      <td>Jennifer</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
    </tr>
    <tr>
      <td>Jeremiah</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
    </tr>
    <tr>
      <td>Jocelyn</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
    </tr>
    <tr>
      <td>Benjamin</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
      <td>6</td>
    </tr>
    <tr>
      <td>Zed</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
      <td>7</td>
    </tr>
   <tr>
      <td>Frank</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
     <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
      <td>8</td>
    </tr>
   <tr>
      <td>Chris</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
      <td>9</td>
    </tr>
   <tr>
      <td>Sarah</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
      <td>10</td>
    </tr>
   <tr>
      <td>Rob</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
      <td>11</td>
    </tr>
   <tr>
      <td>Danielle</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
      <td>12</td>
    </tr>
   <tr>
      <td>Jessica</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
      <td>13</td>
    </tr>
  </tbody>
</table>
</div>

Note that an a desktop your table should fit normally. On mobile it obvioulsy does not. There you need some CSS tricks to get things to work. This code makes that happen.

Source and documentation: https://css-tricks.com/idea-simple-responsive-spreadsheet/


问:
PHP array_filter return from multidimensional array
```<code>PHP Data = $data['Sold_items']:
[Sold_items] => Array
(
    [0] => Array
        (
            [CGST_Percentage] => 9
            [SGST_Percentage] => 9
        )

    [1] => Array
        (
            [CGST_Percentage] => 9
            [SGST_Percentage] => 9
        )

)

PHP Array Filter Line:
    $GST_Percentage = 9;
    array_filter($data['Sold_items'], $this->sold_item_by_gst_percentage($data['Sold_items'], $GST_Percentage);

PHP sold_item_by_gst_percentage function:

private function sold_item_by_gst_percentage($GST, $GST_Percentage){
    return ($GST['CGST_Percentage'] == $GST_Percentage);
}
</code>```

Anyone can Please tell me why it displaying notice Undefined index: CGST_Percentage and warning array_filter() expects parameter 2 to be a valid callback, no array or string givenHow can I resolve this please help me.

答:
http://php.net/array_filter
"The callback function to use"

You not define function to call, you use it, call it. If you not know how, you can use doublecall. Copyed from example 3

```<code>array_filter($arr, function($value)
   {
    global $xxx;
    return $this->sold_item_by_gst_percentage($row, $xxx);
   }, ARRAY_FILTER_USE_KEY)
</code>```

Or, you use yourself filter by foreach

```<code>function myFilter($arr,$your_value,$your_index='CGST_Percentage')
    {
    foreach ($arr as $index=>$row)
        if ($row[$your_index]==$your_value)
            return $row;
    }
---
// $arr = $data['Sold_items']
// $your_index = 'CGST_Percentage'
// $your_value = $GST_Percentage
</code>```

Body:
PHP Data = $data['Sold_items']:
[Sold_items] => Array
(
    [0] => Array
        (
            [CGST_Percentage] => 9
            [SGST_Percentage] => 9
        )

    [1] => Array
        (
            [CGST_Percentage] => 9
            [SGST_Percentage] => 9
        )

)

PHP Array Filter Line:
    $GST_Percentage = 9;
    array_filter($data['Sold_items'], $this->sold_item_by_gst_percentage($data['Sold_items'], $GST_Percentage);

PHP sold_item_by_gst_percentage function:

private function sold_item_by_gst_percentage($GST, $GST_Percentage){
    return ($GST['CGST_Percentage'] == $GST_Percentage);
}

Anyone can Please tell me why it displaying notice Undefined index: CGST_Percentage and warning array_filter() expects parameter 2 to be a valid callback, no array or string givenHow can I resolve this please help me.

Body:
http://php.net/array_filter
"The callback function to use"

You not define function to call, you use it, call it. If you not know how, you can use doublecall. Copyed from example 3

array_filter($arr, function($value)
   {
    global $xxx;
    return $this->sold_item_by_gst_percentage($row, $xxx);
   }, ARRAY_FILTER_USE_KEY)

Or, you use yourself filter by foreach

function myFilter($arr,$your_value,$your_index='CGST_Percentage')
    {
    foreach ($arr as $index=>$row)
        if ($row[$your_index]==$your_value)
            return $row;
    }
---
// $arr = $data['Sold_items']
// $your_index = 'CGST_Percentage'
// $your_value = $GST_Percentage


问:
How to insert moment JS time into MySQL
```<code>//In Node/JS
myDate = moment(data.myTime.format('YYYY/MM/DD HH:MM:SS')).toISOString();
//myDate shows '2014-09-24T04:09:00.000Z'

Insert INTO (dateColumn..) Values(myDate)...
</code>```

This is the error I get after inserting, note column in Mysql is a "datetime" type.

MySQL Error:: { [Error: ER_TRUNCATED_WRONG_VALUE: Incorrect datetime value: '2014-09- 24T04:09:00.000Z' for column '_dateColumn' at row 1]
      code: 'ER_TRUNCATED_WRONG_VALUE',

Title: How to insert moment JS time into MySQL

Body:
//In Node/JS
myDate = moment(data.myTime.format('YYYY/MM/DD HH:MM:SS')).toISOString();
//myDate shows '2014-09-24T04:09:00.000Z'

Insert INTO (dateColumn..) Values(myDate)...

This is the error I get after inserting, note column in Mysql is a "datetime" type.

MySQL Error:: { [Error: ER_TRUNCATED_WRONG_VALUE: Incorrect datetime value: '2014-09- 24T04:09:00.000Z' for column '_dateColumn' at row 1]
      code: 'ER_TRUNCATED_WRONG_VALUE',

Body: moment().format("YYYY-MM-DD HH:mm:ss")


问:
Manual Login flow with Facebook in Mac os App
I am learning mac app development and i want to implement login with Facebook in my mac OS app. But i try to find SDK of Facebook in developer account but did not got any SDK for mac. I read somewhere that we can implement manually login flow using Facebook graph API but i don't know how to implement. Any one did Facebook login for mac desktop app than please suggest me how to implement.

Thank you.

答:
Manually Build a Login Flow
https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow?locale=en_US

Anyone implemented this approach under macOS?


问:
Access to a single pixel in C#
I'm working on a school project right now. It's meant to be a 3D editing software, (like a very minimized version of Maya). I have to write it in C#, using the 'Windows Application Project'.
I intend to implement all the 3D stuff myself, from projections to shading.
My question is, how can I get direct access to a single pixel in the C# windows application?
I know I'm going to have a main view port in the window. But I haven't decided yet how it will be made. Is there a built in object that I can use, that will let me define the boundaries of the view port, and then paint each pixel individually?
(I'm just shooting in the dark here, I don't know much about C#. I mostly program in C)

Thanks,
Malki.

答:
A 3D editor application needs not only to draw on the screen - it needs to do it damn fast. The standard approach in .NET would be using Bitmap and Graphics classes, like described by person-b. But this will be slow. You can improve speed by using Bitmap.LockBits() and clever optimizations, but all in all I doubt you will still get the performance you need. You'll eat away all the CPU and will still be stuck with less than some 10-20 FPS (number is a wild guess). Hardware acceleration is the real way to go. shuggycouk has links in the right direction.

Unfortunately the hardware approach will also take away the projections and shading, because that's what the hardware is there for. So I don't know if you can use that... Perhaps seek information on "overlays" in .NET. That's the way all the media player software display movies. It's definately way faster than standard GDI/GDI+ and is still 2D. Or perhaps you could do a tricky workaround with DirectX - use it for drawing 2D shapes you define yourself. ;)

OwnerDisplayName: Malki

Title: Access to a single pixel in C#

OwnerDisplayName: Vilx-


问:
python+selenium xpath Unable to locate element
```<code>company_name = 'google'
browser.get('https://m.tianyancha.com/search?key=&checkFrom=searchBox')
ele = browser.find_element_by_xpath("//input[@id='live-search']")
ele.clear()
ele.send_keys(company_name, Keys.ENTER)
name = browser.find_element_by_xpath(
            "//div[@class='new-border-bottom pt5 pb5 ml15 mr15'][1]//a[@class='query_name in-block']/span/em")

if name.text:
    if name.text == company_name:
        check = '1'
    else:
        check = '0'
else:
    check = '0'
</code>```

the error is :

NoSuchElementException: Message: no such element: Unable to locate
  element: {"method":"xpath","selector":"//div[@class='new-border-bottom
  pt5 pb5 ml15 mr15'][1]//a[@class='query_name in-block']/span/em"}

答:
Your relative Xpath is wrong.

```<code>name = browser.find_element_by_xpath(
            "//div[@class='new-border-bottom pt5 pb5 ml15 mr15'][1]//a[@class='query_name in-block']/span/em"
</code>```

you cannot have // two times in your xpath. // means relative from the element you start with.

Check your Xpath for name.

Body:
company_name = 'google'
browser.get('https://m.tianyancha.com/search?key=&checkFrom=searchBox')
ele = browser.find_element_by_xpath("//input[@id='live-search']")
ele.clear()
ele.send_keys(company_name, Keys.ENTER)
name = browser.find_element_by_xpath(
            "//div[@class='new-border-bottom pt5 pb5 ml15 mr15'][1]//a[@class='query_name in-block']/span/em")

if name.text:
    if name.text == company_name:
        check = '1'
    else:
        check = '0'
else:
    check = '0'

the error is :

NoSuchElementException: Message: no such element: Unable to locate
  element: {"method":"xpath","selector":"//div[@class='new-border-bottom
  pt5 pb5 ml15 mr15'][1]//a[@class='query_name in-block']/span/em"}

Body:
Your relative Xpath is wrong.

name = browser.find_element_by_xpath(
            "//div[@class='new-border-bottom pt5 pb5 ml15 mr15'][1]//a[@class='query_name in-block']/span/em"

you cannot have // two times in your xpath. // means relative from the element you start with.

Check your Xpath for name.


问:
Any possible to way to ignore decorators only for tests?
I am currently running in to an issue with decorators in my unit tests written for a reactjs application.

I love the way we avoid so much boilerplate by introducing decorators in our react components, components are looking clean and code become more readable with this.
But now feeling irritated too much this nonsense decorators, because I am unable to run a single unit test which is a must test in my application context. Code described below:

```<code>@translate(['common'])
export default class MyComponent extends React.Component {
 ...
 componentDidMount() {
  // Ajax call on success setting the state this.setState({ myData: response.data })
 }
 ...
}
</code>```

Want to test this component state, I received from a ajax success response.

My test looks as below

```<code>describe('<MyComponent />', function () {
 sinon.stub(dataService, 'fetchData')
  callsFake(function () {
   return Promise.resolve(['one', 'two', 'three'])
  });
 it('should match the state with data fetched', function () {
  const wrapper = mount(<MyComponent />);
  return dataService.fetchData()
   .then(function () {
    expect(wrapper.state('myData')).to.have.lengthOf(3);
   });
 });
});
</code>```

Above test works well if I remove @translate(['common']) from my component, but doesn't work if exists.
I know translate is a HOC and I need to adjust my test accordingly but believe me I tried everything, nothing works for me.
Also there is a way to get this working by adding multiple export in component one is pure and other is wrapped with translate but for this solution also I have to drop the decorators which I like to have in my source code.

So is there any way we can configure our webpack to ignore or skip these decorators from my source code during running my tests?

答:
Because decorators are just sugar for Higher-Order Functions you can separate the class declaration and the decoration of the class, however you lose the pretty @ decoration syntax because you can only use decorators on an export when exporting a class:

```<code>export class MyComponent extends React.Component {
 ...
 componentDidMount() {
  // Ajax call on success setting the state this.setState({ myData: response.data })
 }
 ...
}

export default translate(['common'])(MyComponent)
</code>```

In your tests you can now import the underlying, "undecorated" class:

```<code>import {MyComponent} from '...'
</code>```

So is there any way we can configure our webpack to ignore or skip these decorators from my source code during running my tests?

I don't believe there exists any way to make webpack ignore the decoration of classes. It would be possible to create some plugin that parsed files and removed decoration statements, but this is overkill and would have myriad implications on other parts of the application development and build process.

Body:
I am currently running in to an issue with decorators in my unit tests written for a reactjs application.

I love the way we avoid so much boilerplate by introducing decorators in our react components, components are looking clean and code become more readable with this.
But now feeling irritated too much this nonsense decorators, because I am unable to run a single unit test which is a must test in my application context. Code described below:

@translate(['common'])
export default class MyComponent extends React.Component {
 ...
 componentDidMount() {
  // Ajax call on success setting the state this.setState({ myData: response.data })
 }
 ...
}

Want to test this component state, I received from a ajax success response.

My test looks as below

describe('<MyComponent />', function () {
 sinon.stub(dataService, 'fetchData')
  callsFake(function () {
   return Promise.resolve(['one', 'two', 'three'])
  });
 it('should match the state with data fetched', function () {
  const wrapper = mount(<MyComponent />);
  return dataService.fetchData()
   .then(function () {
    expect(wrapper.state('myData')).to.have.lengthOf(3);
   });
 });
});

Above test works well if I remove @translate(['common']) from my component, but doesn't work if exists.
I know translate is a HOC and I need to adjust my test accordingly but believe me I tried everything, nothing works for me.
Also there is a way to get this working by adding multiple export in component one is pure and other is wrapped with translate but for this solution also I have to drop the decorators which I like to have in my source code.

So is there any way we can configure our webpack to ignore or skip these decorators from my source code during running my tests?

Body:
Because decorators are just sugar for Higher-Order Functions you can separate the class declaration and the decoration of the class, however you lose the pretty @ decoration syntax because you can only use decorators on an export when exporting a class:

export class MyComponent extends React.Component {
 ...
 componentDidMount() {
  // Ajax call on success setting the state this.setState({ myData: response.data })
 }
 ...
}

export default translate(['common'])(MyComponent)

In your tests you can now import the underlying, "undecorated" class:

import {MyComponent} from '...'

So is there any way we can configure our webpack to ignore or skip these decorators from my source code during running my tests?

I don't believe there exists any way to make webpack ignore the decoration of classes. It would be possible to create some plugin that parsed files and removed decoration statements, but this is overkill and would have myriad implications on other parts of the application development and build process.


问:
Telegraf parsing logstash-style "grok" patterns
I have been trying to ingest data into influx from a log file. The structure is as follows

```<code>20171130-22:02:21.832 : something data work now
20171230-22:02:22.843 : something data2
20171231-22:02:23.232 : something data3
</code>```

I have used this pattern

```<code>[inputs.logparser.grok]
        #patterns = ['%{ts-"20060102-15:04:05.999":timestamp}%{GREEDYDATA:random_data}']
        patterns = ['(?<timestamp>\d{8}-\d{2}:\d{2}:\d{2}\.\d+)\s*:\s*%{GREEDYDATA:random_data}']
</code>```

Can I get help regarding formulating the pattern ?

答:
You may use

```<code>(?<timestamp>\d{8}-\d{2}:\d{2}:\d{2}\.\d+)\s*:\s*%{GREEDYDATA:random_data}
</code>```

Details

(?<timestamp>\d{8}-\d{2}:\d{2}:\d{2}\.\d+) - timestamp field pattern:

\d{8} - 9 digits

- - a hyphen

\d{2}:\d{2}:\d{2} - 2 digits, :, 2 digits, : and 2 digits

\.\d+ - a dot and 1+ digits

\s*:\s* - : enclosed with 0+ whitespace chars

%{GREEDYDATA:random_data} - a .*, anything up to the end of the line

Body:
I have been trying to ingest data into influx from a log file. The structure is as follows

20171130-22:02:21.832 : something data work now
20171230-22:02:22.843 : something data2
20171231-22:02:23.232 : something data3

I have used this pattern

[inputs.logparser.grok]
        #patterns = ['%{ts-"20060102-15:04:05.999":timestamp}%{GREEDYDATA:random_data}']
        patterns = ['(?<timestamp>\d{8}-\d{2}:\d{2}:\d{2}\.\d+)\s*:\s*%{GREEDYDATA:random_data}']

Can I get help regarding formulating the pattern ?

Body:
You may use

(?<timestamp>\d{8}-\d{2}:\d{2}:\d{2}\.\d+)\s*:\s*%{GREEDYDATA:random_data}

Details

(?<timestamp>\d{8}-\d{2}:\d{2}:\d{2}\.\d+) - timestamp field pattern:

\d{8} - 9 digits

- - a hyphen

\d{2}:\d{2}:\d{2} - 2 digits, :, 2 digits, : and 2 digits

\.\d+ - a dot and 1+ digits

\s*:\s* - : enclosed with 0+ whitespace chars

%{GREEDYDATA:random_data} - a .*, anything up to the end of the line


问:
How to store the result of each iteration of a for loop into an array in java
Score Finder (100 Marks)

Praveen is finding a job as a Computer Science teacher in school.
He has been rejected many times by different schools but this time he is determined to get the job.
He goes to the principal of the school St. Mary.

The principal says that in his school there is Grading and Credit system.
There are N subjects and each subject has a credit Ci attached to it (1 <= i <= N).
Each student gets a particular grade in each subject and each grade has a point value which are:

```<code>A = 10,
A(minus) = 9,
B = 8,
B(minus) = 7,
C = 6,
C(minus) = 5
</code>```

Now if there are 3 subjects of credits 4, 3 and 2 respectively and a particular student scores A(minus),
B and C in these 3 subjects respectively then his score would be calculated as follows:
Total Score=Summation of product of Grade point and corresponding credit for each subject.

```<code>= ( (9*4) + (3*8) + (2*6) ) = 72.
</code>```

He wants Praveen to tell total distinct Scores that are possible
to be given to a student given credits of N subjects by assigning different grades to each subject.

Input Format
Your function contains a single argument- a one-dimensional Integer Array A of N elements where each represents Credit of that subject.
The first line of input contains an Integer N denoting the size of the array.
Next N lines of input each containing an Integer denoting the credit Ci of ith subject

```<code>Constraints
1 <= N <= 100
1 <= Ci <= 5
</code>```

Output Format
You must return a single integer denoting the total number of scores that are possible to be given.

```<code>Sample TestCase 1
Input

2
1
2
Output

16
</code>```

now I am writing code like this

```<code>package javaapplication1;

import java.util.Scanner;

public class CandidateCode {
    private static void possibleCombination(int input) {
        int i=0;
        int[] a=new int[Grades.length];

        a[i]=input;
        System.out.println("the a is "+a[i]);
    }

    private static final int[] Grades = new int[]{10, 9, 8, 7, 6, 5, 4, 3, 2, 1};

    public static void main(String[] args) {
        int i=0,j,totalSummation=0;
        Scanner uInput = new Scanner(System.in);
        System.out.println("Enter length of Array:");
        int index = uInput.nextInt();
        int[] Credit = new int[index];
        for (i = 0; i <= Credit.length-1; i++) {
            Credit[i] = uInput.nextInt();
            System.out.println("credit is" + Credit[i]);
            for ( j = 0; j <= Grades.length - 1; j++) {
                totalSummation = +(Grades[j] * Credit[i]);
                possibleCombination(totalSummation);
                // System.out.println("total sum is " + totalSummation);
            }
        }
    }
}
</code>```

Now I want to store the values calculated in each iteration...
Meaning for
iteration first the values are 10,9,8,7,6,5,4,3,2,1
itertion second the values are 20,18,16,14,10,8,6,4,2

i want to sum each value of 1st iteration with all the values of 2nd iteration.
i,e 10+20, 10+18, 10+16, 10+14, 10+10, 10+8, 10+6, 10+4, 10+2
similarly for 9,8,7,6,5,4,3,2,1

To achieve this I need to store the values per iteration but I am stuck here, please guys help me to get rid of this problem thank you in advance.

答:
If you don't want to store in a multi-dimensional array then you need to store each iteration in single dimensional array as below. But this code will work only for two credits.

```<code>public class CandidateCode {

        private static int possibleCombination(int input)
        {   int i=0;
            int[] a=new int[Grades.length];
             a[i]=input;
              return a[i];

        }
        private static final int[] Grades = new int[]{10, 9, 8, 7, 6, 5, 4,
                           3, 2, 1};

        public static void main(String[] args) {
            int i=0,j,totalSummation=0;
            Scanner uInput = new Scanner(System.in);
            System.out.println("Enter length of Array:");
            int index = uInput.nextInt();
            int[] Credit = new int[index];
            int[] creditarr = new int[10];
            int[] credit1 = new int[10];
            int[] credit2 = new int[10];
            for (i = 0; i <= Credit.length-1; i++) {
                Credit[i] = uInput.nextInt();

                System.out.println("credit is" + Credit[i]);
                for ( j = 0; j <= Grades.length - 1; j++) {
                    totalSummation = +(Grades[j] * Credit[i]);
                     creditarr[j]=possibleCombination(totalSummation);
                     if(Credit[i]==1) {
                     credit1[j]=creditarr[j];
                     }
                     if(Credit[i]==2){
                     credit2[j]=creditarr[j];
                     }
                    }
                }

            for(int k=0;k<credit1.length;k++) {
                for(int l=0;l<credit2.length;l++) {
                    int final_no=credit1[k]+credit2[l];
                    System.out.println("final_no :"  +final_no);
                }
            }
            }

         }
</code>```

Is this what you want?

I guess the below code would be the best solution.This code will work for the no of credits you mention.

```<code>public class Candidate {
 private static final int[] Grades = new int[]{10, 9, 8, 7, 6, 5};

public static void main(String[] args) {
    // TODO Auto-generated method stub
    int i=0,score=0,totalsummation=0;
    Scanner uInput = new Scanner(System.in);
    System.out.println("Enter length of Array:");
    int arraylength = uInput.nextInt();
    int[] credits= new int[arraylength];
    ArrayList<Integer> combination = new ArrayList<Integer>();
    for (i = 0; i <credits.length; i++) {
        credits[i] = uInput.nextInt();
    }
    switch(credits.length) {
    case 1:
        for(int c1=10;c1>=5;c1--) {
            totalsummation = c1*credits[0];
            combination.add(totalsummation);
        }
        break;

    case 2:
        for(int g:Grades) {
            for(int c2=10;c2>=5;c2--) {
                totalsummation=g*credits[0]+c2*credits[1];
                combination.add(totalsummation);
            }
        }
        break;

    case 3:
            for(int g:Grades) {
            for(int c3=10;c3>=5;c3--) {
                totalsummation=g*credits[0]+c3*credits[1]+c3*credits[2];
                combination.add(totalsummation);
            }
        }
            break;
    case 4:
        for(int g:Grades) {
            for(int c4=10;c4>=5;c4--) {
                totalsummation=g*credits[0]+c4*credits[1]+c4*credits[2]+c4*credits[3];
                combination.add(totalsummation);
            }
        }
        break;

    case 5:
        for(int g:Grades) {
            for(int c5=10;c5>=5;c5--) {
                totalsummation=g*credits[0]+c5*credits[1]+c5*credits[2]+c5*credits[3]+c5*credits[4];
                combination.add(totalsummation);
            }
        }
        break;

        default:
            System.out.println("Invalid Input");
    }

 ArrayList<Integer> distinctnos =(ArrayList<Integer>) combination.stream().distinct().collect(Collectors.toList());
     System.out.println(distinctnos.size());            }
}
</code>```

Hope this answers your question.

Body:
Score Finder (100 Marks)

Praveen is finding a job as a Computer Science teacher in school.
He has been rejected many times by different schools but this time he is determined to get the job.
He goes to the principal of the school St. Mary.

The principal says that in his school there is Grading and Credit system.
There are N subjects and each subject has a credit Ci attached to it (1 <= i <= N).
Each student gets a particular grade in each subject and each grade has a point value which are:

A = 10,
A(minus) = 9,
B = 8,
B(minus) = 7,
C = 6,
C(minus) = 5

Now if there are 3 subjects of credits 4, 3 and 2 respectively and a particular student scores A(minus),
B and C in these 3 subjects respectively then his score would be calculated as follows:
Total Score=Summation of product of Grade point and corresponding credit for each subject.

= ( (9*4) + (3*8) + (2*6) ) = 72.

He wants Praveen to tell total distinct Scores that are possible
to be given to a student given credits of N subjects by assigning different grades to each subject.

Input Format
Your function contains a single argument- a one-dimensional Integer Array A of N elements where each represents Credit of that subject.
The first line of input contains an Integer N denoting the size of the array.
Next N lines of input each containing an Integer denoting the credit Ci of ith subject

Constraints
1 <= N <= 100
1 <= Ci <= 5

Output Format
You must return a single integer denoting the total number of scores that are possible to be given.

Sample TestCase 1
Input

2
1
2
Output

16

now I am writing code like this

package javaapplication1;

import java.util.Scanner;

public class CandidateCode {
    private static void possibleCombination(int input) {
        int i=0;
        int[] a=new int[Grades.length];

        a[i]=input;
        System.out.println("the a is "+a[i]);
    }

    private static final int[] Grades = new int[]{10, 9, 8, 7, 6, 5, 4, 3, 2, 1};

    public static void main(String[] args) {
        int i=0,j,totalSummation=0;
        Scanner uInput = new Scanner(System.in);
        System.out.println("Enter length of Array:");
        int index = uInput.nextInt();
        int[] Credit = new int[index];
        for (i = 0; i <= Credit.length-1; i++) {
            Credit[i] = uInput.nextInt();
            System.out.println("credit is" + Credit[i]);
            for ( j = 0; j <= Grades.length - 1; j++) {
                totalSummation = +(Grades[j] * Credit[i]);
                possibleCombination(totalSummation);
                // System.out.println("total sum is " + totalSummation);
            }
        }
    }
}

Now I want to store the values calculated in each iteration...
Meaning for
iteration first the values are 10,9,8,7,6,5,4,3,2,1
itertion second the values are 20,18,16,14,10,8,6,4,2

i want to sum each value of 1st iteration with all the values of 2nd iteration.
i,e 10+20, 10+18, 10+16, 10+14, 10+10, 10+8, 10+6, 10+4, 10+2
similarly for 9,8,7,6,5,4,3,2,1

To achieve this I need to store the values per iteration but I am stuck here, please guys help me to get rid of this problem thank you in advance.

Body:
If you don't want to store in a multi-dimensional array then you need to store each iteration in single dimensional array as below. But this code will work only for two credits.

public class CandidateCode {

        private static int possibleCombination(int input)
        {   int i=0;
            int[] a=new int[Grades.length];
             a[i]=input;
              return a[i];

        }
        private static final int[] Grades = new int[]{10, 9, 8, 7, 6, 5, 4,
                           3, 2, 1};

        public static void main(String[] args) {
            int i=0,j,totalSummation=0;
            Scanner uInput = new Scanner(System.in);
            System.out.println("Enter length of Array:");
            int index = uInput.nextInt();
            int[] Credit = new int[index];
            int[] creditarr = new int[10];
            int[] credit1 = new int[10];
            int[] credit2 = new int[10];
            for (i = 0; i <= Credit.length-1; i++) {
                Credit[i] = uInput.nextInt();

                System.out.println("credit is" + Credit[i]);
                for ( j = 0; j <= Grades.length - 1; j++) {
                    totalSummation = +(Grades[j] * Credit[i]);
                     creditarr[j]=possibleCombination(totalSummation);
                     if(Credit[i]==1) {
                     credit1[j]=creditarr[j];
                     }
                     if(Credit[i]==2){
                     credit2[j]=creditarr[j];
                     }
                    }
                }

            for(int k=0;k<credit1.length;k++) {
                for(int l=0;l<credit2.length;l++) {
                    int final_no=credit1[k]+credit2[l];
                    System.out.println("final_no :"  +final_no);
                }
            }
            }

         }

Is this what you want?

I guess the below code would be the best solution.This code will work for the no of credits you mention.

public class Candidate {
 private static final int[] Grades = new int[]{10, 9, 8, 7, 6, 5};

public static void main(String[] args) {
    // TODO Auto-generated method stub
    int i=0,score=0,totalsummation=0;
    Scanner uInput = new Scanner(System.in);
    System.out.println("Enter length of Array:");
    int arraylength = uInput.nextInt();
    int[] credits= new int[arraylength];
    ArrayList<Integer> combination = new ArrayList<Integer>();
    for (i = 0; i <credits.length; i++) {
        credits[i] = uInput.nextInt();
    }
    switch(credits.length) {
    case 1:
        for(int c1=10;c1>=5;c1--) {
            totalsummation = c1*credits[0];
            combination.add(totalsummation);
        }
        break;

    case 2:
        for(int g:Grades) {
            for(int c2=10;c2>=5;c2--) {
                totalsummation=g*credits[0]+c2*credits[1];
                combination.add(totalsummation);
            }
        }
        break;

    case 3:
            for(int g:Grades) {
            for(int c3=10;c3>=5;c3--) {
                totalsummation=g*credits[0]+c3*credits[1]+c3*credits[2];
                combination.add(totalsummation);
            }
        }
            break;
    case 4:
        for(int g:Grades) {
            for(int c4=10;c4>=5;c4--) {
                totalsummation=g*credits[0]+c4*credits[1]+c4*credits[2]+c4*credits[3];
                combination.add(totalsummation);
            }
        }
        break;

    case 5:
        for(int g:Grades) {
            for(int c5=10;c5>=5;c5--) {
                totalsummation=g*credits[0]+c5*credits[1]+c5*credits[2]+c5*credits[3]+c5*credits[4];
                combination.add(totalsummation);
            }
        }
        break;

        default:
            System.out.println("Invalid Input");
    }

 ArrayList<Integer> distinctnos =(ArrayList<Integer>) combination.stream().distinct().collect(Collectors.toList());
     System.out.println(distinctnos.size());            }
}

Hope this answers your question.


问:
How do i get the url (window.location) of the current request in Angular 5?
How do i get the url of the current request in Angular 5?

I tried a couple of solutions i found online but nothing seems to work.
- $window
- Wrapping native window in WindowRef example

I've been looking for this all morning, but kinda new to Angular and get lost in the different examples online targeting different versions of Angular.

UPDATE: I'm using TypeScript

Thanks

答: To fetch the current URL in the browser address bar you can use window.location.href.You don't need an angular wrapper for getting the current URL.</p>


问:
Laravel eloquent multiple whereNotIn
I'm trying to make a query where I use multiple whereNotIn arrays. For some reason, they block each other and ignores the other query parameters.

Any clues on how to solve this?

```<code>$products = Products::orderBy('id','DESC')
    ->where('status', '=', 4)
    ->whereNotIn('category', $excluded)
    ->whereNotIn('location', ['New York', 'Boston', 'Washington, DC', 'Charlotte'])
    ->take(400)
    ->get();
</code>```

答:
Is $excluded an array? If not you can just

```<code>->where('category', "<>", $excluded);
</code>```

Title: Laravel eloquent multiple whereNotIn

Body:
I'm trying to make a query where I use multiple whereNotIn arrays. For some reason, they block each other and ignores the other query parameters.

Any clues on how to solve this?

$products = Products::orderBy('id','DESC')
    ->where('status', '=', 4)
    ->whereNotIn('category', $excluded)
    ->whereNotIn('location', ['New York', 'Boston', 'Washington, DC', 'Charlotte'])
    ->take(400)
    ->get();

Body:
Is $excluded an array? If not you can just

->where('category', "<>", $excluded);


问:
Moving array to charsequence using BIFs in (free)RPGLE
Can someone tell me how to convert a char array to a character?

I've defined

```<code> D  charseq                     100a   value
</code>```

and

```<code> D  chrseq         s              1a   dim(100)
</code>```

Now I reversed charseq and stored each character using BIF %subst(string:index:length) in the corresponding field in chrseq:

```<code> C     1             do        101           x
 C                   eval      chrseq(101-x) = %subst(charseq:x:1)
 C                   enddo
</code>```

But now here is my problem: How do I convert the chrseq to my charseq?
In good old RPG/400 I'd done this via MOVEA but is there any (modern) RPGLE version??

Here's the code:

```<code> P*            -------------------------------------------------------------
 P*            getLastChar - Get last non-blank char in parameter
 P*            -------------------------------------------------------------
 P getLastChar     b                   export
 D getLastChar     pi             1a
 D*  Input-parameter
 D  charseq                     100a   value
 D*  Local fields
 D  lastChar       s              1a   inz(' ')
 D  chrseq         s              1a   dim(100)
 C
 C*            -------------------------------------------------------------
 C*            Error handling
 C*            -------------------------------------------------------------
 C     charseq       ifeq      *blanks
 C                   return    x'00'
 C                   endif
 C
 C*            -------------------------------------------------------------
 C*            Reverse input char sequence
 C*            -------------------------------------------------------------
 C     1             do        101           x
 C                   eval      chrseq(101-x) = %subst(charseq:x:1)
 C                   enddo
 C*  Now: How do I get chrseq(1) to chrseq(100) into charseq back?
 C*            -------------------------------------------------------------
 C*            Get last non-blank char
 C*            -------------------------------------------------------------
 C                   eval      charseq = %triml(charseq)
 C                   eval      lastChar = %subst(charseq:1:1)
 C
 C
 C                   return    lastChar
 C
 P getLastChar     e
</code>```

Thanks in advance!

答:
So something similar to what Liam suggested is to use a data structure and just assign the data structure to your second parameter.

```<code>dcl-proc ReverseCharacters;
  dcl-pi *n Char(100);
    charseq         Char(100) Const;
  end-pi;

  dcl-ds chards;
    chrseq         Char(1) Dim(100);
  end-ds;

  dcl-s charseq    Char(100);
  dcl-s x          Int(5);

  for x = 100 downto 1;
    chrseq(x) = %substr(charseq:x:1);
  end-for;

  return %triml(chrds);
end-proc;
</code>```

But if all you want to do is return the last character of a string, I would do it this way.

```<code>dcl-proc LastChar;
  dcl-pi *n Char(1);
    str     Varchar(100) Const;
  end-pi;

  if %len(str) = 0;
    return '';
  endif;
  return %substr(str: %len(%trimr(str)): 1);
end-proc;
</code>```

Body:
Can someone tell me how to convert a char array to a character?

I've defined

 D  charseq                     100a   value

and

 D  chrseq         s              1a   dim(100)

Now I reversed charseq and stored each character using BIF %subst(string:index:length) in the corresponding field in chrseq:

 C     1             do        101           x
 C                   eval      chrseq(101-x) = %subst(charseq:x:1)
 C                   enddo

But now here is my problem: How do I convert the chrseq to my charseq?
In good old RPG/400 I'd done this via MOVEA but is there any (modern) RPGLE version??

Here's the code:

 P*            -------------------------------------------------------------
 P*            getLastChar - Get last non-blank char in parameter
 P*            -------------------------------------------------------------
 P getLastChar     b                   export
 D getLastChar     pi             1a
 D*  Input-parameter
 D  charseq                     100a   value
 D*  Local fields
 D  lastChar       s              1a   inz(' ')
 D  chrseq         s              1a   dim(100)
 C
 C*            -------------------------------------------------------------
 C*            Error handling
 C*            -------------------------------------------------------------
 C     charseq       ifeq      *blanks
 C                   return    x'00'
 C                   endif
 C
 C*            -------------------------------------------------------------
 C*            Reverse input char sequence
 C*            -------------------------------------------------------------
 C     1             do        101           x
 C                   eval      chrseq(101-x) = %subst(charseq:x:1)
 C                   enddo
 C*  Now: How do I get chrseq(1) to chrseq(100) into charseq back?
 C*            -------------------------------------------------------------
 C*            Get last non-blank char
 C*            -------------------------------------------------------------
 C                   eval      charseq = %triml(charseq)
 C                   eval      lastChar = %subst(charseq:1:1)
 C
 C
 C                   return    lastChar
 C
 P getLastChar     e

Thanks in advance!

Body:
So something similar to what Liam suggested is to use a data structure and just assign the data structure to your second parameter.

dcl-proc ReverseCharacters;
  dcl-pi *n Char(100);
    charseq         Char(100) Const;
  end-pi;

  dcl-ds chards;
    chrseq         Char(1) Dim(100);
  end-ds;

  dcl-s charseq    Char(100);
  dcl-s x          Int(5);

  for x = 100 downto 1;
    chrseq(x) = %substr(charseq:x:1);
  end-for;

  return %triml(chrds);
end-proc;

But if all you want to do is return the last character of a string, I would do it this way.

dcl-proc LastChar;
  dcl-pi *n Char(1);
    str     Varchar(100) Const;
  end-pi;

  if %len(str) = 0;
    return '';
  endif;
  return %substr(str: %len(%trimr(str)): 1);
end-proc;


问:
entity framework Unable to load the specified metadata resource

Possible Duplicate:

  MetadataException: Unable to load the specified metadata resource

I hope someone can help with this. i have tried following other posts on here and dozens on other sites but i can get this working.

the entity framework was all working, then the next day just started giving me the error: Unable to load the specified metadata resource. on the constructor of the entities class.

I have checked the connection strings, deleted and re added everything but i still cant get this working.

my model namespace is WraithNath.co.uk.Models

the metadata artificat is embed in assembly

my connection strings are as follows:

```<code><add name="ConnectionString" connectionString="Data Source=.\SQL2008;AttachDbFilename=|DataDirectory|\WraithNath.co.uk.mdf;Integrated Security=True;" providerName="System.Data.SqlClient" />
   <add name="Entities" connectionString="metadata=res://*/Models.WraithNath.co.uk.csdl|res://*/Models.WraithNath.co.uk.ssdl|res://*/Models.WraithNath.co.uk.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQL2008;AttachDbFilename=|DataDirectory|\WraithNath.co.uk.mdf;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</code>```

I cant find the 3 files i need in the assembly when looking at it in Reflector.

Is there a step by step guide to sort this out? i have already tried every link on the first 3 pages of google for search results 'entity framework Unable to load the specified metadata resource'.

答:
Craig Stuntz has written an extensive (in my opinion) blog post on troubleshooting this exact error message, I personally would start there.

The following res: (resource) references need to point to your model.

```<code><add name="Entities" connectionString="metadata=
    res://*/Models.WraithNath.co.uk.csdl|
    res://*/Models.WraithNath.co.uk.ssdl|
    res://*/Models.WraithNath.co.uk.msl;
</code>```

Make sure each one has the name of your .edmx file after the "*/", with the "edmx" changed to the extension for that res (.csdl, .ssdl, or .msl).

It also may help to specify the assembly rather than using "//*/".

Worst case, you can check everything (a bit slower but should always find the resource) by using

```<code><add name="Entities" connectionString="metadata=
        res://*/;provider= <!-- ... -->
</code>```

Body:
Possible Duplicate:

  MetadataException: Unable to load the specified metadata resource

I hope someone can help with this. i have tried following other posts on here and dozens on other sites but i can get this working.

the entity framework was all working, then the next day just started giving me the error: Unable to load the specified metadata resource. on the constructor of the entities class.

I have checked the connection strings, deleted and re added everything but i still cant get this working.

my model namespace is WraithNath.co.uk.Models

the metadata artificat is embed in assembly

my connection strings are as follows:

<add name="ConnectionString" connectionString="Data Source=.\SQL2008;AttachDbFilename=|DataDirectory|\WraithNath.co.uk.mdf;Integrated Security=True;" providerName="System.Data.SqlClient" />
   <add name="Entities" connectionString="metadata=res://*/Models.WraithNath.co.uk.csdl|res://*/Models.WraithNath.co.uk.ssdl|res://*/Models.WraithNath.co.uk.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQL2008;AttachDbFilename=|DataDirectory|\WraithNath.co.uk.mdf;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />

I cant find the 3 files i need in the assembly when looking at it in Reflector.

Is there a step by step guide to sort this out? i have already tried every link on the first 3 pages of google for search results 'entity framework Unable to load the specified metadata resource'.

Body:
Craig Stuntz has written an extensive (in my opinion) blog post on troubleshooting this exact error message, I personally would start there.

The following res: (resource) references need to point to your model.

<add name="Entities" connectionString="metadata=
    res://*/Models.WraithNath.co.uk.csdl|
    res://*/Models.WraithNath.co.uk.ssdl|
    res://*/Models.WraithNath.co.uk.msl;

Make sure each one has the name of your .edmx file after the "*/", with the "edmx" changed to the extension for that res (.csdl, .ssdl, or .msl).

It also may help to specify the assembly rather than using "//*/".

Worst case, you can check everything (a bit slower but should always find the resource) by using

<add name="Entities" connectionString="metadata=
        res://*/;provider= <!-- ... -->


问:
get path from Google Drive URI
I'm using Android file selection and selecting files from app storage (images, videos, documents). I have an function "getPath" . Im getting path from uri. I have no problem with gallery images or download documents. But when i select a file from google drive i cant get path. This is the google drive uri "content://com.google.android.apps.docs.storage/document/acc%3D25%3Bdoc%3D12"
Can you help me about it ?

This is also my "getPath" function.

```<code>public static String getPath(final Context context, final Uri uri) {

    // check here to KITKAT or new version
    final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;

    // DocumentProvider
    if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {

        // ExternalStorageProvider
        if (isExternalStorageDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];

            if ("primary".equalsIgnoreCase(type)) {
                return Environment.getExternalStorageDirectory() + "/"
                        + split[1];
            }
        }
        // DownloadsProvider
        else if (isDownloadsDocument(uri)) {

            final String id = DocumentsContract.getDocumentId(uri);
            final Uri contentUri = ContentUris.withAppendedId(
                    Uri.parse("content://downloads/public_downloads"),
                    Long.valueOf(id));

            return getDataColumn(context, contentUri, null, null);
        }
        // MediaProvider
        else if (isMediaDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];

            Uri contentUri = null;
            if ("image".equals(type)) {
                contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
            } else if ("video".equals(type)) {
                contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
            } else if ("audio".equals(type)) {
                contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
            }

            final String selection = "_id=?";
            final String[] selectionArgs = new String[] { split[1] };

            return getDataColumn(context, contentUri, selection,
                    selectionArgs);
        }
        else if(isGoogleDriveUri(uri)){
                //Get google drive path here

        }
    }
    // MediaStore (and general)
    else if ("content".equalsIgnoreCase(uri.getScheme())) {

        // Return the remote address
        if (isGooglePhotosUri(uri))
            return uri.getLastPathSegment();

        return getDataColumn(context, uri, null, null);
    }
    // File
    else if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }

    return nopath;
}

public static String iStreamToString(InputStream is1)
{
    BufferedReader rd = new BufferedReader(new InputStreamReader(is1), 4096);
    String line;
    StringBuilder sb =  new StringBuilder();
    try {
        while ((line = rd.readLine()) != null) {
            sb.append(line);
        }
        rd.close();

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    String contentOfMyInputStream = sb.toString();
    return contentOfMyInputStream;
}
</code>```

答:
I have no problem with gallery images or download documents

You will, on many devices.

But when i select a file from google drive i cant get path

There is no path. ACTION_GET_CONTENT does not allow the user to choose a file. It allows the user to choose a piece of content. That content might be a local file. That content might also be:

Something on a file server on the network

Something in a cloud storage service, such as Google Drive, and therefore is not on the device at the moment

Something in an encrypted volume

Something that is a file, but is not a file that you can access directly, such as from internal storage of another app

And so on

You have two main options. If you only want files, then use a third-party file chooser library to replace all of the code in your question.

Or, if you still want to use ACTION_GET_CONTENT or ACTION_OPEN_DOCUMENT, you can take the Uri that you get from data.getData() in onActivityResult() and do two things with it:

First, use DocumentFile.fromSingleUri() to get a DocumentFile object pointing to that Uri. You can call getName() on the DocumentFile to get a "display name" for the content, which should be something that the user will recognize.

Then, use a ContentResolver and openInputStream() to get at the content itself, similar to how you might use a FileInputStream to get at the bytes in a file.

Title: get path from Google Drive URI

Body:
I'm using Android file selection and selecting files from app storage (images, videos, documents). I have an function "getPath" . Im getting path from uri. I have no problem with gallery images or download documents. But when i select a file from google drive i cant get path. This is the google drive uri "content://com.google.android.apps.docs.storage/document/acc%3D25%3Bdoc%3D12"
Can you help me about it ?

This is also my "getPath" function.

public static String getPath(final Context context, final Uri uri) {

    // check here to KITKAT or new version
    final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;

    // DocumentProvider
    if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {

        // ExternalStorageProvider
        if (isExternalStorageDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];

            if ("primary".equalsIgnoreCase(type)) {
                return Environment.getExternalStorageDirectory() + "/"
                        + split[1];
            }
        }
        // DownloadsProvider
        else if (isDownloadsDocument(uri)) {

            final String id = DocumentsContract.getDocumentId(uri);
            final Uri contentUri = ContentUris.withAppendedId(
                    Uri.parse("content://downloads/public_downloads"),
                    Long.valueOf(id));

            return getDataColumn(context, contentUri, null, null);
        }
        // MediaProvider
        else if (isMediaDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];

            Uri contentUri = null;
            if ("image".equals(type)) {
                contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
            } else if ("video".equals(type)) {
                contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
            } else if ("audio".equals(type)) {
                contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
            }

            final String selection = "_id=?";
            final String[] selectionArgs = new String[] { split[1] };

            return getDataColumn(context, contentUri, selection,
                    selectionArgs);
        }
        else if(isGoogleDriveUri(uri)){
                //Get google drive path here

        }
    }
    // MediaStore (and general)
    else if ("content".equalsIgnoreCase(uri.getScheme())) {

        // Return the remote address
        if (isGooglePhotosUri(uri))
            return uri.getLastPathSegment();

        return getDataColumn(context, uri, null, null);
    }
    // File
    else if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }

    return nopath;
}

public static String iStreamToString(InputStream is1)
{
    BufferedReader rd = new BufferedReader(new InputStreamReader(is1), 4096);
    String line;
    StringBuilder sb =  new StringBuilder();
    try {
        while ((line = rd.readLine()) != null) {
            sb.append(line);
        }
        rd.close();

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    String contentOfMyInputStream = sb.toString();
    return contentOfMyInputStream;
}


问:
Fill intersection of two circles
I'm trying to draw two circles where the intersection has a different fill color.

<svg width="300" height="200" xmlns="http://www.w3.org/2000/svg">
  <g>
    <circle r="85" id="circle_left" cy="100" cx="100" stroke-width="1.5" stroke="#000" fill="none" />
    <circle r="85" id="circle_right" cy="100" cx="200" stroke-width="1.5"  stroke="#000" fill="none"/>
  </g>
</svg>```

Is there a way to do this with mask?

Example png:

答:
Define a clipPath consisting of the right circle and set it as the clip-path of the left (or the other way around):

<svg width="300" height="200" xmlns="http://www.w3.org/2000/svg">
    <defs>
        <clipPath id="mask_left">
            <circle r="85" id="circle_right" cy="100" cx="200" stroke-width="1.5"  stroke="#000" fill="none"/>
        </clipPath>
    </defs>
    <g>
        <circle r="85" id="center" cy="100" cx="100" fill="orange" clip-path="url(#mask_left)"/>
        <circle r="85" id="circle_left" cy="100" cx="100" stroke-width="1.5" stroke="#000" fill="none" />
        <circle r="85" id="circle_right" cy="100" cx="200" stroke-width="1.5"  stroke="#000" fill="none"/>
    </g>
</svg>```
</div>
</div>
</p>

<p>Or, if you don't want to re-define the same shapes:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code><svg width="300" height="200" xmlns="http://www.w3.org/2000/svg">
    <defs>
        <circle r="85" id="circle_left" cy="100" cx="100"/>
        <circle r="85" id="circle_right" cy="100" cx="200"/>
        <clipPath id="mask_left">
            <use xlink:href="#circle_right" />
        </clipPath>
    </defs>
    <g>
        <use xlink:href="#circle_left" id="center" fill="orange" clip-path="url(#mask_left)"/>
        <use xlink:href="#circle_left" stroke-width="1.5" stroke="#000" fill="none"/>
        <use xlink:href="#circle_right" stroke-width="1.5" stroke="#000" fill="none"/>
    </g>
</svg></code>```

If you want to use a mask (not really necessary, but you specifically asked for it), it would look almost identical.

<svg width="300" height="200" xmlns="http://www.w3.org/2000/svg">
    <defs>
        <circle r="85" id="circle_left" cy="100" cx="100"/>
        <circle r="85" id="circle_right" cy="100" cx="200"/>
        <mask id="mask_left">
            <use xlink:href="#circle_right" fill="white"/>
        </mask>
    </defs>
    <g>
        <use xlink:href="#circle_left" id="center" fill="orange" mask="url(#mask_left)"/>
        <use xlink:href="#circle_left" stroke-width="1.5" stroke="#000" fill="none"/>
        <use xlink:href="#circle_right" stroke-width="1.5" stroke="#000" fill="none"/>
    </g>
</svg>```

Title: Fill intersection of two circles

Body:
I'm trying to draw two circles where the intersection has a different fill color.

<svg width="300" height="200" xmlns="http://www.w3.org/2000/svg">
  <g>
    <circle r="85" id="circle_left" cy="100" cx="100" stroke-width="1.5" stroke="#000" fill="none" />
    <circle r="85" id="circle_right" cy="100" cx="200" stroke-width="1.5"  stroke="#000" fill="none"/>
  </g>
</svg>

Is there a way to do this with mask?

Example png:

Body:
Define a clipPath consisting of the right circle and set it as the clip-path of the left (or the other way around):

<svg width="300" height="200" xmlns="http://www.w3.org/2000/svg">
    <defs>
        <clipPath id="mask_left">
            <circle r="85" id="circle_right" cy="100" cx="200" stroke-width="1.5"  stroke="#000" fill="none"/>
        </clipPath>
    </defs>
    <g>
        <circle r="85" id="center" cy="100" cx="100" fill="orange" clip-path="url(#mask_left)"/>
        <circle r="85" id="circle_left" cy="100" cx="100" stroke-width="1.5" stroke="#000" fill="none" />
        <circle r="85" id="circle_right" cy="100" cx="200" stroke-width="1.5"  stroke="#000" fill="none"/>
    </g>
</svg>

Or, if you don't want to re-define the same shapes:

<svg width="300" height="200" xmlns="http://www.w3.org/2000/svg">
    <defs>
        <circle r="85" id="circle_left" cy="100" cx="100"/>
        <circle r="85" id="circle_right" cy="100" cx="200"/>
        <clipPath id="mask_left">
            <use xlink:href="#circle_right" />
        </clipPath>
    </defs>
    <g>
        <use xlink:href="#circle_left" id="center" fill="orange" clip-path="url(#mask_left)"/>
        <use xlink:href="#circle_left" stroke-width="1.5" stroke="#000" fill="none"/>
        <use xlink:href="#circle_right" stroke-width="1.5" stroke="#000" fill="none"/>
    </g>
</svg>

If you want to use a mask (not really necessary, but you specifically asked for it), it would look almost identical.

<svg width="300" height="200" xmlns="http://www.w3.org/2000/svg">
    <defs>
        <circle r="85" id="circle_left" cy="100" cx="100"/>
        <circle r="85" id="circle_right" cy="100" cx="200"/>
        <mask id="mask_left">
            <use xlink:href="#circle_right" fill="white"/>
        </mask>
    </defs>
    <g>
        <use xlink:href="#circle_left" id="center" fill="orange" mask="url(#mask_left)"/>
        <use xlink:href="#circle_left" stroke-width="1.5" stroke="#000" fill="none"/>
        <use xlink:href="#circle_right" stroke-width="1.5" stroke="#000" fill="none"/>
    </g>
</svg>


问:
How to fetch data using php curl after getting logged IN from another url?
```<code>$url="http://www.example.com/sign_in";

//url, i need to fetch data from
$url2="http://www.example.com/xref/quicksearches?quick_search[match]=pants&commit=Go!";

$username = "user_name123";
$password = "password@123";

$field='authenticity_token';
$cookie= "cookies.txt";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$response = curl_exec($ch);
if (curl_errno($ch)) die(curl_error($ch));
$dom = new DomDocument();
$dom->loadHTML($response);
$tokens = $dom->getElementsByTagName("input");
for ($i = 0; $i < $tokens->length; $i++) {
$meta = $tokens->item($i);
if($meta->getAttribute('name') == 'authenticity_token')
$token = $meta->getAttribute('value');
}

$postinfo = "user[login]=".$username."&user[password]=".$password."&authenticity_token=".$token;
echo $token;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);

$html = curl_exec($ch);
print($html);

curl_close($ch);
</code>```

Now i can successfully able to LOG IN but i need to fetch data from $url2. How can i achieve that ?

curl_multi_init() doesn't work for me.
i am fetching authenticity token from the first url and then logging in but dont know how to go to second url and fetch that page.
I am using cURL for the first time :)

答:
so what i was doing wrong is, i was fetching data from second URL before closing first connection. here is the answer</p>

```<code>`$url="http://www.example.com/sign_in";

//url, i need to fetch data from
$url2="http://www.example.com/xref/quicksearches?quick_search[match]=pants&commit=Go!";

$username = "user_name123";
$password = "password@123";

$field='authenticity_token';
$cookie= "cookies.txt";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$response = curl_exec($ch);
if (curl_errno($ch)) die(curl_error($ch));
$dom = new DomDocument();
$dom->loadHTML($response);
$tokens = $dom->getElementsByTagName("input");
for ($i = 0; $i < $tokens->length; $i++) {
$meta = $tokens->item($i);
if($meta->getAttribute('name') == 'authenticity_token')
$token = $meta->getAttribute('value');
}

$postinfo = "user[login]=".$username."&user[password]=".$password."&authenticity_token=".$token;
echo $token;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);

$html = curl_exec($ch);
print($html);

curl_close($ch);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

$html = curl_exec($ch);
print($html);
curl_close($ch);`
</code>```

Body:
$url="http://www.example.com/sign_in";

//url, i need to fetch data from
$url2="http://www.example.com/xref/quicksearches?quick_search[match]=pants&commit=Go!";

$username = "user_name123";
$password = "password@123";

$field='authenticity_token';
$cookie= "cookies.txt";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$response = curl_exec($ch);
if (curl_errno($ch)) die(curl_error($ch));
$dom = new DomDocument();
$dom->loadHTML($response);
$tokens = $dom->getElementsByTagName("input");
for ($i = 0; $i < $tokens->length; $i++) {
$meta = $tokens->item($i);
if($meta->getAttribute('name') == 'authenticity_token')
$token = $meta->getAttribute('value');
}

$postinfo = "user[login]=".$username."&user[password]=".$password."&authenticity_token=".$token;
echo $token;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);

$html = curl_exec($ch);
print($html);

curl_close($ch);

Now i can successfully able to LOG IN but i need to fetch data from $url2. How can i achieve that ?

curl_multi_init() doesn't work for me.
i am fetching authenticity token from the first url and then logging in but dont know how to go to second url and fetch that page.
I am using cURL for the first time :)

Body:
so what i was doing wrong is, i was fetching data from second URL before closing first connection. here is the answer

`$url="http://www.example.com/sign_in";

//url, i need to fetch data from
$url2="http://www.example.com/xref/quicksearches?quick_search[match]=pants&commit=Go!";

$username = "user_name123";
$password = "password@123";

$field='authenticity_token';
$cookie= "cookies.txt";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$response = curl_exec($ch);
if (curl_errno($ch)) die(curl_error($ch));
$dom = new DomDocument();
$dom->loadHTML($response);
$tokens = $dom->getElementsByTagName("input");
for ($i = 0; $i < $tokens->length; $i++) {
$meta = $tokens->item($i);
if($meta->getAttribute('name') == 'authenticity_token')
$token = $meta->getAttribute('value');
}

$postinfo = "user[login]=".$username."&user[password]=".$password."&authenticity_token=".$token;
echo $token;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);

$html = curl_exec($ch);
print($html);

curl_close($ch);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

$html = curl_exec($ch);
print($html);
curl_close($ch);`


问:
Cache evict a single object in java spring
I am trying to cache a list of object, let say 'Orders'. It caches it perfectly.

to put a new object in a cache list what I am doing is this;

```<code>    cacheManager.getCacheNames().parallelStream().forEach(name -> cacheManager.getCache(name).put("order", order));
</code>```

And to evict that specific order from the cache I did;

```<code>    cacheManager.getCacheNames().parallelStream().forEach(name -> cacheManager.getCache(name).evict(orderId));
</code>```

But evict doesn't work for me.

How can I remove/ update the out dated object in a cache? Is there a way to iterate a cache until I get the desired object and update it.

Any help would be appreciated.

答:
For putting object to the cache you should use orderId instead of string value "order"

```<code>cacheManager.getCacheNames().parallelStream().forEach(name -> cacheManager.getCache(name).put(orderId, order));
</code>```

Body:
I am trying to cache a list of object, let say 'Orders'. It caches it perfectly.

to put a new object in a cache list what I am doing is this;

    cacheManager.getCacheNames().parallelStream().forEach(name -> cacheManager.getCache(name).put("order", order));

And to evict that specific order from the cache I did;

    cacheManager.getCacheNames().parallelStream().forEach(name -> cacheManager.getCache(name).evict(orderId));

But evict doesn't work for me.

How can I remove/ update the out dated object in a cache? Is there a way to iterate a cache until I get the desired object and update it.

Any help would be appreciated.

Body:
For putting object to the cache you should use orderId instead of string value "order"

cacheManager.getCacheNames().parallelStream().forEach(name -> cacheManager.getCache(name).put(orderId, order));


问:
How to run test on specific browser by selenium grid
I have register two platform with chrome browser on windows 7 and windows 10 into selenium grid server.

I want to run a test at Chrome browser on Windows 10 but when i run the test, the test randomly run on Windows 7 and randomly run on Windows 10 on chrome.

Do you have an idea how to do the configuration to run the test on specific browser and platform when we have registered multiple platform?

hub:

```<code>java -jar selenium-server-standalone-3.7.1.jar -role hub
</code>```

register node on windows 7:

```<code>java -Dwebdriver.chrome.driver=chromedriver_2.33.exe -jar selenium-server-standalone-3.7.1.jar -role node -hub http://localhost:4444
</code>```

register node on windows 10:

```<code>java -Dwebdriver.chrome.driver=chromedriver_2.33.exe -jar selenium-server-standalone-3.7.1.jar -role node -hub http://localhost:4444
</code>```

protractor.conf.js

```<code>exports.config = {

    specs: [
        '**/*.mytest.e2e-spec.ts'
    ],
    multiCapabilities: [
        {
            browserName: 'chrome',
            platform: 'WIN10',
        }
    ],
    seleniumAddress: 'http://localhost:4444/wd/hub',
    baseUrl: 'http://localhost:4200/',
    framework: 'jasmine',
    jasmineNodeOpts: {
        print: function () {
        }
    },
    onPrepare: function () {
        require('ts-node').register({
            project: 'e2e/tsconfig.e2e.json'
        });
    }
};
</code>```

答:
You need to tweak the commands for registering the nodes as follows :

Register node on Windows 7:

```<code>java -Dwebdriver.chrome.driver=chromedriver_2.33.exe -jar selenium-server-standalone-3.7.1.jar -role node -hub http://localhost:4444/grid/register
</code>```

Register node on Windows 10:

```<code>java -Dwebdriver.chrome.driver=chromedriver_2.33.exe -jar selenium-server-standalone-3.7.1.jar -role node -hub http://localhost:4444/grid/register
</code>```

Body:
I have register two platform with chrome browser on windows 7 and windows 10 into selenium grid server.

I want to run a test at Chrome browser on Windows 10 but when i run the test, the test randomly run on Windows 7 and randomly run on Windows 10 on chrome.

Do you have an idea how to do the configuration to run the test on specific browser and platform when we have registered multiple platform?

hub:

java -jar selenium-server-standalone-3.7.1.jar -role hub

register node on windows 7:

java -Dwebdriver.chrome.driver=chromedriver_2.33.exe -jar selenium-server-standalone-3.7.1.jar -role node -hub http://localhost:4444

register node on windows 10:

java -Dwebdriver.chrome.driver=chromedriver_2.33.exe -jar selenium-server-standalone-3.7.1.jar -role node -hub http://localhost:4444

protractor.conf.js

exports.config = {

    specs: [
        '**/*.mytest.e2e-spec.ts'
    ],
    multiCapabilities: [
        {
            browserName: 'chrome',
            platform: 'WIN10',
        }
    ],
    seleniumAddress: 'http://localhost:4444/wd/hub',
    baseUrl: 'http://localhost:4200/',
    framework: 'jasmine',
    jasmineNodeOpts: {
        print: function () {
        }
    },
    onPrepare: function () {
        require('ts-node').register({
            project: 'e2e/tsconfig.e2e.json'
        });
    }
};

Body:
You need to tweak the commands for registering the nodes as follows :

Register node on Windows 7:

java -Dwebdriver.chrome.driver=chromedriver_2.33.exe -jar selenium-server-standalone-3.7.1.jar -role node -hub http://localhost:4444/grid/register

Register node on Windows 10:

java -Dwebdriver.chrome.driver=chromedriver_2.33.exe -jar selenium-server-standalone-3.7.1.jar -role node -hub http://localhost:4444/grid/register


问:
Overriding Angular Material Size and Styling of md-dialog-container
I am using Angular Material and I am using md-dialog for my popups for my gallery. The default animation and styling looks nice. However, I would like to change the width and height of size of the md-dialog-container? which is hidden. Only added when I click the modal and when you open the chrome dev tools you can see the md-dialog-container appearing. Do include how to override the rest of the styling.

Much appreciate with some help. Thanks.

答:
```<code>    const dialogRef = this.dialog.open(WorkModalComponent, {
       width: '1200px',
       data: workObj,
       panelClass: 'my-dialog-container-class' // Replace with your actual dialog container class
    });
</code>```

<p>add the panelClass to your Dialog and add your CSS style to this class. </p>

Body:
    const dialogRef = this.dialog.open(WorkModalComponent, {
       width: '1200px',
       data: workObj,
       panelClass: 'my-dialog-container-class' // Replace with your actual dialog container class
    });

add the panelClass to your Dialog and add your CSS style to this class.