问:
Current page using Angular
I have a "Remove All" button that removes all records from a Ng-table and MongoDB.
In my system, there are several views and each and every one of them display different data. Now, I don't know how to get the current page name and send it as a parameter for remove. It is working only if I insert to the code the name of the view and click on the button.

HTML:

```<code>                <ul class="pager" ng-show="currentPage==login">
                   <li>
                    <button ng-click="removeLogs('$scope.logType')" id="deleteAllErrors" name="deleteError" class="btn btn-danger">Remove All</button></li>
                </ul>
</code>```

Angular:

```<code>//  login, signUp, addErr, refreshLog, refreshErr, badProd - $scope.currentPage

    $scope.removeLogs = function(logType){
        console.log("Admin request to delete logType: "+logType+" & "+currentPage.current.name);
        var rmLogs = {
            'email': localStorageService.get('email'),
            'password': localStorageService.get('password'),
            'logType': logType
        };
        $http.post(''+appPath+'/removeLogs', rmLogs)
            .then(function(data){
                $scope.statusMsg = "Logs Deleted Successfully";
                console.log("Admin X has delete logType");
                $scope.updateAdmin();
        });
    };
</code>```

答:
You can inject $route in controller's DI and access the params like this.

```<code>var currentMethod = $route.current.params.name;
</code>```

Or you can use $routeParams https://docs.angularjs.org/api/ngRoute/service/$routeParams

Title: Current page using Angular

Body:
I have a "Remove All" button that removes all records from a Ng-table and MongoDB.
In my system, there are several views and each and every one of them display different data. Now, I don't know how to get the current page name and send it as a parameter for remove. It is working only if I insert to the code the name of the view and click on the button.

HTML:

                    <button ng-click="removeLogs('$scope.logType')" id="deleteAllErrors" name="deleteError" class="btn btn-danger">Remove All</button>

Angular:

//  login, signUp, addErr, refreshLog, refreshErr, badProd - $scope.currentPage

    $scope.removeLogs = function(logType){
        console.log("Admin request to delete logType: "+logType+" & "+currentPage.current.name);
        var rmLogs = {
            'email': localStorageService.get('email'),
            'password': localStorageService.get('password'),
            'logType': logType
        };
        $http.post(''+appPath+'/removeLogs', rmLogs)
            .then(function(data){
                $scope.statusMsg = "Logs Deleted Successfully";
                console.log("Admin X has delete logType");
                $scope.updateAdmin();
        });
    };

Body:
You can inject $route in controller's DI and access the params like this.

var currentMethod = $route.current.params.name;

Or you can use $routeParams https://docs.angularjs.org/api/ngRoute/service/$routeParams


来源: stackexchange

问:
How to detect texture disruption
Let's say we have a number of color images that are examples of some textured pattern. There is a rare occurrence where this texture is "disrupted" by some foreign object. What would be the best way to detect these rare anomalies?

I thought about training a CNN, but the number of good examples vastly outnumbers the bad examples, so I have my doubts. I started looking into grey level co-occurrence matrices (GLCM) and local binary patterns (LBP), but I think color information could play an important part in determining the occurrence of a disruption. Could I find the distribution from these extracted features (of either GLCM or LBP) and calculate the probability that a new image belongs to this distribution?

Thanks for your help!

答:
It is difficult to figure out your problem without seeing some sample images. In principle there's a wide variety of approaches you could use to detect texture disruption, namely GLCM features, LBPs, Law's masks, vector quantization, etc. Measuring the local entropy is a possible way to go. Consider the image below, in which we can clearly distinguish two types of texture:

The following snippet reads the image, computes the local entropy for each pixel on a circular neighbourhood or a given radius 25 and displays the results:

from skimage import io
from skimage.filters.rank import entropy
from skimage.morphology import disk

img = io.imread('https://i.stack.imgur.com/Wv74a.png')
R = 25
filtered = entropy(img, disk(R))
io.imshow(filtered)
```

It clearly emerges from the resulting entropy map that the local entropy values could be utilized to detect texture disruption.

ContentLicense: CC BY-SA 3.0

Title: How to detect texture disruption

Body:
It is difficult to figure out your problem without seeing some sample images. In principle there's a wide variety of approaches you could use to detect texture disruption, namely GLCM features, LBPs, Law's masks, vector quantization, etc. Measuring the local entropy is a possible way to go. Consider the image below, in which we can clearly distinguish two types of texture:

The following snippet reads the image, computes the local entropy for each pixel on a circular neighbourhood or a given radius 25 and displays the results:

from skimage import io
from skimage.filters.rank import entropy
from skimage.morphology import disk

img = io.imread('https://i.stack.imgur.com/Wv74a.png')
R = 25
filtered = entropy(img, disk(R))
io.imshow(filtered)

It clearly emerges from the resulting entropy map that the local entropy values could be utilized to detect texture disruption.


问:
PCA Biplot - Arrow length
I'm using PCA to generate the Biplot from my dataset here with the tool S-Plus

The script to run my data is:

```<code>a= princomp(x =  ~ ., data = Week.2.Mon.portsweep,scores=T,cor =F)
a$loadings
a$scores
biplot(a,scale=F)
</code>```

The biplot result is

With my knowledge, I interpret the biplot as following:

Left & bottom axes: Scores of PC1 & PC2

Right & top axes: Loadings values of PC1 & PC2

The observations are in black and plotted based on the scores of PCs

The arrow vectors indicate which variables account for most of PCs.

The position of arrow name is based on combination of loading values of PC1&PC2

Arrow length - ???

However, I dont know the what the length of arrow is based on.
I read some references that the length of arrow is proportion of variance. Is that true? How can we calculate it based on the biplot graph?

Could you guys help me ? Thanks

答:
I looked inside the stats:::biplot.princomp and stats:::biplot.default.
 The lengths of arrows are calculated as follows.

(1) The scale = F option of biplot is specified.

```<code># Data generating process
set.seed(12345)
library(MASS)
n <- 100
mu <- c(1,-2,-0.5)
Sigma <- diag(rep(1,3))
X <- mvrnorm(n, mu=mu, Sigma=Sigma)

pca <- princomp(X, cor=T, scores=T)
biplot(pca, choices = 1:2, scale = F)

# Calculates arrow lengths
lam <- 1
len <- t(t(pca$loadings[, 1:2]) * lam)*0.8

# Plot arrows in green and see if overlap the red ones
mapply(function(x,y) arrows(0, 0, x, y, col = "green",
            length = .1), x=len[,1], y=len[,2])
</code>```

(2) The scale = 0.5 option of biplot is specified.

```<code>scale <- 0.5
biplot(pca, choices = 1:2, scale = scale)

lam <- (pca$sdev[1:2]*sqrt(pca$n.obs))^scale
len <- t(t(pca$loadings[, 1:2]) * lam)*0.8

mapply(function(x,y) arrows(0, 0, x, y, col = "green", length = .1),
       len[,1], len[,2])
</code>```

Title: PCA Biplot - Arrow length

Body:
I'm using PCA to generate the Biplot from my dataset here with the tool S-Plus

The script to run my data is:

a= princomp(x =  ~ ., data = Week.2.Mon.portsweep,scores=T,cor =F)
a$loadings
a$scores
biplot(a,scale=F)

The biplot result is

With my knowledge, I interpret the biplot as following:

Left & bottom axes: Scores of PC1 & PC2

Right & top axes: Loadings values of PC1 & PC2

The observations are in black and plotted based on the scores of PCs

The arrow vectors indicate which variables account for most of PCs.

The position of arrow name is based on combination of loading values of PC1&PC2

Arrow length - ???

However, I dont know the what the length of arrow is based on.
I read some references that the length of arrow is proportion of variance. Is that true? How can we calculate it based on the biplot graph?

Could you guys help me ? Thanks

Body:
I looked inside the stats:::biplot.princomp and stats:::biplot.default.
 The lengths of arrows are calculated as follows.

(1) The scale = F option of biplot is specified.

# Data generating process
set.seed(12345)
library(MASS)
n <- 100
mu <- c(1,-2,-0.5)
Sigma <- diag(rep(1,3))
X <- mvrnorm(n, mu=mu, Sigma=Sigma)

pca <- princomp(X, cor=T, scores=T)
biplot(pca, choices = 1:2, scale = F)

# Calculates arrow lengths
lam <- 1
len <- t(t(pca$loadings[, 1:2]) * lam)*0.8

# Plot arrows in green and see if overlap the red ones
mapply(function(x,y) arrows(0, 0, x, y, col = "green",
            length = .1), x=len[,1], y=len[,2])

(2) The scale = 0.5 option of biplot is specified.

scale <- 0.5
biplot(pca, choices = 1:2, scale = scale)

lam <- (pca$sdev[1:2]*sqrt(pca$n.obs))^scale
len <- t(t(pca$loadings[, 1:2]) * lam)*0.8

mapply(function(x,y) arrows(0, 0, x, y, col = "green", length = .1),
       len[,1], len[,2])


问:
How do I map with rarely used state in clojure?
The situation is as follows: I'm transforming a sequence of values. The transformation of each value breaks down into a number of different cases. Most values are completely independent of each other. However there is one special case that requires me to keep track of how many special cases I've encountered so far. In imperative programming this is pretty straightforward:

```<code>int i = 0;
List<String> results = new ArrayList<>();
for (String value : values) {
  if (case1(value)) {
    results.add(handleCase1(value));
  } else if (case2(value)) {
  ...
  } else if (special(value)) {
    results.add(handleSpecial(value, i));
    i++;
  }
}
</code>```

However in Clojure the best I've come up with is:

```<code>(first
 (reduce
  (fn [[results i] value]
      (cond
       (case-1? value) [(conj results (handle-case-1 value)) i]
       (case-2? value) ...
       (special? value) [(conj results (handle-special value i))
                         (inc i)]))
  [[] 0] values))
</code>```

Which is pretty ugly considering that without the special case this would become:

```<code>(map #(cond
       (case-1? %) (handle-case-1 %)
       (case-2? %) ...)
      values)
