问:
Can google cloud pubsub subscription really be deleted automatically?
From the doc:

Subscriptions with no activity (push successes or pull requests) for 31 days may be deleted automatically

I need to set up a push message subscription which usage may be very low (a few messages per year) but is vital to the app.

The sentence above from the official documentation made me jump !
Should I rely on google pubsub or move away from it ?
Is there more information on this automatic mechanism ?

Need advice.

答:
Yes, the subscriptions are deleted automatically after 31 days of inactivity in Google Cloud Pub/Sub. If you are only sending a few messages a year, then it sounds like Cloud Pub/Sub might be overkill for your use case. Since you have a push endpoint set up, can you just send the message to the endpoint directly from your publisher as an HTTP request and then consider it processed when you get a 200 response? Or is it the case that your push endpoint may be unavailable for long enough periods of time that you can't depend on that working? With such a low throughput, you don't need a lot of the features of Pub/Sub, e.g., flow control.

If you stick with Cloud Pub/Sub, you have a couple of options:

Send a periodic heartbeat message from your publisher to ensure the subscription is not deleted.

Check for the existence of your subscription before publishing your message and if necessary, recreate the subscription.


来源: stackexchange

问:
How to Modify Attribute Value in XML using Xpath Java including commented Section
My requirement is updating reloadable="true" to reloadable="false". The below code is doing perfectly but it is not updating the attribute which is in comment section.
I know that comment() function would do but really no luck till now, below is by code

```<code>NodeList contextRoots = XMLUtil.xPathNodeList("//*[contains(@reloadable, 'true')]", ServerXML.getDocumentElement());
            for(int id = 0; id < contextRoots.getLength(); id++)
            {
                Node value = contextRoots.item(id).getAttributes().getNamedItem("reloadable");
                String val = value.getNodeValue();
                value.setNodeValue(val.replaceAll("true", "false"));
            }
            return ServerXML;
</code>```

Below is the XML

```<code>    <Context docBase="/UserManager" path="" reloadable="true"/>
    <Context docBase="/UserManager" path="" reloadable="true"/>

    <Context docBase="/AdminConsole" path="" reloadable="true"/>
    <Context docBase="/AdminConsole" path="" reloadable="true"/>

    <Context docBase="/public#cert" path="" reloadable="true"/>
    <Context docBase="/public#cert" path="" reloadable="true"/>

    <!-- Remove below comment block if CQI is installed-->
    <!-- <Context docBase="CQI" path="" reloadable="true" />
    <Context docBase="CQI" path="" reloadable="true" /> -->
</code>```

答:
You could detect if node is a COMMENT_NODE and see if it's data starts with <Context and replace reloadable=true with reloadable=false as in below code:

```<code> InputSource inputSource = new InputSource( new FileInputStream( new File("commentupdate.xml")  ) );

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse( inputSource );
NodeList nodeList = doc.getDocumentElement().getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++)
{
    if ( nodeList.item(i).getNodeType() == Element.COMMENT_NODE )
    {
        Comment comment=(Comment) nodeList.item(i);
        String data = comment.getData();
        if ( data.trim().startsWith( "<Context") )
        {
            data = data.replaceAll("reloadable\\s*=\\s*\"true\"", "reloadable=\"false\"");
            Comment newComment = doc.createComment(data);
            comment.getParentNode().appendChild(newComment);
            comment.getParentNode().removeChild(comment);
        }

    }
}

TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty( OutputKeys.METHOD, "xml" );
transformer.setOutputProperty( OutputKeys.OMIT_XML_DECLARATION, "true" );
transformer.setOutputProperty( OutputKeys.INDENT, "yes");
StreamResult sr = new StreamResult( new File( "commentupdate.xml" ) );
transformer.transform( new DOMSource(doc), sr );
</code>```

ContentLicense: CC BY-SA 3.0

Body:
My requirement is updating reloadable="true" to reloadable="false". The below code is doing perfectly but it is not updating the attribute which is in comment section.
I know that comment() function would do but really no luck till now, below is by code

NodeList contextRoots = XMLUtil.xPathNodeList("//*[contains(@reloadable, 'true')]", ServerXML.getDocumentElement());
            for(int id = 0; id < contextRoots.getLength(); id++)
            {
                Node value = contextRoots.item(id).getAttributes().getNamedItem("reloadable");
                String val = value.getNodeValue();
                value.setNodeValue(val.replaceAll("true", "false"));
            }
            return ServerXML;

Below is the XML

    <Context docBase="/UserManager" path="" reloadable="true"/>
    <Context docBase="/UserManager" path="" reloadable="true"/>

    <Context docBase="/AdminConsole" path="" reloadable="true"/>
    <Context docBase="/AdminConsole" path="" reloadable="true"/>

    <Context docBase="/public#cert" path="" reloadable="true"/>
    <Context docBase="/public#cert" path="" reloadable="true"/>

Body:
You could detect if node is a COMMENT_NODE and see if it's data starts with <Context and replace reloadable=true with reloadable=false as in below code:

 InputSource inputSource = new InputSource( new FileInputStream( new File("commentupdate.xml")  ) );

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse( inputSource );
NodeList nodeList = doc.getDocumentElement().getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++)
{
    if ( nodeList.item(i).getNodeType() == Element.COMMENT_NODE )
    {
        Comment comment=(Comment) nodeList.item(i);
        String data = comment.getData();
        if ( data.trim().startsWith( "<Context") )
        {
            data = data.replaceAll("reloadable\\s*=\\s*\"true\"", "reloadable=\"false\"");
            Comment newComment = doc.createComment(data);
            comment.getParentNode().appendChild(newComment);
            comment.getParentNode().removeChild(comment);
        }

    }
}

TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty( OutputKeys.METHOD, "xml" );
transformer.setOutputProperty( OutputKeys.OMIT_XML_DECLARATION, "true" );
transformer.setOutputProperty( OutputKeys.INDENT, "yes");
StreamResult sr = new StreamResult( new File( "commentupdate.xml" ) );
transformer.transform( new DOMSource(doc), sr );


问:
WCF - Fastest interprocess communication
A have a web-accessible (via basicHttpBinding) WCF service which I also want to access from other .NET services on the same machine with as higher performance as possible. I understand that the netNamedPipeBinding is ideal for this, but wonder what the best configuration would be given that I'm only even going to be communicating with other .NET processes.

For example, I needn't necessarily use an encoding such as SOAP as this is perhaps too bulky and I don't need the compatibility with any other clients other than a .NET client. I also don't think I need any security.

What would be the best binding configuration for this purpose (or any other configurations for that matter)

答:
Certainly the Named Pipe transport is the best choice.

Transport security with EncryptAndSign is enabled by default on the standard NetNamedPipeBinding. You certainly want to remove this, as doing so will speed things up without any real impact on security, for the reasons I discuss here.

I also suspect, but have not yet confirmed, that changing the message encoding binding element may help. This is because the default is the WCF proprietary 'binary encoding with in-band dictionary', which is an encoding of an XML infoset which aims to reduce redundant bytes e.g. in opening and closing element tags: a worthy aim when network IO is involved, but maybe wasted CPU effort when message transfer is entirely in-memory (provided the messages are not too big). Thus changing to a plain text encoding might also provide a speed improvement.

ContentLicense: CC BY-SA 2.5


问:
How to implement 2D vector array?
I'm using the vector class in the STL library for the first time. How should I add to a specific row of the vector array?

```<code>struct x{
     vector <vector <int> > v;
     int row;
 };

vector< int* > my ints;
int add;
</code>```

if i wanted to add to first row of v with the first pointer of integers, could I do

```<code>myints[0]->v[myints[0]->row].push_back(add);
</code>```

Is this method fine to create a 2 D vector of vector ints where each row could potentially be of different length (i.e. have a different number of columns)?

答:
We can easily use vector as 2d array. We use resize() method for this purpose.
The code below can be helpful to understand this issue.

Code Snippet :

```<code>#include<bits/stdc++.h>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int row, col;
    cin>>row>>col;

    vector <vector<int>> v;
    v.resize(col,vector<int>(row));

    //v = {{1,2,3}, {4,5,6}, {7,8,9}};

    /** input from use **/
    for(int i=0; i<row; i++)
    {
       for(int j=0; j<col; j++)
       {
          cin>>v[i][j];
       }
    }

    for(int i=0;i<row; i++)
    {
       for(int j=0;j<col;j++)
       {
          cout<<v[i][j]<<" ";
       }
    }
    return 0;
}
</code>```

Title: How to implement 2D vector array?

Body:
I'm using the vector class in the STL library for the first time. How should I add to a specific row of the vector array?

struct x{
     vector <vector <int> > v;
     int row;
 };

vector< int* > my ints;
int add;

if i wanted to add to first row of v with the first pointer of integers, could I do

myints[0]->v[myints[0]->row].push_back(add);

Is this method fine to create a 2 D vector of vector ints where each row could potentially be of different length (i.e. have a different number of columns)?

Body:
We can easily use vector as 2d array. We use resize() method for this purpose.
The code below can be helpful to understand this issue.

Code Snippet :

#include<bits/stdc++.h>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int row, col;
    cin>>row>>col;

    vector <vector<int>> v;
    v.resize(col,vector<int>(row));

    //v = {{1,2,3}, {4,5,6}, {7,8,9}};

    /** input from use **/
    for(int i=0; i<row; i++)
    {
       for(int j=0; j<col; j++)
       {
          cin>>v[i][j];
       }
    }

    for(int i=0;i<row; i++)
    {
       for(int j=0;j<col;j++)
       {
          cout<<v[i][j]<<" ";
       }
    }
    return 0;
}


