问:
Unexpected text in jade when try to use lable after input(type="checkbox")
I need to use following html code as jade.

```<code><div class="checkbox">
    <input type="checkbox"/>
    <label>Remember me</label>
</div>
</code>```

I did that as follows.

```<code>.checkbox
    input(type='checkbox')
    |
    label remember me
</code>```

(note: other code segments are excluded here)

But when I execute this following error shows.

Error:  G:\Test_Programmes\Node js\sgm\views\login.jade:28

      26|                         div.checkbox

      27|                             input(type='checkbox')

  28|                             |

      29|                             label remember me

      30|

      31|

  unexpected text |

at Lexer.fail (G:\Test_Programmes\Node js\sgm\node_modules\jade\lib\lexer.js:887:11)

     at Lexer.next (G:\Test_Programmes\Node js\sgm\node_modules\jade\lib\lexer.js:947:15)

     at Lexer.lookahead (G:\Test_Programmes\Node js\sgm\node_modules\jade\lib\lexer.js:113:46)

     at Parser.lookahead (G:\Test_Programmes\Node js\sgm\node_modules\jade\lib\parser.js:102:23)

     at Parser.peek (G:\Test_Programmes\Node js\sgm\node_modules\jade\lib\parser.js:79:17)

    at Parser.tag (G:\Test_Programmes\Node js\sgm\node_modules\jade\lib\parser.js:832:30)

    at Parser.parseTag (G:\Test_Programmes\Node js\sgm\node_modules\jade\lib\parser.js:759:17)

     at Parser.parseExpr (G:\Test_Programmes\Node js\sgm\node_modules\jade\lib\parser.js:211:21)

     at Parser.block (G:\Test_Programmes\Node js\sgm\node_modules\jade\lib\parser.js:729:25)

     at Parser.tag (G:\Test_Programmes\Node js\sgm\node_modules\jade\lib\parser.js:838:24)

But when I remove the | from line 28, then the check box is not align.

Click here to view screenshot

This is my code for that form.

```<code>    form.form-group(action="/users/login")
        label.h1 Sign in
        div.row
            div.col-md-3

            div.col-md-6
                div
                    div.form-group
                        input.form-control(
                            name= "username",
                            placeholder= "Enter user name"
                        )
                    div.form-group
                        input.form-control(
                        name= "password",
                        placeholder= "Enter password"
                        )
                    div.checkbox
                        input(type='checkbox')
                        label remember me

                    div.form-group
                        button.btn.btn-primary.form-control Sign in
            div.col-md-6
</code>```

Can anyone help me with this situation? (use checkbox in proper alignment)

答:
You have to put your checkbox inside label tag, Like this:

```<code>div.checkbox
    label
        input(type='checkbox')
        | remember me
</code>```

Edit adding some explanation about the use of |:

If you remove the pipe character, pug will transform 'remember' word to tag, but we just need to insert text after the input tag and inside label tag, however there are many ways to do that, we can use a pipe like above Or we can use:

dot .:

```<code>div.checkbox
    label
        input(type='checkbox')
        .
            remember me
</code>```

Interpolation within a plain text block:

```<code>div.checkbox
    label.
        #[input(type='checkbox')] remember me
</code>```

Body:
I need to use following html code as jade.

    <input type="checkbox"/>
    Remember me

I did that as follows.

.checkbox
    input(type='checkbox')
    |
    label remember me

(note: other code segments are excluded here)

But when I execute this following error shows.

Error:  G:\Test_Programmes\Node js\sgm\views\login.jade:28

      26|                         div.checkbox

      27|                             input(type='checkbox')

  28|                             |

      29|                             label remember me

      30|

      31|

  unexpected text |

at Lexer.fail (G:\Test_Programmes\Node js\sgm\node_modules\jade\lib\lexer.js:887:11)

     at Lexer.next (G:\Test_Programmes\Node js\sgm\node_modules\jade\lib\lexer.js:947:15)

     at Lexer.lookahead (G:\Test_Programmes\Node js\sgm\node_modules\jade\lib\lexer.js:113:46)

     at Parser.lookahead (G:\Test_Programmes\Node js\sgm\node_modules\jade\lib\parser.js:102:23)

     at Parser.peek (G:\Test_Programmes\Node js\sgm\node_modules\jade\lib\parser.js:79:17)

    at Parser.tag (G:\Test_Programmes\Node js\sgm\node_modules\jade\lib\parser.js:832:30)

    at Parser.parseTag (G:\Test_Programmes\Node js\sgm\node_modules\jade\lib\parser.js:759:17)

     at Parser.parseExpr (G:\Test_Programmes\Node js\sgm\node_modules\jade\lib\parser.js:211:21)

     at Parser.block (G:\Test_Programmes\Node js\sgm\node_modules\jade\lib\parser.js:729:25)

     at Parser.tag (G:\Test_Programmes\Node js\sgm\node_modules\jade\lib\parser.js:838:24)

But when I remove the | from line 28, then the check box is not align.

Click here to view screenshot

This is my code for that form.

    form.form-group(action="/users/login")
        label.h1 Sign in
        div.row
            div.col-md-3

            div.col-md-6
                div
                    div.form-group
                        input.form-control(
                            name= "username",
                            placeholder= "Enter user name"
                        )
                    div.form-group
                        input.form-control(
                        name= "password",
                        placeholder= "Enter password"
                        )
                    div.checkbox
                        input(type='checkbox')
                        label remember me

                    div.form-group
                        button.btn.btn-primary.form-control Sign in
            div.col-md-6

Can anyone help me with this situation? (use checkbox in proper alignment)

Body:
You have to put your checkbox inside label tag, Like this:

div.checkbox
    label
        input(type='checkbox')
        | remember me

Edit adding some explanation about the use of |:

If you remove the pipe character, pug will transform 'remember' word to tag, but we just need to insert text after the input tag and inside label tag, however there are many ways to do that, we can use a pipe like above Or we can use:

dot .:

div.checkbox
    label
        input(type='checkbox')
        .
            remember me

Interpolation within a plain text block:

div.checkbox
    label.
        #[input(type='checkbox')] remember me


来源: stackexchange

问:
Difference between "Push Notifications" and "In-App Notifications" in Facebook Analytics
From the control panel at https://www.facebook.com/analytics/, I can see this:

What is the difference between "Push Notifications" and "In-App Notifications". I am new to push notifications from Facebook, but I have used Urban Airship and I would have thought that "Push Notifications" and "In-App Notifications" are synonyms. I know this may be a basic question about terminology more than a technical problem, but it would help to start by knowing the terminology used by Facebook Analytics. Thank you.

Edit: I was reading for example at https://github.com/facebook/FBNotifications the following sentence:

Facebook In-App Notifications enables you to create rich and customizable in-app notifications and deliver them via push notifications

Does it mean that "push notification" is the delivery method/system, and "in-app notification" is the notification itself, such as its content, design, etc.?

