问:
How do I change NavBar Color in CSS
Hello I have view some of responsive multi level menu.
I Copy exactly the css and javascript. Here is my NavBar. The problem is, Im having trouble to change the default color(green) to other color. Here is the CSS file.

```<code> @import url(http://fonts.googleapis.com/css?
 family=Open+Sans:400italic,400,300,600);

@font-face {
font-family: 'icomoon';
src:url('../fonts/icomoon.eot');
src:url('../fonts/icomoon.eot?#iefix') format('embedded-opentype'),
    url('../fonts/icomoon.woff') format('woff'),
    url('../fonts/icomoon.ttf') format('truetype'),
    url('../fonts/icomoon.svg#icomoon') format('svg');
font-weight: normal;
font-style: normal;
}

/* minimal styles for that navi */
.rmm {margin: 0 auto;}
.rmm ul {margin: 0; padding:0; list-style: none; position: relative;
background: #000;}
.rmm ul:after {content: ""; clear: both; display: block;}
.rmm ul li {float: left;}
.rmm ul li:hover {background: #202020;}
.rmm ul li:hover > ul {display: block;}
.rmm ul li:hover a{color: #fff;}
.rmm ul li a {color: #fff; display: block; text-decoration: none;}
.rmm ul ul {display: none; margin:0; padding: 0; position: absolute; top:
100%;}
.rmm ul ul li {float: none; position: relative;}
.rmm ul ul li a{color: #fff;}
.rmm ul ul li a:hover {background: #202020;}
.rmm ul ul ul {position: absolute; left: 100%; top:0; width: 100%;}

/* mobile menu header button */
.rmm-toggled {width: 100%; background-color: #555555; min-height: 50px;
margin: 0 auto; display: none;}
.rmm-closed ~ .rmm-mobile {display: none!important;}
.rmm-toggled-controls{width: 100%;}
.rmm-toggled-title{width: 60%; float: left; font-size: 27px; color: #fff;
font-weight:600; display: block; padding: 8px 0; text-decoration: none;
text-transform: uppercase; text-align: left; padding-left: 35px;}
.rmm-toggled-button{width: 20%; float: left; margin-top: 3px;
display:block;
width: 32px;
padding:0 !important;
margin:10px 10px 0 0;
border:1px solid #fff;
border-radius:3px;
float: right;
}
.rmm-toggled-button span{float: left; display:block; margin: 3px 6px;
height: 3px; background:white; width:20px;}

/* normalny back button visible only on mobiles  */
.rmm .rmm-back{display: none; font-size: 12px;}
.rmm .rmm-back:after {display: none;}
.rmm .rmm-back a:after {
font-family: 'icomoon';
speak: none;
-webkit-font-smoothing: antialiased;
content: "\e000";
position: relative;
display: inline-block;
-webkit-transform: rotate(-60deg);
transform: rotate(-60deg);
top: 1px;
right: -2px ;
float: left;
font-size: 10px;
 }
.rmm-mobile .rmm-back{display: block;}

   /* mobile menu list */
  .rmm-mobile{width: 100%;}
  .rmm-mobile .rmm-dropdown:hover ~ ul, .rmm-mobile .rmm-dropdown:hover > ul
  ,.rmm-mobile .rmm-dropdown:hover + ul {display: none!important;}
   .rmm-mobile ul{width: 100%; position: inherit!important;}
   .rmm-mobile li{width: 100%; }

   /* mobile menu js action */
  .rmm-dropdown{display: block!important;}
  .rmm-mobile .rmm-subview{display: block!important; width: 100%;}
  .rmm-mobile .rmm-subover-hidden{display: none!important;}
  .rmm-mobile .rmm-subover-visible{display: block;}
  .rmm-mobile .rmm-subover-header{display: none!important; padding: 0;
   margin:0;}

  /* mobile menu content */
  .rmm-mobile .rmm-submenu{position: relative; left: 0px;}

  .rmm .rmm-mobile li:hover > ul {display: none;}

  /* arrow down for wide screen */
  .rmm.style {text-align: left; font-family: Tahoma;}
  .rmm.style ul {box-shadow: 0px 0px 9px rgba(0, 0, 0, 0.15);
   background:#990;
   text-transform: uppercase; display: inline-table; text-align:left;}
  .rmm.style ul li {text-align:left;}
  .rmm.style ul li:hover {background: #4b545f;}
  .rmm.style ul ul {display: none; margin:0; background: #5f6975; border-
   radius: 0px; padding: 0; position: absolute;}
  .rmm.style ul li a {color: #fff; font-weight:600; display: block; padding:
   15px 35px; text-decoration: none; font-weight:600; }
  .rmm.style ul ul li {border-bottom: 1px solid #575F6A; border-top: 1px
  solid #6B727C;}
  .rmm.style ul ul li a {padding: 12px 35px; color: #fff; }
  .rmm.style ul ul li a:hover {background: #4b545f;}

    /* arrow down for wide screen */
   .rmm.style ul li > a:not(:only-child):after {
   font-family: 'icomoon';
    speak: none;
   -webkit-font-smoothing: antialiased;
   content: "\e000";
   position: relative;
   display: inline-block;
   -webkit-transform: rotate(210deg);
    transform: rotate(210deg);
    top: -4px;
    left: 1px;
     font-size: 10px;
    }

   /* arrow left for wide screen submenus  */
   .rmm.style ul ul li > a:not(:only-child):after {-webkit-transform:
   rotate(120deg)!important; transform: rotate(120deg)!important; top: 2px;
   font-size: 14px; float: right; margin-right: -20px;}

   /* mobile style */
   .rmm.style .rmm-mobile li > a:not(:only-child):after {-webkit-transform:
     rotate(120deg)!important; transform: rotate(120deg)!important; top:
    4px!important; font-size: 14px!important; float: right; margin-right:
   -20px;}
   .rmm.style .rmm-mobile li{background: #3ab4a6; border-bottom: 1px solid
    #575f6a!important; border-top: 0!important; }
</code>```

I have tried to change the color or add something for background-color. But the default color still Green. The javascript is to executed to function of the mobile version. Nothing to do with the color. Please Help. Im still newbie :)
Here is My HTML

```<code><!DOCTYPE html>
<html>
<head>
<title></title>

<!-- Include scripts -->
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js">
</script>
<script type="text/javascript" src="js/responsivemultimenu.js"></script>

<!-- Include styles -->
<link rel="stylesheet" href="css/responsivemultimenu.css" type="text/css"/>

<!-- Include media queries -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-
scale=1, user-scalable=no"/>
</head>
<body >

<div >

    <div class="rmm style">
        <ul>
        <li>

                <a href="KPIhome.php" title="KPI">eKPI</a>

        </li>

        <?php if(isset($_SESSION['admin']) || $_SESSION['user_level'] == 5
|| $_SESSION['user_level']==7 || $_SESSION['user_level'] ==1 ){ ?>

            <li>

                <a href="#">Value Graph</a>
                <ul>
                    <li <?php if($page == 'home.php'){echo '
class="active"';};?>>
                        <a href="sales_form.php">Sales Achievement against
Target</a>
                    </li>
                    <li <?php if($page == 'home.php'){echo '
class="active"';};?>>
                        <a href="promo_form.php">Promotion Sales Achievement
against Target </a>
                    </li>
                    <li  <?php if($page == 'home.php'){echo '
class="active"';};?>>
                        <a href="manhour_form.php">Sales per Manhour</a>
                    </li>
                    <li  <?php if($page == 'home.php'){echo '
class="active"';};?>>
                        <a href="trans_form.php">Transaction per Manhour</a>
                    </li>
                    <li  <?php if($page == 'home.php'){echo '
class="active"';};?>>
                        <a href="salmonform.php">Salmon Usage Per 1K</a>
                    </li>

                </ul>
            </li>

            <?php } ?>

             <?php if(isset($_SESSION['admin']) || $_SESSION['user_level']
  == 5 || $_SESSION['user_level']==7 || $_SESSION['user_level'] ==1){ ?>

            <li>

                <a href="#">Percentage Graph</a>
                <ul>
                    <li <?php if($page == 'home.php'){echo '
 class="active"';};?>>
                        <a href="sales_form2.php">Sales Achievement against
Target (%)</a>
                    </li>
                    <li <?php if($page == 'home.php'){echo '
class="active"';};?>>
                        <a href="promo_form2.php">Promotion Sales
Achievement against Target (%)</a>
                    </li>
                    <li  <?php if($page == 'home.php'){echo '
class="active"';};?>>
                        <a href="wastage_form.php">Wastage against Target
(%)</a>
                    </li>

                </ul>
            </li>

            <?php } ?>

             <?php if(isset($_SESSION['admin']) || $_SESSION['user_level']
== 5 || $_SESSION['user_level']==7 || $_SESSION['user_level'] ==1){ ?>

            <li>

                <a href="#">Over Budget</a>
                <ul>
                    <li <?php if($page == 'home.php'){echo '
class="active"';};?>>
                        <a href="obtargetform.php">Sales Achievement</a>
                    </li>
                    <li <?php if($page == 'home.php'){echo '
class="active"';};?>>
                        <a href="obmtdform.php">Sales Month to Date
 Achievement</a>
                    </li>
                    <li  <?php if($page == 'home.php'){echo '
class="active"';};?>>
                        <a href="obtargetform2.php">Promotion Sales
Achievement</a>
                    </li>
                    <li  <?php if($page == 'home.php'){echo '
class="active"';};?>>
                        <a href="obmtdform2.php">Promotion Month to Date
Sales Achivement</a>
                    </li>

                </ul>
            </li>

            <?php } ?>

             <?php if(isset($_SESSION['admin'])&& $_SESSION['user_level'] == 0 || $_SESSION['user_level']==7 ){ ?>
            <li>

                <a href="#">Report</a>
                <ul>
                    <li <?php if($page == 'home.php'){echo ' class="active"';};?>>
                        <a href="typereport.php">Add Report</a>
                    </li>

                </ul>
            </li>

            <?php } ?>

        <li>

                <a href="KPIhome.php" title="KPI">Website</a>

        </li>

        <li>

                <a href="KPIhome.php" title="KPI">Admin</a>

        </li>

        </ul>
    </div>
</div>
</code>```

答:
Find

```<code>  /* arrow down for wide screen */
  .rmm.style {text-align: left; font-family: Tahoma;}
  .rmm.style ul {box-shadow: 0px 0px 9px rgba(0, 0, 0, 0.15);
   background:#990;
</code>```

Replace #990 with the desired color. Enjoy.

Title: How do I change NavBar Color in CSS

Body:
Hello I have view some of responsive multi level menu.
I Copy exactly the css and javascript. Here is my NavBar. The problem is, Im having trouble to change the default color(green) to other color. Here is the CSS file.

 @import url(http://fonts.googleapis.com/css?
 family=Open+Sans:400italic,400,300,600);

@font-face {
font-family: 'icomoon';
src:url('../fonts/icomoon.eot');
src:url('../fonts/icomoon.eot?#iefix') format('embedded-opentype'),
    url('../fonts/icomoon.woff') format('woff'),
    url('../fonts/icomoon.ttf') format('truetype'),
    url('../fonts/icomoon.svg#icomoon') format('svg');
font-weight: normal;
font-style: normal;
}