问:
an error occurred while processing this directive
On my site:

http://bammeh.com/tempemail/

I keep getting erros all over my site when using PHP files that arent CHMOD to 644 or 755.

If I chmod recursively this directory 755 I get:

[an error occurred while processing this directive]

And I f I chmod it recursively to 644 I get:

Forbidden

You don't have permission to access /disposable/admin/ on this server.

Help? :( I use Hostmonster as my host. is it on their end?

答:
SuPHP was the root cause of me getting this error. I switched to a new VPS and by default it was using SuPHP. I switched to use PHP-FPM which allowed the scripts with permissions 664 to execute properly.

The current CRM I'm using had issues during the updates and they were failing because the file permissions set to 664 for some files which were part of the update. I couldn't change the permissions of these during the update process. It needed to be able to execute all the files otherwise the updates would fail.

After the updates I run a script to reset the folders to 755 and files to 644.

Hope this helps anyone who runs into this again.


问:
How to set the permission of the file based one the suffix during creating using vim?
When I create a new python script, I usually want to make it executable. I can do it in two steps: first create the file using vim; the set the permission using chmod. The question is: is it possible to merge the two steps into one?

What I would like to see is: when I create the file from vim, it will check the suffix and set proper permissions (configurable). And I expect it also works for files like .sh, .exe... Thanks.

答:
I use the following; it checks the file's shebang (e.g. #!/usr/bin/python) instead of the file extension.

```<code>" On the initial save, make the file executable if it has a shebang line,
" e.g. #!/usr/bin/env ...
" This uses the user's umask for determining the executable bits to be set.
function! s:GetShebang()
    return matchstr(getline(1), '^#!\S\+')
endfunction
function! s:MakeExecutable()
    if exists('b:executable') | return | endif
    let l:shebang = s:GetShebang()
    if empty(l:shebang) ||
    \   executable(expand('%:p')) ||
    \   ! executable('chmod')
        return
    endif

    call system('chmod +x ' . shellescape(expand('%')))
    if v:shell_error
        echohl ErrorMsg
        echomsg 'Cannot make file executable: ' . v:shell_error
        echohl None
        let b:executable = 0
    else
        echomsg 'Detected shebang' l:shebang . '; made file executable as' getfperm(expand('%'))
        let b:executable = 1
    endif
endfunction
augroup ExecutableFileDetect
    autocmd!
    autocmd BufWritePost * call <SID>MakeExecutable()
augroup END
</code>```

Body:
I use the following; it checks the file's shebang (e.g. #!/usr/bin/python) instead of the file extension.

" On the initial save, make the file executable if it has a shebang line,
" e.g. #!/usr/bin/env ...
" This uses the user's umask for determining the executable bits to be set.
function! s:GetShebang()
    return matchstr(getline(1), '^#!\S\+')
endfunction
function! s:MakeExecutable()
    if exists('b:executable') | return | endif
    let l:shebang = s:GetShebang()
    if empty(l:shebang) ||
    \   executable(expand('%:p')) ||
    \   ! executable('chmod')
        return
    endif

    call system('chmod +x ' . shellescape(expand('%')))
    if v:shell_error
        echohl ErrorMsg
        echomsg 'Cannot make file executable: ' . v:shell_error
        echohl None
        let b:executable = 0
    else
        echomsg 'Detected shebang' l:shebang . '; made file executable as' getfperm(expand('%'))
        let b:executable = 1
    endif
endfunction
augroup ExecutableFileDetect
    autocmd!
    autocmd BufWritePost * call <SID>MakeExecutable()
augroup END


问:
Set restrictions by ReceivedTime on mail list
Am trying to read mails that received only today. Below is the code where am restricting but its throwing an condition not valid error. The same is working fine when I gave a condition like unread = True.

```<code>Set myItems = myItems.Restrict("DateValue[ReceivedTime]='" & Format(DateValue(Now),"ddddd h:nn AMPM") & "'")
</code>```

Please help me on this.

答:
I see at least two problems.

You have "DateValue[ReceivedTime]" rather than "[ReceivedTime]".

You are restricting emails to those received at exactly midnight today rather than those received after midnight.

Try this code:

```<code>Sub RestrictByDate()

  Dim FmtToday As String
  Dim FldrInbox As Folder
  Dim MailItemsToday As Items
  Dim MailItemCrnt As MailItem

  FmtToday = Format(DateValue(Now()), "ddddd h:nn AMPM")

  ' #### Replace "xxxx" with the name of the store containing the target Inbox
  Set FldrInbox = Session.Folders("xxxx").Folders("Inbox")

  Set MailItemsToday = FldrInbox.Items.Restrict("[ReceivedTime] > '" & FmtToday & "'")

  Debug.Print "Number of emails received today=" & MailItemsToday.Count
  For Each MailItemCrnt In MailItemsToday
    With MailItemCrnt
      Debug.Print .ReceivedTime & " " & .Subject
    End With
  Next

End Sub
</code>```

Body:
Am trying to read mails that received only today. Below is the code where am restricting but its throwing an condition not valid error. The same is working fine when I gave a condition like unread = True.

Set myItems = myItems.Restrict("DateValue[ReceivedTime]='" & Format(DateValue(Now),"ddddd h:nn AMPM") & "'")

Please help me on this.

Body:
I see at least two problems.

You have "DateValue[ReceivedTime]" rather than "[ReceivedTime]".

You are restricting emails to those received at exactly midnight today rather than those received after midnight.

Try this code:

Sub RestrictByDate()

  Dim FmtToday As String
  Dim FldrInbox As Folder
  Dim MailItemsToday As Items
  Dim MailItemCrnt As MailItem

  FmtToday = Format(DateValue(Now()), "ddddd h:nn AMPM")

  ' #### Replace "xxxx" with the name of the store containing the target Inbox
  Set FldrInbox = Session.Folders("xxxx").Folders("Inbox")

  Set MailItemsToday = FldrInbox.Items.Restrict("[ReceivedTime] > '" & FmtToday & "'")

  Debug.Print "Number of emails received today=" & MailItemsToday.Count
  For Each MailItemCrnt In MailItemsToday
    With MailItemCrnt
      Debug.Print .ReceivedTime & " " & .Subject
    End With
  Next

End Sub


问:
How to get the ul li list values using jquery
I have  two lists of items in
s. I just want to get the all the items from one of the ul which have id of sortable2

```<code><ul id="sortable1" class="connectedSortable">
  <li class="ui-state-default">Item 1</li>
  <li class="ui-state-default">Item 2</li>
  <li class="ui-state-default">Item 3</li>
  <li class="ui-state-default">Item 4</li>
  <li class="ui-state-default">Item 5</li>
</ul>

<ul id="sortable2" class="connectedSortable" name="test">
  <li class="ui-state-highlight">Item 1</li>
  <li class="ui-state-highlight">Item 2</li>
  <li class="ui-state-highlight">Item 3</li>
  <li class="ui-state-highlight">Item 4</li>
  <li class="ui-state-highlight">Item 5</li>
</ul>
</code>```

I am trying this code but it is not working because I want the list data based on id. I don't know how I can achieve it.

Here is my code so far:

```<code>function myFunction() {
    var elementsLI = document.getElementsByTagName('li')
    var length = document.getElementsByTagName('li').length;
    for(var i = 0; i <= length ; ++i){
        alert(elementsLI[i].value);
    }
}
</code>```

答:
My solution with JQuery select the ul, then each li and get the text value:

```<code>$($('.advancedSearchCheckBoxList')).each(function(){// id of ul
  var li = $(this).find('li')//get each li in ul
  li.each(function(){// id of ul
     labels.push( $(this).text() )
  })
})
</code>```

labels=[]
$($('.advancedSearchCheckBoxList')).each(function(){// id of ul
  var li = $(this).find('li')//get each li in ul
  li.each(function(){// id of ul
     labels.push( $(this).text() )
  })
})
console.log( JSON.stringify( labels, null, 2) )```
<pre class="snippet-code-css lang-css prettyprint-override"><code>.advancedSearchCheckBoxList {
  list-style-type: none;
}</code>```

<input type="checkbox" name="fieldSelections[moods][]" value="1950's" id="moods1950's">
1950's[3]

<input type="checkbox" name="fieldSelections[moods][]" value="1960's" id="moods1960's">
1960's[9]

<input type="checkbox" name="fieldSelections[moods][]" value="1970's" id="moods1970's">
1970's[54]

<input type="checkbox" name="fieldSelections[moods][]" value="1980's" id="moods1980's">
1980's[44]

<input type="checkbox" name="fieldSelections[moods][]" value="1990's" id="moods1990's">
1990's[24]

<input type="checkbox" name="fieldSelections[moods][]" value="Acapella" id="moodsAcapella">
Acapella[4]

<input type="checkbox" name="fieldSelections[moods][]" value="Active" id="moodsActive">
Active[384]

<input type="checkbox" name="fieldSelections[moods][]" value="Aggressive" id="moodsAggressive">
Aggressive[1,173]

<input type="checkbox" name="fieldSelections[moods][]" value="Aggressive. Chaotic" id="moodsAggressive. Chaotic">
Aggressive. Chaotic[2]

<input type="checkbox" name="fieldSelections[moods][]" value="Ambient" id="moodsAmbient">
Ambient[130]

<input type="checkbox" name="fieldSelections[moods][]" value="Angry" id="moodsAngry">
Angry[44]

<input type="checkbox" name="fieldSelections[moods][]" value="Atmospheric" id="moodsAtmospheric">
Atmospheric[280]

<input type="checkbox" name="fieldSelections[moods][]" value="Beautiful" id="moodsBeautiful">
Beautiful[48]

<input type="checkbox" name="fieldSelections[moods][]" value="Bouncy" id="moodsBouncy">
Bouncy[311]

<input type="checkbox" name="fieldSelections[moods][]" value="Bright" id="moodsBright">
Bright[208]

<input type="checkbox" name="fieldSelections[moods][]" value="Building" id="moodsBuilding">
Building[745]

<input type="checkbox" name="fieldSelections[moods][]" value="Busy" id="moodsBusy">
Busy[53]

<input type="checkbox" name="fieldSelections[moods][]" value="Calm" id="moodsCalm">
Calm[510]

<input type="checkbox" name="fieldSelections[moods][]" value="Chaotic" id="moodsChaotic">
Chaotic[76]

<input type="checkbox" name="fieldSelections[moods][]" value="Chase" id="moodsChase">
Chase[13]

<input type="checkbox" name="fieldSelections[moods][]" value="Childish" id="moodsChildish">
Childish[8]

<input type="checkbox" name="fieldSelections[moods][]" value="Chill Out" id="moodsChill Out">
Chill Out[2]

<input type="checkbox" name="fieldSelections[moods][]" value="Chillout" id="moodsChillout">
Chillout[51]

<input type="checkbox" name="fieldSelections[moods][]" value="Confident" id="moodsConfident">
Confident[830]

<input type="checkbox" name="fieldSelections[moods][]" value="Cozy" id="moodsCozy">
Cozy[15]

<input type="checkbox" name="fieldSelections[moods][]" value="Dance" id="moodsDance">
Dance[151]

<input type="checkbox" name="fieldSelections[moods][]" value="Danceable" id="moodsDanceable">
Danceable[793]

<input type="checkbox" name="fieldSelections[moods][]" value="Dancebale" id="moodsDancebale">
Dancebale[3]

<input type="checkbox" name="fieldSelections[moods][]" value="Dark" id="moodsDark">
Dark[382]

<input type="checkbox" name="fieldSelections[moods][]" value="Despair" id="moodsDespair">
Despair[35]

<input type="checkbox" name="fieldSelections[moods][]" value="Dreamy" id="moodsDreamy">
Dreamy[397]

<input type="checkbox" name="fieldSelections[moods][]" value="Driving" id="moodsDriving">
Driving[534]

<input type="checkbox" name="fieldSelections[moods][]" value="Easy Listening" id="moodsEasy Listening">
Easy Listening[1,112]

<input type="checkbox" name="fieldSelections[moods][]" value="Eerie" id="moodsEerie">
Eerie[29]

<input type="checkbox" name="fieldSelections[moods][]" value="Electric" id="moodsElectric">
Electric[2]

<input type="checkbox" name="fieldSelections[moods][]" value="Electronic" id="moodsElectronic">
Electronic[246]

<input type="checkbox" name="fieldSelections[moods][]" value="Elegant" id="moodsElegant">
Elegant[30]

<input type="checkbox" name="fieldSelections[moods][]" value="Emotional" id="moodsEmotional">
Emotional[235]

<input type="checkbox" name="fieldSelections[moods][]" value="Energetic" id="moodsEnergetic">
Energetic[2,284]

<input type="checkbox" name="fieldSelections[moods][]" value="Epic" id="moodsEpic">
Epic[33]

<input type="checkbox" name="fieldSelections[moods][]" value="Epic. Aggressive" id="moodsEpic. Aggressive">
Epic. Aggressive[1]

<input type="checkbox" name="fieldSelections[moods][]" value="Ethnic" id="moodsEthnic">
Ethnic[28]

<input type="checkbox" name="fieldSelections[moods][]" value="Experimental" id="moodsExperimental">
Experimental[19]

<input type="checkbox" name="fieldSelections[moods][]" value="Fast" id="moodsFast">
Fast[103]

<input type="checkbox" name="fieldSelections[moods][]" value="Feel Good" id="moodsFeel Good">
Feel Good[531]

<input type="checkbox" name="fieldSelections[moods][]" value="Free" id="moodsFree">
Free[75]

<input type="checkbox" name="fieldSelections[moods][]" value="Funky" id="moodsFunky">
Funky[166]

<input type="checkbox" name="fieldSelections[moods][]" value="Futuristic" id="moodsFuturistic">
Futuristic[172]

<input type="checkbox" name="fieldSelections[moods][]" value="Gangster" id="moodsGangster">
Gangster[239]

<input type="checkbox" name="fieldSelections[moods][]" value="Gentle" id="moodsGentle">
Gentle[240]

<input type="checkbox" name="fieldSelections[moods][]" value="Goovy" id="moodsGoovy">
Goovy[4]

<input type="checkbox" name="fieldSelections[moods][]" value="Gritty" id="moodsGritty">
Gritty[141]

<input type="checkbox" name="fieldSelections[moods][]" value="Groovy" id="moodsGroovy">
Groovy[412]

<input type="checkbox" name="fieldSelections[moods][]" value="Happy" id="moodsHappy">
Happy[868]

<input type="checkbox" name="fieldSelections[moods][]" value="Heartbreak" id="moodsHeartbreak">
Heartbreak[28]

<input type="checkbox" name="fieldSelections[moods][]" value="Heavy" id="moodsHeavy">
Heavy[192]

<input type="checkbox" name="fieldSelections[moods][]" value="Humorous" id="moodsHumorous">
Humorous[256]

<input type="checkbox" name="fieldSelections[moods][]" value="Jazzy" id="moodsJazzy">
Jazzy[45]

<input type="checkbox" name="fieldSelections[moods][]" value="Laidback" id="moodsLaidback">
Laidback[4]

<input type="checkbox" name="fieldSelections[moods][]" value="Laid Back" id="moodsLaid Back">
Laid Back[211]

<input type="checkbox" name="fieldSelections[moods][]" value="Latin" id="moodsLatin">
Latin[3]

<input type="checkbox" name="fieldSelections[moods][]" value="Light" id="moodsLight">
Light[98]

<input type="checkbox" name="fieldSelections[moods][]" value="Love" id="moodsLove">
Love[44]

<input type="checkbox" name="fieldSelections[moods][]" value="Lush" id="moodsLush">
Lush[44]

<input type="checkbox" name="fieldSelections[moods][]" value="Melancholic" id="moodsMelancholic">
Melancholic[1,141]

<input type="checkbox" name="fieldSelections[moods][]" value="Melodic" id="moodsMelodic">
Melodic[201]

<input type="checkbox" name="fieldSelections[moods][]" value="Melody" id="moodsMelody">
Melody[1]

<input type="checkbox" name="fieldSelections[moods][]" value="Montage" id="moodsMontage">
Montage[1]

<input type="checkbox" name="fieldSelections[moods][]" value="Motivating" id="moodsMotivating">
Motivating[34]

<input type="checkbox" name="fieldSelections[moods][]" value="Mysterious" id="moodsMysterious">
Mysterious[157]

<input type="checkbox" name="fieldSelections[moods][]" value="Mystersious" id="moodsMystersious">
Mystersious[1]

<input type="checkbox" name="fieldSelections[moods][]" value="Pain" id="moodsPain">
Pain[16]

<input type="checkbox" name="fieldSelections[moods][]" value="Party" id="moodsParty">
Party[71]

<input type="checkbox" name="fieldSelections[moods][]" value="Positive" id="moodsPositive">
Positive[133]

<input type="checkbox" name="fieldSelections[moods][]" value="Quirky" id="moodsQuirky">
Quirky[94]

<input type="checkbox" name="fieldSelections[moods][]" value="Relaxed" id="moodsRelaxed">
Relaxed[397]

<input type="checkbox" name="fieldSelections[moods][]" value="Rhythmic" id="moodsRhythmic">
Rhythmic[731]

<input type="checkbox" name="fieldSelections[moods][]" value="Sad" id="moodsSad">
Sad[104]

<input type="checkbox" name="fieldSelections[moods][]" value="Seductive" id="moodsSeductive">
Seductive[320]

<input type="checkbox" name="fieldSelections[moods][]" value="Sensual" id="moodsSensual">
Sensual[65]

<input type="checkbox" name="fieldSelections[moods][]" value="Sentimental" id="moodsSentimental">
Sentimental[295]

<input type="checkbox" name="fieldSelections[moods][]" value="Serious" id="moodsSerious">
Serious[54]

<input type="checkbox" name="fieldSelections[moods][]" value="Short" id="moodsShort">
Short[7]

<input type="checkbox" name="fieldSelections[moods][]" value="Slow" id="moodsSlow">
Slow[96]

<input type="checkbox" name="fieldSelections[moods][]" value="Smooth" id="moodsSmooth">
Smooth[170]

<input type="checkbox" name="fieldSelections[moods][]" value="Soft" id="moodsSoft">
Soft[36]

<input type="checkbox" name="fieldSelections[moods][]" value="Sophisticated" id="moodsSophisticated">
Sophisticated[45]

<input type="checkbox" name="fieldSelections[moods][]" value="Soulful" id="moodsSoulful">
Soulful[354]

<input type="checkbox" name="fieldSelections[moods][]" value="Sparse" id="moodsSparse">
Sparse[129]

<input type="checkbox" name="fieldSelections[moods][]" value="Speaking" id="moodsSpeaking">
Speaking[28]

<input type="checkbox" name="fieldSelections[moods][]" value="Stong" id="moodsStong">
Stong[4]

<input type="checkbox" name="fieldSelections[moods][]" value="Stressful" id="moodsStressful">
Stressful[647]

<input type="checkbox" name="fieldSelections[moods][]" value="Strong" id="moodsStrong">
Strong[124]

<input type="checkbox" name="fieldSelections[moods][]" value="Tender" id="moodsTender">
Tender[95]

<input type="checkbox" name="fieldSelections[moods][]" value="Tense" id="moodsTense">
Tense[64]

<input type="checkbox" name="fieldSelections[moods][]" value="Upbeat" id="moodsUpbeat">
Upbeat[525]

<input type="checkbox" name="fieldSelections[moods][]" value="Uplifting" id="moodsUplifting">
Uplifting[226]

<input type="checkbox" name="fieldSelections[moods][]" value="Uptempo" id="moodsUptempo">
Uptempo[93]

<input type="checkbox" name="fieldSelections[moods][]" value="Warm" id="moodsWarm">
Warm[105]

<input type="checkbox" name="fieldSelections[moods][]" value="Whimsical" id="moodsWhimsical">
Whimsical[39]

<input type="checkbox" name="fieldSelections[moods][]" value="Wild" id="moodsWild">
Wild[14]

<input type="checkbox" name="fieldSelections[moods][]" value="Youthful" id="moodsYouthful">
Youthful[35]

```

Body:
I have  two lists of items in
s. I just want to get the all the items from one of the ul which have id of sortable2

Item 1

Item 2

Item 3

Item 4

Item 5

Item 1

Item 2

Item 3

Item 4

Item 5

I am trying this code but it is not working because I want the list data based on id. I don't know how I can achieve it.

Here is my code so far:

function myFunction() {
    var elementsLI = document.getElementsByTagName('li')
    var length = document.getElementsByTagName('li').length;
    for(var i = 0; i <= length ; ++i){
        alert(elementsLI[i].value);
    }
}

Body:
My solution with JQuery select the ul, then each li and get the text value:

$($('.advancedSearchCheckBoxList')).each(function(){// id of ul
  var li = $(this).find('li')//get each li in ul
  li.each(function(){// id of ul
     labels.push( $(this).text() )
  })
})

labels=[]
$($('.advancedSearchCheckBoxList')).each(function(){// id of ul
  var li = $(this).find('li')//get each li in ul
  li.each(function(){// id of ul
     labels.push( $(this).text() )
  })
})
console.log( JSON.stringify( labels, null, 2) )

.advancedSearchCheckBoxList {
  list-style-type: none;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="advancedSearchCheckBoxList"><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="1950's" id="moods1950's"></div><label class="advancedSearchLabel" for="moods1950's">1950's<span class="advancedSearchFacetCount">[3]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="1960's" id="moods1960's"></div><label class="advancedSearchLabel" for="moods1960's">1960's<span class="advancedSearchFacetCount">[9]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="1970's" id="moods1970's"></div><label class="advancedSearchLabel" for="moods1970's">1970's<span class="advancedSearchFacetCount">[54]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="1980's" id="moods1980's"></div><label class="advancedSearchLabel" for="moods1980's">1980's<span class="advancedSearchFacetCount">[44]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="1990's" id="moods1990's"></div><label class="advancedSearchLabel" for="moods1990's">1990's<span class="advancedSearchFacetCount">[24]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Acapella" id="moodsAcapella"></div><label class="advancedSearchLabel" for="moodsAcapella">Acapella<span class="advancedSearchFacetCount">[4]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Active" id="moodsActive"></div><label class="advancedSearchLabel" for="moodsActive">Active<span class="advancedSearchFacetCount">[384]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Aggressive" id="moodsAggressive"></div><label class="advancedSearchLabel" for="moodsAggressive">Aggressive<span class="advancedSearchFacetCount">[1,173]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Aggressive. Chaotic" id="moodsAggressive. Chaotic"></div><label class="advancedSearchLabel" for="moodsAggressive. Chaotic">Aggressive. Chaotic<span class="advancedSearchFacetCount">[2]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Ambient" id="moodsAmbient"></div><label class="advancedSearchLabel" for="moodsAmbient">Ambient<span class="advancedSearchFacetCount">[130]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Angry" id="moodsAngry"></div><label class="advancedSearchLabel" for="moodsAngry">Angry<span class="advancedSearchFacetCount">[44]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Atmospheric" id="moodsAtmospheric"></div><label class="advancedSearchLabel" for="moodsAtmospheric">Atmospheric<span class="advancedSearchFacetCount">[280]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Beautiful" id="moodsBeautiful"></div><label class="advancedSearchLabel" for="moodsBeautiful">Beautiful<span class="advancedSearchFacetCount">[48]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Bouncy" id="moodsBouncy"></div><label class="advancedSearchLabel" for="moodsBouncy">Bouncy<span class="advancedSearchFacetCount">[311]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Bright" id="moodsBright"></div><label class="advancedSearchLabel" for="moodsBright">Bright<span class="advancedSearchFacetCount">[208]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Building" id="moodsBuilding"></div><label class="advancedSearchLabel" for="moodsBuilding">Building<span class="advancedSearchFacetCount">[745]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Busy" id="moodsBusy"></div><label class="advancedSearchLabel" for="moodsBusy">Busy<span class="advancedSearchFacetCount">[53]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Calm" id="moodsCalm"></div><label class="advancedSearchLabel" for="moodsCalm">Calm<span class="advancedSearchFacetCount">[510]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Chaotic" id="moodsChaotic"></div><label class="advancedSearchLabel" for="moodsChaotic">Chaotic<span class="advancedSearchFacetCount">[76]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Chase" id="moodsChase"></div><label class="advancedSearchLabel" for="moodsChase">Chase<span class="advancedSearchFacetCount">[13]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Childish" id="moodsChildish"></div><label class="advancedSearchLabel" for="moodsChildish">Childish<span class="advancedSearchFacetCount">[8]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Chill Out" id="moodsChill Out"></div><label class="advancedSearchLabel" for="moodsChill Out">Chill Out<span class="advancedSearchFacetCount">[2]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Chillout" id="moodsChillout"></div><label class="advancedSearchLabel" for="moodsChillout">Chillout<span class="advancedSearchFacetCount">[51]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Confident" id="moodsConfident"></div><label class="advancedSearchLabel" for="moodsConfident">Confident<span class="advancedSearchFacetCount">[830]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Cozy" id="moodsCozy"></div><label class="advancedSearchLabel" for="moodsCozy">Cozy<span class="advancedSearchFacetCount">[15]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Dance" id="moodsDance"></div><label class="advancedSearchLabel" for="moodsDance">Dance<span class="advancedSearchFacetCount">[151]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Danceable" id="moodsDanceable"></div><label class="advancedSearchLabel" for="moodsDanceable">Danceable<span class="advancedSearchFacetCount">[793]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Dancebale" id="moodsDancebale"></div><label class="advancedSearchLabel" for="moodsDancebale">Dancebale<span class="advancedSearchFacetCount">[3]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Dark" id="moodsDark"></div><label class="advancedSearchLabel" for="moodsDark">Dark<span class="advancedSearchFacetCount">[382]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Despair" id="moodsDespair"></div><label class="advancedSearchLabel" for="moodsDespair">Despair<span class="advancedSearchFacetCount">[35]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Dreamy" id="moodsDreamy"></div><label class="advancedSearchLabel" for="moodsDreamy">Dreamy<span class="advancedSearchFacetCount">[397]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Driving" id="moodsDriving"></div><label class="advancedSearchLabel" for="moodsDriving">Driving<span class="advancedSearchFacetCount">[534]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Easy Listening" id="moodsEasy Listening"></div><label class="advancedSearchLabel" for="moodsEasy Listening">Easy Listening<span class="advancedSearchFacetCount">[1,112]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Eerie" id="moodsEerie"></div><label class="advancedSearchLabel" for="moodsEerie">Eerie<span class="advancedSearchFacetCount">[29]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Electric" id="moodsElectric"></div><label class="advancedSearchLabel" for="moodsElectric">Electric<span class="advancedSearchFacetCount">[2]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Electronic" id="moodsElectronic"></div><label class="advancedSearchLabel" for="moodsElectronic">Electronic<span class="advancedSearchFacetCount">[246]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Elegant" id="moodsElegant"></div><label class="advancedSearchLabel" for="moodsElegant">Elegant<span class="advancedSearchFacetCount">[30]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Emotional" id="moodsEmotional"></div><label class="advancedSearchLabel" for="moodsEmotional">Emotional<span class="advancedSearchFacetCount">[235]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Energetic" id="moodsEnergetic"></div><label class="advancedSearchLabel" for="moodsEnergetic">Energetic<span class="advancedSearchFacetCount">[2,284]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Epic" id="moodsEpic"></div><label class="advancedSearchLabel" for="moodsEpic">Epic<span class="advancedSearchFacetCount">[33]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Epic. Aggressive" id="moodsEpic. Aggressive"></div><label class="advancedSearchLabel" for="moodsEpic. Aggressive">Epic. Aggressive<span class="advancedSearchFacetCount">[1]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Ethnic" id="moodsEthnic"></div><label class="advancedSearchLabel" for="moodsEthnic">Ethnic<span class="advancedSearchFacetCount">[28]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Experimental" id="moodsExperimental"></div><label class="advancedSearchLabel" for="moodsExperimental">Experimental<span class="advancedSearchFacetCount">[19]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Fast" id="moodsFast"></div><label class="advancedSearchLabel" for="moodsFast">Fast<span class="advancedSearchFacetCount">[103]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Feel Good" id="moodsFeel Good"></div><label class="advancedSearchLabel" for="moodsFeel Good">Feel Good<span class="advancedSearchFacetCount">[531]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Free" id="moodsFree"></div><label class="advancedSearchLabel" for="moodsFree">Free<span class="advancedSearchFacetCount">[75]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Funky" id="moodsFunky"></div><label class="advancedSearchLabel" for="moodsFunky">Funky<span class="advancedSearchFacetCount">[166]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Futuristic" id="moodsFuturistic"></div><label class="advancedSearchLabel" for="moodsFuturistic">Futuristic<span class="advancedSearchFacetCount">[172]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Gangster" id="moodsGangster"></div><label class="advancedSearchLabel" for="moodsGangster">Gangster<span class="advancedSearchFacetCount">[239]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Gentle" id="moodsGentle"></div><label class="advancedSearchLabel" for="moodsGentle">Gentle<span class="advancedSearchFacetCount">[240]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Goovy" id="moodsGoovy"></div><label class="advancedSearchLabel" for="moodsGoovy">Goovy<span class="advancedSearchFacetCount">[4]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Gritty" id="moodsGritty"></div><label class="advancedSearchLabel" for="moodsGritty">Gritty<span class="advancedSearchFacetCount">[141]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Groovy" id="moodsGroovy"></div><label class="advancedSearchLabel" for="moodsGroovy">Groovy<span class="advancedSearchFacetCount">[412]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Happy" id="moodsHappy"></div><label class="advancedSearchLabel" for="moodsHappy">Happy<span class="advancedSearchFacetCount">[868]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Heartbreak" id="moodsHeartbreak"></div><label class="advancedSearchLabel" for="moodsHeartbreak">Heartbreak<span class="advancedSearchFacetCount">[28]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Heavy" id="moodsHeavy"></div><label class="advancedSearchLabel" for="moodsHeavy">Heavy<span class="advancedSearchFacetCount">[192]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Humorous" id="moodsHumorous"></div><label class="advancedSearchLabel" for="moodsHumorous">Humorous<span class="advancedSearchFacetCount">[256]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Jazzy" id="moodsJazzy"></div><label class="advancedSearchLabel" for="moodsJazzy">Jazzy<span class="advancedSearchFacetCount">[45]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Laidback" id="moodsLaidback"></div><label class="advancedSearchLabel" for="moodsLaidback">Laidback<span class="advancedSearchFacetCount">[4]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Laid Back" id="moodsLaid Back"></div><label class="advancedSearchLabel" for="moodsLaid Back">Laid Back<span class="advancedSearchFacetCount">[211]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Latin" id="moodsLatin"></div><label class="advancedSearchLabel" for="moodsLatin">Latin<span class="advancedSearchFacetCount">[3]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Light" id="moodsLight"></div><label class="advancedSearchLabel" for="moodsLight">Light<span class="advancedSearchFacetCount">[98]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Love" id="moodsLove"></div><label class="advancedSearchLabel" for="moodsLove">Love<span class="advancedSearchFacetCount">[44]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Lush" id="moodsLush"></div><label class="advancedSearchLabel" for="moodsLush">Lush<span class="advancedSearchFacetCount">[44]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Melancholic" id="moodsMelancholic"></div><label class="advancedSearchLabel" for="moodsMelancholic">Melancholic<span class="advancedSearchFacetCount">[1,141]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Melodic" id="moodsMelodic"></div><label class="advancedSearchLabel" for="moodsMelodic">Melodic<span class="advancedSearchFacetCount">[201]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Melody" id="moodsMelody"></div><label class="advancedSearchLabel" for="moodsMelody">Melody<span class="advancedSearchFacetCount">[1]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Montage" id="moodsMontage"></div><label class="advancedSearchLabel" for="moodsMontage">Montage<span class="advancedSearchFacetCount">[1]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Motivating" id="moodsMotivating"></div><label class="advancedSearchLabel" for="moodsMotivating">Motivating<span class="advancedSearchFacetCount">[34]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Mysterious" id="moodsMysterious"></div><label class="advancedSearchLabel" for="moodsMysterious">Mysterious<span class="advancedSearchFacetCount">[157]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Mystersious" id="moodsMystersious"></div><label class="advancedSearchLabel" for="moodsMystersious">Mystersious<span class="advancedSearchFacetCount">[1]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Pain" id="moodsPain"></div><label class="advancedSearchLabel" for="moodsPain">Pain<span class="advancedSearchFacetCount">[16]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Party" id="moodsParty"></div><label class="advancedSearchLabel" for="moodsParty">Party<span class="advancedSearchFacetCount">[71]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Positive" id="moodsPositive"></div><label class="advancedSearchLabel" for="moodsPositive">Positive<span class="advancedSearchFacetCount">[133]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Quirky" id="moodsQuirky"></div><label class="advancedSearchLabel" for="moodsQuirky">Quirky<span class="advancedSearchFacetCount">[94]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Relaxed" id="moodsRelaxed"></div><label class="advancedSearchLabel" for="moodsRelaxed">Relaxed<span class="advancedSearchFacetCount">[397]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Rhythmic" id="moodsRhythmic"></div><label class="advancedSearchLabel" for="moodsRhythmic">Rhythmic<span class="advancedSearchFacetCount">[731]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Sad" id="moodsSad"></div><label class="advancedSearchLabel" for="moodsSad">Sad<span class="advancedSearchFacetCount">[104]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Seductive" id="moodsSeductive"></div><label class="advancedSearchLabel" for="moodsSeductive">Seductive<span class="advancedSearchFacetCount">[320]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Sensual" id="moodsSensual"></div><label class="advancedSearchLabel" for="moodsSensual">Sensual<span class="advancedSearchFacetCount">[65]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Sentimental" id="moodsSentimental"></div><label class="advancedSearchLabel" for="moodsSentimental">Sentimental<span class="advancedSearchFacetCount">[295]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Serious" id="moodsSerious"></div><label class="advancedSearchLabel" for="moodsSerious">Serious<span class="advancedSearchFacetCount">[54]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Short" id="moodsShort"></div><label class="advancedSearchLabel" for="moodsShort">Short<span class="advancedSearchFacetCount">[7]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Slow" id="moodsSlow"></div><label class="advancedSearchLabel" for="moodsSlow">Slow<span class="advancedSearchFacetCount">[96]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Smooth" id="moodsSmooth"></div><label class="advancedSearchLabel" for="moodsSmooth">Smooth<span class="advancedSearchFacetCount">[170]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Soft" id="moodsSoft"></div><label class="advancedSearchLabel" for="moodsSoft">Soft<span class="advancedSearchFacetCount">[36]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Sophisticated" id="moodsSophisticated"></div><label class="advancedSearchLabel" for="moodsSophisticated">Sophisticated<span class="advancedSearchFacetCount">[45]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Soulful" id="moodsSoulful"></div><label class="advancedSearchLabel" for="moodsSoulful">Soulful<span class="advancedSearchFacetCount">[354]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Sparse" id="moodsSparse"></div><label class="advancedSearchLabel" for="moodsSparse">Sparse<span class="advancedSearchFacetCount">[129]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Speaking" id="moodsSpeaking"></div><label class="advancedSearchLabel" for="moodsSpeaking">Speaking<span class="advancedSearchFacetCount">[28]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Stong" id="moodsStong"></div><label class="advancedSearchLabel" for="moodsStong">Stong<span class="advancedSearchFacetCount">[4]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Stressful" id="moodsStressful"></div><label class="advancedSearchLabel" for="moodsStressful">Stressful<span class="advancedSearchFacetCount">[647]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Strong" id="moodsStrong"></div><label class="advancedSearchLabel" for="moodsStrong">Strong<span class="advancedSearchFacetCount">[124]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Tender" id="moodsTender"></div><label class="advancedSearchLabel" for="moodsTender">Tender<span class="advancedSearchFacetCount">[95]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Tense" id="moodsTense"></div><label class="advancedSearchLabel" for="moodsTense">Tense<span class="advancedSearchFacetCount">[64]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Upbeat" id="moodsUpbeat"></div><label class="advancedSearchLabel" for="moodsUpbeat">Upbeat<span class="advancedSearchFacetCount">[525]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Uplifting" id="moodsUplifting"></div><label class="advancedSearchLabel" for="moodsUplifting">Uplifting<span class="advancedSearchFacetCount">[226]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Uptempo" id="moodsUptempo"></div><label class="advancedSearchLabel" for="moodsUptempo">Uptempo<span class="advancedSearchFacetCount">[93]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Warm" id="moodsWarm"></div><label class="advancedSearchLabel" for="moodsWarm">Warm<span class="advancedSearchFacetCount">[105]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Whimsical" id="moodsWhimsical"></div><label class="advancedSearchLabel" for="moodsWhimsical">Whimsical<span class="advancedSearchFacetCount">[39]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Wild" id="moodsWild"></div><label class="advancedSearchLabel" for="moodsWild">Wild<span class="advancedSearchFacetCount">[14]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Youthful" id="moodsYouthful"></div><label class="advancedSearchLabel" for="moodsYouthful">Youthful<span class="advancedSearchFacetCount">[35]</span></label></li></ul>


问:
Dynamic Reports BigDecimal
I am trying to build a report with multiple columns. I have a column total that represents the summation of the previous columns.

However, the value I am getting is of type BigDecimal and the return type of the .add method is BigDecimal and not integer, for example: 12.00 and I want it to be shown as only 12 in the report.

Here is my code:

```<code>TextColumnBuilder<Integer> col1 = col.column("Locked Users" , "Locked" , DataTypes.integerType());
TextColumnBuilder<Integer> col2 = col.column("Unlocked Users" , "unlocked" , DataTypes.integerType());
TextColumnBuilder<Integer> col3 = col.column("Failed Logins" , "invalid" , DataTypes.integerType());
TextColumnBuilder<Integer> col4 = col.column("Forgot Password" , "Passforget" , DataTypes.integerType());
TextColumnBuilder<BigDecimal> col5 = col1.add(col2).add(col3).add(col4).setTitle("Total");
</code>```

How can I do it?

答:
By default Big Decimal type has following format "#,##0.00#"

You could override it for your column

```<code> col5.setPattern("#,##0");
</code>```

Title: Dynamic Reports BigDecimal

Body:
I am trying to build a report with multiple columns. I have a column total that represents the summation of the previous columns.

However, the value I am getting is of type BigDecimal and the return type of the .add method is BigDecimal and not integer, for example: 12.00 and I want it to be shown as only 12 in the report.

Here is my code:

TextColumnBuilder<Integer> col1 = col.column("Locked Users" , "Locked" , DataTypes.integerType());
TextColumnBuilder<Integer> col2 = col.column("Unlocked Users" , "unlocked" , DataTypes.integerType());
TextColumnBuilder<Integer> col3 = col.column("Failed Logins" , "invalid" , DataTypes.integerType());
TextColumnBuilder<Integer> col4 = col.column("Forgot Password" , "Passforget" , DataTypes.integerType());
TextColumnBuilder<BigDecimal> col5 = col1.add(col2).add(col3).add(col4).setTitle("Total");

How can I do it?

Body:
By default Big Decimal type has following format "#,##0.00#"

You could override it for your column

 col5.setPattern("#,##0");


问:
Adding to arrays based on names of elements in another array
Couldn't find a less confusing title but here is the pseudo-code:

```<code>for all video['tags'][i] in video['tags'][3..-1]
  topic = video['tags'][i]
  topic_array += video['id']
end
</code>```

Let's say there are 2 elements in the video['tags'][3..-1]:

```<code>video['tags'][3..-1] # => ["Health", "Politics"]
video['id']          # => 35
</code>```

I want to add the integer 35 to two different arrays named Health and Politics. Those arrays may or may not exist beforehand.

End result example:

```<code>Health # => [21, 25, 35]
Politics # => [35]
</code>```

答:
Instead of using multiple arrays to store ids for each tag, i would use one hash in which each key is a tag and its value is the array of ids, for example:

```<code>tags = { "Health" => [21, 25] }
</code>```

With that in place, you could solve your problem with something like this:

```<code>video["tags"][3..-1].each do |tag|
  tags.key?(tag) ? tags[tag] << video["id"] : tags[tag] = [video["id"]]
end
</code>```

Check for tags contents:

```<code>tags
#=> {"Health"=>[21, 25, 35], "Politics"=>[35]}
</code>```

To get the ids, you simply fetch/read the key (i.e tag) you want from tags hash, for example:

```<code>tags["Health"]
#=> [21, 25, 35]
</code>```

Body:
Couldn't find a less confusing title but here is the pseudo-code:

for all video['tags'][i] in video['tags'][3..-1]
  topic = video['tags'][i]
  topic_array += video['id']
end

Let's say there are 2 elements in the video['tags'][3..-1]:

video['tags'][3..-1] # => ["Health", "Politics"]
video['id']          # => 35

I want to add the integer 35 to two different arrays named Health and Politics. Those arrays may or may not exist beforehand.

End result example:

Health # => [21, 25, 35]
Politics # => [35]

Body:
Instead of using multiple arrays to store ids for each tag, i would use one hash in which each key is a tag and its value is the array of ids, for example:

tags = { "Health" => [21, 25] }

With that in place, you could solve your problem with something like this:

video["tags"][3..-1].each do |tag|
  tags.key?(tag) ? tags[tag] << video["id"] : tags[tag] = [video["id"]]
end

Check for tags contents:

tags
#=> {"Health"=>[21, 25, 35], "Politics"=>[35]}

To get the ids, you simply fetch/read the key (i.e tag) you want from tags hash, for example:

tags["Health"]
#=> [21, 25, 35]


问:
What is the difference between valueforKey:, objectForKey:, and valueForKeyPath:?
I have 2 questions:

What is the difference between valueForKey: and objectForKey:? Is it that one is for NSDictionarys (objectForKey:) and for others it is valueforKey:, or is it the reverse?

Also what is the difference between valueForKey: and valueForKeyPath:? Has it got something to do with Core Data?

Please help.

答:
objectForKey: is a method on NSDictionary for accessing the object associated with a key. valueForKey: is a method on NSObject for accessing any value associated with any object, through the name of a accessor method, property, and/or instance variable.

valueForKeyPath: can be seen as a shorthand for several calls to valueForKey:. You can think of it as sort of a xpath, if you will.

These two statements will result in the same output:

```<code>// Using nested valueForKey:
NSLog(@"%@", [[myObject valueForKey:@"foo"] valueForKey:@"bar"]);
// Can be done with a single valueForKeyPath;
NSLog(@"%@", [myObject valueForKeyPath:@"foo.bar"]);
</code>```

valueForKey:and valueForKeyPath: are part of KVC (Key Value Coding). Introduction and in-depth documentation can be found here: http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/KeyValueCoding/

Body:
objectForKey: is a method on NSDictionary for accessing the object associated with a key. valueForKey: is a method on NSObject for accessing any value associated with any object, through the name of a accessor method, property, and/or instance variable.

valueForKeyPath: can be seen as a shorthand for several calls to valueForKey:. You can think of it as sort of a xpath, if you will.

These two statements will result in the same output:

// Using nested valueForKey:
NSLog(@"%@", [[myObject valueForKey:@"foo"] valueForKey:@"bar"]);
// Can be done with a single valueForKeyPath;
NSLog(@"%@", [myObject valueForKeyPath:@"foo.bar"]);

valueForKey:and valueForKeyPath: are part of KVC (Key Value Coding). Introduction and in-depth documentation can be found here: http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/KeyValueCoding/


问:
Refused to execute script from
I am getting this error While accessing this URL via ajax with jasonp datatype.
Please help someone  to resolve this issue

Refused to execute script from 'https://script.google.com/macros/s/AKfycbw4SWi16wWTR622NUVlsFacqrCWz7KB8DaZ…020319074134340642_1499172512130&name=dfgdg&comment=dfgdfg&_=1499172512131' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

答:
```<code>$ curl <your link>
> moved permanently to <new link>

$ curl <new link>
> moved permanently to:

https://accounts.google.com/ServiceLogin?service=wise&passive=1209600&continue=https://script.google.com/macros/s/AKfycbw4SWi16wWTR622NUVlsFacqrCWz7KB8DaZ/&followup=https://script.google.com/macros/s/AKfycbw4SWi16wWTR622NUVlsFacqrCWz7KB8DaZ/

$ curl -I <final link>

> ...
> Content-Type: text/html; charset=UTF-8
> ...
</code>```

So the script is delivered as html, you need to change that on the server.

Title: Refused to execute script from

Body:
$ curl <your link>
> moved permanently to <new link>

$ curl <new link>
> moved permanently to:

https://accounts.google.com/ServiceLogin?service=wise&amp;passive=1209600&amp;continue=https://script.google.com/macros/s/AKfycbw4SWi16wWTR622NUVlsFacqrCWz7KB8DaZ/&amp;followup=https://script.google.com/macros/s/AKfycbw4SWi16wWTR622NUVlsFacqrCWz7KB8DaZ/

$ curl -I <final link>

> ...
> Content-Type: text/html; charset=UTF-8
> ...

So the script is delivered as html, you need to change that on the server.


问:
How to achieve speed more than 1000 msg/sec to SQS?
I have the following code that sends a batch message to SQS.
My goal is to send 1000 msg/sec in while true loop.

I have a bottleneck - select random ids from CSV file. How can I improve the algorithm to achieve the goal?

```<code>async def send_to_sqs(file_path, loop):
    ids = load_file_to_list(file_path)
    while True:
        messages = []
        for id in ids:
            message = {'Id': id}
            messages.append(message)

        for i in range(0, 10000, 10): #butch size is 10
            messages_batch = messages[i:i+10]

            entries = []
            for message in messages_batch:
                entries.append({'Id': str(message['Id']),
                'MessageBody': json.dumps(message)})
            await sqs.send_message_batch(QueueUrl=sqs_url, Entries=entries)

def load_file_to_list(file_path):
   with open(file_path, 'r') as f:
     reader = csv.reader(f)
     return list(reader)
</code>```

答: I would try gathering all of the possible random id's from your CSV file in memory before you start your while loop.  That way the loop does not have to open the file and get a random number.  You could then write a function that selects a random number from the list of random numbers held in memory.  This would speed things up a lot.</p>

Body:
I have the following code that sends a batch message to SQS.
My goal is to send 1000 msg/sec in while true loop.

I have a bottleneck - select random ids from CSV file. How can I improve the algorithm to achieve the goal?

async def send_to_sqs(file_path, loop):
    ids = load_file_to_list(file_path)
    while True:
        messages = []
        for id in ids:
            message = {'Id': id}
            messages.append(message)

        for i in range(0, 10000, 10): #butch size is 10
            messages_batch = messages[i:i+10]

            entries = []
            for message in messages_batch:
                entries.append({'Id': str(message['Id']),
                'MessageBody': json.dumps(message)})
            await sqs.send_message_batch(QueueUrl=sqs_url, Entries=entries)

def load_file_to_list(file_path):
   with open(file_path, 'r') as f:
     reader = csv.reader(f)
     return list(reader)


问:
SQL Query performance with inner queries
I am not sure whether the title of this question is correct or not.

I have a table for example users which contains different types of users. Like user type 10, 20, 30 etc.

In a query I need to join the user table, but I want only user type 20. So which of the below query perform better.

```<code> SELECT fields
 FROM consumer c
 INNER JOIN user u ON u.userid = c.userid
 WHERE u.type = 20
</code>```

In another way,

```<code> SELECT fields
 FROM consumer c
 INNER JOIN (SELECT user_fields FROM  user WHERE type = 20) u ON u.userid = c.userid
</code>```

Please advice.

答:
Both your options are valid. Personally would code it like this;

```<code>SELECT fields
FROM consumer c
INNER JOIN user u ON u.userid = c.userid and u.type = 20
</code>```

Run both queries in SQL Management Studio (query) and tick 'Include actual execution plan'. This will let you see the performance of your queries against each other. It will depend on your particular database.

Body:
I am not sure whether the title of this question is correct or not.

I have a table for example users which contains different types of users. Like user type 10, 20, 30 etc.

In a query I need to join the user table, but I want only user type 20. So which of the below query perform better.

 SELECT fields
 FROM consumer c
 INNER JOIN user u ON u.userid = c.userid
 WHERE u.type = 20

In another way,

 SELECT fields
 FROM consumer c
 INNER JOIN (SELECT user_fields FROM  user WHERE type = 20) u ON u.userid = c.userid

Please advice.

Body:
Both your options are valid. Personally would code it like this;

SELECT fields
FROM consumer c
INNER JOIN user u ON u.userid = c.userid and u.type = 20

Run both queries in SQL Management Studio (query) and tick 'Include actual execution plan'. This will let you see the performance of your queries against each other. It will depend on your particular database.


问:
Pass HTML Table string through Json from controller to view
I want to achieve this:

```<code>public System.Web.Mvc.ActionResult ExposureGrid(Guid? id, decimal stdDev)
        {
            //return null;
            try
            {
                var str = "<table border=1>";
                str += "<tr><th>Date</th><th>Expected Credit Exposure</th><th>Max Credit Exposure</th></tr>";

                str += "<tr><td>12/1/2010</td><td>100,000</td><td>50</td></tr>";
                str += "<tr><td>12/2/2010</td><td>101,000</td><td>100</td></tr>";
                str += "<tr><td>12/3/2010</td><td>102,000</td><td>150</td></tr>";
                str += "<tr><td>12/4/2010</td><td>103,000</td><td>200</td></tr>";
                str += "<tr><td>12/5/2010</td><td>104,000</td><td>250</td></tr>";
                str += "<tr><td>12/6/2010</td><td>105,000</td><td>300</td></tr>";
                str += "<tr><td>12/7/2010</td><td>106,000</td><td>350</td></tr>";

            str += "</table>";
            return Json(str);
            }
            catch (Exception e)
            {
                return Json(e.ToString());
            }
        }
</code>```

Then I take that Json and put it on my view like this:

```<code>$.ajax({
                type: "POST",
                url: "<%= Url.Action("ExposureGrid", "Indications") %> ",
                dataType: "jsonData",
                data: tableJSON,
                success: function(data) {
                      existingDiv = document.getElementById('table');
                      existingDiv.innerHTML = data;
                }
            });
</code>```

But what shows on the view in HTML is this:

"\u003ctable border=1\u003e\u003ctr\u003e\u003cth\u003eDate\u003c/th\u003e\u003cth\u003eExpected Credit Exposure\u003c/th\u003e\u003cth\u003eMax Credit Exposure\u003c/th\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e12/1/2010\u003c/td\u003e\u003ctd\u003e100,000\u003c/td\u003e\u003ctd\u003e50\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e12/2/2010\u003c/td\u003e\u003ctd\u003e101,000\u003c/td\u003e\u003ctd\u003e100\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e12/3/2010\u003c/td\u003e\u003ctd\u003e102,000\u003c/td\u003e\u003ctd\u003e150\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e12/4/2010\u003c/td\u003e\u003ctd\u003e103,000\u003c/td\u003e\u003ctd\u003e200\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e12/5/2010\u003c/td\u003e\u003ctd\u003e104,000\u003c/td\u003e\u003ctd\u003e250\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e12/6/2010\u003c/td\u003e\u003ctd\u003e105,000\u003c/td\u003e\u003ctd\u003e300\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e12/7/2010\u003c/td\u003e\u003ctd\u003e106,000\u003c/td\u003e\u003ctd\u003e350\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e"

How do I fix this?

答:
change:

```<code>dataType: "jsonData",
</code>```

to

```<code>dataType: "json",
</code>```

hopefully, issue should be resolved.

Body:
I want to achieve this:

public System.Web.Mvc.ActionResult ExposureGrid(Guid? id, decimal stdDev)
        {
            //return null;
            try
            {
                var str = "
";
                str += "
Date	Expected Credit Exposure	Max Credit Exposure
";

                str += "
12/1/2010	100,000	50
";
                str += "
12/2/2010	101,000	100
";
                str += "
12/3/2010	102,000	150
";
                str += "
12/4/2010	103,000	200
";
                str += "
12/5/2010	104,000	250
";
                str += "
12/6/2010	105,000	300
";
                str += "
12/7/2010	106,000	350
";

            str += "
";
            return Json(str);
            }
            catch (Exception e)
            {
                return Json(e.ToString());
            }
        }

Then I take that Json and put it on my view like this:

$.ajax({
                type: "POST",
                url: "<%= Url.Action("ExposureGrid", "Indications") %> ",
                dataType: "jsonData",
                data: tableJSON,
                success: function(data) {
                      existingDiv = document.getElementById('table');
                      existingDiv.innerHTML = data;
                }
            });

But what shows on the view in HTML is this:

"\u003ctable border=1\u003e\u003ctr\u003e\u003cth\u003eDate\u003c/th\u003e\u003cth\u003eExpected Credit Exposure\u003c/th\u003e\u003cth\u003eMax Credit Exposure\u003c/th\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e12/1/2010\u003c/td\u003e\u003ctd\u003e100,000\u003c/td\u003e\u003ctd\u003e50\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e12/2/2010\u003c/td\u003e\u003ctd\u003e101,000\u003c/td\u003e\u003ctd\u003e100\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e12/3/2010\u003c/td\u003e\u003ctd\u003e102,000\u003c/td\u003e\u003ctd\u003e150\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e12/4/2010\u003c/td\u003e\u003ctd\u003e103,000\u003c/td\u003e\u003ctd\u003e200\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e12/5/2010\u003c/td\u003e\u003ctd\u003e104,000\u003c/td\u003e\u003ctd\u003e250\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e12/6/2010\u003c/td\u003e\u003ctd\u003e105,000\u003c/td\u003e\u003ctd\u003e300\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e12/7/2010\u003c/td\u003e\u003ctd\u003e106,000\u003c/td\u003e\u003ctd\u003e350\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e"

How do I fix this?

Body:
change:

dataType: "jsonData",

to

dataType: "json",

hopefully, issue should be resolved.


问:
Removing Slide Layouts from Presentation
I have a following code for removing slide layout parts:

```<code>var presentation = output.PresentationPart;

var usedSlideLayouts = presentation.SlideParts.Select(it => it.SlideLayoutPart).ToList();
foreach (var sm in presentation.SlideMasterParts)
{
    var slideLayoutIds = sm.SlideMaster.SlideLayoutIdList.Elements<SlideLayoutId>().ToList();
    var slideLayoutParts = sm.SlideLayoutParts.ToList();

    var i = 0;
    foreach (var slp in slideLayoutParts)
    {
        var isUsed = usedSlideLayouts.Any(usl => usl == slp);

        if (!isUsed)
        {
            var slideLayoutId = slideLayoutIds[i];
            slideLayoutId.Remove();
            sm.DeletePart(slp);
        }

        i++;
    }
}
</code>```

When i save the presentation after running it my presentation is corrupted (needs to be restored before opening in power point).

From what I saw (by unzipping the pptx) this could be because of the fact that there is only one slide layout but it's internal URI is like 'slideLayout2.xml'. Is there a way to refresh that internal URI?

For anyone wondering I attached a powerpoint in this github issue:
https://github.com/OfficeDev/Open-XML-SDK/issues/218

答:
Your slideLayoutId is the wrong one. The SlideLayoutParts are not necessarily returned in the same order as the SlideLayoutIds.

You can solve this by changing the line

```<code>var slideLayoutId = slideLayoutIds[i];
</code>```

to

```<code>var slideLayoutId = slideLayoutIds.Where(sid => sid.RelationshipId == sm.GetIdOfPart(slp)).FirstOrDefault();
</code>```

This picks the correct slideLayoutId based on the RelationshipId.

Body:
I have a following code for removing slide layout parts:

var presentation = output.PresentationPart;

var usedSlideLayouts = presentation.SlideParts.Select(it => it.SlideLayoutPart).ToList();
foreach (var sm in presentation.SlideMasterParts)
{
    var slideLayoutIds = sm.SlideMaster.SlideLayoutIdList.Elements<SlideLayoutId>().ToList();
    var slideLayoutParts = sm.SlideLayoutParts.ToList();

    var i = 0;
    foreach (var slp in slideLayoutParts)
    {
        var isUsed = usedSlideLayouts.Any(usl => usl == slp);

        if (!isUsed)
        {
            var slideLayoutId = slideLayoutIds[i];
            slideLayoutId.Remove();
            sm.DeletePart(slp);
        }

        i++;
    }
}

When i save the presentation after running it my presentation is corrupted (needs to be restored before opening in power point).

From what I saw (by unzipping the pptx) this could be because of the fact that there is only one slide layout but it's internal URI is like 'slideLayout2.xml'. Is there a way to refresh that internal URI?

For anyone wondering I attached a powerpoint in this github issue:
https://github.com/OfficeDev/Open-XML-SDK/issues/218

Body:
Your slideLayoutId is the wrong one. The SlideLayoutParts are not necessarily returned in the same order as the SlideLayoutIds.

You can solve this by changing the line

var slideLayoutId = slideLayoutIds[i];

to

var slideLayoutId = slideLayoutIds.Where(sid => sid.RelationshipId == sm.GetIdOfPart(slp)).FirstOrDefault();

This picks the correct slideLayoutId based on the RelationshipId.


问:
How to make type safe filtration in Scala?
I have different types of entities in db and I want to be able to filter them by some conditions in a type safe way. I'm using Slick for db access, but it doesn't really matter I think.

For example, let's say I have User and Post entities. User has id and email fields, Post has id and title fields.

Right now I'm using ADT to represent filters. Looks like this:

```<code>sealed trait Filter {

  def byId(id: Long): Filter = and(ById(id))

  def byEmail(email: String): Filter = and(ByEmail(email))

  def byTitle(title: String): Filter = and(ByTitle(title))

  def and(other: Filter): Filter = And(this, other)

}

object Filter {
  def apply(): Filter = NoFilter
}

case class ById(id: Long) extends Filter

case class ByEmail(email: String) extends Filter

case class ByTitle(title: String) extends Filter

case class And(a: Filter, b: Filter) extends Filter

case object NoFilter extends Filter
</code>```

And interpreter for it in UserDao. PostDao looks the same:

```<code>trait Dao[A] {
  def find(filter: Filter, offset: Int, limit: Int):Seq[A]
}

object UserDao extends Dao[User]{

  override def find(filter: Filter, offset: Int, limit: Int): Seq[Any] = {
    filterTable(filter).drop(offset).take(limit).result
  }

  private def filterTable(table: Query[UserTable, User, Seq], filter: Filter): Query[UserTable, User, Seq] =
    filter match {
      case ById(id) => table.filter(_.id === id)
      case ByEmail(email) => table.filter(_.email === email)
      case And(a, b) => filterTable(filterTable(table, a), b)
      case NoFilter => table
      case other =>
        log.warn(s"Filter not supported $other")
        table
    }
}
</code>```

And is used by generic service:

```<code>class Service[A](dao: Dao[A]) {
  def find(filter: Filter): Seq[A] = {
    // do some stuff
    dao.find(filter, offset = 0, limit = 100)
    // do some other stuff
  }
}
</code>```

As you see it works, but it's not type safe. Although filtering users by title won't fail it doesn't make sense and could be cause of a bug. I thought maybe I create different sets of ADT for different entities, but then I will have to duplicate filters which are very similar(id filter, for example). So in summary I want to have filters which:

Type safe. You can't create Filter ByTitle for User

You don't need to duplicate common filters like ById, And, Or, In and so on.

How can I do it? Maybe ADT is not what I need?

答:
If you create a bunch of "marker" traits for your domain objects, then you can parametrize your Filter type with the type of data it can be filtering:

```<code>  trait Filter[-T]

  case class ById(id: Long) extends Filter[HasId]
  case class ByEmail(email: String) extends Filter[HasEmail]
  case class ByTitle(title: String) extends Filter[HasTitle]
  case class And[A, B](a: Filter[A], b: Filter[B]) extends Filter[A with B]
  case class Or[A, B](a: Filter[A], b: Filter[B]) extends Filter[A with B]
</code>```

Now, you can declare filterTable to constrain the type of filter it will accept:

```<code>def filterTable(table: Query[UserTable, User, Seq], filter: Filter[User]) = ...
</code>```

So, filterTable(myTable, ById(1) and ByEmail("foo")) will compile, but
filterTable(myTable, ByTitle("foo")) will not.

Body:
I have different types of entities in db and I want to be able to filter them by some conditions in a type safe way. I'm using Slick for db access, but it doesn't really matter I think.

For example, let's say I have User and Post entities. User has id and email fields, Post has id and title fields.

Right now I'm using ADT to represent filters. Looks like this:

sealed trait Filter {

  def byId(id: Long): Filter = and(ById(id))

  def byEmail(email: String): Filter = and(ByEmail(email))

  def byTitle(title: String): Filter = and(ByTitle(title))

  def and(other: Filter): Filter = And(this, other)

}

object Filter {
  def apply(): Filter = NoFilter
}

case class ById(id: Long) extends Filter

case class ByEmail(email: String) extends Filter

case class ByTitle(title: String) extends Filter

case class And(a: Filter, b: Filter) extends Filter

case object NoFilter extends Filter

And interpreter for it in UserDao. PostDao looks the same:

trait Dao[A] {
  def find(filter: Filter, offset: Int, limit: Int):Seq[A]
}

object UserDao extends Dao[User]{

  override def find(filter: Filter, offset: Int, limit: Int): Seq[Any] = {
    filterTable(filter).drop(offset).take(limit).result
  }

  private def filterTable(table: Query[UserTable, User, Seq], filter: Filter): Query[UserTable, User, Seq] =
    filter match {
      case ById(id) => table.filter(_.id === id)
      case ByEmail(email) => table.filter(_.email === email)
      case And(a, b) => filterTable(filterTable(table, a), b)
      case NoFilter => table
      case other =>
        log.warn(s"Filter not supported $other")
        table
    }
}

And is used by generic service:

class Service[A](dao: Dao[A]) {
  def find(filter: Filter): Seq[A] = {
    // do some stuff
    dao.find(filter, offset = 0, limit = 100)
    // do some other stuff
  }
}

As you see it works, but it's not type safe. Although filtering users by title won't fail it doesn't make sense and could be cause of a bug. I thought maybe I create different sets of ADT for different entities, but then I will have to duplicate filters which are very similar(id filter, for example). So in summary I want to have filters which:

Type safe. You can't create Filter ByTitle for User

You don't need to duplicate common filters like ById, And, Or, In and so on.

How can I do it? Maybe ADT is not what I need?

Body:
If you create a bunch of "marker" traits for your domain objects, then you can parametrize your Filter type with the type of data it can be filtering:

  trait Filter[-T]

  case class ById(id: Long) extends Filter[HasId]
  case class ByEmail(email: String) extends Filter[HasEmail]
  case class ByTitle(title: String) extends Filter[HasTitle]
  case class And[A, B](a: Filter[A], b: Filter[B]) extends Filter[A with B]
  case class Or[A, B](a: Filter[A], b: Filter[B]) extends Filter[A with B]

Now, you can declare filterTable to constrain the type of filter it will accept:

def filterTable(table: Query[UserTable, User, Seq], filter: Filter[User]) = ...

So, filterTable(myTable, ById(1) and ByEmail("foo")) will compile, but
filterTable(myTable, ByTitle("foo")) will not.


问:
Community Detection in complete and weighted networks
I do have a complete network graph where every vertex is connected with each other and they only differ in form of their different weights. A example network would be: a trade network, where every country is connected with each other somehow and only differ in form of different trading volumina.

Now the question is how I could perform a community detection in that form of network. The usual suspects (algorithm) are only able to perform in either unweighted or incomplete networks well. The main problem is that the geodesic is everywhere the same.

Two option came into my mind:

Cut the network into smaller pieces by cutting them at a certain "weight-threshold-level"

Or use a hierarchical cluster algorithm to turn the whole network into a blockmodel. But I think the problem "no variance in geodesic terms" will remain.

答:
Several methods were suggested.

One simple yet effective method was suggested in Fast unfolding of communities in large networks (Blondel et al., 2008). It supports weighted networks. Quoting from the abstract:

We propose a simple method to extract the community structure of large
  networks. Our method is a heuristic method that is based on modularity
  optimization. It is shown to outperform all other known community
  detection method in terms of computation time. Moreover, the quality
  of the communities detected is very good, as measured by the so-called
  modularity.

Quoting from the paper:

We now introduce our algorithm that finds high modularity partitions
  of large networks in short time and that unfolds a complete
  hierarchical community structure for the network, thereby giving
  access to different resolutions of community detection.

So it supposed to work well for complete graph, but you should better check it.

A C++ implementation is available here (now maintained here).

Your other idea - using weight-threshold - may prove as a good pre-processing step, especially for algorithms which won't partition complete graphs. I believe it is best to set it to some percentile (e.g. to the median) of the weights.