答:
I found the answer at https://developers.facebook.com/docs/push-notifications/overview#app-events:

Push Notifications

Push notifications generally appear on the lock screen of a device, but they may also appear in a banner or other format, depending on the device. You can add a deep link to a push notification that opens up a specific experience in your app.

In-App Notifications

In-app notifications use rich media—such as photos, animated GIFs, emoji and more—to help you create engaging experiences that people receive directly in your app.

Find a more detailed explanation at https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages. Using the terminology they incorporate in that link, "Notification message" would be what the Facebook documentation calls "Push Notification", and "Data message" would be what in the Facebook documents appears as "In-App Notifications".

Also, at the beginning of this video, the speaker clearly explains what "Push Notifications" and "In-App Notifications" are, even with images in the phone to visualize it. The video is from the official Facebook Developers account, so it is a reliable source: https://www.youtube.com/watch?v=0K7AjHrK4TA.

ContentLicense: CC BY-SA 3.0


问:
Is there an easier alternative to Abstract Factory for sealed classes?
Based on this question, THE way to initialize new object with runtime parameters when using ioc-container is to create Abstract Factory.

In my example, I have this class:

```<code>internal sealed class AssetsDownloadingProcess
{
    private readonly IBackgroundWorker _backgroundWorker;
    private readonly IAssetsStorage _assetsStorage;
    private readonly Parameters _parameters;

    public AssetsDownloadingProcess(IBackgroundWorker backgroundWorker,
        IAssetsStorage assetsStorage, Parameters parameters)
    {
        _parameters = parameters.Clone();

        _backgroundWorker = backgroundWorker;
        _assetsStorage = assetsStorage;
    }
}
</code>```

And a factory to construct it:

```<code>internal sealed class AssetsDownloadingProcessFactory
{
    private readonly IBackgroundWorker _backgroundWorker;
    private readonly IAssetsStorage _assetsStorage;

    public AssetsDownloadingProcessFactory(IBackgroundWorker backgroundWorker,
        IAssetsStorage assetsStorage)
    {
        _backgroundWorker = backgroundWorker;
        _assetsStorage = assetsStorage;
    }

    public AssetsDownloadingProcess CreateProcess(
        AssetsDownloadingProcess.Parameters parameters)
    {
        return new AssetsDownloadingProcess(
            _backgroundWorker, _assetsStorage, parameters);
    }
}
</code>```

as you can see, AssetsDownloadingProcess does not implement any interface and will never be replaced with another class. Therefore this factory is nothing more than useless piece of code. It could be completely omitted in favour of AssetsDownloadingProcessFactory constructor. However, then I can't use dependency injection to constructor.

I would like to use benefits of Injection from my IoC Container without the hassle of creating factory and creating useless code. What is the correct way to do this? Am I missing something or using DI wrong?

答:
In general, you should prevent using runtime data to create and initialize your application components, as described here. The mere fact that runtime data is passed in through the constructor forces you to create a Factory.

The solution given by the article to the problem of injecting runtime data into components is to let runtime data flow through method calls on an initialized object graph by either:

pass runtime data through method calls of the API, or

retrieve runtime data from specific abstractions that allow resolving runtime data.

When runtime data is not used during object graph construction, the component can be created using DI inside the Composition Root and you problem therefore goes away.

Doing so however is not always feasible, and when it isn't, an Abstract Factory is the solution.

Since Object Composition should solely take place in the application's Composition Root however, this means that your Abstract Factory must be an Abstraction. Only this way can you prevent that the construction of your AssetsDownloadingProcess component takes place inside the Composition Root.

The way to do this is to:

Define an abstraction, i.e. IAssetsDownloadingProcessFactory in the application layer where the consumers of this factory live.

Create an implementation of this abstraction inside the Composition Root.

Not using an abstraction means that consumers will take a dependency on the concrete AssetsDownloadingProcessFactory class (which is a Dependency Inversion Principle violation) and it pulls the object composition out of the Composition Root. This will cause object composition to be scattered throughout the application, which hinders maintainability.

Body:
Based on this question, THE way to initialize new object with runtime parameters when using ioc-container is to create Abstract Factory.

In my example, I have this class:

internal sealed class AssetsDownloadingProcess
{
    private readonly IBackgroundWorker _backgroundWorker;
    private readonly IAssetsStorage _assetsStorage;
    private readonly Parameters _parameters;

    public AssetsDownloadingProcess(IBackgroundWorker backgroundWorker,
        IAssetsStorage assetsStorage, Parameters parameters)
    {
        _parameters = parameters.Clone();

        _backgroundWorker = backgroundWorker;
        _assetsStorage = assetsStorage;
    }
}

And a factory to construct it:

internal sealed class AssetsDownloadingProcessFactory
{
    private readonly IBackgroundWorker _backgroundWorker;
    private readonly IAssetsStorage _assetsStorage;

    public AssetsDownloadingProcessFactory(IBackgroundWorker backgroundWorker,
        IAssetsStorage assetsStorage)
    {
        _backgroundWorker = backgroundWorker;
        _assetsStorage = assetsStorage;
    }

    public AssetsDownloadingProcess CreateProcess(
        AssetsDownloadingProcess.Parameters parameters)
    {
        return new AssetsDownloadingProcess(
            _backgroundWorker, _assetsStorage, parameters);
    }
}

as you can see, AssetsDownloadingProcess does not implement any interface and will never be replaced with another class. Therefore this factory is nothing more than useless piece of code. It could be completely omitted in favour of AssetsDownloadingProcessFactory constructor. However, then I can't use dependency injection to constructor.

I would like to use benefits of Injection from my IoC Container without the hassle of creating factory and creating useless code. What is the correct way to do this? Am I missing something or using DI wrong?

ContentLicense: CC BY-SA 4.0


问:
Calculate Time Remaining
What's a good algorithm for determining the remaining time for something to complete?  I know how many total lines there are, and how many have completed already, how should I estimate the time remaining?</p>

答:
Why not?

(linesProcessed / TimeTaken) (timetaken / linesProcessed) * LinesLeft = TimeLeft

TimeLeft will then be expressed in whatever unit of time timeTaken is.

Edit:

Thanks for the comment you're right this should be:

(TimeTaken / linesProcessed) * linesLeft = timeLeft

so we have

(10 / 100) * 200 = 20 Seconds now 10 seconds go past

(20 / 100) * 200 = 40 Seconds left now 10 more seconds and we process 100 more lines

(30 / 200) * 100 = 15 Seconds and now we all see why the copy file dialog jumps from 3 hours to 30 minutes :-)

OwnerDisplayName: Aaron Smith

ContentLicense: CC BY-SA 2.5

Title: Calculate Time Remaining

OwnerDisplayName: Josh

LastEditorDisplayName: Josh


问:
Use Lodash to produce new object from existing object based on array of keys
I am relatively new to Lodash and I'm trying to do something that I'm sure is really easy.