</code>```

The trouble is that I'm manually stitching a sequence together during the reduction. Also most cases don't even care about the index but must nonetheless pass it along for the next reduction step.

Is there a cleaner solution to this problem?

答:
You want a purely functional approach? Try using a Map collection for your temporary value needs. This keeps your results nice and clean, and an easy way to access those temporary values when needed.

When we encounter a special value, we also update the counter in the map as well as the result list. This way we can use reduce to store some state as we process, but keep everything purely functional without atoms.

```<code>(def transformed-values
  (reduce
    (fn [{:keys [special-values-count] :as m} value]
      (cond
        (case-1 value) (update m :results conj (handle-case-1 value))
        (case-2 value) (update m :results conj (handle-case-2 value))
        ...
        (special-case? value) (-> m
                                  (update :results conj (handle-special value special-values-count))
                                  (update :special-values-count inc))
        :else m))
    {:results [] :special-values-count 0}
    your-list-of-string-values))

(:results transformed-values)
;=> ["value1" "Value2" "VALUE3" ...]

(:special-values-count transformed-values)
;=> 2
</code>```

Body:
The situation is as follows: I'm transforming a sequence of values. The transformation of each value breaks down into a number of different cases. Most values are completely independent of each other. However there is one special case that requires me to keep track of how many special cases I've encountered so far. In imperative programming this is pretty straightforward:

int i = 0;
List<String> results = new ArrayList<>();
for (String value : values) {
  if (case1(value)) {
    results.add(handleCase1(value));
  } else if (case2(value)) {
  ...
  } else if (special(value)) {
    results.add(handleSpecial(value, i));
    i++;
  }
}

However in Clojure the best I've come up with is:

(first
 (reduce
  (fn [[results i] value]
      (cond
       (case-1? value) [(conj results (handle-case-1 value)) i]
       (case-2? value) ...
       (special? value) [(conj results (handle-special value i))
                         (inc i)]))
  [[] 0] values))

Which is pretty ugly considering that without the special case this would become:

(map #(cond
       (case-1? %) (handle-case-1 %)
       (case-2? %) ...)
      values)

The trouble is that I'm manually stitching a sequence together during the reduction. Also most cases don't even care about the index but must nonetheless pass it along for the next reduction step.

Is there a cleaner solution to this problem?

Body:
You want a purely functional approach? Try using a Map collection for your temporary value needs. This keeps your results nice and clean, and an easy way to access those temporary values when needed.

When we encounter a special value, we also update the counter in the map as well as the result list. This way we can use reduce to store some state as we process, but keep everything purely functional without atoms.

(def transformed-values
  (reduce
    (fn [{:keys [special-values-count] :as m} value]
      (cond
        (case-1 value) (update m :results conj (handle-case-1 value))
        (case-2 value) (update m :results conj (handle-case-2 value))
        ...
        (special-case? value) (-> m
                                  (update :results conj (handle-special value special-values-count))
                                  (update :special-values-count inc))
        :else m))
    {:results [] :special-values-count 0}
    your-list-of-string-values))

(:results transformed-values)
;=> ["value1" "Value2" "VALUE3" ...]

(:special-values-count transformed-values)
;=> 2


问:
Mysql select N of X duplicates, omitting 1 duplicate
Considering this table:

```<code>+-----+--------+
| id  | value  |
+-----+--------+
|  1  |   22   |
+-----+--------+
|  2  |   12   |
+-----+--------+
|  3  |   22   |
+-----+--------+
|  4  |   22   |
+-----+ -------+
</code>```

I can select all where the column value is duplicated like so:

```<code>select value from table having count(value) > 1 ;
</code>```

This will output the Ids 1,3 and 4.

What I'm attempting to do is select where duplicates, but leaving 1 (one) duplicate un selected, so the above would output only the Ids 3 and 4 (or 1 and 3 etc... the duplicate omitted does not matter, only that it is.

How can I achieve this?

This question IS NOT a duplicate of

Using LIMIT within GROUP BY to get N results per group?

答:
You can do either as:

```<code>select *
 from test t1
where exists (select 1
                from test t2
               where t2.value = t1.value
              having count(value)>1)
limit 2
</code>```

OR:

```<code>select t1.*
  from test t1 inner join
       (select value from test t2 having count(value)>1) t2
       on t1.value = t2.value
 limit 2;
</code>```

Body:
Considering this table:

+-----+--------+
| id  | value  |
+-----+--------+
|  1  |   22   |
+-----+--------+
|  2  |   12   |
+-----+--------+
|  3  |   22   |
+-----+--------+
|  4  |   22   |
+-----+ -------+

I can select all where the column value is duplicated like so:

select value from table having count(value) > 1 ;

This will output the Ids 1,3 and 4.

What I'm attempting to do is select where duplicates, but leaving 1 (one) duplicate un selected, so the above would output only the Ids 3 and 4 (or 1 and 3 etc... the duplicate omitted does not matter, only that it is.

How can I achieve this?

This question IS NOT a duplicate of

Using LIMIT within GROUP BY to get N results per group?

Body:
You can do either as:

select *
 from test t1
where exists (select 1
                from test t2
               where t2.value = t1.value
              having count(value)>1)
limit 2

OR:

select t1.*
  from test t1 inner join
       (select value from test t2 having count(value)>1) t2
       on t1.value = t2.value
 limit 2;


问:
BLOB Storage - 100+ GB, MySQL, SQLite, or PostgreSQL + Python
I have an idea for a simple application which will monitor a group of folders, index any files it finds. A gui will allow me quickly tag new files and move them into a single database for storage and also provide an easy mechanism for querying the db by tag, name, file type and date. At the moment I have about 100+ GB of files on a couple removable hard drives, the database will be at least that big. If possible I would like to support full text search of the embedded binary and text documents. This will be a single user application.

Not trying to start a DB war, but what open source DB is going to work best for me? I am pretty sure SQLLite is off the table but I could be wrong.

答:
I always hate to answer "don't", but you'd be better off indexing with something like Lucene (PyLucene).   That and storing the paths in the database rather than the file contents is almost always recommended.

To add to that, none of those database engines will store LOBs in a separate dataspace (they'll be embedded in the table's data space) so any of those engines should perfom nearly equally as well (well except sqllite).  You need to move to Informix, DB2, SQLServer or others to get that kind of binary object handling.

OwnerDisplayName: Ethan Post

LastEditorDisplayName: Eddie

OwnerDisplayName: hometoast

ContentLicense: CC BY-SA 2.5


问:
iphone UITableView Custom Cell selected image
I have a custom UITableViewCell which fills the cell with a background PNG and a label.

When the user selected the cell, I wish to have the back ground change for an instant to visually give them indication that the row was selected. Similar to the default behavior when a custom cell is not used.

How is that done?

答:
let me clear first do you wish to change the backgroundimage.png??

if yes and you are using UIImageView for that then you can write following code in rowDidSelected event..

```<code>UIImageView *myImageView = [Cell viewWithTag:1]; //Tag is given in Interface Builder for the ImageView
myImageView.image = [[UIImage alloc] imageNamed:@"newimage.png"];
</code>```

Body:
let me clear first do you wish to change the backgroundimage.png??

if yes and you are using UIImageView for that then you can write following code in rowDidSelected event..

UIImageView *myImageView = [Cell viewWithTag:1]; //Tag is given in Interface Builder for the ImageView
myImageView.image = [[UIImage alloc] imageNamed:@"newimage.png"];


问:
Declaring Method with generic type
I was using generic types in C# and I am new to using generic types. So, right now I am stuck with a problem. I have some classes like these:

```<code>public class MyModel1
{
}

public class MyModel2
{
}

public class BaseClass<T>
{
}

public class ChildClass1 : BaseClass<MyModel1>
{
}

public class ChildClass2 : BaseClass<MyModel2>
{
}

public class AnotherClass
{
    //What will be the syntax of declaring this method
    //The syntax of the following method is wrong and incomplete.
    //It's there just to give an idea about whai i want to do.
    public void MyMethod<T>()
      where T : BaseClass<..what to write..>
    {

    }
}
</code>```

My question is what will be the correct syntax of declaring MyMethod if I want to call MyMethod like this:

```<code>MyMethod<ChildClass1>();
</code>```

答:
This will work (by which I mean it compiles)

```<code>public void MyMethod<T>()
    where T : BaseClass<MyModel1>
{ }
</code>```

so does this:

```<code>public void MyMethod<T>()
    where T : ChildClass1
{ }
</code>```

Further edit after reading your comment...

You can do this:

```<code>public class AnotherClass<TBaseClass, TModel> where TBaseClass : BaseClass<TModel>
{
    public void MyMethod(TBaseClass input)
    { }
}
</code>```

I have a term for this, hopefully non-offensive. I call it The Generic Rabbit Hole of Madness. It's what happens when we try to combine generics and inheritance so that one set of classes can accomplish a broad set of goals that become increasingly confusing, and we solve it by adding more generic parameters and more generic classes.

You reach the bottom of the hole if you

- use <dynamic>

- check to see what the actual type is using GetType(), typeof, or is

- get it to compile but can't remember what it's supposed to do

Title: Declaring Method with generic type

Body:
I was using generic types in C# and I am new to using generic types. So, right now I am stuck with a problem. I have some classes like these:

public class MyModel1
{
}

public class MyModel2
{
}

public class BaseClass<T>
{
}

public class ChildClass1 : BaseClass<MyModel1>
{
}

public class ChildClass2 : BaseClass<MyModel2>
{
}

public class AnotherClass
{
    //What will be the syntax of declaring this method
    //The syntax of the following method is wrong and incomplete.
    //It's there just to give an idea about whai i want to do.
    public void MyMethod<T>()
      where T : BaseClass<..what to write..>
    {

    }
}

My question is what will be the correct syntax of declaring MyMethod if I want to call MyMethod like this:

MyMethod<ChildClass1>();

Body:
This will work (by which I mean it compiles)

public void MyMethod<T>()
    where T : BaseClass<MyModel1>
{ }

so does this:

public void MyMethod<T>()
    where T : ChildClass1
{ }

Further edit after reading your comment...

You can do this:

public class AnotherClass<TBaseClass, TModel> where TBaseClass : BaseClass<TModel>
{
    public void MyMethod(TBaseClass input)
    { }
}

I have a term for this, hopefully non-offensive. I call it The Generic Rabbit Hole of Madness. It's what happens when we try to combine generics and inheritance so that one set of classes can accomplish a broad set of goals that become increasingly confusing, and we solve it by adding more generic parameters and more generic classes.

You reach the bottom of the hole if you

- use <dynamic>

- check to see what the actual type is using GetType(), typeof, or is

- get it to compile but can't remember what it's supposed to do


问:
Angular build failing due to Uglify.js
Today morning we just ran into an issue where we had the build failing and the reason was totally unknown. The stack trace is not revealing anything apart form the Uglify files and its all of a sudden we have encountered this. I am using Angular CLI

```<code>ng build --target=production --env=prod

 18% building modules 67/67 modules 0 activeTemplate parse warnings:
The <template> element is deprecated. Use <ng-template> instead ("[WARNING ->]<template #innerView></template>
<template #template let-ctx>
    <template [swapCmp]="ctx.component""): ng:///Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/angular2-modal/esm/overlay/overlay.component.d.ts.ModalOverlay.html@0:0
Warning: Can't resolve all parameters for UserDetail in /Users/shivganesh/Documents/Vetahealth/CODE/Physician/src/app/models/user-detail.model.ts: (?). This will become an error in Angular v5.x
Hash: 57f5ee6a7de2d0427083
Time: 83888ms
chunk    {0} main.72d8abfc264b3e8c979e.bundle.js (main) 3.04 MB {3} [initial] [rendered]
chunk    {1} scripts.155fe32b210641a6bc1c.bundle.js (scripts) 1.15 MB {4} [initial] [rendered]
chunk    {2} styles.68eaa60430e83a5adf34.bundle.css (styles) 599 bytes {4} [initial] [rendered]
chunk    {3} vendor.7b3b095ed3817b60967b.bundle.js (vendor) 4.05 MB [initial] [rendered]
chunk    {4} inline.27f2c1c1353b86214c6d.bundle.js (inline) 0 bytes [entry] [rendered]

ERROR in main.72d8abfc264b3e8c979e.bundle.js from UglifyJs
TypeError: Cannot set property 'fixed' of undefined
    at TreeWalker.eval [as visit] (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:5581:25)
    at TreeWalker._visit (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:1339:24)
    at AST_This._walk (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:480:24)
    at AST_Dot.eval (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:1061:29)
    at TreeWalker._visit (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:1343:21)
    at AST_Dot._walk (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:1060:24)
    at AST_Dot.walk (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:483:21)
    at TreeWalker.eval [as visit] (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:5719:31)
    at TreeWalker._visit (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:1339:24)
    at AST_ForIn._walk (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:653:24)
    at walk_body (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:530:17)
    at AST_BlockStatement.eval (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:541:13)
    at TreeWalker._visit (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:1343:21)
    at AST_BlockStatement._walk (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:540:24)
    at AST_BlockStatement.walk (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:483:21)
    at TreeWalker.eval [as visit] (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:5698:42)

npm ERR! Darwin 16.6.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
npm ERR! node v7.9.0
npm ERR! npm  v4.2.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! vetahealth-admin@0.0.0 build: `ng build --target=production --env=prod`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the vetahealth-admin@0.0.0 build script 'ng build --target=production --env=prod'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the vetahealth-admin package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     ng build --target=production --env=prod
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs vetahealth-admin
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls vetahealth-admin
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/shivganesh/.npm/_logs/2017-06-02T22_40_30_878Z-debug.log
</code>```

I am totally confused why is Uglify behaving this way. Till last monday it was all fine and today all of a sudden it broke. I have also pasted below my package.json and the npm logs.

Package.json

```<code>{
  "name": "vetahealth-admin",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "ng": "ng",
    "start": "ng serve --port 8080",
    "build": "ng build --target=production --env=prod",
    "lint": "tslint \"src/**/*.ts\" --project src/tsconfig.json --type-check && tslint \"e2e/**/*.ts\" --project e2e/tsconfig.json --type-check",
    "test": "ng test",
    "pree2e": "webdriver-manager update --standalone false --gecko false",
    "e2e": "protractor",
    "docs": "npm run typedoc -- --options typedoc.json --exclude '**/*.spec.ts' ./src/",
    "typedoc": "typedoc"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "4.1.3",
    "@angular/compiler": "4.1.3",
    "@angular/core": "4.1.3",
    "@angular/forms": "4.1.3",
    "@angular/http": "4.1.3",
    "@angular/platform-browser": "4.1.3",
    "@angular/platform-browser-dynamic": "4.1.3",
    "@angular/platform-server": "4.1.3",
    "@angular/router": "4.1.3",
    "@ngtools/webpack": "^1.3.1",
    "@swimlane/ngx-datatable": "9.3.0",
    "@angular/animations": "^4.0.0",
    "angular-2-local-storage": "^1.0.1",
    "angular2-highcharts": "^0.5.5",
    "angular2-modal": "^2.0.3",
    "angular2-moment": "^1.2.0",
    "angular2-text-mask": "^8.0.1",
    "angular2-toaster": "^4.0.0",
    "animate.css": "^3.5.2",
    "bootstrap": "^3.3.7",
    "core-js": "^2.4.1",
    "font-awesome": "^4.7.0",
    "install": "^0.10.1",
    "jquery": "^3.1.1",
    "metismenu": "^2.5.0",
    "moment": "^2.18.1",
    "npm": "^5.0.1",
    "pikaday": "^1.5.1",
    "primeng": "^4.0.1",
    "rxjs": "^5.0.1",
    "slimscroll": "^0.9.1",
    "ts-helpers": "^1.1.1",
    "typescript": "2.2.2",
    "underscore": "^1.8.3",
    "compass-mixins": "0.12.10",
    "zone.js": "^0.8.11"
  },
  "devDependencies": {
    "@angular/cli": "^1.0.0",
    "@angular/compiler-cli": "4.1.3",
    "@types/jasmine": "2.5.51",
    "@types/lodash": "4.14.65",
    "@types/moment": "^2.13.0",
    "@types/node": "^7.0.27",
    "codelyzer": "~3.0.1",
    "jasmine-core": "2.6.2",
    "jasmine-spec-reporter": "4.1.0",
    "karma": "1.7.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.6.0",
    "protractor": "~5.1.2",
    "ts-node": "3.0.4",
    "tslint": "^5.4.2",
    "typedoc": "^0.7.1",
    "typescript": "~2.3"
  }
}
</code>```

Npm Logs

```<code>Shivs-MacBook-Pro:Physician shivganesh$ cat /Users/shivganesh/.npm/_logs/2017-06-02T22_40_30_878Z-debug.log
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'build' ]
2 info using npm@4.2.0
3 info using node@v7.9.0
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle vetahealth-admin@0.0.0~prebuild: vetahealth-admin@0.0.0
6 silly lifecycle vetahealth-admin@0.0.0~prebuild: no script for prebuild, continuing
7 info lifecycle vetahealth-admin@0.0.0~build: vetahealth-admin@0.0.0
8 verbose lifecycle vetahealth-admin@0.0.0~build: unsafe-perm in lifecycle true
9 verbose lifecycle vetahealth-admin@0.0.0~build: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
10 verbose lifecycle vetahealth-admin@0.0.0~build: CWD: /Users/shivganesh/Documents/Vetahealth/CODE/Physician
11 silly lifecycle vetahealth-admin@0.0.0~build: Args: [ '-c', 'ng build --target=production --env=prod' ]
12 silly lifecycle vetahealth-admin@0.0.0~build: Returned: code: 1  signal: null
13 info lifecycle vetahealth-admin@0.0.0~build: Failed to exec build script
14 verbose stack Error: vetahealth-admin@0.0.0 build: `ng build --target=production --env=prod`
14 verbose stack Exit status 1
14 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:279:16)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at EventEmitter.emit (events.js:194:7)
14 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at ChildProcess.emit (events.js:194:7)
14 verbose stack     at maybeClose (internal/child_process.js:899:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
15 verbose pkgid vetahealth-admin@0.0.0
16 verbose cwd /Users/shivganesh/Documents/Vetahealth/CODE/Physician
17 error Darwin 16.6.0
18 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
19 error node v7.9.0
20 error npm  v4.2.0
21 error code ELIFECYCLE
22 error errno 1
23 error vetahealth-admin@0.0.0 build: `ng build --target=production --env=prod`
23 error Exit status 1
24 error Failed at the vetahealth-admin@0.0.0 build script 'ng build --target=production --env=prod'.
24 error Make sure you have the latest version of node.js and npm installed.
24 error If you do, this is most likely a problem with the vetahealth-admin package,
24 error not with npm itself.
24 error Tell the author that this fails on your system:
24 error     ng build --target=production --env=prod
24 error You can get information on how to open an issue for this project with:
24 error     npm bugs vetahealth-admin
24 error Or if that isn't available, you can get their info via:
24 error     npm owner ls vetahealth-admin
24 error There is likely additional logging output above.
25 verbose exit [ 1, true ]
</code>```

答:
So the way you can solve such issues is as follows:-

Check whether the previous releases are also having the same issue, which in my case turned out to be true. This way I eliminated the doubt that the developers or the solution went wrong somewhere.

Now go ahead and create a new project with the latest version of angular-cli

The above step gives you an option of getting a blank project with the working dependencies in place.

List the various dependencies and then try to merge them into the correct place.

You may find there are mismatch or inconsistency but give a try to get at least the versions mentioned for the angular files.

Thats it. You are done. I did have to uninstall the ng version since the version of angular-cli on my system was higher than what the project uses.

Hope this was helpful.

Title: Angular build failing due to Uglify.js

Body:
Today morning we just ran into an issue where we had the build failing and the reason was totally unknown. The stack trace is not revealing anything apart form the Uglify files and its all of a sudden we have encountered this. I am using Angular CLI

ng build --target=production --env=prod

 18% building modules 67/67 modules 0 activeTemplate parse warnings:
The <template> element is deprecated. Use <ng-template> instead ("[WARNING ->]<template #innerView></template>
<template #template let-ctx>
    <template [swapCmp]="ctx.component""): ng:///Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/angular2-modal/esm/overlay/overlay.component.d.ts.ModalOverlay.html@0:0
Warning: Can't resolve all parameters for UserDetail in /Users/shivganesh/Documents/Vetahealth/CODE/Physician/src/app/models/user-detail.model.ts: (?). This will become an error in Angular v5.x
Hash: 57f5ee6a7de2d0427083
Time: 83888ms
chunk    {0} main.72d8abfc264b3e8c979e.bundle.js (main) 3.04 MB {3} [initial] [rendered]
chunk    {1} scripts.155fe32b210641a6bc1c.bundle.js (scripts) 1.15 MB {4} [initial] [rendered]
chunk    {2} styles.68eaa60430e83a5adf34.bundle.css (styles) 599 bytes {4} [initial] [rendered]
chunk    {3} vendor.7b3b095ed3817b60967b.bundle.js (vendor) 4.05 MB [initial] [rendered]
chunk    {4} inline.27f2c1c1353b86214c6d.bundle.js (inline) 0 bytes [entry] [rendered]

ERROR in main.72d8abfc264b3e8c979e.bundle.js from UglifyJs
TypeError: Cannot set property 'fixed' of undefined
    at TreeWalker.eval [as visit] (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:5581:25)
    at TreeWalker._visit (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:1339:24)
    at AST_This._walk (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:480:24)
    at AST_Dot.eval (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:1061:29)
    at TreeWalker._visit (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:1343:21)
    at AST_Dot._walk (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:1060:24)
    at AST_Dot.walk (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:483:21)
    at TreeWalker.eval [as visit] (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:5719:31)
    at TreeWalker._visit (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:1339:24)
    at AST_ForIn._walk (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:653:24)
    at walk_body (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:530:17)
    at AST_BlockStatement.eval (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:541:13)
    at TreeWalker._visit (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:1343:21)
    at AST_BlockStatement._walk (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:540:24)
    at AST_BlockStatement.walk (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:483:21)
    at TreeWalker.eval [as visit] (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:5698:42)

npm ERR! Darwin 16.6.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
npm ERR! node v7.9.0
npm ERR! npm  v4.2.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! vetahealth-admin@0.0.0 build: `ng build --target=production --env=prod`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the vetahealth-admin@0.0.0 build script 'ng build --target=production --env=prod'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the vetahealth-admin package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     ng build --target=production --env=prod
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs vetahealth-admin
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls vetahealth-admin
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/shivganesh/.npm/_logs/2017-06-02T22_40_30_878Z-debug.log

I am totally confused why is Uglify behaving this way. Till last monday it was all fine and today all of a sudden it broke. I have also pasted below my package.json and the npm logs.

Package.json

{
  "name": "vetahealth-admin",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "ng": "ng",
    "start": "ng serve --port 8080",
    "build": "ng build --target=production --env=prod",
    "lint": "tslint \"src/**/*.ts\" --project src/tsconfig.json --type-check && tslint \"e2e/**/*.ts\" --project e2e/tsconfig.json --type-check",
    "test": "ng test",
    "pree2e": "webdriver-manager update --standalone false --gecko false",
    "e2e": "protractor",
    "docs": "npm run typedoc -- --options typedoc.json --exclude '**/*.spec.ts' ./src/",
    "typedoc": "typedoc"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "4.1.3",
    "@angular/compiler": "4.1.3",
    "@angular/core": "4.1.3",
    "@angular/forms": "4.1.3",
    "@angular/http": "4.1.3",
    "@angular/platform-browser": "4.1.3",
    "@angular/platform-browser-dynamic": "4.1.3",
    "@angular/platform-server": "4.1.3",
    "@angular/router": "4.1.3",
    "@ngtools/webpack": "^1.3.1",
    "@swimlane/ngx-datatable": "9.3.0",
    "@angular/animations": "^4.0.0",
    "angular-2-local-storage": "^1.0.1",
    "angular2-highcharts": "^0.5.5",
    "angular2-modal": "^2.0.3",
    "angular2-moment": "^1.2.0",
    "angular2-text-mask": "^8.0.1",
    "angular2-toaster": "^4.0.0",
    "animate.css": "^3.5.2",
    "bootstrap": "^3.3.7",
    "core-js": "^2.4.1",
    "font-awesome": "^4.7.0",
    "install": "^0.10.1",
    "jquery": "^3.1.1",
    "metismenu": "^2.5.0",
    "moment": "^2.18.1",
    "npm": "^5.0.1",
    "pikaday": "^1.5.1",
    "primeng": "^4.0.1",
    "rxjs": "^5.0.1",
    "slimscroll": "^0.9.1",
    "ts-helpers": "^1.1.1",
    "typescript": "2.2.2",
    "underscore": "^1.8.3",
    "compass-mixins": "0.12.10",
    "zone.js": "^0.8.11"
  },
  "devDependencies": {
    "@angular/cli": "^1.0.0",
    "@angular/compiler-cli": "4.1.3",
    "@types/jasmine": "2.5.51",
    "@types/lodash": "4.14.65",
    "@types/moment": "^2.13.0",
    "@types/node": "^7.0.27",
    "codelyzer": "~3.0.1",
    "jasmine-core": "2.6.2",
    "jasmine-spec-reporter": "4.1.0",
    "karma": "1.7.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.6.0",
    "protractor": "~5.1.2",
    "ts-node": "3.0.4",
    "tslint": "^5.4.2",
    "typedoc": "^0.7.1",
    "typescript": "~2.3"
  }
}

Npm Logs

Shivs-MacBook-Pro:Physician shivganesh$ cat /Users/shivganesh/.npm/_logs/2017-06-02T22_40_30_878Z-debug.log
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'build' ]
2 info using npm@4.2.0
3 info using node@v7.9.0
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle vetahealth-admin@0.0.0~prebuild: vetahealth-admin@0.0.0
6 silly lifecycle vetahealth-admin@0.0.0~prebuild: no script for prebuild, continuing
7 info lifecycle vetahealth-admin@0.0.0~build: vetahealth-admin@0.0.0
8 verbose lifecycle vetahealth-admin@0.0.0~build: unsafe-perm in lifecycle true
9 verbose lifecycle vetahealth-admin@0.0.0~build: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
10 verbose lifecycle vetahealth-admin@0.0.0~build: CWD: /Users/shivganesh/Documents/Vetahealth/CODE/Physician
11 silly lifecycle vetahealth-admin@0.0.0~build: Args: [ '-c', 'ng build --target=production --env=prod' ]
12 silly lifecycle vetahealth-admin@0.0.0~build: Returned: code: 1  signal: null
13 info lifecycle vetahealth-admin@0.0.0~build: Failed to exec build script
14 verbose stack Error: vetahealth-admin@0.0.0 build: `ng build --target=production --env=prod`
14 verbose stack Exit status 1
14 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:279:16)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at EventEmitter.emit (events.js:194:7)
14 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at ChildProcess.emit (events.js:194:7)
14 verbose stack     at maybeClose (internal/child_process.js:899:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
15 verbose pkgid vetahealth-admin@0.0.0
16 verbose cwd /Users/shivganesh/Documents/Vetahealth/CODE/Physician
17 error Darwin 16.6.0
18 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
19 error node v7.9.0
20 error npm  v4.2.0
21 error code ELIFECYCLE
22 error errno 1
23 error vetahealth-admin@0.0.0 build: `ng build --target=production --env=prod`
23 error Exit status 1
24 error Failed at the vetahealth-admin@0.0.0 build script 'ng build --target=production --env=prod'.
24 error Make sure you have the latest version of node.js and npm installed.
24 error If you do, this is most likely a problem with the vetahealth-admin package,
24 error not with npm itself.
24 error Tell the author that this fails on your system:
24 error     ng build --target=production --env=prod
24 error You can get information on how to open an issue for this project with:
24 error     npm bugs vetahealth-admin
24 error Or if that isn't available, you can get their info via:
24 error     npm owner ls vetahealth-admin
24 error There is likely additional logging output above.
25 verbose exit [ 1, true ]


问:
Appending the datetime to the end of every line in a 600 million row file
I have a 680 million rows (19gig) file that I need the datetime appended onto every line. I get this file every night and I have to add the time that I processed it to the end of each line. I have tried many ways to do this including sed/awk and loading it into a SQL database with the last column being defaulted to the current timestamp.

I was wondering if there is a fast way to do this? My fastest way so far takes two hours and that is just not fast enough given the urgency of the information in this file.  It is a flat CSV file.

edit1:

Here's what I've done so far:

```<code>awk -v date="$(date +"%Y-%m-%d %r")" '{ print $0","date}' lrn.ae.txt > testoutput.txt
</code>```

Time = 117 minutes

```<code>perl -ne 'chomp; printf "%s.pdf\n", $_' EXPORT.txt > testoutput.txt
</code>```

Time = 135 minutes

```<code>mysql load data local infile '/tmp/input.txt' into table testoutput
</code>```

Time = 211 minutes

答:
You don't specify if the timestamps have to be different for each of the lines.  Would a "start of processing" time be enough?

If so, a simple solution is to use the paste command, with a pre-generated file of timestamps, exactly the same length as the file you're processing.  Then just paste the whole thing together.  Also, if the whole process is I/O bound, as others are speculating, then maybe running this on a box with an SSD drive would help speed up the process.

I just tried it locally on a 6 million row file (roughly 1% of yours), and it's actually able to do it in less than one second, on Macbook Pro, with an SSD drive.

```<code> ~> date; time paste file1.txt timestamps.txt > final.txt; date
 Mon Jun  5 10:57:49 MDT 2017

 real   0m0.944s
 user   0m0.680s
 sys    0m0.222s
 Mon Jun  5 10:57:49 MDT 2017
</code>```

I'm going to now try a ~500 million row file, and see how that fares.

Updated:

Ok, the results are in.  Paste is blazing fast compared to your solution, it took just over 90 seconds total to process the whole thing, 600M rows of simple data.

```<code>~> wc -l huge.txt
600000000 huge.txt
~> wc -l hugetimestamps.txt
600000000 hugetimestamps.txt
~> date; time paste huge.txt hugetimestamps.txt > final.txt; date
Mon Jun  5 11:09:11 MDT 2017

real    1m35.652s
user    1m8.352s
sys 0m22.643s
Mon Jun  5 11:10:47 MDT 2017
</code>```

You still need to prepare the timestamps file ahead of time, but that's a trivial bash loop.  I created mine in less than one minute.

Body:
I have a 680 million rows (19gig) file that I need the datetime appended onto every line. I get this file every night and I have to add the time that I processed it to the end of each line. I have tried many ways to do this including sed/awk and loading it into a SQL database with the last column being defaulted to the current timestamp.

I was wondering if there is a fast way to do this? My fastest way so far takes two hours and that is just not fast enough given the urgency of the information in this file.  It is a flat CSV file.

edit1:

Here's what I've done so far:

awk -v date="$(date +"%Y-%m-%d %r")" '{ print $0","date}' lrn.ae.txt > testoutput.txt

Time = 117 minutes

perl -ne 'chomp; printf "%s.pdf\n", $_' EXPORT.txt > testoutput.txt

Time = 135 minutes

mysql load data local infile '/tmp/input.txt' into table testoutput

Time = 211 minutes

Body:
You don't specify if the timestamps have to be different for each of the lines.  Would a "start of processing" time be enough?

If so, a simple solution is to use the paste command, with a pre-generated file of timestamps, exactly the same length as the file you're processing.  Then just paste the whole thing together.  Also, if the whole process is I/O bound, as others are speculating, then maybe running this on a box with an SSD drive would help speed up the process.

I just tried it locally on a 6 million row file (roughly 1% of yours), and it's actually able to do it in less than one second, on Macbook Pro, with an SSD drive.

 ~> date; time paste file1.txt timestamps.txt > final.txt; date
 Mon Jun  5 10:57:49 MDT 2017

 real   0m0.944s
 user   0m0.680s
 sys    0m0.222s
 Mon Jun  5 10:57:49 MDT 2017

I'm going to now try a ~500 million row file, and see how that fares.

Updated:

Ok, the results are in.  Paste is blazing fast compared to your solution, it took just over 90 seconds total to process the whole thing, 600M rows of simple data.

~> wc -l huge.txt
600000000 huge.txt
~> wc -l hugetimestamps.txt
600000000 hugetimestamps.txt
~> date; time paste huge.txt hugetimestamps.txt > final.txt; date
Mon Jun  5 11:09:11 MDT 2017

real    1m35.652s
user    1m8.352s
sys 0m22.643s
Mon Jun  5 11:10:47 MDT 2017

You still need to prepare the timestamps file ahead of time, but that's a trivial bash loop.  I created mine in less than one minute.


问:
Trying to get validate function to work with redux-form
I have tried this before on another application and just copied the code over and edited the paths, and things I need to for this application. I am not getting any errors, but I cannot seem to get this to work. It doesn't show any error messages or apply my classes to the inputs.</p>

```<code>import React, { Component } from 'react';
import {Field, reduxForm} from 'redux-form';
import {connect} from 'react-redux';
import * as actions from '../../actions';

class Signin extends Component {
  constructor(props) {
    super(props);

    this.onSubmit = this.onSubmit.bind(this);
  }

  renderField(field) {
    const { meta: {touched, error} } = field;
    const className = `form-group ${touched && error ? 'has-danger' : ''}`;

    return (
      <div className={className}>
        <label><strong>{field.label}:</strong></label>
        <input
          className="form-control"
          type="text"
          {...field.input}
        />
        <div className="text-help">
          { touched ? error : ''}
        </div>
      </div>
    )
  }

  onSubmit({email, password}) {
    console.log(email, password);
  }

  render() {
    const { handleSubmit } = this.props;

    return (
      <form onSubmit={handleSubmit(this.onSubmit)}>
        <Field
          label="Email"
          name="email"
          component={this.renderField}
        />
        <Field
          label="Password"
          name="password"
          component={this.renderField}
        />
        <button type="submit" className="btn btn-success">Sign In</button>
      </form>
    );
  }
}

function validate(values) {
  const errors = {};

  //Validate the inputs from values
  if(!values.email) {
    errors.title = "Enter an email!";
  }
  if(!values.password) {
    errors.categories = "Enter a password!";
  }
  //If errors is empty, the form is fine to submit
  //If errors has any properties, redux form assumes form is invalid
  return errors;
}

export default reduxForm({
  validate,
  form: 'signin'
})(connect(null, actions)(Signin));
</code>```

答:
So the problem is with Validate function where the error log is attached since the error maps to title and categories whereas the Field name is email and password </p>

<p>Use </p>

```<code>function validate(values) {
  const errors = {};

  //Validate the inputs from values
  if(!values.email) {
    errors.email = "Enter an email!";
  }
  if(!values.password) {
    errors.password = "Enter a password!";
  }
  //If errors is empty, the form is fine to submit
  //If errors has any properties, redux form assumes form is invalid
  return errors;
}
</code>```

Body:
I have tried this before on another application and just copied the code over and edited the paths, and things I need to for this application. I am not getting any errors, but I cannot seem to get this to work. It doesn't show any error messages or apply my classes to the inputs.

import React, { Component } from 'react';
import {Field, reduxForm} from 'redux-form';
import {connect} from 'react-redux';
import * as actions from '../../actions';

class Signin extends Component {
  constructor(props) {
    super(props);

    this.onSubmit = this.onSubmit.bind(this);
  }

  renderField(field) {
    const { meta: {touched, error} } = field;
    const className = `form-group ${touched && error ? 'has-danger' : ''}`;

    return (

        {field.label}:
        <input
          className="form-control"
          type="text"
          {...field.input}
        />

          { touched ? error : ''}

    )
  }

  onSubmit({email, password}) {
    console.log(email, password);
  }

  render() {
    const { handleSubmit } = this.props;

    return (
      <form onSubmit={handleSubmit(this.onSubmit)}>
        <Field
          label="Email"
          name="email"
          component={this.renderField}
        />
        <Field
          label="Password"
          name="password"
          component={this.renderField}
        />
        <button type="submit" className="btn btn-success">Sign In</button>
      </form>
    );
  }
}

function validate(values) {
  const errors = {};

  //Validate the inputs from values
  if(!values.email) {
    errors.title = "Enter an email!";
  }
  if(!values.password) {
    errors.categories = "Enter a password!";
  }
  //If errors is empty, the form is fine to submit
  //If errors has any properties, redux form assumes form is invalid
  return errors;
}

export default reduxForm({
  validate,
  form: 'signin'
})(connect(null, actions)(Signin));

Body:
So the problem is with Validate function where the error log is attached since the error maps to title and categories whereas the Field name is email and password

Use

function validate(values) {
  const errors = {};

  //Validate the inputs from values
  if(!values.email) {
    errors.email = "Enter an email!";
  }
  if(!values.password) {
    errors.password = "Enter a password!";
  }
  //If errors is empty, the form is fine to submit
  //If errors has any properties, redux form assumes form is invalid
  return errors;
}


问:
kubectl error: "You must be logged in to the server (the server has asked for the client to provide credentials)"
I'm running the following command and getting an error:

```<code>$ kubectl get nodes
error: You must be logged in to the server (the server has asked for the client to provide credentials)
</code>```

What's going on?

答:
Re-setting the compute/zone seems to do the trick.
Using this command

```<code>gcloud container clusters list
</code>```

I got

```<code>NAME  ZONE            MASTER_VERSION  MASTER_IP      MACHINE_TYPE   NODE_VERSION  NUM_NODES  STATUS
k0    europe-west1-d  1.6.4           35.187.164.84  n1-standard-1  1.6.4         3          RUNNING
</code>```

So the zone seemed to configured, but it was only after re-executing

```<code>gcloud config set compute/zone europe-west1-d
</code>```

did things start working again.

So the real question is: why has is the compute zone config suddenly no longer valid?

Body:
I'm running the following command and getting an error:

$ kubectl get nodes
error: You must be logged in to the server (the server has asked for the client to provide credentials)

What's going on?

Body:
Re-setting the compute/zone seems to do the trick.
Using this command

gcloud container clusters list

I got

NAME  ZONE            MASTER_VERSION  MASTER_IP      MACHINE_TYPE   NODE_VERSION  NUM_NODES  STATUS
k0    europe-west1-d  1.6.4           35.187.164.84  n1-standard-1  1.6.4         3          RUNNING

So the zone seemed to configured, but it was only after re-executing

gcloud config set compute/zone europe-west1-d

did things start working again.

So the real question is: why has is the compute zone config suddenly no longer valid?


问:
Is there a better way to block property overloading?
```<code><?php
class Item {
 public function __set($name, $value){
  throw new Exception('Overloading is forbidden.');
 }

 public function __get($name){
  throw new Exception('Overloading is forbidden.');
 }
}
</code>```

<p>I want to make sure I set all required object properties, but if I mistype a property name PHP just adds a new property and the prop I wanted to initialize remains null. </p>

答:
From your comment:

I want to make sure I set all required object properties, but if I mistype a property name PHP just adds a new property and the prop I wanted to initialize remains null.

If you want to make sure you have set all required object properties, consider making them required arguments to the constructor, e.g.

```<code>class Item
{
    public function __construct($required, $alsoRequired, $moreRequired)
    {
        // assign to corresponding properties
    }
}
</code>```

This way you can be sure the object is in valid state.

If you cannot set them at object creation, consider adding a validator method to your object. Call this method before doing any critical things with your object to make sure all required properties are set. This would be a much more useful addition to your API than implementing a typo safeguard.

In addition, you should not have an issue with this if you use proper setters. Access your object through an interface instead of assigning properties directly. If you mistype a method name, PHP will tell you (unless you implemented __call).

On a sidenote, __get and __set are not lazy replacements for proper Getters and Setters. They are interceptors that will be triggered when trying to access a non accessible property. This is much more related to error handling. Also note that they are much slower than proper Getter and Setter.

Body:
<?php
class Item {
 public function __set($name, $value){
  throw new Exception('Overloading is forbidden.');
 }

 public function __get($name){
  throw new Exception('Overloading is forbidden.');
 }
}

I want to make sure I set all required object properties, but if I mistype a property name PHP just adds a new property and the prop I wanted to initialize remains null.

Body:
From your comment:

I want to make sure I set all required object properties, but if I mistype a property name PHP just adds a new property and the prop I wanted to initialize remains null.

If you want to make sure you have set all required object properties, consider making them required arguments to the constructor, e.g.

class Item
{
    public function __construct($required, $alsoRequired, $moreRequired)
    {
        // assign to corresponding properties
    }
}

This way you can be sure the object is in valid state.

If you cannot set them at object creation, consider adding a validator method to your object. Call this method before doing any critical things with your object to make sure all required properties are set. This would be a much more useful addition to your API than implementing a typo safeguard.

In addition, you should not have an issue with this if you use proper setters. Access your object through an interface instead of assigning properties directly. If you mistype a method name, PHP will tell you (unless you implemented __call).

On a sidenote, __get and __set are not lazy replacements for proper Getters and Setters. They are interceptors that will be triggered when trying to access a non accessible property. This is much more related to error handling. Also note that they are much slower than proper Getter and Setter.


问:
@Input property is undefined
I have 2 components one of them sets input property of another component.
The problem is that the input property is undefined at time of use.

First component:

```<code>import {Component, Input, OnInit} from "@angular/core";
import {Comparison} from "../../../common/domain/comparison";
@Component({
    selector: 'oe-comparison-list',
        template: `<div class="row" *ngFor="let comparisons of comparisonRows">
    <oe-comparison-thumbnail *ngFor="let comparison of comparisons" [comparison]="comparison"></oe-comparison-thumbnail>
</div>`,
    styleUrls: ['./comparison-list.component.css']
})
export class ComparisonListComponent implements OnInit {

    @Input("comparisons")
    private comparisons: Array<Comparison>;
    private comparisonRows: Array<Array<Comparison>>;
    private static readonly COLUMNS: number = 4;

    constructor() {
    }

    ngOnInit(): void {
        this.rows();
    }

    private rows(): void {
        //todo
        this.comparisonRows = [];
        let comparisonArray = [];
        for (let i: number = 0; i < this.comparisons.length; ++i) {
            if (i == 0 || i % ComparisonListComponent.COLUMNS != 0) {
                comparisonArray.push(this.comparisons[i]);
            } else {
                this.comparisonRows.push(comparisonArray);
                comparisonArray = [];
            }
        }
        if (this.comparisons.length < ComparisonListComponent.COLUMNS) {
            this.comparisonRows.push(comparisonArray);
        }
    }
}
</code>```

Second component

```<code>import {AfterViewChecked, Component, Inject, OnInit} from "@angular/core";
import {Comparison} from "../../../common/domain/comparison";
import {IComparisonService} from "../../../common/services/icomparison.service";
@Component({
    selector: 'oe-comparisons-view',
    template: `<oe-comparison-list [comparisons]="comparisons"></oe-comparison-list>`,
    styleUrls: ['./comparisons-view.component.css']
})
export class ComparisonsViewComponent implements AfterViewChecked, OnInit {

    private comparisons: Array<Comparison>;

    constructor(@Inject('IComparisonService') private comparisonService: IComparisonService) {

    }

    ngOnInit(): void {
        this.comparisonService.fetchComparisons()
            .then(comparisons => this.comparisons = comparisons);
    }
    ngAfterViewChecked(): void {
    }
}
</code>```

If i pass simple array from ngOnInit() from second component without promise everything works just fine.
How can i resolve this problem?

ADDED
Service implementation

```<code>import {Injectable} from '@angular/core';
import {Comparison} from "../../../domain/comparison";
import {IComparisonService} from "../../icomparison.service";

@Injectable()
export class ComparisonServiceMock implements IComparisonService {

    private selectedComparison: Comparison;

    constructor() {
    }

    fetchComparisons(): Promise<Array<Comparison>> {
        let comparison: Array<Comparison> = [
            new Comparison(0, "Toys", "Toys comparison description", new Date(), "toys"),
            new Comparison(1, "Tablets", "Tablets comparison description", new Date(), "tablets"),
            new Comparison(2, "Jogurts", "Jogurts comparison description", new Date(), "jogurts"),
        ];
        return Promise.resolve(comparison);
    }

    selectComparison(comparison: Comparison): void {
        this.selectedComparison = comparison;
    }

    getSelectedComparison(): Comparison {
        return this.selectedComparison;
    }

}
</code>```

答:
I think there is a problem with your input variable declaration, try changing:

```<code>@Input("comparisons")
private comparisons: Array<Comparison>;
</code>```

to

```<code>@Input("comparisons") comparisons: Array<Comparison>;
</code>```

or, equivalently

```<code>@Input() comparisons: Array<Comparison>;
</code>```

Update
You may also need to set the comparisons property in ComparisonsViewComponent to public.

Recent Angular versions dont support accessing private members in template code. See https://github.com/angular/angular-cli/issues/5620

Title: @Input property is undefined

Body:
I have 2 components one of them sets input property of another component.
The problem is that the input property is undefined at time of use.

First component:

import {Component, Input, OnInit} from "@angular/core";
import {Comparison} from "../../../common/domain/comparison";
@Component({
    selector: 'oe-comparison-list',
        template: `

    <oe-comparison-thumbnail *ngFor="let comparison of comparisons" [comparison]="comparison"></oe-comparison-thumbnail>

`,
    styleUrls: ['./comparison-list.component.css']
})
export class ComparisonListComponent implements OnInit {

    @Input("comparisons")
    private comparisons: Array<Comparison>;
    private comparisonRows: Array<Array<Comparison>>;
    private static readonly COLUMNS: number = 4;

    constructor() {
    }

    ngOnInit(): void {
        this.rows();
    }

    private rows(): void {
        //todo
        this.comparisonRows = [];
        let comparisonArray = [];
        for (let i: number = 0; i < this.comparisons.length; ++i) {
            if (i == 0 || i % ComparisonListComponent.COLUMNS != 0) {
                comparisonArray.push(this.comparisons[i]);
            } else {
                this.comparisonRows.push(comparisonArray);
                comparisonArray = [];
            }
        }
        if (this.comparisons.length < ComparisonListComponent.COLUMNS) {
            this.comparisonRows.push(comparisonArray);
        }
    }
}

Second component

import {AfterViewChecked, Component, Inject, OnInit} from "@angular/core";
import {Comparison} from "../../../common/domain/comparison";
import {IComparisonService} from "../../../common/services/icomparison.service";
@Component({
    selector: 'oe-comparisons-view',
    template: `<oe-comparison-list [comparisons]="comparisons"></oe-comparison-list>`,
    styleUrls: ['./comparisons-view.component.css']
})
export class ComparisonsViewComponent implements AfterViewChecked, OnInit {

    private comparisons: Array<Comparison>;

    constructor(@Inject('IComparisonService') private comparisonService: IComparisonService) {

    }

    ngOnInit(): void {
        this.comparisonService.fetchComparisons()
            .then(comparisons => this.comparisons = comparisons);
    }
    ngAfterViewChecked(): void {
    }
}

If i pass simple array from ngOnInit() from second component without promise everything works just fine.
How can i resolve this problem?

ADDED
Service implementation

import {Injectable} from '@angular/core';
import {Comparison} from "../../../domain/comparison";
import {IComparisonService} from "../../icomparison.service";

@Injectable()
export class ComparisonServiceMock implements IComparisonService {

    private selectedComparison: Comparison;

    constructor() {
    }

    fetchComparisons(): Promise<Array<Comparison>> {
        let comparison: Array<Comparison> = [
            new Comparison(0, "Toys", "Toys comparison description", new Date(), "toys"),
            new Comparison(1, "Tablets", "Tablets comparison description", new Date(), "tablets"),
            new Comparison(2, "Jogurts", "Jogurts comparison description", new Date(), "jogurts"),
        ];
        return Promise.resolve(comparison);
    }

    selectComparison(comparison: Comparison): void {
        this.selectedComparison = comparison;
    }

    getSelectedComparison(): Comparison {
        return this.selectedComparison;
    }

}

Body:
I think there is a problem with your input variable declaration, try changing:

@Input("comparisons")
private comparisons: Array<Comparison>;

to

@Input("comparisons") comparisons: Array<Comparison>;

or, equivalently

@Input() comparisons: Array<Comparison>;

Update
You may also need to set the comparisons property in ComparisonsViewComponent to public.

Recent Angular versions dont support accessing private members in template code. See https://github.com/angular/angular-cli/issues/5620


问:
TinyMCE not working when loading two textareas
I have two textareas that I load when the page loads, these two textareas are in the same table row. My tinyMCE looks like this

```<code>            tinyMCE.init({
                mode : "textareas",
                theme : "simple"
            });
</code>```

For some odd reason only the first textarea gets assigned the editor and the second does not. Although it only does this in Firefox. The text areas have different names and don't contain ids. Any advice will be appreciated.

答: Give them different ids. Tinymce editor id is equal to the textareas id; if no textarea id is present "content" is used as default. In your case for both textareas. Because there is already a tinymce editor with id "content" when the second textarea is being converted into a tinymce editor instance - it fails.</p>

Body:
I have two textareas that I load when the page loads, these two textareas are in the same table row. My tinyMCE looks like this

            tinyMCE.init({
                mode : "textareas",
                theme : "simple"
            });

For some odd reason only the first textarea gets assigned the editor and the second does not. Although it only does this in Firefox. The text areas have different names and don't contain ids. Any advice will be appreciated.


问:
Triggering a pipeline and waiting for it to finish from another pipeline
I have two different project repositories: my application repository, and an API repository. My application communicates with the API.

I want to set up some integration and E2E tests of my application. The application will need to use the latest version of the API project when running these tests.

The API project is already setup to deploy when triggered

```<code>deploy_integration_tests:
  stage: deploy
  script:
  - echo "deploying..."
  environment:
    name: integration_testing
  only:
    - triggers
</code>```

My application has an integration testing job set up like this:

```<code>integration_test
  stage: integration_test
  script:
    - echo "Building and deploying API..."
    - curl.exe -X POST -F token=<token> -F ref=develop <url_for_api_trigger>
    - echo "Now running the integration test that depends on the API deployment..."
</code>```

The problem I am having is that the trigger only queues the API pipeline (both projects are using the same runner) and continues before the API pipeline has actually run.

Is there a way to wait for the API pipeline to run before trying to run the integration test?

I can do something like this:

```<code>integration_test_dependency
  stage: integration_test_dependency
  script:
    - echo "Building and deploying API..."
    - curl.exe -X POST -F token=<token> -F ref=develop <url_for_api_trigger>

integration_test
  stage: integration_test
  script:
    - echo "Now running the integration test that depends on the API deployment..."
</code>```

But that still doesn't grantee that the API pipeline runs and finishes before moving on to the integration_test stage.

Is there a way to do this?

答:
Currently this isn't possible. There are some issues in gitlab about this:

https://gitlab.com/gitlab-org/gitlab-ce/issues/25457

https://gitlab.com/gitlab-org/gitlab-ce/issues/29347

https://gitlab.com/gitlab-org/gitlab-ce/issues/22972

etc

Your best bet is to lend weight to some of these issues.

Body:
I have two different project repositories: my application repository, and an API repository. My application communicates with the API.

I want to set up some integration and E2E tests of my application. The application will need to use the latest version of the API project when running these tests.

The API project is already setup to deploy when triggered

deploy_integration_tests:
  stage: deploy
  script:
  - echo "deploying..."
  environment:
    name: integration_testing
  only:
    - triggers

My application has an integration testing job set up like this:

integration_test
  stage: integration_test
  script:
    - echo "Building and deploying API..."
    - curl.exe -X POST -F token=<token> -F ref=develop <url_for_api_trigger>
    - echo "Now running the integration test that depends on the API deployment..."

The problem I am having is that the trigger only queues the API pipeline (both projects are using the same runner) and continues before the API pipeline has actually run.

Is there a way to wait for the API pipeline to run before trying to run the integration test?

I can do something like this:

integration_test_dependency
  stage: integration_test_dependency
  script:
    - echo "Building and deploying API..."
    - curl.exe -X POST -F token=<token> -F ref=develop <url_for_api_trigger>

integration_test
  stage: integration_test
  script:
    - echo "Now running the integration test that depends on the API deployment..."

But that still doesn't grantee that the API pipeline runs and finishes before moving on to the integration_test stage.

Is there a way to do this?


问:
How to create IObservable from delegate that does not inherit from EventHandler?
I am using Accord (previously AForge) to capture image frames from a webcam.

These images arrive via a VideoCaptureDevice.NewFrame event:

```<code>public delegate void NewFrameEventHandler(object sender, NewFrameEventArgs eventArgs);

public class NewFrameEventArgs : EventArgs
{
    public Bitmap Frame { get; }

    public NewFrameEventArgs(Bitmap frame);
}
</code>```

The problem is, I tried to use Observable.FromEvent, but got lost in the many possible overloads:

```<code>void Run()
{
    var videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);

    VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString);

    // regular way
    videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);

    // intended rx way
    var receivedFrames = Observable.FromEvent(????)    /////////// How?
}