/* minimal styles for that navi */
.rmm {margin: 0 auto;}
.rmm ul {margin: 0; padding:0; list-style: none; position: relative;
background: #000;}
.rmm ul:after {content: ""; clear: both; display: block;}
.rmm ul li {float: left;}
.rmm ul li:hover {background: #202020;}
.rmm ul li:hover > ul {display: block;}
.rmm ul li:hover a{color: #fff;}
.rmm ul li a {color: #fff; display: block; text-decoration: none;}
.rmm ul ul {display: none; margin:0; padding: 0; position: absolute; top:
100%;}
.rmm ul ul li {float: none; position: relative;}
.rmm ul ul li a{color: #fff;}
.rmm ul ul li a:hover {background: #202020;}
.rmm ul ul ul {position: absolute; left: 100%; top:0; width: 100%;}

/* mobile menu header button */
.rmm-toggled {width: 100%; background-color: #555555; min-height: 50px;
margin: 0 auto; display: none;}
.rmm-closed ~ .rmm-mobile {display: none!important;}
.rmm-toggled-controls{width: 100%;}
.rmm-toggled-title{width: 60%; float: left; font-size: 27px; color: #fff;
font-weight:600; display: block; padding: 8px 0; text-decoration: none;
text-transform: uppercase; text-align: left; padding-left: 35px;}
.rmm-toggled-button{width: 20%; float: left; margin-top: 3px;
display:block;
width: 32px;
padding:0 !important;
margin:10px 10px 0 0;
border:1px solid #fff;
border-radius:3px;
float: right;
}
.rmm-toggled-button span{float: left; display:block; margin: 3px 6px;
height: 3px; background:white; width:20px;}

/* normalny back button visible only on mobiles  */
.rmm .rmm-back{display: none; font-size: 12px;}
.rmm .rmm-back:after {display: none;}
.rmm .rmm-back a:after {
font-family: 'icomoon';
speak: none;
-webkit-font-smoothing: antialiased;
content: "\e000";
position: relative;
display: inline-block;
-webkit-transform: rotate(-60deg);
transform: rotate(-60deg);
top: 1px;
right: -2px ;
float: left;
font-size: 10px;
 }
.rmm-mobile .rmm-back{display: block;}

   /* mobile menu list */
  .rmm-mobile{width: 100%;}
  .rmm-mobile .rmm-dropdown:hover ~ ul, .rmm-mobile .rmm-dropdown:hover > ul
  ,.rmm-mobile .rmm-dropdown:hover + ul {display: none!important;}
   .rmm-mobile ul{width: 100%; position: inherit!important;}
   .rmm-mobile li{width: 100%; }

   /* mobile menu js action */
  .rmm-dropdown{display: block!important;}
  .rmm-mobile .rmm-subview{display: block!important; width: 100%;}
  .rmm-mobile .rmm-subover-hidden{display: none!important;}
  .rmm-mobile .rmm-subover-visible{display: block;}
  .rmm-mobile .rmm-subover-header{display: none!important; padding: 0;
   margin:0;}

  /* mobile menu content */
  .rmm-mobile .rmm-submenu{position: relative; left: 0px;}

  .rmm .rmm-mobile li:hover > ul {display: none;}

  /* arrow down for wide screen */
  .rmm.style {text-align: left; font-family: Tahoma;}
  .rmm.style ul {box-shadow: 0px 0px 9px rgba(0, 0, 0, 0.15);
   background:#990;
   text-transform: uppercase; display: inline-table; text-align:left;}
  .rmm.style ul li {text-align:left;}
  .rmm.style ul li:hover {background: #4b545f;}
  .rmm.style ul ul {display: none; margin:0; background: #5f6975; border-
   radius: 0px; padding: 0; position: absolute;}
  .rmm.style ul li a {color: #fff; font-weight:600; display: block; padding:
   15px 35px; text-decoration: none; font-weight:600; }
  .rmm.style ul ul li {border-bottom: 1px solid #575F6A; border-top: 1px
  solid #6B727C;}
  .rmm.style ul ul li a {padding: 12px 35px; color: #fff; }
  .rmm.style ul ul li a:hover {background: #4b545f;}

    /* arrow down for wide screen */
   .rmm.style ul li > a:not(:only-child):after {
   font-family: 'icomoon';
    speak: none;
   -webkit-font-smoothing: antialiased;
   content: "\e000";
   position: relative;
   display: inline-block;
   -webkit-transform: rotate(210deg);
    transform: rotate(210deg);
    top: -4px;
    left: 1px;
     font-size: 10px;
    }

   /* arrow left for wide screen submenus  */
   .rmm.style ul ul li > a:not(:only-child):after {-webkit-transform:
   rotate(120deg)!important; transform: rotate(120deg)!important; top: 2px;
   font-size: 14px; float: right; margin-right: -20px;}

   /* mobile style */
   .rmm.style .rmm-mobile li > a:not(:only-child):after {-webkit-transform:
     rotate(120deg)!important; transform: rotate(120deg)!important; top:
    4px!important; font-size: 14px!important; float: right; margin-right:
   -20px;}
   .rmm.style .rmm-mobile li{background: #3ab4a6; border-bottom: 1px solid
    #575f6a!important; border-top: 0!important; }

I have tried to change the color or add something for background-color. But the default color still Green. The javascript is to executed to function of the mobile version. Nothing to do with the color. Please Help. Im still newbie :)
Here is My HTML

<!DOCTYPE html>

<title></title>

<link rel="stylesheet" href="css/responsivemultimenu.css" type="text/css"/>

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-
scale=1, user-scalable=no"/>

                eKPI

        <?php if(isset($_SESSION['admin']) || $_SESSION['user_level'] == 5
|| $_SESSION['user_level']==7 || $_SESSION['user_level'] ==1 ){ ?>

                Value Graph

                    <li <?php if($page == 'home.php'){echo '
class="active"';};?>>
                        Sales Achievement against
Target

                    <li <?php if($page == 'home.php'){echo '
class="active"';};?>>
                        Promotion Sales Achievement
against Target

                    <li  <?php if($page == 'home.php'){echo '
class="active"';};?>>
                        Sales per Manhour

                    <li  <?php if($page == 'home.php'){echo '
class="active"';};?>>
                        Transaction per Manhour

                    <li  <?php if($page == 'home.php'){echo '
class="active"';};?>>
                        Salmon Usage Per 1K

            <?php } ?>

             <?php if(isset($_SESSION['admin']) || $_SESSION['user_level']
  == 5 || $_SESSION['user_level']==7 || $_SESSION['user_level'] ==1){ ?>

                Percentage Graph

                    <li <?php if($page == 'home.php'){echo '
 class="active"';};?>>
                        Sales Achievement against
Target (%)

                    <li <?php if($page == 'home.php'){echo '
class="active"';};?>>
                        Promotion Sales
Achievement against Target (%)

                    <li  <?php if($page == 'home.php'){echo '
class="active"';};?>>
                        Wastage against Target
(%)

            <?php } ?>

             <?php if(isset($_SESSION['admin']) || $_SESSION['user_level']
== 5 || $_SESSION['user_level']==7 || $_SESSION['user_level'] ==1){ ?>

                Over Budget

                    <li <?php if($page == 'home.php'){echo '
class="active"';};?>>
                        Sales Achievement

                    <li <?php if($page == 'home.php'){echo '
class="active"';};?>>
                        Sales Month to Date
 Achievement

                    <li  <?php if($page == 'home.php'){echo '
class="active"';};?>>
                        Promotion Sales
Achievement

                    <li  <?php if($page == 'home.php'){echo '
class="active"';};?>>
                        Promotion Month to Date
Sales Achivement

            <?php } ?>

             <?php if(isset($_SESSION['admin'])&& $_SESSION['user_level'] == 0 || $_SESSION['user_level']==7 ){ ?>

                Report

                    <li <?php if($page == 'home.php'){echo ' class="active"';};?>>
                        Add Report

            <?php } ?>

                Website

                Admin

Body:
Find

  /* arrow down for wide screen */
  .rmm.style {text-align: left; font-family: Tahoma;}
  .rmm.style ul {box-shadow: 0px 0px 9px rgba(0, 0, 0, 0.15);
   background:#990;

Replace #990 with the desired color. Enjoy.


来源: stackexchange

问:
Make a HMTL  hyperlink not appear as a hyperlink
I'm making a website (for schoolwork) using a combination of php, html and css. I'm currently working on the initial design stages of my site and as I'm inexperienced at html / css, I am going slowly through tutorials trying to learn.

Including the hyperlink my banner looks like:

Not including the hyperlink my banner looks like:

I want to have the functionality of the link, but the visual design effect of without the link.

The necessary code is:

```<code><html>
    <head>
        <link rel="stylesheet" type="text/css" href="style.css">
    </head>
    <center>
    <div id = "indexBackgroundOne"><h2 style="font-family:verdana"> Q U E S T S ®</h2></div>
    </center>
</html>
</code>```

Thanks!

答:
If you are using inline css you can use like this - </p>

```<code><html>
    <head>
        <link rel="stylesheet" type="text/css" href="style.css">
    </head>
    <center>
    <div id = "indexBackgroundOne"><h2 style="font-family:verdana;text-decoration: none;color:black;"><a href=""  style="text-decoration: none;color:black;"> Q U E S T S ®</a></h2></div>
    </center>
</html>
</code>```

ContentLicense: CC BY-SA 3.0

Title: Make a HMTL <a href> hyperlink not appear as a hyperlink

Body:
I'm making a website (for schoolwork) using a combination of php, html and css. I'm currently working on the initial design stages of my site and as I'm inexperienced at html / css, I am going slowly through tutorials trying to learn.

Including the hyperlink my banner looks like:

Not including the hyperlink my banner looks like:

I want to have the functionality of the link, but the visual design effect of without the link.

The necessary code is:

        <link rel="stylesheet" type="text/css" href="style.css">

 Q U E S T S ®

Thanks!

Body:
If you are using inline css you can use like this -

<html>
    <head>
        <link rel="stylesheet" type="text/css" href="style.css">
    </head>
    <center>
    <div id = "indexBackgroundOne"><h2 style="font-family:verdana;text-decoration: none;color:black;"><a href=""  style="text-decoration: none;color:black;"> Q U E S T S &reg;</a></h2></div>
    </center>
</html>


问:
How to push to AWS EC2 Service Container from a specific git branch (ie 'staging')
I'm completely new to AWS, EC2, and the Service Container, but I did manage to successfully push my sinatra application with docker fairly easily following this guide here:

http://blog.honeybadger.io/how-to-deploy-a-sinatra-app-in-docker-to-amazon-s-ec2-container-service/

Now I have 2 service containers, one for production and one for staging. My original hypothesis was that I could push to the staging container from the git staging branch and to the production container from the git production branch from my local machine. When I made a change on the staging branch and pushed the image to the staging container the staging site did not reflect the new changes (I did clear cache in the browser).

Q1: Does EC2 SC automatically accept the master branch regardless of which branch the project is pushed from?

Q2: What is the simplest way to accomplish staging and production servers with AWS (perhaps not SC, perhaps beanstalk?).

Note: Not using Heroku since the company contracting me wants all their systems on AWS.

答:
Login to the AWS console, and got to your EC2 Instances

Select your instance (for example you-app-staging) and right-click > Instance State > Reboot

After a few minutes the instance will reboot and you will see the changes to that instance.

A1: no, you're pushing a image then AWS takes that image and hits play so if you build the image in the branch and deploy it from that branch, you will see the branch pushed

A2: Maybe over complicated solution with the service containers, now things work as expected


问:
Matching TV and Movie File names with NLP/Machine Learning?
So i've wondered if there would be a way to tokenize/tag TV or Movie Files using NLP/Machine Learing.

I know there are a lot of regexp approaches out there which do this already but shouldn't it be possible to get this done with NLP/Machine Learning as well?

Example:
The.Heart.Guy.S01E07.Die.Belastungsprobe.German.DL.720p.HDTV.x264-GDR

Should be something like:

The Heart Guy SHOW-NAME
1 SEASON
7 EPISODE
Die Belastungsprobe EP-NAME
German DL LANGUAGE
720p RESOLUTION
HDTV SOURCE
x264 CODEC
GDR GROUP

Anyone ever tried something like this? Or any hints where one should start or if it's even possible to get something like this working.

答:
I suspect using regexes is the easiest solution to this, but if you're willing to put in some time Conditional Random Fields are also a great solution. Here's an article about the New York Times using a CRF based model on recipe data.

Another example of CRFs on short text is libpostal, which extracts parts of postal addresses.


问:
LinkedList vs Stack
In java, you can use stack implemented by LinkedList. In other words, you can use linkedlist to achieve all functionality of stack. In this sense, why we still need stack class, why don't we just stick with linked list to keep the simplicity?
Thanks</p>

答: The Stack class extends Vector, so it is synchronized. The LinkedList class is not. The optimal choice depends on what you're trying to do and the constraints, but in general, there is a bit more overhead for synchronized classes. Also, as @NESPowerGlove mentioned, Deque and its implementations are preferred to Stack

Title: LinkedList vs Stack


问:
AttributeError: 'FreqDist' object has no attribute 'inc'
I am a beginner in Python and NLTK. I am trying to run the following code from a tutorial:

```<code>from nltk.corpus import gutenberg
from nltk import FreqDist

fd = FreqDist()

for word in gutenberg.words('austen-sense.txt'):
    fd.inc(word)
</code>```

If I run this I get the following error:

```<code>AttributeError: 'FreqDist' object has no attribute 'inc'
</code>```

Any idea what I am doing wrong?

答:
For people looking for how to change the book example to NLTK 3.0:</p>

```<code>import nltk
from nltk.corpus import brown

suffix_fdist = nltk.FreqDist()
for word in brown.words():
    word = word.lower()
    suffix_fdist[word[-1:]] +=1
    suffix_fdist[word[-2:]] +=1
    suffix_fdist[word[-3:]] +=1
common_suffixes = []
for suffix in suffix_fdist.most_common(100):
    common_suffixes.append(str(suffix.__getitem__(0)))
print common_suffixes
</code>```

Body:
I am a beginner in Python and NLTK. I am trying to run the following code from a tutorial:

from nltk.corpus import gutenberg
from nltk import FreqDist

fd = FreqDist()

for word in gutenberg.words('austen-sense.txt'):
    fd.inc(word)

If I run this I get the following error:

AttributeError: 'FreqDist' object has no attribute 'inc'

Any idea what I am doing wrong?

Body:
For people looking for how to change the book example to NLTK 3.0:

import nltk
from nltk.corpus import brown

suffix_fdist = nltk.FreqDist()
for word in brown.words():
    word = word.lower()
    suffix_fdist[word[-1:]] +=1
    suffix_fdist[word[-2:]] +=1
    suffix_fdist[word[-3:]] +=1
common_suffixes = []
for suffix in suffix_fdist.most_common(100):
    common_suffixes.append(str(suffix.__getitem__(0)))
print common_suffixes


问:
Javascript: For loop isn't working
So I think there's something wrong with my for loop somewhere...

I have all the classes on a separate css file so I'm seeing everything on the DOM correctly on the front end.

My problem is that I need to make rows 1 and 3 have apply this class and I can get it work:

```<code><i class="fa fa fa-trophy fa-4" aria-hidden="true">
</code>```

In theory, I'm supposed to have a dynamic data table with 10 rows which are users in our app that came in first through tenth.

Rows 1-3: Are the users that came in first, second and third place... hence they get the "fa-trophy" class.

Rows 4-10: Are the remaining users hence they get the "fa-user-circle-o" class.

What am I doing wrong?

Javascript:

```<code>for(var i = 0; i < data.leaderboards.length; i++){

        row = $('<div class="leaderboard-row">');
        row.append('<div class="user-circle"><i class="fa fa-user-circle-o fa-4" aria-hidden="true">' + '</i></div>');
        row.append('<div class="leaderboard-col col1">' + (i + 1) + '</div>');
        row.append('<div class="leaderboard-col col2"><span class="truncate">' + data.leaderboards[i].username + '</span></div>');
        row.append('<div class="leaderboard-col col3"><span class="truncate">' + data.leaderboards[i].win_amount.formatMoney(0, '.', ',') + '</span></div>');

        if(data.leaderboards[i].level_unlocked > _currLevel){
            row.append('<div class="leaderboard-col col4">Won Playing ' + data.leaderboards[i].game_name + '</div>');
        }
        else{
            row.append('<div class="leaderboard-col col4">Won Playing <a href="/game/' + data.leaderboards[i].game_slug + '">' + data.leaderboards[i].game_name + '</a></div>');
        }
        _table.append(row);
    }
</code>```

答:
Why don't you assign the fa-trophy class when i <= 2 ? Something like

```<code>if (i <= 2) {
    // assign fa-trophy class for the first 3 places
    row.append('<div class="user-circle"><i class="fa fa-trophy fa-4" aria-hidden="true">' + '</i></div>');
} else {
    // do something else with 4th place onwards
    row.append('<div class="user-circle"><i class="fa fa-user-circle-o fa-4" aria-hidden="true">' + '</i></div>');
}
</code>```

Title: Javascript: For loop isn't working

Body:
So I think there's something wrong with my for loop somewhere...

I have all the classes on a separate css file so I'm seeing everything on the DOM correctly on the front end.

My problem is that I need to make rows 1 and 3 have apply this class and I can get it work:

In theory, I'm supposed to have a dynamic data table with 10 rows which are users in our app that came in first through tenth.

Rows 1-3: Are the users that came in first, second and third place... hence they get the "fa-trophy" class.

Rows 4-10: Are the remaining users hence they get the "fa-user-circle-o" class.

What am I doing wrong?

Javascript:

for(var i = 0; i < data.leaderboards.length; i++){

        row = $('
');
        row.append('
' + '
');
        row.append('
' + (i + 1) + '
');
        row.append('
' + data.leaderboards[i].username + '
');
        row.append('
' + data.leaderboards[i].win_amount.formatMoney(0, '.', ',') + '
');

        if(data.leaderboards[i].level_unlocked > _currLevel){
            row.append('
Won Playing ' + data.leaderboards[i].game_name + '
');
        }
        else{
            row.append('
Won Playing ' + data.leaderboards[i].game_name + '
');
        }
        _table.append(row);
    }

Body:
Why don't you assign the fa-trophy class when i <= 2 ? Something like

if (i <= 2) {
    // assign fa-trophy class for the first 3 places
    row.append('<div class="user-circle"><i class="fa fa-trophy fa-4" aria-hidden="true">' + '</i></div>');
} else {
    // do something else with 4th place onwards
    row.append('<div class="user-circle"><i class="fa fa-user-circle-o fa-4" aria-hidden="true">' + '</i></div>');
}


问:
Adding a method to a Rails ActiveRecord class
In plain Ruby, this works just fine:

```<code>class TestSuper
  def foo
    puts "In TestSuper.foo"
  end
end

class TestClass < TestSuper
  def foo
    super
    puts "In TestClass.bar"
  end
end

class TestClass
  def bar
    puts "In TestClass.bar, second definition"
    puts "Calling foo:"
    foo
  end
end

t = TestClass.new
t.foo
t.bar
</code>```

I can call foo() and bar() on a TestClass instance and get exactly what I expect:

```<code>In TestSuper.foo
In TestClass.bar
In TestClass.bar, second definition
Calling foo:
In TestSuper.foo
In TestClass.bar
</code>```

However, when I try something very similar in a Rails migration, I get errors:

```<code>#### my_model.rb ####
puts "In my_model.rb"
class MyModel
  has_many :foo
end

#### my_migration.rb ####
puts "In my_migration.rb"
class MyModel
  def bar
    foo.each{ |f| f.baz }
  end
end

class MyMigration < ActiveRecord::Migration
  def self.up
    MyModel.find(1).bar
  end

  def self.down
    # Not applicable
  end
end
</code>```

The first problem is that MyModel.find() disappears unless I explicitly have it extend ActiveRecord in my_migration.rb. Otherwise, it drops the superclass.

If I do that, I then get an error on the foo call in MyModel.bar().

If I comment out the class (re)definition in my_migration.rb, find() and bar() both work just fine.

During the course of my debugging, I added the puts statements to see when each file & class was being executed. It appears that my_model.rb doesn't even get loaded if MyModel is already defined (which I'm doing in my_migration.rb).

So: why does this happen in Rails, and how can I work around it?

答:
theory #2: at the top of your migration</p>

```<code>require 'app/models/my_model'
</code>```

ContentLicense: CC BY-SA 2.5

Body:
In plain Ruby, this works just fine:

class TestSuper
  def foo
    puts "In TestSuper.foo"
  end
end

class TestClass < TestSuper
  def foo
    super
    puts "In TestClass.bar"
  end
end

class TestClass
  def bar
    puts "In TestClass.bar, second definition"
    puts "Calling foo:"
    foo
  end
end

t = TestClass.new
t.foo
t.bar

I can call foo() and bar() on a TestClass instance and get exactly what I expect:

In TestSuper.foo
In TestClass.bar
In TestClass.bar, second definition
Calling foo:
In TestSuper.foo
In TestClass.bar

However, when I try something very similar in a Rails migration, I get errors:

#### my_model.rb ####
puts "In my_model.rb"
class MyModel
  has_many :foo
end

#### my_migration.rb ####
puts "In my_migration.rb"
class MyModel
  def bar
    foo.each{ |f| f.baz }
  end
end

class MyMigration < ActiveRecord::Migration
  def self.up
    MyModel.find(1).bar
  end

  def self.down
    # Not applicable
  end
end

The first problem is that MyModel.find() disappears unless I explicitly have it extend ActiveRecord in my_migration.rb. Otherwise, it drops the superclass.

If I do that, I then get an error on the foo call in MyModel.bar().

If I comment out the class (re)definition in my_migration.rb, find() and bar() both work just fine.

During the course of my debugging, I added the puts statements to see when each file & class was being executed. It appears that my_model.rb doesn't even get loaded if MyModel is already defined (which I'm doing in my_migration.rb).

So: why does this happen in Rails, and how can I work around it?

Body:
theory #2: at the top of your migration

require 'app/models/my_model'


问:
Can one large size favicon serve all devices and browsers?
All discussion about favicons recommend creating favicons of different sizes to target different clients. See this answer for example: Does a favicon have to be 32x32 or 16x16?

My question: Is it really necessary to generate favicons with so many different size? What if I created one large favicon of size 200x200? I see various browsers like Chrome and Firefox automatically scaling it down to display a pretty scaled-down favicon in the browser tab.

What's the problem in going for one large favicon of size 200x200 then?

Note: I want the favicon to work on any device browser that conforms to the standard (if there is one for favicon). For example, if iOS Safari violates the standard then I am not too bothered with supporting it.

答: The question you referred is 3 years old and nowadays I'd (and I usually am) create one, high res favicon and assume browsers would (and from my experience it will) scale it down if needed.


问:
When Django models field is empty, set value to the Default value
Whenever the user doesn't add a value, I need my Django models to replace the otherwise empty field with the value set in default.

My models looks like this:

```<code>not_before = models.TimeField(blank=True, null=True, default='00:00:00')
max_num_per_day = models.IntegerField(blank=True, null=True, default=0)
</code>```

I tried every combination of null, blank and default but no matter what I do, the fields gets replaced by null instead of '00:00:00' and 0.

Is there anyway I can force it to the default value whenever the field is empty?

答:
from what I understood from your question is you just want to set it to default. you can use:
https://code.djangoproject.com/ticket/6754

don't

```<code>not_before = models.TimeField(blank=True, null=True, default='00:00:00')
</code>```

instead,

```<code>import datetime
not_before = models.TimeField(default=datetime.time(0,0))
max_num_per_day = models.IntegerField(default=0)
</code>```

Body:
Whenever the user doesn't add a value, I need my Django models to replace the otherwise empty field with the value set in default.

My models looks like this:

not_before = models.TimeField(blank=True, null=True, default='00:00:00')
max_num_per_day = models.IntegerField(blank=True, null=True, default=0)

I tried every combination of null, blank and default but no matter what I do, the fields gets replaced by null instead of '00:00:00' and 0.

Is there anyway I can force it to the default value whenever the field is empty?

Body:
from what I understood from your question is you just want to set it to default. you can use:
https://code.djangoproject.com/ticket/6754

don't

not_before = models.TimeField(blank=True, null=True, default='00:00:00')

instead,

import datetime
not_before = models.TimeField(default=datetime.time(0,0))
max_num_per_day = models.IntegerField(default=0)


问:
How can infinite scrollview anchor be maintained?
I have a custom scrollview, source code here https://gist.github.com/anonymous/e605afc18a5a1edd5429c19a1092da2c#file-customscrollview-java.
Whenever new items are loaded on top and bottom on initial load, the anchor jumps when the control falls through this if https://gist.github.com/anonymous/e605afc18a5a1edd5429c19a1092da2c#file-customscrollview-java-L466.

This question is particularly related to how to maintain anchor position when the scrollY exceeds max scrollY for scrollview?

答: turns out the problem was somewhere else, the code is fine ;)</p>


问:
Run method before suite in TestNG via XML
I have an XML TestNG suite:

<suite name="mySuite" parallel="classes" thread-count="5">
    <test name="myTest">
        <packages>
            <package name="mypack.*"/>
        </packages>
    </test>
</suite>
```

<p>and I'd like to run a method every time before the suite.</p>

<p>Is it possible to have something like this:</p>

<pre class="lang-xml prettyprint-override"><code><suite name="mySuite" parallel="classes" thread-count="5">
    <before-suite>...</before-suite> <!-- Here I want to run a single method  -->
    <test name="myTest">
        <packages>
            <package name="mypack.*"/>
        </packages>
    </test>
</suite>
</code>```

?

答:
There are 2 options you have:

Use @BeforeSuite annotation on your method which you want to run before each suite

Implement the ISuiteListener onStart method, add the implemented listener to your xml in the listeners section.

Body:
I have an XML TestNG suite:

<suite name="mySuite" parallel="classes" thread-count="5">
    <test name="myTest">
        <packages>
            <package name="mypack.*"/>
        </packages>
    </test>
</suite>

and I'd like to run a method every time before the suite.

Is it possible to have something like this:

<suite name="mySuite" parallel="classes" thread-count="5">
    <before-suite>...</before-suite>
    <test name="myTest">
        <packages>
            <package name="mypack.*"/>
        </packages>
    </test>
</suite>

?


问:
In Delphi: How to skip sections of code while debugging?
I often accidently step into code that I'm not interested in while debugging in Delphi.

Let's start by saying that I know that you can step over with F8, and that you can run to a certain line with f4.

Example:

```<code>function TMyClass.DoStuff():Integer;
begin
  // do some stuff
  bla();
end;

procedure TMyClass.Foo()
begin
  if DoStuff()=0 then // press F7 when entering this line
    beep;
end;
</code>```

Example: I want to step into method DoStuff() by pressing F7, but instead of going there, I first end up in FastMM4.FastGetMem(), which is a massive blob of assembly code that obviously I'm not interested in at the moment.

There are several ways to go about this, and I don't like any of them:

Add a breakpoint on "bla" (almost useless if you only want to step into DoStuff on special occasions, like iteration 23498938);

Instead of pressing F7, manually move the cursor to "bla", and press F4 (Works for this simple example. In practice, it doesn't);

In case of FastMM: temporarily disable fastmm;

Is there any way to hint the IDE that I'm never interested into stepping into a certain block of code, or do I always have to set extra breakpoints or use F4 to try to avoid this?

I'm hoping for some magic compiler directive like {$NODEBUG BEGIN/END} or something like that.

In most cases being able to exclude entire units would be fine-grained enough for me, but being able to avoid certain methods or even lines of code would be even better.

Update: Maybe codegear should introduce something like skip-points (as opposed to break-points) :-)

答: There is a "magic nodebug switch".  {$D-} will disable the generation of debug code.  Place that at the top of your FastMM unit and you won't end up tracing into it.  And if you do end up in a function you don't want to be in, SHIFT-F8 will get you out very quickly.  (WARNING: Don't use SHIFT-F8 from inside an assembly-code routine that plays around with the stack.  Unpredictable behavior can result. F4 to the bottom of it instead.)

OwnerDisplayName: Wouter van Nifterick

Body:
I often accidently step into code that I'm not interested in while debugging in Delphi.

Let's start by saying that I know that you can step over with F8, and that you can run to a certain line with f4.

Example:

function TMyClass.DoStuff():Integer;
begin
  // do some stuff
  bla();
end;

procedure TMyClass.Foo()
begin
  if DoStuff()=0 then // press F7 when entering this line
    beep;
end;

Example: I want to step into method DoStuff() by pressing F7, but instead of going there, I first end up in FastMM4.FastGetMem(), which is a massive blob of assembly code that obviously I'm not interested in at the moment.

There are several ways to go about this, and I don't like any of them:

Add a breakpoint on "bla" (almost useless if you only want to step into DoStuff on special occasions, like iteration 23498938);

Instead of pressing F7, manually move the cursor to "bla", and press F4 (Works for this simple example. In practice, it doesn't);

In case of FastMM: temporarily disable fastmm;

Is there any way to hint the IDE that I'm never interested into stepping into a certain block of code, or do I always have to set extra breakpoints or use F4 to try to avoid this?

I'm hoping for some magic compiler directive like {$NODEBUG BEGIN/END} or something like that.

In most cases being able to exclude entire units would be fine-grained enough for me, but being able to avoid certain methods or even lines of code would be even better.

Update: Maybe codegear should introduce something like skip-points (as opposed to break-points) :-)

LastEditorDisplayName: Wouter van Nifterick

OwnerDisplayName: Mason Wheeler


问:
RegEx to close an unclosed tag
I have received some invalid XML data from a poll provider and would like to clean up several unclosed tags before processing.

The data currently looks like this:

```<code><questions>
<question number="1">
<title>What is your name?</title>
<answer>John Doe<answer> <!-- this is the problem -->
</question>
<question number="2">
...
</question>
</code>```

Is there a way with regular expressions to clean this and go ahead and close that <answer> tag?

I have this: "<answer>.*?(?<closingtag><answer>)" to find the occurrences, but how do I do a specific replacement on that <closingtag> named group?

Sorry for this very basic question, but I am struggling a bit with my regex expression.

Thanks,

Hal

答:
If the problem is always a missing / (that is, there is a matching tag, but it's not currently a closing one), you could do something like this:

Find: <([^/>]+)>([^<]*?)<\1>

Replace with: <\1>\2</\1>

This would attempt to find tags that are two-in-a-row-unclosed tags (not including self-closing tags), and replace them with the tag, the content, and then a closing version of the tag.

There are some caveats, of course - if a tag has an attribute that includes a /, or if the value of the unclosed tag includes < (or other tags) this regex wouldn't work.

Title: RegEx to close an unclosed tag

Body:
I have received some invalid XML data from a poll provider and would like to clean up several unclosed tags before processing.

The data currently looks like this:

<questions>
<question number="1">
<title>What is your name?</title>
<answer>John Doe<answer>
</question>
<question number="2">
...
</question>

Is there a way with regular expressions to clean this and go ahead and close that <answer> tag?

I have this: "<answer>.*?(?<closingtag><answer>)" to find the occurrences, but how do I do a specific replacement on that <closingtag> named group?

Sorry for this very basic question, but I am struggling a bit with my regex expression.

Thanks,

Hal


问:
PHP files not working when using Bootstrap
I am new to Programming hence need some help. Below is the code I am using for a Contact Form using Bootstrap but my PHP code doesn't seem to work.
I have been keeping "index.php" file with other files of Bootstrap. But when I run this it shows an error and doesn't run.
And when I save this file as "index.html", the HTML part of the code runs but PHP files don't.
In order to run PHP file in wamp server where should I save the files in Bootstrap or in Wamp?</p>

```<code><?php

if ($_POST['submit']) {

    if(!$_POST['name']) {
        $error="<br/>-Please enter your name";
    }

    if(!$_POST['email']) {
        $error.="<br/>- Please enter your email";
    }

    if(!$_POST['subject']) {
        $error.="<br/>- Please enter a subject";
    }

    if(!$_POST['message']) {
        $error.="<br/>- Please enter a message";
    }

    if(!$_POST['check']) {
        $error.="<br/>- Please confirm you are human";
    }

    if($error) {
        $result="Whoops, there is an error; Please correct the following: $error";
    } else {
        mail("namitajamwal19@gmail.com", "Contact message", "Name: ".$_POST['name']."
        Email: ".$_POST['name']."
        Subject: ".$_POST['subject']."
        Message: ".$_POST['message']);"

        {
        $result="Thank you, I'll be in touch shortly";
        }
    }
}
?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>Contact Us</title>

    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>

    <section id="contact">
        <div class="container">

            <div class="row">
                <div class="col-md-6 col-md-offset-3">
                    <h1>Contact Us</h1>

                    <?php echo $result;?>

                    <p>Send a message via the form below</p>

                    <form method="post" role="form">

                        <div class="form-group">
                            <input type="text" name="name" class="form-control" placeholder="Your Name" value="<?php echo $_POST['name']; ?>">
                        </div>

                        <div class="form-group">
                            <input type="email" name="email" class="form-control" placeholder="Your email" value="<?php echo $_POST['email']; ?>">
                        </div>

                        <div class="form-group">
                            <textarea name="subject" rows="5" class="form-control" placeholder="Subject"><?php echo $_POST['subject']; ?></textarea>
                        </div>

                        <div class="form-group">
                            <textarea name="message" rows="5" class="form-control" placeholder="Message..."><?php echo $_POST['message']; ?></textarea>
                        </div>

                        <div class="checkbox">
                            <label>
                                <input type="checkbox" name="check">I am Human
                            </label>
                        </div>

                        <div align="center">
                        <input type="submit" name="submit" class="btn btn-secondary" value="send message"/>
                        </div>
                    </form>

                </div>
            </div>

        </div>
    </section>

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>
</code>```

答:
```<code>You need to change your extension `.html` to `.php`
</code>```

If you still want to serve php files as .html create an .htaccess file in
in your directory and

```<code> `AddType application/x-httpd-php .html .htm`
</code>```

it will start working

Body:
I am new to Programming hence need some help. Below is the code I am using for a Contact Form using Bootstrap but my PHP code doesn't seem to work.
I have been keeping "index.php" file with other files of Bootstrap. But when I run this it shows an error and doesn't run.
And when I save this file as "index.html", the HTML part of the code runs but PHP files don't.
In order to run PHP file in wamp server where should I save the files in Bootstrap or in Wamp?

<?php

if ($_POST['submit']) {

    if(!$_POST['name']) {
        $error="
-Please enter your name";
    }

    if(!$_POST['email']) {
        $error.="
- Please enter your email";
    }

    if(!$_POST['subject']) {
        $error.="
- Please enter a subject";
    }

    if(!$_POST['message']) {
        $error.="
- Please enter a message";
    }

    if(!$_POST['check']) {
        $error.="
- Please confirm you are human";
    }

    if($error) {
        $result="Whoops, there is an error; Please correct the following: $error";
    } else {
        mail("namitajamwal19@gmail.com", "Contact message", "Name: ".$_POST['name']."
        Email: ".$_POST['name']."
        Subject: ".$_POST['subject']."
        Message: ".$_POST['message']);"

        {
        $result="Thank you, I'll be in touch shortly";
        }
    }
}
?>

<!DOCTYPE html>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Contact Us</title>

    <link href="css/bootstrap.min.css" rel="stylesheet">

Contact Us

                    <?php echo $result;?>

Send a message via the form below

                    <form method="post" role="form">

                            <input type="text" name="name" class="form-control" placeholder="Your Name" value="<?php echo $_POST['name']; ?>">

                            <input type="email" name="email" class="form-control" placeholder="Your email" value="<?php echo $_POST['email']; ?>">

                            <textarea name="subject" rows="5" class="form-control" placeholder="Subject"><?php echo $_POST['subject']; ?></textarea>

                            <textarea name="message" rows="5" class="form-control" placeholder="Message..."><?php echo $_POST['message']; ?></textarea>

                                <input type="checkbox" name="check">I am Human

                        <input type="submit" name="submit" class="btn btn-secondary" value="send message"/>

                    </form>

Body:
You need to change your extension `.html` to `.php`

If you still want to serve php files as .html create an .htaccess file in
in your directory and

 `AddType application/x-httpd-php .html .htm`

it will start working


问:
Getting Information from Req.User() into Req.params() in ExpressJS
After people log into my Express app, I'd like to redirect them to a url that reads:

```<code>www.mysite.com/:user
</code>```

What I'm having trouble with is that my req.params object is coming up as an empty object literal when people get re-directed after logging in.

Ideally what I'd like to do is to somehow take the information stored in req.user and pass some of that information into the URL.

So basically I'd like to get from here:

```<code>router.post('/login',
passport.authenticate('local', {successRedirect:'/', failureRedirect: '/login', failureFlash: true}));
</code>```

To here:

```<code>router.get('/:user', function(req, res) {
    //stuff
}
</code>```

After logging in the req.user object reads like this:

```<code>{
  username: joesmith@mail.com,
  name: Joe Smith,
  password:  dkei348#$kDL^583L,
  formulas: []
}
</code>```

And the code I'm attempting to use is as follows:

```<code>router.get('/:user', function(req, res) {
var user = req.user.name;
req.params = {
  "user": user
}
</code>```

But this doesn't work because initially req.user.name is undefined if someone isn't already logged in, so I can't get past the console error.

Apparently I don't understand how req.params is generated in enough detail to get around this problem.

Thank you.

答: Looks like you are wanting to access whatever /:user value is. e.g. www.mysite.com/stretch0. Therefore you would access it like var user = req.params.user;

Body:
After people log into my Express app, I'd like to redirect them to a url that reads:

www.mysite.com/:user

What I'm having trouble with is that my req.params object is coming up as an empty object literal when people get re-directed after logging in.

Ideally what I'd like to do is to somehow take the information stored in req.user and pass some of that information into the URL.

So basically I'd like to get from here:

router.post('/login',
passport.authenticate('local', {successRedirect:'/', failureRedirect: '/login', failureFlash: true}));

To here:

router.get('/:user', function(req, res) {
    //stuff
}

After logging in the req.user object reads like this:

{
  username: joesmith@mail.com,
  name: Joe Smith,
  password:  dkei348#$kDL^583L,
  formulas: []
}

And the code I'm attempting to use is as follows:

router.get('/:user', function(req, res) {
var user = req.user.name;
req.params = {
  "user": user
}

But this doesn't work because initially req.user.name is undefined if someone isn't already logged in, so I can't get past the console error.

Apparently I don't understand how req.params is generated in enough detail to get around this problem.

Thank you.


问:
Why i don't see the Shield around my spaceship?
I'm using unity version 5.6.1f1 Personal.

I'm trying to use this shader code and csharp script from wiki page:

Shield

In the editor i did: Assets > Create > Shader > Standrad Surface Shader
The double click on the created shader opened it in visual studio and added this code:

```<code>Shader "Custom/NewSurfaceShader" {
    Properties
    {
        _Color("_Color", Color) = (0.0,1.0,0.0,1.0)
        _Inside("_Inside", Range(0.0,2.0)) = 0.0
        _Rim("_Rim", Range(0.0,1.0)) = 1.2
        _Texture("_Texture", 2D) = "white" {}
    _Speed("_Speed", Range(0.5,5.0)) = 0.5
        _Tile("_Tile", Range(1.0,10.0)) = 5.0
        _Strength("_Strength", Range(0.0,5.0)) = 1.5
    }

        SubShader
    {
        Tags
    {
        "Queue" = "Transparent"
        "IgnoreProjector" = "True"
        "RenderType" = "Transparent"

    }

        Cull Back
        ZWrite On
        ZTest LEqual

        CGPROGRAM
#pragma surface surf BlinnPhongEditor alpha vertex:vert
        //#pragma target 3.0

        fixed4 _Color;
    sampler2D _CameraDepthTexture;
    fixed _Inside;
    fixed _Rim;
    sampler2D _Texture;
    fixed _Speed;
    fixed _Tile;
    fixed _Strength;

    struct EditorSurfaceOutput
    {
        half3 Albedo;
        half3 Normal;
        half3 Emission;
        half3 Gloss;
        half Specular;
        half Alpha;
    };

    inline half4 LightingBlinnPhongEditor_PrePass(EditorSurfaceOutput s, half4 light)
    {
        half3 spec = light.a * s.Gloss;

        half4 c;

        c.rgb = (s.Albedo * light.rgb + light.rgb * spec);

        c.a = s.Alpha + Luminance(spec);

        return c;

    }

    inline half4 LightingBlinnPhongEditor(EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
    {
        viewDir = normalize(viewDir);
        half3 h = normalize(lightDir + viewDir);

        half diff = max(0, dot(s.Normal, lightDir));

        float nh = max(0, dot(s.Normal, h));
        float3 spec = pow(nh, s.Specular*128.0) * s.Gloss;

        half4 res;
        res.rgb = _LightColor0.rgb * (diff * atten * 2.0);
        res.w = spec * Luminance(_LightColor0.rgb);

        return LightingBlinnPhongEditor_PrePass(s, res);
    }

    struct Input
    {
        float4 screenPos;
        float3 viewDir;
        float2 uv_Texture;
    };

    void vert(inout appdata_full v, out Input o)
    {
        UNITY_INITIALIZE_OUTPUT(Input,o);
    }

    void surf(Input IN, inout EditorSurfaceOutput o)
    {
        o.Albedo = fixed3(0.0,0.0,0.0);
        o.Normal = fixed3(0.0,0.0,1.0);
        o.Emission = 0.0;
        o.Gloss = 0.0;
        o.Specular = 0.0;
        o.Alpha = 1.0;
        float4 ScreenDepthDiff0 = LinearEyeDepth(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(IN.screenPos)).r) - IN.screenPos.z;
        float4 Saturate0 = fixed4(0.3,0.3,0.3,1.0);//
        float4 Fresnel0_1_NoInput = fixed4(0,0,1,1);
        float dNorm = 1.0 - dot(normalize(float4(IN.viewDir, 1.0).xyz), normalize(Fresnel0_1_NoInput.xyz));
        float4 Fresnel0 = float4(dNorm,dNorm,dNorm,dNorm);
        float4 Step0 = step(Fresnel0,float4(1.0, 1.0, 1.0, 1.0));
        float4 Clamp0 = clamp(Step0,_Inside.xxxx,float4(1.0, 1.0, 1.0, 1.0));
        float4 Pow0 = pow(Fresnel0,(_Rim).xxxx);
        float4 Multiply5 = _Time * _Speed.xxxx;
        float4 UV_Pan0 = float4((IN.uv_Texture.xyxy).x,(IN.uv_Texture.xyxy).y + Multiply5.x,(IN.uv_Texture.xyxy).z,(IN.uv_Texture.xyxy).w);
        float4 Multiply1 = UV_Pan0 * _Tile.xxxx;
        float4 Tex2D0 = tex2D(_Texture,Multiply1.xy);
        float4 Multiply2 = Tex2D0 * _Strength.xxxx;
        float4 Multiply0 = Pow0 * Multiply2;
        float4 Multiply3 = Clamp0 * Multiply0;
        float4 Multiply4 = Saturate0 * Multiply3;
        o.Emission = Multiply3.xyz * _Color.rgb;
        o.Alpha = Multiply3.w * _Color.a;

    }
    ENDCG
    }
        Fallback "Diffuse"
}
</code>```

Then created a csharp script file:

```<code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ShieldUvAnimation : MonoBehaviour {

    public GameObject iShield;
    public float iSpeed;

    private Material mMaterial;
    private float mTime;

    // Use this for initialization
    void Start()
    {
        mMaterial = iShield.GetComponent<Renderer>().material;

        mTime = 0.0f;
    }

    // Update is called once per frame
    void Update()
    {
        mTime += Time.deltaTime * iSpeed;

        mMaterial.SetFloat("_Offset", Mathf.Repeat(mTime, 1.0f));
    }

}
</code>```

Then i created a material new material and dragged the shader to the material.
Then created a new empty GameObject.

Then attached the csharp script to the new empty GameObject.

Now the first problem i had is that i could not drag the new material to the empty GameObject. So i changed the csharp script i changed the line:

```<code>private Material mMaterial;
</code>```

To be public

```<code>public Material mMaterial;
</code>```

And removed the line in the Start:

```<code>mMaterial = iShield.GetComponent<Renderer>().material;
</code>```

Then i dragged the new material to the public mMaterial.
Last i dragged my spaceship object to the iShield.

I changed the iSpeed to 1.

Running the game i'm not getting any errors or exceptions but i don't see any shield.

答:
Your shader doesn't have property "_Offset".

Script "ShieldUvAnimation" will work with "ShaderLab - ForceField.shader".

Your link shield

Body:
I'm using unity version 5.6.1f1 Personal.

I'm trying to use this shader code and csharp script from wiki page:

Shield

In the editor i did: Assets > Create > Shader > Standrad Surface Shader
The double click on the created shader opened it in visual studio and added this code:

Shader "Custom/NewSurfaceShader" {
    Properties
    {
        _Color("_Color", Color) = (0.0,1.0,0.0,1.0)
        _Inside("_Inside", Range(0.0,2.0)) = 0.0
        _Rim("_Rim", Range(0.0,1.0)) = 1.2
        _Texture("_Texture", 2D) = "white" {}
    _Speed("_Speed", Range(0.5,5.0)) = 0.5
        _Tile("_Tile", Range(1.0,10.0)) = 5.0
        _Strength("_Strength", Range(0.0,5.0)) = 1.5
    }

        SubShader
    {
        Tags
    {
        "Queue" = "Transparent"
        "IgnoreProjector" = "True"
        "RenderType" = "Transparent"

    }

        Cull Back
        ZWrite On
        ZTest LEqual

        CGPROGRAM
#pragma surface surf BlinnPhongEditor alpha vertex:vert
        //#pragma target 3.0

        fixed4 _Color;
    sampler2D _CameraDepthTexture;
    fixed _Inside;
    fixed _Rim;
    sampler2D _Texture;
    fixed _Speed;
    fixed _Tile;
    fixed _Strength;

    struct EditorSurfaceOutput
    {
        half3 Albedo;
        half3 Normal;
        half3 Emission;
        half3 Gloss;
        half Specular;
        half Alpha;
    };

    inline half4 LightingBlinnPhongEditor_PrePass(EditorSurfaceOutput s, half4 light)
    {
        half3 spec = light.a * s.Gloss;

        half4 c;

        c.rgb = (s.Albedo * light.rgb + light.rgb * spec);

        c.a = s.Alpha + Luminance(spec);

        return c;

    }

    inline half4 LightingBlinnPhongEditor(EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
    {
        viewDir = normalize(viewDir);
        half3 h = normalize(lightDir + viewDir);

        half diff = max(0, dot(s.Normal, lightDir));

        float nh = max(0, dot(s.Normal, h));
        float3 spec = pow(nh, s.Specular*128.0) * s.Gloss;

        half4 res;
        res.rgb = _LightColor0.rgb * (diff * atten * 2.0);
        res.w = spec * Luminance(_LightColor0.rgb);

        return LightingBlinnPhongEditor_PrePass(s, res);
    }

    struct Input
    {
        float4 screenPos;
        float3 viewDir;
        float2 uv_Texture;
    };

    void vert(inout appdata_full v, out Input o)
    {
        UNITY_INITIALIZE_OUTPUT(Input,o);
    }

    void surf(Input IN, inout EditorSurfaceOutput o)
    {
        o.Albedo = fixed3(0.0,0.0,0.0);
        o.Normal = fixed3(0.0,0.0,1.0);
        o.Emission = 0.0;
        o.Gloss = 0.0;
        o.Specular = 0.0;
        o.Alpha = 1.0;
        float4 ScreenDepthDiff0 = LinearEyeDepth(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(IN.screenPos)).r) - IN.screenPos.z;
        float4 Saturate0 = fixed4(0.3,0.3,0.3,1.0);//
        float4 Fresnel0_1_NoInput = fixed4(0,0,1,1);
        float dNorm = 1.0 - dot(normalize(float4(IN.viewDir, 1.0).xyz), normalize(Fresnel0_1_NoInput.xyz));
        float4 Fresnel0 = float4(dNorm,dNorm,dNorm,dNorm);
        float4 Step0 = step(Fresnel0,float4(1.0, 1.0, 1.0, 1.0));
        float4 Clamp0 = clamp(Step0,_Inside.xxxx,float4(1.0, 1.0, 1.0, 1.0));
        float4 Pow0 = pow(Fresnel0,(_Rim).xxxx);
        float4 Multiply5 = _Time * _Speed.xxxx;
        float4 UV_Pan0 = float4((IN.uv_Texture.xyxy).x,(IN.uv_Texture.xyxy).y + Multiply5.x,(IN.uv_Texture.xyxy).z,(IN.uv_Texture.xyxy).w);
        float4 Multiply1 = UV_Pan0 * _Tile.xxxx;
        float4 Tex2D0 = tex2D(_Texture,Multiply1.xy);
        float4 Multiply2 = Tex2D0 * _Strength.xxxx;
        float4 Multiply0 = Pow0 * Multiply2;
        float4 Multiply3 = Clamp0 * Multiply0;
        float4 Multiply4 = Saturate0 * Multiply3;
        o.Emission = Multiply3.xyz * _Color.rgb;
        o.Alpha = Multiply3.w * _Color.a;

    }
    ENDCG
    }
        Fallback "Diffuse"
}

Then created a csharp script file:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ShieldUvAnimation : MonoBehaviour {

    public GameObject iShield;
    public float iSpeed;

    private Material mMaterial;
    private float mTime;

    // Use this for initialization
    void Start()
    {
        mMaterial = iShield.GetComponent<Renderer>().material;

        mTime = 0.0f;
    }

    // Update is called once per frame
    void Update()
    {
        mTime += Time.deltaTime * iSpeed;

        mMaterial.SetFloat("_Offset", Mathf.Repeat(mTime, 1.0f));
    }

}

Then i created a material new material and dragged the shader to the material.
Then created a new empty GameObject.

Then attached the csharp script to the new empty GameObject.

Now the first problem i had is that i could not drag the new material to the empty GameObject. So i changed the csharp script i changed the line:

private Material mMaterial;

To be public

public Material mMaterial;

And removed the line in the Start:

mMaterial = iShield.GetComponent<Renderer>().material;

Then i dragged the new material to the public mMaterial.
Last i dragged my spaceship object to the iShield.

I changed the iSpeed to 1.

Running the game i'm not getting any errors or exceptions but i don't see any shield.


问:
Telerik MVC Extensions GridBindingToData sample: CRUD operations using ADO.NET DataTable (arbitrary table)?
In GridBindingToDataTableSample sample that can be found at this URL:
http://www.telerik.com/community/code-library/aspnet-mvc/grid/crud-operations-using-ado-net-datatable.aspx
they hard coded dataKeys and columns collection.
I need a generic CRUD code that would work with Html.Telerik().Grid HTML helper.

Imagine that I will have some metadata TableColumnMedatata table that will contain Table/Column metadata:

```
table    column        type     length    pk
=============================================
EmpLoc   EmployeeID    int      4         1
EmpLoc   LocID         int      4         1
---------------------------------------------
Orders   OrderID       int      4         1
Orders   CustomerID    nchar    10        0
Orders   EmployeeID    int      4         0
Orders   OrderDate     datetime 8         0
Orders   ShipVia       int      4         0
Orders   Freight       money    8         0
Orders   ShipName      nvarchar 80        0
---------------------------------------------
Employees EmployeeID   int      4         1
Employees LastName     nvarchar 40        0
Employees FirstName    nvarchar 20        0
```

I need some suggestions on how to modify index.aspx to enable universal form to work against any DataTable retrieved from SQL Server.

Thanks,
Rad

答: You can enumerate the table columns and create grid columns on the fly.</p>

Body:
In GridBindingToDataTableSample sample that can be found at this URL:
http://www.telerik.com/community/code-library/aspnet-mvc/grid/crud-operations-using-ado-net-datatable.aspx
they hard coded dataKeys and columns collection.
I need a generic CRUD code that would work with Html.Telerik().Grid HTML helper.

Imagine that I will have some metadata TableColumnMedatata table that will contain Table/Column metadata:

table    column        type     length    pk
=============================================
EmpLoc   EmployeeID    int      4         1
EmpLoc   LocID         int      4         1
---------------------------------------------
Orders   OrderID       int      4         1
Orders   CustomerID    nchar    10        0
Orders   EmployeeID    int      4         0
Orders   OrderDate     datetime 8         0
Orders   ShipVia       int      4         0
Orders   Freight       money    8         0
Orders   ShipName      nvarchar 80        0
---------------------------------------------
Employees EmployeeID   int      4         1
Employees LastName     nvarchar 40        0
Employees FirstName    nvarchar 20        0

I need some suggestions on how to modify index.aspx to enable universal form to work against any DataTable retrieved from SQL Server.

Thanks,
Rad


问:
how to insert scroll button on drop down in php html
I want scroll button after i click on the Select your country textbox anyone know how to insert scroll button. Here my code :

```<code><form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
    <label for='formCountry'>Select your country of residence</label><br>
    <select name="formCountry">
        <option value="">Select a country...</option>
        <option value="US">United States</option>
        <option value="UK">United Kingdom</option>
        <option value="France">France</option>
        <option value="Mexico">Mexico</option>
        <option value="Russia">Russia</option>
        <option value="Japan">Japan</option>
    </select>
    <input type="submit" name="formSubmit" value="Submit" />
</form>
</code>```

Thanks in advance :)

答:
it's automatic take scorll button in dropdown but if you still limit the showing option,than use below code :

apply height and overflow in css:

CSS:

```<code>.select{
    height:100px;
    overflow:scroll;
}
</code>```

HTML:

```<code>   <select name="formCountry" class="select">
        <option value="">Select a country...</option>
        <option value="US">United States</option>
        <option value="UK">United Kingdom</option>
        <option value="France">France</option>
        <option value="Mexico">Mexico</option>
        <option value="Russia">Russia</option>
        <option value="Japan">Japan</option>
    </select>
</code>```

Body:
I want scroll button after i click on the Select your country textbox anyone know how to insert scroll button. Here my code :

<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
    Select your country of residence

    <select name="formCountry">
        <option value="">Select a country...</option>
        <option value="US">United States</option>
        <option value="UK">United Kingdom</option>
        <option value="France">France</option>
        <option value="Mexico">Mexico</option>
        <option value="Russia">Russia</option>
        <option value="Japan">Japan</option>
    </select>
    <input type="submit" name="formSubmit" value="Submit" />
</form>

Thanks in advance :)

Body:
it's automatic take scorll button in dropdown but if you still limit the showing option,than use below code :

apply height and overflow in css:

CSS:

.select{
    height:100px;
    overflow:scroll;
}

HTML:

   <select name="formCountry" class="select">
        <option value="">Select a country...</option>
        <option value="US">United States</option>
        <option value="UK">United Kingdom</option>
        <option value="France">France</option>
        <option value="Mexico">Mexico</option>
        <option value="Russia">Russia</option>
        <option value="Japan">Japan</option>
    </select>


问:
Data structures linked list
I was asked to solve this out:

There are two singly linked lists.
I need to write a method which get those two linked lists and returns a pointer to the starting point where the suffix is the same in those two lists.

Example:

given:

```<code>1->2->4->6->8->10->15
2->4->8->10->15
</code>```

the returned value would be a pointer to the member - 8.

But,
I need to do it without changing the lists or using more memory,
and - we need to scan the lists only once, means T(n)=O(n).

答:
measure the lengths of both lists

skip forward in the longer list until they're the same length

walk forward through both lists in step, and remember the nodes AFTER the last point where the lists have different elements.  These are the pointers you can return.

Now... I know you said that you only want to scan the lists once, and I have done it twice, but you also said that this means T(n) = O(n), and that is not correct.

Scanning the lists twice is also in O(n) and is required to solve the problem without using unbounded extra memory.

Title: Data structures linked list

Body:
I was asked to solve this out:

There are two singly linked lists.
I need to write a method which get those two linked lists and returns a pointer to the starting point where the suffix is the same in those two lists.

Example:

given:

1->2->4->6->8->10->15
2->4->8->10->15

the returned value would be a pointer to the member - 8.

But,
I need to do it without changing the lists or using more memory,
and - we need to scan the lists only once, means T(n)=O(n).


问:
SQL Server text column affects results returned to classic ASP
Using classic asp, I am trying to query a SQL Server database like so:

```<code>strSQL = "select column_1, column_2, column_3, column_4  from someview " &_
         "where RecordNo=" & i
set rs=conn.Execute(strSQL)

if not rs.eof then
    A = rs("column_1")
    B = rs("column_2")
    C = rs("column_3")
    D = rs("column_4")
end if
</code>```

Column_3 is an NText type, the other columns are varchar or int (sometimes there may be more than 4 columns returned) but the query only returns 1 record because of the where clause.

On the ASP page the results vary - sometimes A,B,D are populated, sometimes not - but all columns in the view contain data (when I query the SQL Server I see the expected results - all columns do contain data). If I remove column_3 which is NText from the strSQL everything works fine.

I've seen this behaviour on a couple other pages in the past. If I modify the ASP to get column_3 separately:

```<code> strSQL = "select column_3 from someview where RecordNo=" & i
</code>```

The NText data is returned correctly.

Is there a maximum record length to a SQL Server recordset returned to classic ASP? Apart from splitting out the NTEXT into a separate query, is there anything else I can do?

EDIT: It just occured to me to try changing the connection string - inspired by this comment on a similar problem - the connection is via SQL Server ODBC Driver (Driver={SQL Server};).

答:
One extra tip for those who are working with older code:

When a recordset's column value is blank using ADO/ASP and you have a single line of data, you can bypass this problem by using a parameterised Command statement and returning the string value into a variable:

Some hand-typed code hopefully explains what I mean:

```<code>' DB connection
Set objCon = Server.CreateObject("ADODB.Connection")
objCon.CursorLocation = adUseClient
objCon.Open pubDbConnString

' statement construction
Set cmd = Server.CreateObject("ADODB.Command")
Set cmd.ActiveConnection = objCon

cmd.CommandText = "SELECT ?=T.Column1, ?=T.Column2 From Table T WHERE ID=?"
cmd.CommandType = adCmdText
' add parameters
cmd.Parameters.Append cmd.CreateParameter("@column1Data", adVarChar, adParamOutput, 8000)
cmd.Parameters.Append cmd.CreateParameter("@column2Data", adTinyInt, adParamOutput)
cmd.Parameters.Append cmd.CreateParameter("@id", adBigInt, adParamInput)
cmd.Parameters("@id").value = 1

set objRS = cmd.Execute
</code>```

@column1Data will contain the large string. objRS will actually not have any records in it, so be mindful of this.

In theory, this should also work with named parameters with the same results, but I have not tested this.

Body:
Using classic asp, I am trying to query a SQL Server database like so:

strSQL = "select column_1, column_2, column_3, column_4  from someview " &_
         "where RecordNo=" & i
set rs=conn.Execute(strSQL)

if not rs.eof then
    A = rs("column_1")
    B = rs("column_2")
    C = rs("column_3")
    D = rs("column_4")
end if

Column_3 is an NText type, the other columns are varchar or int (sometimes there may be more than 4 columns returned) but the query only returns 1 record because of the where clause.

On the ASP page the results vary - sometimes A,B,D are populated, sometimes not - but all columns in the view contain data (when I query the SQL Server I see the expected results - all columns do contain data). If I remove column_3 which is NText from the strSQL everything works fine.

I've seen this behaviour on a couple other pages in the past. If I modify the ASP to get column_3 separately:

 strSQL = "select column_3 from someview where RecordNo=" & i

The NText data is returned correctly.

Is there a maximum record length to a SQL Server recordset returned to classic ASP? Apart from splitting out the NTEXT into a separate query, is there anything else I can do?

EDIT: It just occured to me to try changing the connection string - inspired by this comment on a similar problem - the connection is via SQL Server ODBC Driver (Driver={SQL Server};).

Body:
One extra tip for those who are working with older code:

When a recordset's column value is blank using ADO/ASP and you have a single line of data, you can bypass this problem by using a parameterised Command statement and returning the string value into a variable:

Some hand-typed code hopefully explains what I mean:

' DB connection
Set objCon = Server.CreateObject("ADODB.Connection")
objCon.CursorLocation = adUseClient
objCon.Open pubDbConnString

' statement construction
Set cmd = Server.CreateObject("ADODB.Command")
Set cmd.ActiveConnection = objCon

cmd.CommandText = "SELECT ?=T.Column1, ?=T.Column2 From Table T WHERE ID=?"
cmd.CommandType = adCmdText
' add parameters
cmd.Parameters.Append cmd.CreateParameter("@column1Data", adVarChar, adParamOutput, 8000)
cmd.Parameters.Append cmd.CreateParameter("@column2Data", adTinyInt, adParamOutput)
cmd.Parameters.Append cmd.CreateParameter("@id", adBigInt, adParamInput)
cmd.Parameters("@id").value = 1

set objRS = cmd.Execute

@column1Data will contain the large string. objRS will actually not have any records in it, so be mindful of this.

In theory, this should also work with named parameters with the same results, but I have not tested this.


问:
(VueJS) Vuex getter should update based on another module state change
I have two Vuex store modules: ListItems and ListSort.  ListItems has a getter that is essentially computed from the state of both of these modules.  See the below code:

```<code>// Import the ListSort store module
import listSort from './list-sort';

// ListItems getters
const getters = {
  companiesSorted: () => {
    return _.orderBy(state.companies,
      [listSort.state.sortAttribute],
      [listSort.state.sortDirection]);
  },
};
</code>```

However, when the state in ListSort is changed (i.e. sortAttribute or sortDirection are changed), this is not causing the ListItems getter to recompute.  How can I tell Vuex that, given a dependency to computing companiesStored has changed, Vuex should recompute that getter?

Thanks!

答:
How can I tell Vuex that, given a dependency to computing
  companiesStored has changed, Vuex should recompute that getter?

You don't, it's done automatically for you! Isn't Vue awesome for lazy developers?

The only JS module that should import a Vuex module is the JS module that initializes Vuex, thru new Vuex.Store, which bundles the Vuex modules together.

Vuex module getters have access to their local state, and the rootState. The rootState is where you access other module's data.

https://vuex.vuejs.org/en/modules.html#module-local-state

It should look something like this:

```<code>companiesSorted: (state, getters, rootState) => {
    return _.orderBy(state.companies,
      [rootState.listSortModule.sortAttribute],
      [rootState.listSortModule.sortDirection]);
  },
</code>```

Where listSortModule is the name you gave to the module.

Body:
I have two Vuex store modules: ListItems and ListSort.  ListItems has a getter that is essentially computed from the state of both of these modules.  See the below code:

// Import the ListSort store module
import listSort from './list-sort';

// ListItems getters
const getters = {
  companiesSorted: () => {
    return _.orderBy(state.companies,
      [listSort.state.sortAttribute],
      [listSort.state.sortDirection]);
  },
};

However, when the state in ListSort is changed (i.e. sortAttribute or sortDirection are changed), this is not causing the ListItems getter to recompute.  How can I tell Vuex that, given a dependency to computing companiesStored has changed, Vuex should recompute that getter?

Thanks!

Body:
How can I tell Vuex that, given a dependency to computing
  companiesStored has changed, Vuex should recompute that getter?

You don't, it's done automatically for you! Isn't Vue awesome for lazy developers?

The only JS module that should import a Vuex module is the JS module that initializes Vuex, thru new Vuex.Store, which bundles the Vuex modules together.

Vuex module getters have access to their local state, and the rootState. The rootState is where you access other module's data.

https://vuex.vuejs.org/en/modules.html#module-local-state

It should look something like this:

companiesSorted: (state, getters, rootState) => {
    return _.orderBy(state.companies,
      [rootState.listSortModule.sortAttribute],
      [rootState.listSortModule.sortDirection]);
  },

Where listSortModule is the name you gave to the module.


问:
In a cocoa application, 0x7FFF... appears to be an object on the stack, 0x000001... appears to be an object on the heap, but what is 0x618...?
I see these addresses all the time in my Cocoa application,
0x618....

As far as I know, objects are allocated on either the stack or heap

As the application executes, stack frames are produced and placed on the stack, and any local pointers created in the scope of the stack are allocated on the stack (0x7FFF...)

And the actual underlying object that the pointer is referencing, is created on the heap (0x0000010...)

But it actually looks like this 0x618.... area in memory is also used as a heap for objects?  Because if you dereference a pointer to an NSObject subclass in the stack, I have seen it pretty much always point to 0x618...

Are there two heaps for a Cocoa application?

Or is 0x618... the actual heap for the application, and 0x000001 is just some other area of memory used for something else entirely?

答:
The heap is typically below your stack and above your code. It is therefore impossible to be definitive where heap address may start, but your 0x618... would not be unreasonable for a heap address.

Not all objects are on the heap, for example string constants are compiled into your code, and your 0x000001... could easily be one.

There is also the complication of tagged pointers. Some objects are not even heap allocated but their value is combined with some tag bits into a tagged pointer, which isn't a pointer at all but will be found in variables of pointer type. NSNumber is like this for certain values, e.g. @42 returns the "pointer" 0x2a37.

HTH


问:
SQL query for finding records where dont have certain value
I have

table A

```<code>a_id
a001
a002
a003
a004
a005
</code>```

table B

```<code>a_id | status | user_id
a001 | 0      | u001
a001 | 1      | u002
a001 | 2      | u003
a002 | 1      | u001
a002 | 0      | u002
a002 | 0      | u003
a003 | 0      | u002
a003 | 0      | u003
a004 | 0      | u001
</code>```

I want to get
a003 and a004 and a005

because a003,a004,and a005 dont have status 1 and 2

how can i do this?

答:
You can try this</p>

```<code>SELECT
*
FROM tableA a
WHERE NOT EXISTS(SELECT 1 FROM tableB b WHERE b.status <> 0 AND a.a_id = b.a_id)
AND EXISTS(SELECT 1 FROM tableB b WHERE b.status = 0 AND a.a_id = b.a_id)
</code>```

Body:
I have

table A

a_id
a001
a002
a003
a004
a005

table B

a_id | status | user_id
a001 | 0      | u001
a001 | 1      | u002
a001 | 2      | u003
a002 | 1      | u001
a002 | 0      | u002
a002 | 0      | u003
a003 | 0      | u002
a003 | 0      | u003
a004 | 0      | u001

I want to get
a003 and a004 and a005

because a003,a004,and a005 dont have status 1 and 2

how can i do this?

Body:
You can try this

SELECT
*
FROM tableA a
WHERE NOT EXISTS(SELECT 1 FROM tableB b WHERE b.status <> 0 AND a.a_id = b.a_id)
AND EXISTS(SELECT 1 FROM tableB b WHERE b.status = 0 AND a.a_id = b.a_id)


问:
Custom NER model extracts substring of keyword used for training
I trained a custom NER model with more than a million sentences using the training API of OpenNlp for identifying the skill that I taught. During the testing I have found that the model identifying the skill and a substring of skill. For example, I have taught a skill 'Core Java', if the sentence have  word 'Core' then my model will identify it as a skill. I want to avoid such situation. I want only identify the whole word 'Core Java' if the whole word is there in the test sentences.

How can improve my custom model for above mentioned result?

答:
Sounds like you need to provide more training examples.

If the only time the word Core appears in your training data is as part of the phrase Core Java, your model might learn that Core is part of a skill name with 100% probability, and based on what it knows that isn't wrong. To fix it, add more training data where it's used in an unrelated way. Some examples:

```<code>He threw away the apple core.
Core skills in math include addition and subtraction.
The core of the application is implemented in C for speed.
</code>```

Body:
Sounds like you need to provide more training examples.

If the only time the word Core appears in your training data is as part of the phrase Core Java, your model might learn that Core is part of a skill name with 100% probability, and based on what it knows that isn't wrong. To fix it, add more training data where it's used in an unrelated way. Some examples:

He threw away the apple core.
Core skills in math include addition and subtraction.
The core of the application is implemented in C for speed.


问:
How do I add a warning with Groovy AST transformations?
I see on the SourceUnit object that I can addError(SyntaxException), but how do I add a warning?

EDIT: Anyone know how I can either get a CSTNode in the CompilePhase.SEMANTIC_ANALYSIS, or how I can simply add a warning with only having to know the line number and column number (just like the addError function works)?

EDIT 2: I tried just creating a CSTNode myself, but it didn't seem to work as eclipse didn't show the warning.

答: Can you call getErrorCollector() on SourceUnit then add the warnings to that with one of the addWarning(...) methods?


问:
Attach dynamically loaded javascript event handler to dynamically loaded HTML
I have a site which loads content through AJAX. I need to attach onclick handler to some div which was dynamically loaded. It works fine if my event handler is already defined in my main javascript file (whether I attach it through markup via attribute onclick="myFunc" on by more pedantic addEventListener ).

However, I would like this event handler to be defined in a  is before or after the
.

I tried to attach it at the end of the XmlHttpRequest:

```<code>contentDiv.innerHTML = xhr.responseText;
var handlerName = getItFrom(xhr.responseText);
var clickFn = window[handlerName];
loadedDiv.addEventListener('click', clickFn);
</code>```

Doesn't work neither: handlerName is correct, but clickFn remains undefined...

I prefer a pure js answer but jquery is ok if I can easily translate it.

答:
It's doable if you're willing to use jQuery, here I assign an event handler from a script tag of a html string.  A couple of things, the parameter you pass into .html has to be a jQuery object of your string, and you'll need to replace </script> with <\/script> within the string (could use .replace).

$('#content').html($("before

<button id='testo'>Click</button>```

Body:
I have a site which loads content through AJAX. I need to attach onclick handler to some div which was dynamically loaded. It works fine if my event handler is already defined in my main javascript file (whether I attach it through markup via attribute onclick="myFunc" on by more pedantic addEventListener ).

However, I would like this event handler to be defined in a  is before or after the
.

I tried to attach it at the end of the XmlHttpRequest:

contentDiv.innerHTML = xhr.responseText;
var handlerName = getItFrom(xhr.responseText);
var clickFn = window[handlerName];
loadedDiv.addEventListener('click', clickFn);

Doesn't work neither: handlerName is correct, but clickFn remains undefined...

I prefer a pure js answer but jquery is ok if I can easily translate it.

Body:
It's doable if you're willing to use jQuery, here I assign an event handler from a script tag of a html string.  A couple of things, the parameter you pass into .html has to be a jQuery object of your string, and you'll need to replace </script> with <\/script> within the string (could use .replace).

$('#content').html($("<span>before</span><script>$('#testo').click(function () { alert('infunc');});<\/script><span>after</span>"));

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='content'></div>
<button id='testo'>Click</button>


问:
Algorithm that finds the N-th most frequent number in the array
I want to write an algorithm that finds the n-th most frequent number in an array.
I have a solution but not optimal (testing numbers i've already tested)
I wonder if there is a more optimal solution?
Here is my Solution :</p>

```<code>most_freq_element(a,n){
final_cnt = 0, curr_cnt = 1, final_freq_num = -1, curr_freq_num = -1;
for(i = 0; i < n-1; i++)
{
    if (a[i]!=-1){
        curr_freq_num = a[i];
        for(j =i+1; j < n; j++){
            if(curr_freq_num == a[j] && final_freq_num != curr_freq_num){
                curr_cnt++;
            }
        }
        if(final_cnt < curr_cnt){
            final_cnt = curr_cnt;
            curr_cnt = 1;
            final_freq_num = curr_freq_num;
        }
    }
}
printf("Num = %d and times = %d", final_freq_num, final_cnt);
}

nth_most_frequent_element(a,n,k){
if(k==1){
    return most_freq_element(a,n);
}
else{
    for (i=0;i<k;i++){
        int most_freq_num = most_freq_element(a,n);

        for(i = 0; i < n-1; i++){
            if (a[i]==most_freq_num){
                a[i]=-1;
            }
        }
    }
    return most_freq_element(a,n);
}
}
</code>```

答:
I would probably make a hashmap/table, and increment each value on collision, so that the number is the key and the value is the number of collisions. Then, when you're done, aggregate it to a sorted list and grab the nth element. Would run in O(n) which is pretty optimal.

Edit: Actually, the sorting would cost n*log(n).

Body:
I want to write an algorithm that finds the n-th most frequent number in an array.
I have a solution but not optimal (testing numbers i've already tested)
I wonder if there is a more optimal solution?
Here is my Solution :

most_freq_element(a,n){
final_cnt = 0, curr_cnt = 1, final_freq_num = -1, curr_freq_num = -1;
for(i = 0; i < n-1; i++)
{
    if (a[i]!=-1){
        curr_freq_num = a[i];
        for(j =i+1; j < n; j++){
            if(curr_freq_num == a[j] && final_freq_num != curr_freq_num){
                curr_cnt++;
            }
        }
        if(final_cnt < curr_cnt){
            final_cnt = curr_cnt;
            curr_cnt = 1;
            final_freq_num = curr_freq_num;
        }
    }
}
printf("Num = %d and times = %d", final_freq_num, final_cnt);
}

nth_most_frequent_element(a,n,k){
if(k==1){
    return most_freq_element(a,n);
}
else{
    for (i=0;i<k;i++){
        int most_freq_num = most_freq_element(a,n);

        for(i = 0; i < n-1; i++){
            if (a[i]==most_freq_num){
                a[i]=-1;
            }
        }
    }
    return most_freq_element(a,n);
}
}


问:
apns-collapse-id not merging multiple notifications iOS 10
I am trying to collapse/merge multiple notifications belonging to same event in my app. iOS 10 introduced a key name apns-collapse-id in payload. Document says multiple remote notifications with same apns-collapse-id will merged and shown as single notification.

So we have the payload with apns-collapse-id and thread-id in our notification payload. Unfortunately as there is no much content online explaining how these keys actually works, for safe play we have used the same unique value for both apns-collapse-id and thread-id.

We are expecting the multiple remote notifications with same apns-collapse-id to merge. It is not happenning.

Few people suggested APNS collapse does not come for free and I have to implement UNNotificationContentExtension and handle the notifications manually. I know I can add and remove local notification already posted but not really sure how to update the already posted remote notification.

Here is how our payload looks like

```<code>payload {
    "aps": {
        "alert": {
            "title": "Some title : ",
            "body": "Some body text"
        },
        "sound": "default",
        "payload": {
            "target": {
                "some key" : "Some value"
            },
            "thread_id": "Some_string_155863",
        },
        "apns-collapse-id": "Some_string_155863",
        "mutable-content": 1,
        "thread-id": "Some_string_155863",
        "badge": 33
    },
    "thread-id": "Some_string_155863",
    "apns-collapse-id": "Some_string_155863",
    "mutable-content": 1
}
</code>```

as you can see apns-collapse-id and thread-id are repeated multiple times in JSON because we aren't sure where exactly to have them

We are not using HTTPS/2 yet, but I believe iOS 10 notfication still supports legacy HTTPS. I am not really a network guy so I don't understand these things completely. Ignore my arrogance towards Https and Http2

Has anybody managed to get apns-collapse-id to work ? Please help.

答: apns-collapse-id is a request header, so you need to use the HTTP service and not the legacy binary interface.

Body:
I am trying to collapse/merge multiple notifications belonging to same event in my app. iOS 10 introduced a key name apns-collapse-id in payload. Document says multiple remote notifications with same apns-collapse-id will merged and shown as single notification.

So we have the payload with apns-collapse-id and thread-id in our notification payload. Unfortunately as there is no much content online explaining how these keys actually works, for safe play we have used the same unique value for both apns-collapse-id and thread-id.

We are expecting the multiple remote notifications with same apns-collapse-id to merge. It is not happenning.

Few people suggested APNS collapse does not come for free and I have to implement UNNotificationContentExtension and handle the notifications manually. I know I can add and remove local notification already posted but not really sure how to update the already posted remote notification.

Here is how our payload looks like

payload {
    "aps": {
        "alert": {
            "title": "Some title : ",
            "body": "Some body text"
        },
        "sound": "default",
        "payload": {
            "target": {
                "some key" : "Some value"
            },
            "thread_id": "Some_string_155863",
        },
        "apns-collapse-id": "Some_string_155863",
        "mutable-content": 1,
        "thread-id": "Some_string_155863",
        "badge": 33
    },
    "thread-id": "Some_string_155863",
    "apns-collapse-id": "Some_string_155863",
    "mutable-content": 1
}

as you can see apns-collapse-id and thread-id are repeated multiple times in JSON because we aren't sure where exactly to have them

We are not using HTTPS/2 yet, but I believe iOS 10 notfication still supports legacy HTTPS. I am not really a network guy so I don't understand these things completely. Ignore my arrogance towards Https and Http2

Has anybody managed to get apns-collapse-id to work ? Please help.


问:
Could I change my name and surname in all previous commits?
I would like to change my name, surname and email in my all commits, is it possible?</p>

答: Only if you haven't pushed your commits to the world. Other wise everyone else has your old name in their repo which is unlikely you can change everyone's.</p>