I'm wondering which existing Lodash method to use to take an array of keys and an object, then return a new object containing only the properties (from the original object) that match the keys that were passed in.

```<code>let _ = require("lodash");

// DOES THE FUNCTION BELOW ALREADY EXIST?
let only = function (wanted, srcList) {
  return _.reduce(wanted, function(out,key){
    if(_.has(srcList, key)){
      out[key] = srcList[key]
    }
    return out;
  },{})
}

let src = {
  w: "This is doble vuu",
  x: "This is X",
  y: "This is why?",
  z: "This is zeee!"
};

var want = ['x','z'];

let newObject  = only(want,src);

console.log(newObject)
</code>```

The code I have works, but I don't want to re-invent the proverbial wheel, no matter how simple it is.

答:
I believe that you want _.map.

It will return an object with the specified keys if you pass an array of strings as the second argument.

Body:
I am relatively new to Lodash and I'm trying to do something that I'm sure is really easy.

I'm wondering which existing Lodash method to use to take an array of keys and an object, then return a new object containing only the properties (from the original object) that match the keys that were passed in.

let _ = require("lodash");

// DOES THE FUNCTION BELOW ALREADY EXIST?
let only = function (wanted, srcList) {
  return _.reduce(wanted, function(out,key){
    if(_.has(srcList, key)){
      out[key] = srcList[key]
    }
    return out;
  },{})
}

let src = {
  w: "This is doble vuu",
  x: "This is X",
  y: "This is why?",
  z: "This is zeee!"
};

var want = ['x','z'];

let newObject  = only(want,src);

console.log(newObject)

The code I have works, but I don't want to re-invent the proverbial wheel, no matter how simple it is.


问:
What actually gets modified upon modifying an object whose reference is been already created in the following code?
I'm using PHP 7.1.11

Consider below code :

```<code><?php
  class SimpleClass {
    // property declaration
    public $var = 'a default value';

    // method declaration
    public function displayVar() {
      echo $this->var;
    }
  }

  $instance = new SimpleClass();

  $assigned   =  $instance;
  $reference  =& $instance;

  $instance->var = '$assigned will have this value';

  $instance = null; // $instance and $reference become null

  var_dump($instance);
  var_dump($reference);
  var_dump($assigned);
?>
</code>```

The output of above program is as below :

```<code>NULL
NULL
object(SimpleClass)#1 (1) {
   ["var"]=>
     string(30) "$assigned will have this value"
}
</code>```

If you look at the code line $reference  =& $instance; you can notice that a reference to the existing class object(& instance) is created and assigned to the variables $reference.

Then my question is related to the below code lines :

```<code>$instance->var = '$assigned will have this value';

$instance = null; // $instance and $reference become null
</code>```

What these statements are actually modifying the original object or the data present at the reference of an object?

I expected the output of the statement var_dump($assigned); as NULL but it's not. Why so? What's the reason behind this? How the PHP program flow is working here?

Why upon execution of the statement $instance = null; the variable $assigned is not getting assigned to the value NULL?

答:
The important thing to realize with this is that the different variables hold the object identifier, not the object itself. From the PHP documentation for Objects and References:

A PHP reference is an alias, which allows two different variables to write to the same value. As of PHP 5, an object variable doesn't contain the object itself as value anymore. It only contains an object identifier which allows object accessors to find the actual object. When an object is sent by argument, returned or assigned to another variable, the different variables are not aliases: they hold a copy of the identifier, which points to the same object.

So, step by step:

First the object is created, and the object identifier is assigned to $instance.

```<code>$instance = new SimpleClass();
</code>```

a copy of the object identifier is assigned to $assigned.

```<code>$assigned = $instance;
</code>```

a reference to the object identifier is assigned to $reference.

```<code>$reference  =& $instance;
</code>```

obviously, this modifies the var property of the object that all the different variables refer to.

```<code>$instance->var = '$assigned will have this value';
</code>```

This statement replaces the object identifier in $instance with null, and by reference, it's also replaced in $reference.

```<code>$instance = null; // $instance and $reference become null
</code>```

But after setting $instance to null, the object itself still exists, and $assigned still holds a copy of its identifier.

Here's an MSPaint visual aid in case, since I've been told I can be somewhat obtuse. (I left out step 4.)

Body:
I'm using PHP 7.1.11

Consider below code :

<?php
  class SimpleClass {
    // property declaration
    public $var = 'a default value';

    // method declaration
    public function displayVar() {
      echo $this->var;
    }
  }

  $instance = new SimpleClass();

  $assigned   =  $instance;
  $reference  =& $instance;

  $instance->var = '$assigned will have this value';

  $instance = null; // $instance and $reference become null

  var_dump($instance);
  var_dump($reference);
  var_dump($assigned);
?>

The output of above program is as below :

NULL
NULL
object(SimpleClass)#1 (1) {
   ["var"]=>
     string(30) "$assigned will have this value"
}

If you look at the code line $reference  =& $instance; you can notice that a reference to the existing class object(& instance) is created and assigned to the variables $reference.

Then my question is related to the below code lines :

$instance->var = '$assigned will have this value';

$instance = null; // $instance and $reference become null

What these statements are actually modifying the original object or the data present at the reference of an object?

I expected the output of the statement var_dump($assigned); as NULL but it's not. Why so? What's the reason behind this? How the PHP program flow is working here?

Why upon execution of the statement $instance = null; the variable $assigned is not getting assigned to the value NULL?

Body:
The important thing to realize with this is that the different variables hold the object identifier, not the object itself. From the PHP documentation for Objects and References:

A PHP reference is an alias, which allows two different variables to write to the same value. As of PHP 5, an object variable doesn't contain the object itself as value anymore. It only contains an object identifier which allows object accessors to find the actual object. When an object is sent by argument, returned or assigned to another variable, the different variables are not aliases: they hold a copy of the identifier, which points to the same object.

So, step by step:

First the object is created, and the object identifier is assigned to $instance.

$instance = new SimpleClass();

a copy of the object identifier is assigned to $assigned.

$assigned = $instance;

a reference to the object identifier is assigned to $reference.

$reference  =& $instance;

obviously, this modifies the var property of the object that all the different variables refer to.

$instance->var = '$assigned will have this value';

This statement replaces the object identifier in $instance with null, and by reference, it's also replaced in $reference.

$instance = null; // $instance and $reference become null

But after setting $instance to null, the object itself still exists, and $assigned still holds a copy of its identifier.

Here's an MSPaint visual aid in case, since I've been told I can be somewhat obtuse. (I left out step 4.)


问:
How to find the MLE of a uniform distribution?
I am trying to find the maximum likelihood estimators a_hat and b_hat for a given uniform distribution X ~ UNIF(1,3) using R. Below is my code and its output:

```<code>##Example: Uniform Distribution
x<-runif(100,1,3)
n<-length(x)
ll<-function(a,b){

  -sum(1/(b-a)^n,log=TRUE)

}
m0<-mle2(ll,start=list(a=1,b=2))
summary(m0)

> summary(m0)
</code>```

Maximum likelihood estimation

```<code>Call:
mle2(minuslogl = ll, start = list(a = 1, b = 2))

Coefficients:
Estimate Std. Error z value Pr(z)
a   1.5159         NA      NA    NA
b   1.4841         NA      NA    NA

-2 log L: -1.542595e+150
Warning message:
In sqrt(diag(object@vcov)) : NaNs produced
</code>```

I am not able to reason why my coefficients are so off from the original values. I am pretty much sure I am using the correct likelihood function for uniform distribution, but I may be wrong for it as well syntax somewhere. I am using library(bbmle)

答:
Thanks everyone who helped.

I contacted my professor and it turned out I can't use the "bbmle" for distributions which are not differentiable.

In this case log(constant=1/b-a) is not differentiable to get a maxima.

There is another R package called "ExtDist" which output MLE very well for all distributions (so far for me, including uniform) but doesn't provide standard error of them, which infact "bbmle" does

Just to help anyone who may stumble upon this post in future:

Normal, "bbmle":

```<code>#Comparison of mentioned packages
  #Example for normal distribution
  set.seed(123)
  library("bbmle")
  x<-rnorm(100,1,3) #mean=1, sd = 3
  n<-length(x)
  ll<-function(a,b){
    -sum(dnorm(x,a,b,log=TRUE))
  }
  m0<-mle2(ll,start=list(a=1,b=2))
  summary(m0)
</code>```

Results:

```<code>Maximum likelihood estimation

 Call:
 mle2(minuslogl = ll, start = list(a = 1, b = 2))

 Coefficients:
   Estimate Std. Error z value     Pr(z)
 a  1.27122    0.27247  4.6655 3.079e-06 ***
 b  2.72473    0.19267 14.1421 < 2.2e-16 ***
 ---
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

 -2 log L: 484.2609
</code>```

Normal, "ExtDist":

```<code>library("ExtDist")
  m1<-eNormal(X=x,method = "unbiased.MLE")
  m1
</code>```

Results:

```<code> Parameters for the Normal distribution.
 (found using the  unbiased.MLE method.)

  Parameter     Type Estimate      S.E.
       mean location 1.271218 0.2738448
         sd    scale 2.738448 0.1946130
</code>```

Uniform , "bbmle":

```<code>#Example for uniform distribution
  set.seed(123)
  x<-runif(100,1,3) #minimum =1, maximum = 3
  range(x)  #To know beforehand the original minimum and maximum before the      package estimates
 [1] 1.00125 2.98854
  n<-length(x)
  ll<-function(a,b){
    -sum(dunif(x,a,b,log=TRUE))
  }
 m3<-mle2(ll,start=list(a=1,b=2))
 Error in optim(par = c(1, 2), fn = function (p)  :
   initial value in 'vmmin' is not finite
  summary(m3)
</code>```

Error message:

```<code> Error in optim(par = c(1, 2), fn = function (p)  :
 initial value in 'vmmin' is not finite
</code>```

Uniform, "ExtDist":

```<code> m4<-eUniform(X=x,method = "unbiased.MLE")
  m4

 Parameters for the Uniform distribution.
 (found using the  numerical.MLE method.)

  Parameter     Type Estimate
          a boundary 1.001245
          b boundary 2.988544
</code>```

Body:
I am trying to find the maximum likelihood estimators a_hat and b_hat for a given uniform distribution X ~ UNIF(1,3) using R. Below is my code and its output:

##Example: Uniform Distribution
x<-runif(100,1,3)
n<-length(x)
ll<-function(a,b){

  -sum(1/(b-a)^n,log=TRUE)

}
m0<-mle2(ll,start=list(a=1,b=2))
summary(m0)

> summary(m0)

Maximum likelihood estimation

Call:
mle2(minuslogl = ll, start = list(a = 1, b = 2))

Coefficients:
Estimate Std. Error z value Pr(z)
a   1.5159         NA      NA    NA
b   1.4841         NA      NA    NA

-2 log L: -1.542595e+150
Warning message:
In sqrt(diag(object@vcov)) : NaNs produced

I am not able to reason why my coefficients are so off from the original values. I am pretty much sure I am using the correct likelihood function for uniform distribution, but I may be wrong for it as well syntax somewhere. I am using library(bbmle)

Body:
Thanks everyone who helped.

I contacted my professor and it turned out I can't use the "bbmle" for distributions which are not differentiable.

In this case log(constant=1/b-a) is not differentiable to get a maxima.

There is another R package called "ExtDist" which output MLE very well for all distributions (so far for me, including uniform) but doesn't provide standard error of them, which infact "bbmle" does

Just to help anyone who may stumble upon this post in future:

Normal, "bbmle":

#Comparison of mentioned packages
  #Example for normal distribution
  set.seed(123)
  library("bbmle")
  x<-rnorm(100,1,3) #mean=1, sd = 3
  n<-length(x)
  ll<-function(a,b){
    -sum(dnorm(x,a,b,log=TRUE))
  }
  m0<-mle2(ll,start=list(a=1,b=2))
  summary(m0)

Results:

Maximum likelihood estimation

 Call:
 mle2(minuslogl = ll, start = list(a = 1, b = 2))

 Coefficients:
   Estimate Std. Error z value     Pr(z)
 a  1.27122    0.27247  4.6655 3.079e-06 ***
 b  2.72473    0.19267 14.1421 < 2.2e-16 ***
 ---
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

 -2 log L: 484.2609

Normal, "ExtDist":

library("ExtDist")
  m1<-eNormal(X=x,method = "unbiased.MLE")
  m1

Results:

 Parameters for the Normal distribution.
 (found using the  unbiased.MLE method.)

  Parameter     Type Estimate      S.E.
       mean location 1.271218 0.2738448
         sd    scale 2.738448 0.1946130

Uniform , "bbmle":