void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
    // do something
}
</code>```

I know I cannot use Observable.FromEventPattern, but don't know what to use instead, much less how.

答:
I came up with this (and tested it in LinqPad)

```<code>var observable = Observable.FromEvent<NewFrameEventHandler, NewFrameEventArgs>(
    (handler) =>
    {
        NewFrameEventHandler frameHandler = (sender, e) =>
        {
            handler(e);
        };

        return frameHandler;
    },
    eh => videoSource.NewFrame += eh,
    eh => videoSource.NewFrame -= eh
);

observable.Subscribe((frameEventArgs) => { frameEventArgs.Dump(); });
</code>```

It was a nice exercise based on the answers of this question.

So it uses this overload of Observable.FromEvent.

Happy to know if it could be written more compact.

Body:
I am using Accord (previously AForge) to capture image frames from a webcam.

These images arrive via a VideoCaptureDevice.NewFrame event:

public delegate void NewFrameEventHandler(object sender, NewFrameEventArgs eventArgs);

public class NewFrameEventArgs : EventArgs
{
    public Bitmap Frame { get; }

    public NewFrameEventArgs(Bitmap frame);
}

The problem is, I tried to use Observable.FromEvent, but got lost in the many possible overloads:

void Run()
{
    var videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);

    VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString);

    // regular way
    videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);

    // intended rx way
    var receivedFrames = Observable.FromEvent(????)    /////////// How?
}

void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
    // do something
}

I know I cannot use Observable.FromEventPattern, but don't know what to use instead, much less how.

Body:
I came up with this (and tested it in LinqPad)

var observable = Observable.FromEvent<NewFrameEventHandler, NewFrameEventArgs>(
    (handler) =>
    {
        NewFrameEventHandler frameHandler = (sender, e) =>
        {
            handler(e);
        };

        return frameHandler;
    },
    eh => videoSource.NewFrame += eh,
    eh => videoSource.NewFrame -= eh
);

observable.Subscribe((frameEventArgs) => { frameEventArgs.Dump(); });

It was a nice exercise based on the answers of this question.

So it uses this overload of Observable.FromEvent.

Happy to know if it could be written more compact.


问:
Cloudfront Error when uploading images to s3 "No Such Key"
I am developing an iOS app which will allow users to update and change their avatar where the images are being stored in S3 in subdirectories depending on their user id. Eg: "/1005/avatar_3dseuori.jpg".

I have setup cloudfront to distribute these images stored in my S3 bucket, however I am getting the following response:

```<code><Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
</code>```

even though the image exists in my bucket.  If I wait ~5 minutes, I am then able to see the image using my cloudfront origin.  Is this a usual waiting period?

答:
CloudFront is acting as a front-end cache to your S3 origin.

When you request the image from CloudFront, it will check it's cache, and if it does not exist in the cache (and has not expired based on the configured TTL), only then will it request the image from your S3 origin bucket.

If you request the image from CloudFront before the image exists in S3, then CloudFront will cache the NoSuchKey result. This is because the object actually does not exist yet in S3.

After uploading the file to S3, CloudFront will continue to respond with the cached NoSuchKey value until the configured time-to-live expires. In your case, that may be "5 minutes". After that time period, it re-requests the image from S3, this time with a positive result.

To avoid this issue, ensure you prevent requests to CloudFront for images that do not exist.

Body:
I am developing an iOS app which will allow users to update and change their avatar where the images are being stored in S3 in subdirectories depending on their user id. Eg: "/1005/avatar_3dseuori.jpg".

I have setup cloudfront to distribute these images stored in my S3 bucket, however I am getting the following response:

NoSuchKey
<Message>The specified key does not exist.</Message>

even though the image exists in my bucket.  If I wait ~5 minutes, I am then able to see the image using my cloudfront origin.  Is this a usual waiting period?


问:
Finding first and last elements in time added to Guava LinkedHashMultimap/HashMultiMap
I have a stream of timestamped stats coming for every minute(arbitrary number of stats for each min). It's just an ongoing stream of stats and no change in previous is allowed. Also there is no concurrency issue here. So the appropriate data structure is a map<timestamp,list<stats>>. However this map only needs to keep data for last 30 mins so it should also kick out the first element and write the new one(circular buffer). I've been told Guava HashMultimap is a good candidate to use. But I can't figure out how I can use it and find the first and last elements of map and how to delete the last element. When I look at LinkedHashMultiMap I don't see any method for finding first or last elements. I appreciate any help.

答:
There are a couple of approaches you can take. I will explain and show examples of both. I will not address synchronization, if that is necessary let me know and I can add details to ensure the Multimap code is threadsafe. This involves correctly synchronizing on the multimap when accessing its views and wrapping it in a synchronized wrapper. More details can also be found here.

Use a Multimap

Use Guava's Cache

For the Multimap approach, I would recommend you use the LinkedListMultimap. It will ensure your keys are ordered and your values are ordered (since you originally stated Map<Timestamp, List<Stat>>. A LinkedHashMultimap will preserve the order but it will remove duplicate stats. If this isn't a concern, then you could use LinkedHashMultimap.

To get the first key value, you can use the iterator or use Guava's Iterables getFirst(Iteratable, defaultValue) utility method. To get the last key value, you can Iterables getLast(Iteratable, defaultValue) method.
If your goal is just to remove the values older than 30 minutes, you could ignore Iterables and just use the iterator of they Multimap's keys.

```<code>LinkedHashMultimap<Date, Stat> stats = LinkedHashMultimap.create();

//Every minute
stats.putAll(new Date(), newStats);

//To get the first key inserted into the map
Date first = Iterables.getFirst(stats.keys(), null);
//Remove the first entry
stats.remove(first);

//To get the last key inserted into the map
Date last = Iterables.getLast(stats.keys(), null);
//Remove the last entry
stats.remove(last);

//Without using Iterables.
Set<Date> keys = stats.keys();
if (!keys.isEmpty()) {
    keys.iterator().next().remove();
}
</code>```

The Multimap approach requires you to manually manage removing old stats. A slightly simpler approach in this regard would be to use Guava's Cache. Note, however, that this does not maintain order of any kind and would be more difficult to get the values for a time, since you would not have the exact timestamp of when the stats were inserted. You would need to create your own custom Date class with a .hashCode() and .equals(Object) method that would work for your needs. This may be more work than it is worth.

```<code>Cache<CustomDate, List<Stat>> cache = CacheBuilder.newBuilder()
        .expireAfterWrite(30, TimeUnit.MINUTES)
        .build();

cache.put(new CustomDate(), stats);
List<Stat> statsForTime = cache.get(new CustomDate(/*appropriate initialization*/));
</code>```

Body:
There are a couple of approaches you can take. I will explain and show examples of both. I will not address synchronization, if that is necessary let me know and I can add details to ensure the Multimap code is threadsafe. This involves correctly synchronizing on the multimap when accessing its views and wrapping it in a synchronized wrapper. More details can also be found here.

Use a Multimap

Use Guava's Cache

For the Multimap approach, I would recommend you use the LinkedListMultimap. It will ensure your keys are ordered and your values are ordered (since you originally stated Map<Timestamp, List<Stat>>. A LinkedHashMultimap will preserve the order but it will remove duplicate stats. If this isn't a concern, then you could use LinkedHashMultimap.

To get the first key value, you can use the iterator or use Guava's Iterables getFirst(Iteratable, defaultValue) utility method. To get the last key value, you can Iterables getLast(Iteratable, defaultValue) method.
If your goal is just to remove the values older than 30 minutes, you could ignore Iterables and just use the iterator of they Multimap's keys.

LinkedHashMultimap<Date, Stat> stats = LinkedHashMultimap.create();

//Every minute
stats.putAll(new Date(), newStats);

//To get the first key inserted into the map
Date first = Iterables.getFirst(stats.keys(), null);
//Remove the first entry
stats.remove(first);

//To get the last key inserted into the map
Date last = Iterables.getLast(stats.keys(), null);
//Remove the last entry
stats.remove(last);

//Without using Iterables.
Set<Date> keys = stats.keys();
if (!keys.isEmpty()) {
    keys.iterator().next().remove();
}

The Multimap approach requires you to manually manage removing old stats. A slightly simpler approach in this regard would be to use Guava's Cache. Note, however, that this does not maintain order of any kind and would be more difficult to get the values for a time, since you would not have the exact timestamp of when the stats were inserted. You would need to create your own custom Date class with a .hashCode() and .equals(Object) method that would work for your needs. This may be more work than it is worth.

Cache<CustomDate, List<Stat>> cache = CacheBuilder.newBuilder()
        .expireAfterWrite(30, TimeUnit.MINUTES)
        .build();

cache.put(new CustomDate(), stats);
List<Stat> statsForTime = cache.get(new CustomDate(/*appropriate initialization*/));


问:
Web Scraping on a page
I wanted to scrape the table on this link. I was trying to use selenium to get the data after the page loaded but I was unsuccessful. Any other ideas on how I can scrape the table from that webpage?

EDIT -

I tried

```<code>from selenium import webdriver
driver = webdriver.PhantomJS()
driver.get("https://steria.taleo.net/careersection/in_cs_ext_fs/jobsearch.ftl?lang=en&radiusType=K&location=462170431401&searchExpanded=true&radius=1")
print(driver.find_element_by_class_name('table').text)
driver.close()
</code>```

答:
As table content generated dynamically, you should wait until JavaScript executed to be able to get required data:

```<code>from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium import webdriver