#Example for uniform distribution
  set.seed(123)
  x<-runif(100,1,3) #minimum =1, maximum = 3
  range(x)  #To know beforehand the original minimum and maximum before the      package estimates
 [1] 1.00125 2.98854
  n<-length(x)
  ll<-function(a,b){
    -sum(dunif(x,a,b,log=TRUE))
  }
 m3<-mle2(ll,start=list(a=1,b=2))
 Error in optim(par = c(1, 2), fn = function (p)  :
   initial value in 'vmmin' is not finite
  summary(m3)

Error message:

 Error in optim(par = c(1, 2), fn = function (p)  :
 initial value in 'vmmin' is not finite

Uniform, "ExtDist":

 m4<-eUniform(X=x,method = "unbiased.MLE")
  m4

 Parameters for the Uniform distribution.
 (found using the  numerical.MLE method.)

  Parameter     Type Estimate
          a boundary 1.001245
          b boundary 2.988544


问:
Source code string cannot contain null bytes
So i had 676 line program, Now i have had a issue in the past when I opened the file all my code had disapeared so this time i made a backup. However when I try to copy and paste my backedup code then run it, it gives me this syntax error:

```<code>Source code string cannot contain null bytes
</code>```

This was not displayed when I first made the backup and the program was working fine. I really do not want to go through 676 lines redoing it all.
Im a pretty basic programmer when it comes to Python.

I already tried removing all white space and comments/# (Red background colour is at the end of a #)
Already looked through all the code and it really has no errors.

答:
The problem is likely just what the error message tells you: your back-up copy somehow got "infected" with one or more null bytes (ASCII value 00).  Paste your code one block at a time -- say, 50 lines -- to find which contain illegal bytes.  Delete the most recently-added code, maybe 5 lines at a time, to find which has the null byte.  Retype the offending line, and go on to the next.

Another possibility is to write a simple Python script that reads the file and removes the null bytes use the string replace method:

```<code>with open("homework.py", 'r') as infile:
    hw = infile.readlines().replace(chr(0), '')
</code>```

Now close the file, open it again for 'w', and dump the hw variable to it.

Body:
So i had 676 line program, Now i have had a issue in the past when I opened the file all my code had disapeared so this time i made a backup. However when I try to copy and paste my backedup code then run it, it gives me this syntax error:

Source code string cannot contain null bytes

This was not displayed when I first made the backup and the program was working fine. I really do not want to go through 676 lines redoing it all.
Im a pretty basic programmer when it comes to Python.

I already tried removing all white space and comments/# (Red background colour is at the end of a #)
Already looked through all the code and it really has no errors.

Body:
The problem is likely just what the error message tells you: your back-up copy somehow got "infected" with one or more null bytes (ASCII value 00).  Paste your code one block at a time -- say, 50 lines -- to find which contain illegal bytes.  Delete the most recently-added code, maybe 5 lines at a time, to find which has the null byte.  Retype the offending line, and go on to the next.

Another possibility is to write a simple Python script that reads the file and removes the null bytes use the string replace method:

with open("homework.py", 'r') as infile:
    hw = infile.readlines().replace(chr(0), '')

Now close the file, open it again for 'w', and dump the hw variable to it.


问:
Which panel is associated with a particular camera? MEL
I know you can query which camera is associated with a particular panel. But, is there a way you can do it the other way around?

I want to be able to see what panel is associate with a particular camera.

Example:

getPanel -q mainCamera;

// modelPanel1

Thanks for the help yall

答:
If you have the panel, and you want the camera associated with it, you can simply query it

```<code>import maya.cmds as cmds
cmds.modelPanel("modelPanel1", query=True, camera=True)
</code>```

Body:
If you have the panel, and you want the camera associated with it, you can simply query it

import maya.cmds as cmds
cmds.modelPanel("modelPanel1", query=True, camera=True)


问:
Class hierarchy, autowire services for each specific subclass
I have a listener class hierarchy consisting of a base class into which I autowire a base service MyBaseService.

I extend MyBaseService to more concrete sub service classes so in order to make specific implementations for sub listeners.

Using Spring,
how do I specify that a
specific sub listener class
needs to use a specific sub service class?

Here's a diagram:

Code examples:

Services

```<code>public interface BaseService<TContext extends ProcessContext, TTabel extends Tabel> { .. }

public interface SubService extends BaseService <B, BT> { .. }

---- (Implementations of these interfaces in service classes)
</code>```

Listener classes:

```<code>public abstract class AbstractListener {

@Autowired
private BaseService baseService;

public someFunction() {
   baseService.DoStuff(); //SubServiceImpl Also have a dostuff implementation
   }

}

public SubListenerA extends AbstractListener {
    //I need to specify that we will now use subService so subservices DoStuff() is used insted of base services doStuff()
}
</code>```

I don't want to override someFunction.

答:
You have to create beans of Listener classes also, as they're going to be used finally to call service classes. Since we can't have same reference pointing to different beans, we need different beans for it.

Please take a look at the sample below,

```<code>package com.test;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Component;

@SpringBootApplication
public class TestChildInjectionApplication {
    @Autowired
    private SubListenerA listenerA;

    @Autowired
    private SubListenerB listenerB;

    @PostConstruct
    public void init () {
        listenerA.doSomething();
        listenerB.doSomething();
    }

    public static void main(String[] args) {
        SpringApplication.run(TestChildInjectionApplication.class, args);
    }
}

class BaseListener {
    private BaseService service;

    public BaseListener(BaseService service) {
        super();
        this.service = service;
    }

    public void doSomething() {
        service.doStuff();
    }
}

@Component
class SubListenerA extends BaseListener {
    public SubListenerA(ServiceA service) {
        super(service);
    }
}

@Component
class SubListenerB extends BaseListener {
    public SubListenerB(ServiceB service) {
        super(service);
    }
}

class BaseService {
    public void doStuff() {
        System.out.println("################################## in: " + this.getClass());
    }
}

@Component
class ServiceA extends BaseService {}

@Component
class ServiceB extends BaseService {}
</code>```

Body:
I have a listener class hierarchy consisting of a base class into which I autowire a base service MyBaseService.

I extend MyBaseService to more concrete sub service classes so in order to make specific implementations for sub listeners.

Using Spring,
how do I specify that a
specific sub listener class
needs to use a specific sub service class?

Here's a diagram:

Code examples:

Services

public interface BaseService<TContext extends ProcessContext, TTabel extends Tabel> { .. }

public interface SubService extends BaseService  { .. }

---- (Implementations of these interfaces in service classes)

Listener classes:

public abstract class AbstractListener {

@Autowired
private BaseService baseService;

public someFunction() {
   baseService.DoStuff(); //SubServiceImpl Also have a dostuff implementation
   }

}

public SubListenerA extends AbstractListener {
    //I need to specify that we will now use subService so subservices DoStuff() is used insted of base services doStuff()
}

I don't want to override someFunction.

Body:
You have to create beans of Listener classes also, as they're going to be used finally to call service classes. Since we can't have same reference pointing to different beans, we need different beans for it.

Please take a look at the sample below,

package com.test;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Component;

@SpringBootApplication
public class TestChildInjectionApplication {
    @Autowired
    private SubListenerA listenerA;

    @Autowired
    private SubListenerB listenerB;

    @PostConstruct
    public void init () {
        listenerA.doSomething();
        listenerB.doSomething();
    }

    public static void main(String[] args) {
        SpringApplication.run(TestChildInjectionApplication.class, args);
    }
}

class BaseListener {
    private BaseService service;

    public BaseListener(BaseService service) {
        super();
        this.service = service;
    }

    public void doSomething() {
        service.doStuff();
    }
}

@Component
class SubListenerA extends BaseListener {
    public SubListenerA(ServiceA service) {
        super(service);
    }
}

@Component
class SubListenerB extends BaseListener {
    public SubListenerB(ServiceB service) {
        super(service);
    }
}

class BaseService {
    public void doStuff() {
        System.out.println("################################## in: " + this.getClass());
    }
}

@Component
class ServiceA extends BaseService {}

@Component
class ServiceB extends BaseService {}


问:
Collapse (close) Menu in SidebarMenu of Shinydashboard on button click
I am working in an application similar to one below. I have my input panel in sidebar under a menu which is initally expanded. I want to collapse the menu and hide all the input panel so that my sidebar will be clean. But It should appear when I expand (not permanently hide). I tried the following solution but it is not working. Please help me to find a solution or any alternative approach.</p>

```<code>library(shiny)
library(shinydashboard)
library(shinyjs)

ui <- dashboardPage(
  header = dashboardHeader(),
  sidebar = dashboardSidebar(
    sidebarMenu(
      menuItem(
        startExpanded = TRUE,
        "Menu 1",
        column(
          width = 12,
          actionButton("hideMe", label = "Collapse Me", icon = icon("close"))
        )
      )
    )
  ),
  body = dashboardBody()
)
server <- function(input, output, server){
  observeEvent(input$hideMe, {
    shinyjs::hide(selector = "ul.menu-open");
  })
}

runApp(shinyApp(ui, server))
</code>```

答:
You need to add useShinyjs() into ui part

```<code>library(shiny)
library(shinydashboard)
library(shinyjs)

ui <- dashboardPage(
        header = dashboardHeader(),
        sidebar = dashboardSidebar(
                useShinyjs(),
                sidebarMenu(
                        menuItem(
                                startExpanded = TRUE,
                                "Menu 1",
                                column(
                                        width = 12,
                                        actionButton("hideMe", label = "Collapse Me", icon = icon("close"))
                                )
                        )
                )
        ),
        body = dashboardBody()
)
server <- function(input, output, server){
        observeEvent(input$hideMe, {
                shinyjs::hide(selector = "ul.menu-open");
        })
}

runApp(shinyApp(ui, server))
</code>```

Body:
I am working in an application similar to one below. I have my input panel in sidebar under a menu which is initally expanded. I want to collapse the menu and hide all the input panel so that my sidebar will be clean. But It should appear when I expand (not permanently hide). I tried the following solution but it is not working. Please help me to find a solution or any alternative approach.

library(shiny)
library(shinydashboard)
library(shinyjs)

ui <- dashboardPage(
  header = dashboardHeader(),
  sidebar = dashboardSidebar(
    sidebarMenu(
      menuItem(
        startExpanded = TRUE,
        "Menu 1",
        column(
          width = 12,
          actionButton("hideMe", label = "Collapse Me", icon = icon("close"))
        )
      )
    )
  ),
  body = dashboardBody()
)
server <- function(input, output, server){
  observeEvent(input$hideMe, {
    shinyjs::hide(selector = "ul.menu-open");
  })
}

runApp(shinyApp(ui, server))

Body:
You need to add useShinyjs() into ui part

library(shiny)
library(shinydashboard)
library(shinyjs)

ui <- dashboardPage(
        header = dashboardHeader(),
        sidebar = dashboardSidebar(
                useShinyjs(),
                sidebarMenu(
                        menuItem(
                                startExpanded = TRUE,
                                "Menu 1",
                                column(
                                        width = 12,
                                        actionButton("hideMe", label = "Collapse Me", icon = icon("close"))
                                )
                        )
                )
        ),
        body = dashboardBody()
)
server <- function(input, output, server){
        observeEvent(input$hideMe, {
                shinyjs::hide(selector = "ul.menu-open");
        })
}

runApp(shinyApp(ui, server))


问:
Running Jupyter notebook in docker image on Google Cloud
I'm running an Ubuntu 16.04 VM on Google Compute Engine. I've created a static IP address <my_static_ip_address> and my firewall settings allow tcp:80-8888.

I started the Jupyter server within the docker image with

jupyter notebook --ip=0.0.0.0 --port=8888 --no-browser --allow-root

and got this URL

http://0.0.0.0:8888/?token=8b26c453d278eae1da71b80f26a4ef8ea06734e5c636d897

I'm not able to access from external browser with http://<my_static_ip_address>:8888
What am I missing?

答:
I started the Jupyter server within the docker image with

What was the docker command you ran? A common gotcha here would be not mapping a host port to a container port.

For example, if you did this:

docker run -p 8888 jupyter/notebook

Then docker would assign a random host port mapping to port 8888 in the container. In this case, you can see what port was mapped by running docker ps. The port will be much higher than 8888 though, so you won't be able to reach jupyter because your firewall will block the traffic.

What you probably want to do is go ahead and map a host port like so:

docker run -p 8888:8888 jupyter/notebook

This should map any traffic reaching the GCE host on port 8888 to port 8888 in your jupyter container.


问:
Mustache JS and singular/plural
I use mustache for templating my javascript ajax calls, Here is my data and the template:

```<code>{'joined':1} // ajax responde data json.

var myTemplate = '{{ joined }} person joined so far.'
</code>```

It works, however I want to fix the grammer in this, if more than 1 person joins, I want to show 5 people joined so far.

How to achieve this without manipulating the server side ajax json responder ?

答:
Actually you can do it with only Mustache, but for the case your JSON contains not only a number, but an array of values, together with the size of the array:

```<code>var json = {
  'rows': ['a','b','c'],
  'numRows': function() {
      return this.rows.length
   }
} // ajax response data json.
</code>```

In order to do it, you can use one of the following Mustache templates:

In the simple case, when you just need to add "s" for plural:

```<code>var myTemplate = '{{ numRows }} link{{^rows}}s{{/rows}}{{#rows.1}}s{{/rows.1}} parsed so far.'
</code>```

The result:

```<code>0 links parsed so far.
1 link parsed so far.
2 links parsed so far.
</code>```

In the general case, when the plural is special (like people/person):

```<code>var myTemplate2 = '{{ numRows }} {{^rows}}people{{/rows}}{{#rows.0}}{{^rows.1}}person{{/rows.1}}{{/rows.0}}{{#rows.1}}people{{/rows.1}} joined so far.'
</code>```

The result:

```<code>0 people joined so far.
1 person joined so far.
2 people joined so far.
</code>```

You can find both templates applied in practice here:
http://jsfiddle.net/H8tqn/9/

P.S. I will post again here if I can find the solution for this one:

```<code>No people joined so far.
1 person joined so far.
2 people joined so far.
</code>```

Title: Mustache JS and singular/plural

Body:
I use mustache for templating my javascript ajax calls, Here is my data and the template:

{'joined':1} // ajax responde data json.

var myTemplate = '{{ joined }} person joined so far.'

It works, however I want to fix the grammer in this, if more than 1 person joins, I want to show 5 people joined so far.

How to achieve this without manipulating the server side ajax json responder ?

Body:
Actually you can do it with only Mustache, but for the case your JSON contains not only a number, but an array of values, together with the size of the array:

var json = {
  'rows': ['a','b','c'],
  'numRows': function() {
      return this.rows.length
   }
} // ajax response data json.

In order to do it, you can use one of the following Mustache templates:

In the simple case, when you just need to add "s" for plural:

var myTemplate = '{{ numRows }} link{{^rows}}s{{/rows}}{{#rows.1}}s{{/rows.1}} parsed so far.'

The result:

0 links parsed so far.
1 link parsed so far.
2 links parsed so far.

In the general case, when the plural is special (like people/person):

var myTemplate2 = '{{ numRows }} {{^rows}}people{{/rows}}{{#rows.0}}{{^rows.1}}person{{/rows.1}}{{/rows.0}}{{#rows.1}}people{{/rows.1}} joined so far.'

The result:

0 people joined so far.
1 person joined so far.
2 people joined so far.

You can find both templates applied in practice here:
http://jsfiddle.net/H8tqn/9/

P.S. I will post again here if I can find the solution for this one:

No people joined so far.
1 person joined so far.
2 people joined so far.


问:
How Can I Detect If One Div Is Outside Another Div?
I am making a game and I am using div's instead of canvas.rect's and I want one div to always be inside of another div. I ran into this problem when I made a test script that looked like this.

        var mousex, mousey;
          function mousepos(e){
            mousex = e.clientX;
            mousey = e.clientY;
            document.getElementById("xy").innerText = mousex + " , " + mousey;
          }
          function testdiv(){
            document.getElementById("testdiv").style.left = mousex;
            document.getElementById("testdiv").style.top = mousey;
            setTimeout(testdiv, 30);
          }```
<pre class="snippet-code-css lang-css prettyprint-override"><code>          #city{
            border: 1px dotted white;
            background-color: lightgreen;
            height: 500;
            width: 500;
            resize: both;
            overflow: hidden;
            max-height: 500px;
            max-width: 500px;
            min-height: 100px;
            min-width: 100px;
          }
          #xy{
            color: white;
          }
          #testdiv{
            background-color: white;
            position: absolute;
            width: 100px;
            height: 100px;
          }
          #body{
            background-color: black;
          }</code>```

     ```

The code detects your mouse X and mouse Y when your mouse is over the big green div, then it puts the white div's left corner on your mouse X and mouse Y. My problem is that when my mouse is draging the white div down or right, I can drag it off of the green div.

Is there a way I could fix this problem?

答:
You can to try this code:

```<code>  var mousex, mousey;

function mousepos(e) {
    mousex = e.clientX;
    mousey = e.clientY;
    document.getElementById("xy").innerText = mousex + " , " + mousey;
}
var coordCity = document.getElementById("city").getBoundingClientRect();
var elem = document.getElementById("testdiv");
let i = 0

function testdiv() {
    elem.style.left = mousex + 'px';
    elem.style.top = mousey + 'px';
    var coord = elem.getBoundingClientRect();
    if(coord.left < coordCity.left ||
      coord.right > coordCity.right ||
      coord.bottom > coordCity.bottom ||
      coord.top < coordCity.top) {
      console.log('rect is out');
    };
    i++;
    if(i === 100) {
        return;
    }
    setTimeout(testdiv, 50);
}
</code>```

And you need add in css px to value of width and height:

```<code>#city{
            border: 1px dotted white;
            background-color: lightgreen;
            height: 500px;
            width: 500px;
            resize: both;
            overflow: hidden;
            max-height: 500px;
            max-width: 500px;
            min-height: 100px;
            min-width: 100px;
          }
</code>```

And always save youre nodes to variable, because it does youre code faster, I use variable i  for stop test. You can use another solution.
I created next app:
https://codepen.io/piotrazsko/pen/VrrZBq

Body:
I am making a game and I am using div's instead of canvas.rect's and I want one div to always be inside of another div. I ran into this problem when I made a test script that looked like this.

        var mousex, mousey;
          function mousepos(e){
            mousex = e.clientX;
            mousey = e.clientY;
            document.getElementById("xy").innerText = mousex + " , " + mousey;
          }
          function testdiv(){
            document.getElementById("testdiv").style.left = mousex;
            document.getElementById("testdiv").style.top = mousey;
            setTimeout(testdiv, 30);
          }

          #city{
            border: 1px dotted white;
            background-color: lightgreen;
            height: 500;
            width: 500;
            resize: both;
            overflow: hidden;
            max-height: 500px;
            max-width: 500px;
            min-height: 100px;
            min-width: 100px;
          }
          #xy{
            color: white;
          }
          #testdiv{
            background-color: white;
            position: absolute;
            width: 100px;
            height: 100px;
          }
          #body{
            background-color: black;
          }

The code detects your mouse X and mouse Y when your mouse is over the big green div, then it puts the white div's left corner on your mouse X and mouse Y. My problem is that when my mouse is draging the white div down or right, I can drag it off of the green div.

Is there a way I could fix this problem?

Body:
You can to try this code:

  var mousex, mousey;

function mousepos(e) {
    mousex = e.clientX;
    mousey = e.clientY;
    document.getElementById("xy").innerText = mousex + " , " + mousey;
}
var coordCity = document.getElementById("city").getBoundingClientRect();
var elem = document.getElementById("testdiv");
let i = 0

function testdiv() {
    elem.style.left = mousex + 'px';
    elem.style.top = mousey + 'px';
    var coord = elem.getBoundingClientRect();
    if(coord.left < coordCity.left ||
      coord.right > coordCity.right ||
      coord.bottom > coordCity.bottom ||
      coord.top < coordCity.top) {
      console.log('rect is out');
    };
    i++;
    if(i === 100) {
        return;
    }
    setTimeout(testdiv, 50);
}

And you need add in css px to value of width and height:

#city{
            border: 1px dotted white;
            background-color: lightgreen;
            height: 500px;
            width: 500px;
            resize: both;
            overflow: hidden;
            max-height: 500px;
            max-width: 500px;
            min-height: 100px;
            min-width: 100px;
          }

And always save youre nodes to variable, because it does youre code faster, I use variable i  for stop test. You can use another solution.
I created next app:
https://codepen.io/piotrazsko/pen/VrrZBq


问:
About template specialization
I need to provide an insertion/lookup/delete interface for a hash table. I wrote the hash table only to provide the internal bucket/entry management. The hash function should be supplied from outside. I am now stuck on how to expose the interface so that the hash table can handle byte arrays as well as fixed length data types. The problem is that for byte arrays, the hash function needs to know the length of the array while for other types, it can do without that information. My problems is that I can't implement operator[] for byte arrays because the hash function needs two parameters. And I would like to keep operator[] dearly. Is there any way around this (Without specializing for T* and throwing a compiler error for operator[] in that specialization.)?

答:
I am getting confused here because I don't get where operator[] on the hash-table conflicts with operator[] on the data-type that you are storing in it.

If your hash_table has operator[] this could either be a hash_map where you supply the key to operator[] or it could be that operator[] returns you the contents of a cell.

Normally if I do implement my own hash-table I do not directly store the data in the entries but the data plus some "metadata", i.e. info relating to the cell. As your hash-table supports delete you need to ensure that you can still reach any collisions that presumably were moved elsewhere, whatever your strategy now is for finding such a cell. So a deleted cell is available but has a different meaning to one that has never been occupied, as it may be part of a path in a collision course.

The hash function is independent, as you say. It is independent therefore of the storage mechanism, and does not call operator[] of the hash-table at all.

The hash-table uses the hash-function and a comparison function only, and otherwise uses its own storage policy and collision-handling policy.

Title: About template specialization


问:
Pandas - DatetimeIndex as column headings
I have a dataframe that is 438x14401. I have a DateTimeIndex that is the same length (width?) as the columns in the dataframe, which are now just labeled 1 - ... I am trying to replace those values with the dates in my DateTimeIndex.

I am trying to substitude column headings 0 - end with the datetimeindex values, which should match in length. I have tried just renaming the columns with the dates and merging them, with no success. Is this at all possible?

```<code>stations = stations.iloc[:,2:].rename(columns=v, inplace=True)
</code>```

答:
You can assign your DatetimeIndex directly to stations.columns:

Sample df:

```<code>df = pd.DataFrame({'a': [1,2,3], 'b': [9,8,7], 'c': [7,5,1], 'd':[1,3,5]})
df
   a  b  c  d
0  1  9  7  1
1  2  8  5  3
2  3  7  1  5

some_date_range = pd.date_range('2017-01-01', periods=len(df.columns))

df.columns = some_date_range

df
   2017-01-01  2017-01-02  2017-01-03  2017-01-04
0           1           9           7           1
1           2           8           5           3
2           3           7           1           5
</code>```

Keeping first two column values (referencing How do i change a single index value in pandas dataframe? since Index doesn't support mutable operations):

```<code>aslist = df.columns.tolist()
aslist[2:] = pd.date_range('2017-01-01', periods=2)
df.columns = aslist
df
   a  b  2017-01-01 00:00:00  2017-01-02 00:00:00
0  1  9                    7                    1
1  2  8                    5                    3
2  3  7                    1                    5
</code>```

Body:
I have a dataframe that is 438x14401. I have a DateTimeIndex that is the same length (width?) as the columns in the dataframe, which are now just labeled 1 - ... I am trying to replace those values with the dates in my DateTimeIndex.

I am trying to substitude column headings 0 - end with the datetimeindex values, which should match in length. I have tried just renaming the columns with the dates and merging them, with no success. Is this at all possible?

stations = stations.iloc[:,2:].rename(columns=v, inplace=True)

Body:
You can assign your DatetimeIndex directly to stations.columns:

Sample df:

df = pd.DataFrame({'a': [1,2,3], 'b': [9,8,7], 'c': [7,5,1], 'd':[1,3,5]})
df
   a  b  c  d
0  1  9  7  1
1  2  8  5  3
2  3  7  1  5

some_date_range = pd.date_range('2017-01-01', periods=len(df.columns))

df.columns = some_date_range

df
   2017-01-01  2017-01-02  2017-01-03  2017-01-04
0           1           9           7           1
1           2           8           5           3
2           3           7           1           5

Keeping first two column values (referencing How do i change a single index value in pandas dataframe? since Index doesn't support mutable operations):

aslist = df.columns.tolist()
aslist[2:] = pd.date_range('2017-01-01', periods=2)
df.columns = aslist
df
   a  b  2017-01-01 00:00:00  2017-01-02 00:00:00
0  1  9                    7                    1
1  2  8                    5                    3
2  3  7                    1                    5


问:
passing multiple value 1 name javascript
I was working with my thesis, I got stumble when I tried to store a tag to some uploaded file

I've found some javascript to help me create tags on upload page.

```<code>$("#tags input").on({
    focusout : function() {
      var txt = this.value.replace(/[^a-z0-9\+\-\.\#]/ig,''); // allowed characters

      if(txt) {
        $("<span/>", {text:txt.toLowerCase(),value:txt.toLowerCase(), insertBefore:this});
        $("<input/>", {type:"hidden",value:txt.toLowerCase(),name:"Tags", insertBefore:this});
      }
      this.value = "";
    },
    keyup : function(ev) {
      // if: comma|enter (delimit more keyCodes with | pipe)
      if(/(188|13)/.test(ev.which)) $(this).focusout();
    }
  });
  $('#tags').on('click', 'span', function() {
    if(confirm("Remove "+ $(this).text() +"?")) $(this).remove();
  });

});
</code>```

what if I want to pass multiple tags to my upload controller with this js?

I've tried using input type hidden, but it only pass 1 value at a time,
and also, I cant delete the input value, so if I'm mistaken and delete the tag, the hidden input doesn't get deleted too.

pls, help me, Thankyou in advance!

答:
If I'm guessing correctly you're trying to send more tags to the server under the same name=""

You can do that by changing the name Tags with Tags[] like:

```<code>$("<input/>", {
    type:         "hidden",
    value:        txt.toLowerCase(),
    name:         "Tags[]",
    insertBefore: this
});
</code>```

On the serverside Tags will be an array

Body:
I was working with my thesis, I got stumble when I tried to store a tag to some uploaded file

I've found some javascript to help me create tags on upload page.

$("#tags input").on({
    focusout : function() {
      var txt = this.value.replace(/[^a-z0-9\+\-\.\#]/ig,''); // allowed characters

      if(txt) {
        $("", {text:txt.toLowerCase(),value:txt.toLowerCase(), insertBefore:this});
        $("<input/>", {type:"hidden",value:txt.toLowerCase(),name:"Tags", insertBefore:this});
      }
      this.value = "";
    },
    keyup : function(ev) {
      // if: comma|enter (delimit more keyCodes with | pipe)
      if(/(188|13)/.test(ev.which)) $(this).focusout();
    }
  });
  $('#tags').on('click', 'span', function() {
    if(confirm("Remove "+ $(this).text() +"?")) $(this).remove();
  });

});

what if I want to pass multiple tags to my upload controller with this js?

I've tried using input type hidden, but it only pass 1 value at a time,
and also, I cant delete the input value, so if I'm mistaken and delete the tag, the hidden input doesn't get deleted too.

pls, help me, Thankyou in advance!

Body:
If I'm guessing correctly you're trying to send more tags to the server under the same name=""

You can do that by changing the name Tags with Tags[] like:

$("<input/>", {
    type:         "hidden",
    value:        txt.toLowerCase(),
    name:         "Tags[]",
    insertBefore: this
});

On the serverside Tags will be an array