driver = webdriver.PhantomJS()
driver.get("https://steria.taleo.net/careersection/in_cs_ext_fs/jobsearch.ftl?lang=en&radiusType=K&location=462170431401&searchExpanded=true&radius=1")
table = wait(driver, 10).until(EC.presence_of_element_located(("xpath", "//table[@id='jobs' and ./tbody/tr]")))
print(table.text)
next_button = driver.find_element_by_link_text("Next")
next_button.click()

wait(driver, 5).until(lambda x: next_button.get_attribute("aria-disabled") == "true")
table = wait(driver, 10).until(EC.presence_of_element_located(("xpath", "//table[@id='jobs' and ./tbody/tr]")))
print(table.text)
driver.close()
</code>```

Title: Web Scraping on a page

Body:
I wanted to scrape the table on this link. I was trying to use selenium to get the data after the page loaded but I was unsuccessful. Any other ideas on how I can scrape the table from that webpage?

EDIT -

I tried

from selenium import webdriver
driver = webdriver.PhantomJS()
driver.get("https://steria.taleo.net/careersection/in_cs_ext_fs/jobsearch.ftl?lang=en&radiusType=K&location=462170431401&searchExpanded=true&radius=1")
print(driver.find_element_by_class_name('table').text)
driver.close()

Body:
As table content generated dynamically, you should wait until JavaScript executed to be able to get required data:

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium import webdriver

driver = webdriver.PhantomJS()
driver.get("https://steria.taleo.net/careersection/in_cs_ext_fs/jobsearch.ftl?lang=en&radiusType=K&location=462170431401&searchExpanded=true&radius=1")
table = wait(driver, 10).until(EC.presence_of_element_located(("xpath", "//table[@id='jobs' and ./tbody/tr]")))
print(table.text)
next_button = driver.find_element_by_link_text("Next")
next_button.click()

wait(driver, 5).until(lambda x: next_button.get_attribute("aria-disabled") == "true")
table = wait(driver, 10).until(EC.presence_of_element_located(("xpath", "//table[@id='jobs' and ./tbody/tr]")))
print(table.text)
driver.close()


问:
Google maps API Basic Example
I've been unable to get the basic Google maps example working on my site.  I have the following div on my page:

```<code><div id="map_canvas" style="width:100%; height:100%"></div>
</code>```

And the following in the head of my document:

```<code><script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
    function initialize() {
        var latlng = new google.maps.LatLng(-34.397, 150.644);
        var myOptions = {
            zoom: 8,
            center: latlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    }
    jQuery(document).ready(initialize);
</script>
</code>```

It appears that the elements are getting loaded into my DOM, but there is no visible map on the page.

答:
the code looks ok and it's similar to the examples from the documentation so it should be working properly.

Have you tried printing some information on the screen from the initialize function? Check if the latlng, myoptions and map variables are created correctly.

If they are, there's a problem with calling the initialize function...

Title: Google maps API Basic Example

Body:
I've been unable to get the basic Google maps example working on my site.  I have the following div on my page:

And the following in the head of my document:

It appears that the elements are getting loaded into my DOM, but there is no visible map on the page.


问:
Build Boost Coroutine2
As this has been marked as duplicate earlier: This problem has nothing to do with the basic "How to install boost...". Boost is installed and all libraries but coroutine2 are working correctly. So this is a coroutine2 problem.

When trying to compile my project I get the following linker error:

```<code>LNK1104 cannot open file 'libboost_coroutine2-vc140-mt-gd-1_64.lib'
</code>```

After checking I noticed that file was missing, even though I built boost with the following command:

```<code>b2 install --build-type=complete msvc -mt
</code>```

So I tried to build it manually using the following command:

```<code>b2 install --build-type=complete msvc -mt --with-coroutine2
</code>```

Something interesting happened: It built Boost.Context (which was already built by the first command) which it is built on, but no Coroutine2 lib in sight.

Now I tried to run the project on my other computer with boost 1.61 installed - and it worked flawlessly! After checking the coroutine2/detail/config.hpp (which determines which library to link against) I noticed that boost 1.61 wants to load the coroutine lib while boost 1.64 requires a coroutine2 lib...

On Boosts Getting Started page Coroutine2 isn't listed as a "has-to-be-built" library and after dissecting the config.hpp file I came up with the idea to define #define BOOST_COROUTINES2_NO_LIB which resulted in many unknown symbols...

I don't know what else I can do, please help, dear professionals :)

答:
boost.coroutine2 is a header-only library - a libboost_coroutine2-vc140-mt-gd-1_64.lib ist not created. You should check the linker flags of your project and remove the reference to libboost_coroutine2.

EDIT: remove sub directory 'build' from boost.coroutine2

Title: Build Boost Coroutine2

Body:
As this has been marked as duplicate earlier: This problem has nothing to do with the basic "How to install boost...". Boost is installed and all libraries but coroutine2 are working correctly. So this is a coroutine2 problem.

When trying to compile my project I get the following linker error:

LNK1104 cannot open file 'libboost_coroutine2-vc140-mt-gd-1_64.lib'

After checking I noticed that file was missing, even though I built boost with the following command:

b2 install --build-type=complete msvc -mt

So I tried to build it manually using the following command:

b2 install --build-type=complete msvc -mt --with-coroutine2

Something interesting happened: It built Boost.Context (which was already built by the first command) which it is built on, but no Coroutine2 lib in sight.

Now I tried to run the project on my other computer with boost 1.61 installed - and it worked flawlessly! After checking the coroutine2/detail/config.hpp (which determines which library to link against) I noticed that boost 1.61 wants to load the coroutine lib while boost 1.64 requires a coroutine2 lib...

On Boosts Getting Started page Coroutine2 isn't listed as a "has-to-be-built" library and after dissecting the config.hpp file I came up with the idea to define #define BOOST_COROUTINES2_NO_LIB which resulted in many unknown symbols...

I don't know what else I can do, please help, dear professionals :)


问:
Apache Spark - foreach Vs foreachPartition When to use What?
I would like to know if the foreachPartition will results in better performance,  due to an higher level of parallelism, compared to the foreach method considering the case in which I'm flowing through an RDD in order to perform some sums into an accumulator variable.

答:
foreachPartition is only helpful when you're iterating through data which you are aggregating by partition.

A good example is processing clickstreams per user. You'd want to clear your calculation cache every time you finish a user's stream of events, but keep it between records of the same user in order to calculate some user behavior insights.

ContentLicense: CC BY-SA 4.0


问:
Show a child form in the centre of Parent form in C#
I create a new form and call from the parent form as follows:

```<code>loginForm = new SubLogin();
loginForm.Show();
</code>```

I need to display the child form at the centre of the parent. So,in the child form load I do the foll:`

```<code>Point p = new Point(this.ParentForm.Width / 2 - this.Width / 2, this.ParentForm.Height / 2 - this.Height / 2);
this.Location = p;
</code>```

But this is throwing error as parent form is null. I tried setting the Parent property as well, but didn't help. Any inputs on this?

答:
You can set the StartPosition in the constructor of the child form so that all new instances of the form get centered to it's parent:

```<code>public MyForm()
{
    InitializeComponent();

    this.StartPosition = FormStartPosition.CenterParent;
}
</code>```

Of course, you could also set the StartPosition property in the Designer properties for your child form.  When you want to display the child form as a modal dialog, just set the window owner in the parameter for the ShowDialog method:

```<code>private void buttonShowMyForm_Click(object sender, EventArgs e)
{
    MyForm form = new MyForm();
    form.ShowDialog(this);
}
</code>```

OwnerDisplayName: Newbiee

Body:
I create a new form and call from the parent form as follows:

loginForm = new SubLogin();
loginForm.Show();

I need to display the child form at the centre of the parent. So,in the child form load I do the foll:`

Point p = new Point(this.ParentForm.Width / 2 - this.Width / 2, this.ParentForm.Height / 2 - this.Height / 2);
this.Location = p;

But this is throwing error as parent form is null. I tried setting the Parent property as well, but didn't help. Any inputs on this?

Body:
You can set the StartPosition in the constructor of the child form so that all new instances of the form get centered to it's parent:

public MyForm()
{
    InitializeComponent();

    this.StartPosition = FormStartPosition.CenterParent;
}

Of course, you could also set the StartPosition property in the Designer properties for your child form.  When you want to display the child form as a modal dialog, just set the window owner in the parameter for the ShowDialog method:

private void buttonShowMyForm_Click(object sender, EventArgs e)
{
    MyForm form = new MyForm();
    form.ShowDialog(this);
}