问:
excluding web.config with msbuild
I have below msbuild which is executed by team city. I want to exclude web.config but cannot do. In code below you can see i added code but it doesnt work. I am totally novice in msbuild and teamcity

```<code><property name="solution.dir" value="." />
<property name="SolutionFileName" value="MyProj.sln" />
<property name="projectfile" value="${solution.dir}\MyDir\Myproj.csproj" />
<property name="MSBuildPath" value="C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" />
<ItemGroup>
<MyProjectReferences Exclude="web.config" />
</ItemGroup>
<target name="build" depends="clean,UpdateBuildVersion,compile" />
<target name="clean" description="delete build artifacts">
  <property name="build.base" value="${solution.dir}/_deploy/" />
  <property name="dir.publish" value="${build.base}/publish" />
  <property name="dir.package" value="${build.base}/package" />
  <property name="project.fullversion" value="1.0.0.1" />

</target>
<target name="compile" description="compile">

  <exec program="${MSBuildPath}" failonerror="true">
   <arg value="${projectfile}" />
   <arg line="/p:Configuration=Release" />
   <arg line="/p:UseWPP_CopyWebApplication=True" />
   <arg line="/p:PipelineDependsOnBuild=False"/>
   <arg line="/t:Rebuild" />
   <arg line="/t:Package" />
   <arg line="/p:IncludeAppPool=true" />
   <arg line="/p:PackageLocation=${solution.dir}/../publish/package/Myproj.zip" />
  <arg line="/P:DeployIisAppPath=website/MyProj" />
  <!--<arg line="-skip:objectName=filePath,absolutePath=.*web\.config"></arg>-->

  </exec>
 </target>
</code>```

Can somebody point me to right direction?

答:
Ok, to start, the syntax for the build is way off. But you are new to msbuild. So I have tried to interpret what it is you would need based off of what you gave us here.

So here is your script somewhat reinterpreted:

```<code><?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="Choose something else here too">
  <PropertyGroup>
    <SolutionDir>C:\Some\Path\Where\You\Keep\your\Solution\</SolutionDir>
    <BuildDir>C:\Some\Path\where\your\build\goes\that\is\outside\of\your\repo\</BuildDir>
  </PropertyGroup>
  <ItemGroup>
    <MyProject include="$(SolutionDir)MyDir\MyProj.csproj" >
      <Properties>Condiguration=Release;UseWPP_CopyWebApplication=True;PipelineDependsOnBuild=False;IncludeAppPool=true;PackageLocation=$(SolutionDir);DeployIisAppPath=website\MyProj</Properties>
    </MyProject>
  </ItemGroup>
  <Target name="clean">
    <!-- The best thing to do is to call msbuild with the clean target. -->
    <MSBuild Projects="@(MyProject)" Targets="Clean" />
    <!-- Then delete anything else you want to -->
    <Delete Files="" />
    <!-- I like to just delete the build directory for cleaning -->
    <RemoveDir Directories="$(BuildDir)" />
  </Target>

  <Target name="updateBuildVersion">
    <!-- Do what ever you need to here. -->
  </Target>

  <Target name="Build" DependsOnTargets="clean;updateBuildVersion">
    <MSBuild Projects="@(MyProject" Targets="Build" StopOnFirstFailure="true" />
  </Target>
</Project>
</code>```

Comment back here if you have questions and I'll do my best to help answer them.

Title: excluding web.config with msbuild

Body:
I have below msbuild which is executed by team city. I want to exclude web.config but cannot do. In code below you can see i added code but it doesnt work. I am totally novice in msbuild and teamcity

<property name="solution.dir" value="." />
<property name="SolutionFileName" value="MyProj.sln" />
<property name="projectfile" value="${solution.dir}\MyDir\Myproj.csproj" />
<property name="MSBuildPath" value="C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" />
<ItemGroup>
<MyProjectReferences Exclude="web.config" />
</ItemGroup>
<target name="build" depends="clean,UpdateBuildVersion,compile" />
<target name="clean" description="delete build artifacts">
  <property name="build.base" value="${solution.dir}/_deploy/" />
  <property name="dir.publish" value="${build.base}/publish" />
  <property name="dir.package" value="${build.base}/package" />
  <property name="project.fullversion" value="1.0.0.1" />

</target>
<target name="compile" description="compile">

  <exec program="${MSBuildPath}" failonerror="true">
   <arg value="${projectfile}" />
   <arg line="/p:Configuration=Release" />
   <arg line="/p:UseWPP_CopyWebApplication=True" />
   <arg line="/p:PipelineDependsOnBuild=False"/>
   <arg line="/t:Rebuild" />
   <arg line="/t:Package" />
   <arg line="/p:IncludeAppPool=true" />
   <arg line="/p:PackageLocation=${solution.dir}/../publish/package/Myproj.zip" />
  <arg line="/P:DeployIisAppPath=website/MyProj" />

  </exec>
 </target>

Can somebody point me to right direction?

Body:
Ok, to start, the syntax for the build is way off. But you are new to msbuild. So I have tried to interpret what it is you would need based off of what you gave us here.

So here is your script somewhat reinterpreted:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="Choose something else here too">
  <PropertyGroup>
    <SolutionDir>C:\Some\Path\Where\You\Keep\your\Solution\</SolutionDir>
    <BuildDir>C:\Some\Path\where\your\build\goes\that\is\outside\of\your\repo\</BuildDir>
  </PropertyGroup>
  <ItemGroup>
    <MyProject include="$(SolutionDir)MyDir\MyProj.csproj" >
      <Properties>Condiguration=Release;UseWPP_CopyWebApplication=True;PipelineDependsOnBuild=False;IncludeAppPool=true;PackageLocation=$(SolutionDir);DeployIisAppPath=website\MyProj</Properties>
    </MyProject>
  </ItemGroup>
  <Target name="clean">
    <!-- The best thing to do is to call msbuild with the clean target. -->
    <MSBuild Projects="@(MyProject)" Targets="Clean" />
    <!-- Then delete anything else you want to -->
    <Delete Files="" />
    <!-- I like to just delete the build directory for cleaning -->
    <RemoveDir Directories="$(BuildDir)" />
  </Target>

  <Target name="updateBuildVersion">
    <!-- Do what ever you need to here. -->
  </Target>

  <Target name="Build" DependsOnTargets="clean;updateBuildVersion">
    <MSBuild Projects="@(MyProject" Targets="Build" StopOnFirstFailure="true" />
  </Target>
</Project>

Comment back here if you have questions and I'll do my best to help answer them.


来源: stackexchange

问:
Remove rows having same value in all columns
I have a pandas dataframe that I'm trying to drop rows based on all columns having exact same value. Here's an example to help understand the idea.

Input:

```<code>index  A  B  C  D  E  F ....
 0     1  2  3  1  3  4
 1     2  2  2  2  2  2
 2     5  5  5  5  5  5
 3     7  7  6  7  7  7
</code>```

Output:

```<code>index  A  B  C  D  E  F ....
 0     1  2  3  1  3  4
 3     7  7  6  7  7  7
</code>```

There can be many columns here.

答:
An efficient way of doing this with numeric DataFrames is to use the standard deviation (which will be 0 only if all values are the same):

```<code>df[df.std(axis=1) > 0]
Out:
   A  B  C  D  E  F
0  1  2  3  1  3  4
3  7  7  6  7  7  7
</code>```

Timings with 40k rows:

```<code>%timeit df[df.std(axis=1) > 0]
1000 loops, best of 3: 1.69 ms per loop

%timeit df[df.nunique(1)>1]
1 loop, best of 3: 2.62 s per loop
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I have a pandas dataframe that I'm trying to drop rows based on all columns having exact same value. Here's an example to help understand the idea.

Input:

index  A  B  C  D  E  F ....
 0     1  2  3  1  3  4
 1     2  2  2  2  2  2
 2     5  5  5  5  5  5
 3     7  7  6  7  7  7

Output:

index  A  B  C  D  E  F ....
 0     1  2  3  1  3  4
 3     7  7  6  7  7  7

There can be many columns here.

Body:
An efficient way of doing this with numeric DataFrames is to use the standard deviation (which will be 0 only if all values are the same):

df[df.std(axis=1) > 0]
Out:
   A  B  C  D  E  F
0  1  2  3  1  3  4
3  7  7  6  7  7  7

Timings with 40k rows:

%timeit df[df.std(axis=1) > 0]
1000 loops, best of 3: 1.69 ms per loop

%timeit df[df.nunique(1)>1]
1 loop, best of 3: 2.62 s per loop


问:
C-like Array template specialization
How can I write the template for generic array

```<code>template <class T, std::size_t N>
struct Data<T[N]> {}
</code>```

in a way that I can access it's elements by [] operator (or any other way)?

```<code>#include <fstream>
#include <iostream>
#include <sstream>
#include <utility>

template <typename T>
struct Data;

template <typename T>
std::ostream& operator<<(std::ostream& os, const Data<T>& val) {
    return val(os);
}

template <typename T>
Data<std::remove_cv_t<T>> data(const T& val) { return { val }; }

template <>
struct Data<int> {
    std::ostream& operator()(std::ostream& os) const {
        os << val;
        return os;
    }
    const int& val;
};

template <class T, std::size_t N>
struct Data<T[N]> {
    std::ostream& operator()(std::ostream& os) const {
        for (std::size_t i = 0; i < N; i++) {
            os << data(val[i]);
        }
        return os;
    }
    T val;
};
</code>```

Error when accessing:

```<code>error: subscripted value is not an array, pointer, or vector
                    os << data(val[i]);
                               ^~~ ~
</code>```

It seems that I should change <T[N]> for something like <T(&)[N]> to catch reference for the array, but I can't work it out.
Or maybe the T val; should be in T* val;, because the array is degenerating to pointer, so I can "catch" it?

EDIT 1

For T val[N]; the error is:

```<code>error: cannot initialize an array element of type 'int' with an lvalue of type 'int const[2]'
Data<std::remove_cv_t<T>> data(const T& val) { return { val }; }
                                                    ^~~
</code>```

EDIT 2

When I try to use

```<code>template <typename T, size_t N>
struct Data<std::array<T, N> >
</code>```

then it's doesn't correspond to any template.

```<code>error: implicit instantiation of undefined template 'PrettyPrint::Data<int [2]>'
    sstream << PrettyPrint::data(val);
               ^
</code>```

答:
The correct template was

```<code>template <typename T, std::size_t N>
struct Data<T[N]> {
    std::ostream& operator()(std::ostream& os) const {
        for (std::size_t i = 0; i < N; i++) {
            os << data(val[i]);
        }
        return os;
    }
    const T(&val)[N];
};
</code>```

What is the reason for const T(&val)[N];? I'm thinking about catching the reference in contrast to array degeneration to pointer, but I would be really glad if somebody explained it to me in greater depth.

Title: C-like Array template specialization

Body:
How can I write the template for generic array

template <class T, std::size_t N>
struct Data<T[N]> {}

in a way that I can access it's elements by [] operator (or any other way)?

#include <fstream>
#include <iostream>
#include <sstream>
#include <utility>

template <typename T>
struct Data;

template <typename T>
std::ostream& operator<<(std::ostream& os, const Data<T>& val) {
    return val(os);
}

template <typename T>
Data<std::remove_cv_t<T>> data(const T& val) { return { val }; }

template <>
struct Data<int> {
    std::ostream& operator()(std::ostream& os) const {
        os << val;
        return os;
    }
    const int& val;
};

template <class T, std::size_t N>
struct Data<T[N]> {
    std::ostream& operator()(std::ostream& os) const {
        for (std::size_t i = 0; i < N; i++) {
            os << data(val[i]);
        }
        return os;
    }
    T val;
};

Error when accessing:

error: subscripted value is not an array, pointer, or vector
                    os << data(val[i]);
                               ^~~ ~

It seems that I should change <T[N]> for something like <T(&)[N]> to catch reference for the array, but I can't work it out.
Or maybe the T val; should be in T* val;, because the array is degenerating to pointer, so I can "catch" it?

EDIT 1

For T val[N]; the error is:

error: cannot initialize an array element of type 'int' with an lvalue of type 'int const[2]'
Data<std::remove_cv_t<T>> data(const T& val) { return { val }; }
                                                    ^~~

EDIT 2

When I try to use

template <typename T, size_t N>
struct Data<std::array<T, N> >

then it's doesn't correspond to any template.

error: implicit instantiation of undefined template 'PrettyPrint::Data<int [2]>'
    sstream << PrettyPrint::data(val);
               ^

Body:
The correct template was

template <typename T, std::size_t N>
struct Data<T[N]> {
    std::ostream& operator()(std::ostream& os) const {
        for (std::size_t i = 0; i < N; i++) {
            os << data(val[i]);
        }
        return os;
    }
    const T(&val)[N];
};

What is the reason for const T(&val)[N];? I'm thinking about catching the reference in contrast to array degeneration to pointer, but I would be really glad if somebody explained it to me in greater depth.


问:
What is the best way in python to get a denormalized array from this ordered array?
I have this array:

```<code>>>> print raw_data
['LEVEL 1',
'SUBJECT A',
'GROUP X',
'COMMENT i',
'COMMENT ii',
'COMMENT iii',
'GROUP Y',
'COMMENT iv',
'COMMENT v',
'COMMENT vi',
'LEVEL 2',
'SUBJECT B',
'GROUP Z',
'COMMENT vii',
'COMMENT viii',
'COMMENT ix',
'SUBJECT C',
'GROUP X2',
'COMMENT x',
'COMMENT xi',
'COMMENT xii',
'COMMENT xiii',
'GROUP Y2',
'COMMENT xiv',
'COMMENT xv',
'COMMENT xvi']
</code>```

Where the obvious hierarchy is:

Level

Subject

Group

Comments

My objective is to get the array as a denormalized array to be store on a database:

```<code>>>> print result
[
    ['LEVEL 1', 'SUBJECT A', 'GROUP X', 'COMMENT i'],
    ['LEVEL 1', 'SUBJECT A', 'GROUP X', 'COMMENT ii'],
    ['LEVEL 1', 'SUBJECT A', 'GROUP X', 'COMMENT iii'],
    ['LEVEL 1', 'SUBJECT A', 'GROUP Y', 'COMMENT iv'],
    ['LEVEL 1', 'SUBJECT A', 'GROUP Y', 'COMMENT v'],
    ['LEVEL 1', 'SUBJECT A', 'GROUP Y', 'COMMENT vi'],
    ['LEVEL 2', 'SUBJECT B', 'GROUP Z', 'COMMENT vi'],
    ['LEVEL 2', 'SUBJECT B', 'GROUP Z', 'COMMENT vii'],
    ['LEVEL 2', 'SUBJECT B', 'GROUP Z', 'COMMENT viii'],
    ['LEVEL 2', 'SUBJECT B', 'GROUP Z', 'COMMENT ix'],
    ['LEVEL 2', 'SUBJECT C', 'GROUP X1', 'COMMENT x'],
    ['LEVEL 2', 'SUBJECT C', 'GROUP X1', 'COMMENT xi'],
    ['LEVEL 2', 'SUBJECT C', 'GROUP X1', 'COMMENT xii'],
    ['LEVEL 2', 'SUBJECT C', 'GROUP X1', 'COMMENT xiii],'
    ['LEVEL 2', 'SUBJECT C', 'GROUP Y2', 'COMMENT xiv'],
    ['LEVEL 2', 'SUBJECT C', 'GROUP Y2', 'COMMENT xv'],
    ['LEVEL 2', 'SUBJECT C', 'GROUP Y2', 'COMMENT xi']
]
</code>```

I was trying to solve this, but I am quite lost, I think this problem has to be usual, so I would like to know if someone has a efficient approach, this seems to be something like nested sets, but I don't know a lot of this on python, getting the level is easy, but I am getting " headaches" getting this further.

```<code>>>> def addlevel(a):
    if a.startswith('LEVEL'):
        return [1, a]
    elif a.startswith('SUBJECT'):
        return [2, a]
    elif a.startswith('GROUP'):
        return [3, a]
    elif a.startswith('COMMENT'):
        return [4, a]
>>> map(addlevel, raw_data)
[[1, 'LEVEL 1'],
 [2, 'SUBJECT A'],
 [3, 'GROUP X'],
 [4, 'COMMENT i'],
 [4, 'COMMENT ii'],
 [4, 'COMMENT iii'],
 [3, 'GROUP Y'],
 [4, 'COMMENT iv'],
 [4, 'COMMENT v'],
 [4, 'COMMENT vi'],
 [1, 'LEVEL 2'],
 [2, 'SUBJECT B'],
 [3, 'GROUP Z'],
 [4, 'COMMENT vii'],
 [4, 'COMMENT viii'],
 [4, 'COMMENT ix'],
 [2, 'SUBJECT C'],
 [3, 'GROUP X2'],
 [4, 'COMMENT x'],
 [4, 'COMMENT xi'],
 [4, 'COMMENT xii'],
 [4, 'COMMENT xiii'],
 [3, 'GROUP Y2'],
 [4, 'COMMENT xiv'],
 [4, 'COMMENT xv'],
 [4, 'COMMENT xvi']]
</code>```

I would appreciate any clues !

答:
Pseudocode, don't have a handy python interpreter right now:

```<code>Set LEVEL, SUBJECT, GROUP to None, results to []

Loop over the list
  if its a 'LEVEL', set LEVEL to it
  if its a 'SUBJECT', set SUBJECT to it
  if its a 'GROUP', set GROUP to it
  if its a "COMMENT", append [LEVEL SUBJECT GROUP and COMMENT] to results
Ta-da.
</code>```

It just relies on the ordering...

ContentLicense: CC BY-SA 2.5

Body:
I have this array:

>>> print raw_data
['LEVEL 1',
'SUBJECT A',
'GROUP X',
'COMMENT i',
'COMMENT ii',
'COMMENT iii',
'GROUP Y',
'COMMENT iv',
'COMMENT v',
'COMMENT vi',
'LEVEL 2',
'SUBJECT B',
'GROUP Z',
'COMMENT vii',
'COMMENT viii',
'COMMENT ix',
'SUBJECT C',
'GROUP X2',
'COMMENT x',
'COMMENT xi',
'COMMENT xii',
'COMMENT xiii',
'GROUP Y2',
'COMMENT xiv',
'COMMENT xv',
'COMMENT xvi']

Where the obvious hierarchy is:

Level

Subject

Group

Comments

My objective is to get the array as a denormalized array to be store on a database:

>>> print result
[
    ['LEVEL 1', 'SUBJECT A', 'GROUP X', 'COMMENT i'],
    ['LEVEL 1', 'SUBJECT A', 'GROUP X', 'COMMENT ii'],
    ['LEVEL 1', 'SUBJECT A', 'GROUP X', 'COMMENT iii'],
    ['LEVEL 1', 'SUBJECT A', 'GROUP Y', 'COMMENT iv'],
    ['LEVEL 1', 'SUBJECT A', 'GROUP Y', 'COMMENT v'],
    ['LEVEL 1', 'SUBJECT A', 'GROUP Y', 'COMMENT vi'],
    ['LEVEL 2', 'SUBJECT B', 'GROUP Z', 'COMMENT vi'],
    ['LEVEL 2', 'SUBJECT B', 'GROUP Z', 'COMMENT vii'],
    ['LEVEL 2', 'SUBJECT B', 'GROUP Z', 'COMMENT viii'],
    ['LEVEL 2', 'SUBJECT B', 'GROUP Z', 'COMMENT ix'],
    ['LEVEL 2', 'SUBJECT C', 'GROUP X1', 'COMMENT x'],
    ['LEVEL 2', 'SUBJECT C', 'GROUP X1', 'COMMENT xi'],
    ['LEVEL 2', 'SUBJECT C', 'GROUP X1', 'COMMENT xii'],
    ['LEVEL 2', 'SUBJECT C', 'GROUP X1', 'COMMENT xiii],'
    ['LEVEL 2', 'SUBJECT C', 'GROUP Y2', 'COMMENT xiv'],
    ['LEVEL 2', 'SUBJECT C', 'GROUP Y2', 'COMMENT xv'],
    ['LEVEL 2', 'SUBJECT C', 'GROUP Y2', 'COMMENT xi']
]

I was trying to solve this, but I am quite lost, I think this problem has to be usual, so I would like to know if someone has a efficient approach, this seems to be something like nested sets, but I don't know a lot of this on python, getting the level is easy, but I am getting " headaches" getting this further.

>>> def addlevel(a):
    if a.startswith('LEVEL'):
        return [1, a]
    elif a.startswith('SUBJECT'):
        return [2, a]
    elif a.startswith('GROUP'):
        return [3, a]
    elif a.startswith('COMMENT'):
        return [4, a]
>>> map(addlevel, raw_data)
[[1, 'LEVEL 1'],
 [2, 'SUBJECT A'],
 [3, 'GROUP X'],
 [4, 'COMMENT i'],
 [4, 'COMMENT ii'],
 [4, 'COMMENT iii'],
 [3, 'GROUP Y'],
 [4, 'COMMENT iv'],
 [4, 'COMMENT v'],
 [4, 'COMMENT vi'],
 [1, 'LEVEL 2'],
 [2, 'SUBJECT B'],
 [3, 'GROUP Z'],
 [4, 'COMMENT vii'],
 [4, 'COMMENT viii'],
 [4, 'COMMENT ix'],
 [2, 'SUBJECT C'],
 [3, 'GROUP X2'],
 [4, 'COMMENT x'],
 [4, 'COMMENT xi'],
 [4, 'COMMENT xii'],
 [4, 'COMMENT xiii'],
 [3, 'GROUP Y2'],
 [4, 'COMMENT xiv'],
 [4, 'COMMENT xv'],
 [4, 'COMMENT xvi']]

I would appreciate any clues !

Body:
Pseudocode, don't have a handy python interpreter right now:

Set LEVEL, SUBJECT, GROUP to None, results to []

Loop over the list
  if its a 'LEVEL', set LEVEL to it
  if its a 'SUBJECT', set SUBJECT to it
  if its a 'GROUP', set GROUP to it
  if its a "COMMENT", append [LEVEL SUBJECT GROUP and COMMENT] to results
Ta-da.

It just relies on the ordering...


问:
Itunes Store Operation failed with Xcode 9.2
```<code>Im use version Xcode 9.2
When i upload ipa to itunes it crashes "Itunes Store Operation Failed"
I use Application Load Exam to get the information :
</code>```

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)enter code here
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.apple.transporter.launcher.Application.start(Application.java:206)
    at com.apple.transporter.launcher.Application.main(Application.java:519)
Caused by: java.lang.IllegalStateException: could not find needed OSGiFramework
    at com.apple.transporter.osgi.BootstrapHelper.setupClassLoader(BootstrapHelper.java:120)
    at com.apple.transporter.osgi.FelixOSGiBootstrapper.bootstrap(FelixOSGiBootstrapper.java:9)
    ... 6 more

```<code>how to fix
</code>```

答:
Had the same issue, solved by removing the .itmstransporter directory, </p>

```<code>rm -R ~/.itmstransporter
</code>```

Body:
Im use version Xcode 9.2
When i upload ipa to itunes it crashes "Itunes Store Operation Failed"
I use Application Load Exam to get the information :

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)enter code here
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.apple.transporter.launcher.Application.start(Application.java:206)
    at com.apple.transporter.launcher.Application.main(Application.java:519)
Caused by: java.lang.IllegalStateException: could not find needed OSGiFramework
    at com.apple.transporter.osgi.BootstrapHelper.setupClassLoader(BootstrapHelper.java:120)
    at com.apple.transporter.osgi.FelixOSGiBootstrapper.bootstrap(FelixOSGiBootstrapper.java:9)
    ... 6 more

how to fix

Body:
Had the same issue, solved by removing the .itmstransporter directory,

rm -R ~/.itmstransporter


问:
Avoid the “Expression has changed after it was checked” error by calling "ChangeDetectorRef::detectChanges()"
I am trying to implement two way data binding on a date input while applying a pipe on the model:

```<code><!-- The name variable is retrieved within the HTML from a loop expression -->
<input matInput [matDatepicker]="datePicker" placeholder="{{label}}" formControlName="{{name}}"
[ngModel]="data[name] | date"
(ngModelChange)="handleDateChange(data[name], $event)" >
</code>```

Where my component looks something like:

```<code>//...
private data: any;

constructor(private cdRef:ChangeDetectorRef) { }

handleDateChange(field: any, date: any) {
    field = date; // The code is simplified, there is more handling with the date field
    this.cdRef.detectChanges();
}
</code>```

Based on this post, the code above works well only thanks to this.cdRef.detectChanges(); If I remove it I get the following error:
Expression has changed after it was checked

My question is more general than related specifically to the above implementation. I would like to know what are the best practices to deal with the Expression has changed after it was checked error? Is calling cdRef.detectChanges() a good idea?

答:
```<code>(ngModelChange)="handleDateChange(data[name], $event)"
</code>```

This is not correct if you add debug lines in handleDateChange(data[name], $event) you would see date might undefined. You have to put $event as the first argument.

You dont' need to pass data[name] into handleDateChange(), data is accessible in your component. what you need do is:

xxx.component.html

```<code>(ngModelChange)="handleDateChange($event)"
</code>```

xxx.component.ts:

```<code>handleDateChange(event: any) {
  // change your data
  this.data[this.name] = event;
}
</code>```

Body:
I am trying to implement two way data binding on a date input while applying a pipe on the model:

<input matInput [matDatepicker]="datePicker" placeholder="{{label}}" formControlName="{{name}}"
[ngModel]="data[name] | date"
(ngModelChange)="handleDateChange(data[name], $event)" >

Where my component looks something like:

//...
private data: any;

constructor(private cdRef:ChangeDetectorRef) { }

handleDateChange(field: any, date: any) {
    field = date; // The code is simplified, there is more handling with the date field
    this.cdRef.detectChanges();
}

Based on this post, the code above works well only thanks to this.cdRef.detectChanges(); If I remove it I get the following error:
Expression has changed after it was checked

My question is more general than related specifically to the above implementation. I would like to know what are the best practices to deal with the Expression has changed after it was checked error? Is calling cdRef.detectChanges() a good idea?

Body:
(ngModelChange)="handleDateChange(data[name], $event)"

This is not correct if you add debug lines in handleDateChange(data[name], $event) you would see date might undefined. You have to put $event as the first argument.

You dont' need to pass data[name] into handleDateChange(), data is accessible in your component. what you need do is:

xxx.component.html

(ngModelChange)="handleDateChange($event)"

xxx.component.ts:

handleDateChange(event: any) {
  // change your data
  this.data[this.name] = event;
}


问:
How to write a python class that is initialized with either no arguments or one argument
I am transitioning from Java to Python and am currently stumped with this seemingly simple code whose Java equivalent works just fine.

I am trying to create an object called TestClass that either takes one argument called text or no arguments; in which case a default string "foo" is assigned to the text instance variable.

```<code>class TestClass(object):

   def __init__(self):
      self.text = "foo"

   def __init__(self, text):
      self.text = text

a = TestClass()
b = TestClass("bar")
</code>```

I really am unable to pinpoint the issue and get the following error:

a = TestClass()

TypeError: init() missing 1 required positional argument: 'text

Your help would be appreciated, Thank you!

答:
Java doesn't have default values for parameters (last time I checked at least)

In Python, you cannot override methods with different parameters (well it's possible, but the first definition becomes invisible so that's not very useful).

So what you're trying to do translates like this:

```<code>def __init__(self, text="foo"):
   self.text = text
</code>```

That's okay with strings, integers, floats, but be careful with mutable types though: "Least Astonishment" and the Mutable Default Argument

Also, if you want to "emulate" same method name with different argument types, you have to define one method (that doesn't change) and use dynamic type checking to decide what to do:

```<code>def __init__(self, param):
   if isinstance(param,str):
       # param is a string
   elif isinstance(param,int):
       # param is an integer
</code>```

Body:
I am transitioning from Java to Python and am currently stumped with this seemingly simple code whose Java equivalent works just fine.

I am trying to create an object called TestClass that either takes one argument called text or no arguments; in which case a default string "foo" is assigned to the text instance variable.

class TestClass(object):

   def __init__(self):
      self.text = "foo"

   def __init__(self, text):
      self.text = text

a = TestClass()
b = TestClass("bar")

I really am unable to pinpoint the issue and get the following error:

a = TestClass()

TypeError: init() missing 1 required positional argument: 'text

Your help would be appreciated, Thank you!

Body:
Java doesn't have default values for parameters (last time I checked at least)

In Python, you cannot override methods with different parameters (well it's possible, but the first definition becomes invisible so that's not very useful).

So what you're trying to do translates like this:

def __init__(self, text="foo"):
   self.text = text

That's okay with strings, integers, floats, but be careful with mutable types though: "Least Astonishment" and the Mutable Default Argument

Also, if you want to "emulate" same method name with different argument types, you have to define one method (that doesn't change) and use dynamic type checking to decide what to do:

def __init__(self, param):
   if isinstance(param,str):
       # param is a string
   elif isinstance(param,int):
       # param is an integer


问:
Swift 4 alternative if let
I have this code, it checks if a file exists in the document directory, if it does it used this to set up the data for the controller, if it doesn't it uses a file supplier in the bundle, and if also that fails it set up an empty view controller.

Is there a way to conditionally set the url variable so that I can write the parse(fromFile:) method once instead of in an if else? The most intuitive way would appear to be if let url = something || let url = somethingElse then perform in the parse(fromFile: url) in the brackets, but it appears that it's not possible with swift.

```<code>if let url = try? FileManager().url(for: .documentDirectory,
                                    in: .userDomainMask,
                                    appropriateFor: nil,
                                    create: true).appendingPathComponent("database.json") {
    parse(fromFile: url)
} else if let url = Bundle.main.url(forResource: "database", withExtension: "json") {
    parse(fromFile: url)
} else {
    setUpWithNothing()
}
</code>```

答:
You can use the nil-coalescing operator (??):

If the expression with FileManager returns nil (by throwing, thanks to the try?), then Bundle.main.url(...) will be used instead.

If that is also nil, then the conditional binding will fail entirely, and the else block will be run setUpWithNothing().

```<code>if let url = (try? FileManager.default.url(for: .documentDirectory,
                                           in: .userDomainMask,
                                           appropriateFor: nil,
                                           create: true
                                           ).appendingPathComponent("database.json"))
             ?? Bundle.main.url(forResource: "database", withExtension: "json") {
    parse(fromFile: url)
} else {
    setUpWithNothing()
}
</code>```

Title: Swift 4 alternative if let

Body:
I have this code, it checks if a file exists in the document directory, if it does it used this to set up the data for the controller, if it doesn't it uses a file supplier in the bundle, and if also that fails it set up an empty view controller.

Is there a way to conditionally set the url variable so that I can write the parse(fromFile:) method once instead of in an if else? The most intuitive way would appear to be if let url = something || let url = somethingElse then perform in the parse(fromFile: url) in the brackets, but it appears that it's not possible with swift.

if let url = try? FileManager().url(for: .documentDirectory,
                                    in: .userDomainMask,
                                    appropriateFor: nil,
                                    create: true).appendingPathComponent("database.json") {
    parse(fromFile: url)
} else if let url = Bundle.main.url(forResource: "database", withExtension: "json") {
    parse(fromFile: url)
} else {
    setUpWithNothing()
}

Body:
You can use the nil-coalescing operator (??):

If the expression with FileManager returns nil (by throwing, thanks to the try?), then Bundle.main.url(...) will be used instead.

If that is also nil, then the conditional binding will fail entirely, and the else block will be run setUpWithNothing().

if let url = (try? FileManager.default.url(for: .documentDirectory,
                                           in: .userDomainMask,
                                           appropriateFor: nil,
                                           create: true
                                           ).appendingPathComponent("database.json"))
             ?? Bundle.main.url(forResource: "database", withExtension: "json") {
    parse(fromFile: url)
} else {
    setUpWithNothing()
}


问:
support subtraction between two different itemsets when having same items
Using arules, I have got two itemsets, and I want to do subtraction between the two different itemsets when having same items.

```<code>> inspect(fsets_model_test)
    items                        support    count
[1] {SURFSKINTEMP=6,MODIS_LST=1} 0.01235235 663
[2] {TOTCO=13,MODIS_LST=1}       0.01373104 737
[3] {TOTCO=6,MODIS_LST=1}        0.01393598 748
[4] {TOTO3=15,MODIS_LST=1}       0.01265045 679
[5] {TOTH2OVAP=6,MODIS_LST=1}    0.01548236 831
[6] {TOTH2OVAP=1,MODIS_LST=1}    0.01565004 840
> inspect(fsets_nonsesmic_test)
    items                                   support    count
[1] {TOTCO=6,MODIS_LST=1}                   0.02192761 10013
[2] {TOTCO=13,MODIS_LST=1}                  0.02261524 10327
[3] {TOTO3=15,MODIS_LST=1}                  0.02432556 11108
[4] {SURFAIRTEMP=3,TOTH2OVAP=1,MODIS_LST=1} 0.01772735  8095
[5] {TOTH2OVAP=1,MODIS_LST=1}               0.02873605 13122
[6] {SURFAIRTEMP=3,TOTH2OVAP=1}             0.01856828  8479
</code>```

you can see that itemsets fsets_model_test and itemsets fsets_nonsesmic_test have same items {TOTO3=15,MODIS_LST=1}

What I want to do is subtract support between two itemsets, in above case is
0.02432556 - 0.01265045 = 0.01167511, and then get a new itemsets.

How to implement this in arules, thanks

following are the example itemsets

one itemsets

```<code>fsets_model_test <- new("itemsets"
    , items = new("itemMatrix"
    , data = new("ngCMatrix"
    , i = c(5L, 121L, 74L, 121L, 67L, 121L, 59L, 121L, 33L, 121L, 28L,
121L)
    , p = c(0L, 2L, 4L, 6L, 8L, 10L, 12L)
    , Dim = c(125L, 6L)
    , Dimnames = list(NULL, NULL)
    , factors = list()
)
    , itemInfo = structure(list(labels = c("SURFSKINTEMP=1", "SURFSKINTEMP=2",
"SURFSKINTEMP=3", "SURFSKINTEMP=4", "SURFSKINTEMP=5", "SURFSKINTEMP=6",
"SURFSKINTEMP=7", "SURFSKINTEMP=8", "SURFSKINTEMP=9", "SURFSKINTEMP=10",
"SURFSKINTEMP=11", "SURFSKINTEMP=12", "SURFSKINTEMP=13", "SURFSKINTEMP=14",
"SURFSKINTEMP=15", "SURFSKINTEMP=16", "SURFAIRTEMP=1", "SURFAIRTEMP=2",
"SURFAIRTEMP=3", "SURFAIRTEMP=4", "SURFAIRTEMP=5", "SURFAIRTEMP=6",
"SURFAIRTEMP=7", "SURFAIRTEMP=8", "SURFAIRTEMP=9", "SURFAIRTEMP=10",
"SURFAIRTEMP=11", "SURFAIRTEMP=12", "TOTH2OVAP=1", "TOTH2OVAP=2",
"TOTH2OVAP=3", "TOTH2OVAP=4", "TOTH2OVAP=5", "TOTH2OVAP=6", "TOTH2OVAP=7",
"TOTH2OVAP=8", "TOTH2OVAP=9", "TOTH2OVAP=10", "TOTH2OVAP=11",
"TOTH2OVAP=12", "TOTH2OVAP=13", "TOTH2OVAP=14", "TOTH2OVAP=15",
"TOTH2OVAP=16", "TOTH2OVAP=17", "TOTO3=1", "TOTO3=2", "TOTO3=3",
"TOTO3=4", "TOTO3=5", "TOTO3=6", "TOTO3=7", "TOTO3=8", "TOTO3=9",
"TOTO3=10", "TOTO3=11", "TOTO3=12", "TOTO3=13", "TOTO3=14", "TOTO3=15",
"TOTO3=16", "TOTO3=17", "TOTCO=1", "TOTCO=2", "TOTCO=3", "TOTCO=4",
"TOTCO=5", "TOTCO=6", "TOTCO=7", "TOTCO=8", "TOTCO=9", "TOTCO=10",
"TOTCO=11", "TOTCO=12", "TOTCO=13", "TOTCO=14", "TOTCO=15", "TOTCH4=1",
"TOTCH4=2", "TOTCH4=3", "TOTCH4=4", "TOTCH4=5", "TOTCH4=6", "TOTCH4=7",
"TOTCH4=8", "TOTCH4=9", "TOTCH4=10", "TOTCH4=11", "TOTCH4=12",
"TOTCH4=13", "TOTCH4=14", "OLR_ARIS=1", "OLR_ARIS=2", "OLR_ARIS=3",
"OLR_ARIS=4", "OLR_ARIS=5", "OLR_ARIS=6", "OLR_ARIS=7", "OLR_ARIS=8",
"OLR_ARIS=9", "OLR_ARIS=10", "CLROLR_ARIS=1", "CLROLR_ARIS=2",
"CLROLR_ARIS=3", "CLROLR_ARIS=4", "CLROLR_ARIS=5", "CLROLR_ARIS=6",
"CLROLR_ARIS=7", "CLROLR_ARIS=8", "CLROLR_ARIS=9", "CLROLR_ARIS=10",
"OLR_NOAA=1", "OLR_NOAA=2", "OLR_NOAA=3", "OLR_NOAA=4", "OLR_NOAA=5",
"OLR_NOAA=6", "OLR_NOAA=7", "OLR_NOAA=8", "OLR_NOAA=9", "OLR_NOAA=10",
"MODIS_LST=1", "MODIS_LST=2", "MODIS_LST=3", "MODIS_LST=4"),
    variables = structure(c(6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
    6L, 6L, 6L, 6L, 6L, 6L, 6L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
    5L, 5L, 5L, 5L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
    9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
    10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 8L, 8L,
    8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 7L, 7L,
    7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 3L, 3L, 3L,
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L,
    2L), .Label = c("CLROLR_ARIS", "MODIS_LST", "OLR_ARIS", "OLR_NOAA",
    "SURFAIRTEMP", "SURFSKINTEMP", "TOTCH4", "TOTCO", "TOTH2OVAP",
    "TOTO3"), class = "factor"), levels = structure(c(1L, 10L,
    11L, 12L, 13L, 14L, 15L, 16L, 17L, 2L, 3L, 4L, 5L, 6L, 7L,
    8L, 1L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 2L, 3L, 4L,
    1L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 2L, 3L, 4L, 5L,
    6L, 7L, 8L, 9L, 1L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L,
    2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 1L, 10L, 11L, 12L, 13L, 14L,
    15L, 16L, 17L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 10L, 11L, 12L,
    13L, 14L, 15L, 16L, 17L, 2L, 3L, 4L, 5L, 6L, 1L, 10L, 11L,
    12L, 13L, 14L, 15L, 16L, 17L, 2L, 1L, 10L, 11L, 12L, 13L,
    14L, 15L, 16L, 17L, 2L, 1L, 10L, 11L, 12L, 13L, 14L, 15L,
    16L, 17L, 2L, 1L, 10L, 11L, 12L), .Label = c("1", "10", "11",
    "12", "13", "14", "15", "16", "17", "2", "3", "4", "5", "6",
    "7", "8", "9"), class = "factor")), .Names = c("labels",
"variables", "levels"), row.names = c(NA, -125L), class = "data.frame")
    , itemsetInfo = structure(list(), .Names = character(0), row.names = integer(0), class = "data.frame")
)
    , tidLists = NULL
    , quality = structure(list(support = c(0.0123523493684093, 0.0137310429630734,
0.0139359839028207, 0.0126504452807691, 0.0154823564481872, 0.0156500353988896
), count = c(663, 737, 748, 679, 831, 840)), .Names = c("support",
"count"), row.names = c(NA, 6L), class = "data.frame")
    , info = structure(list(data = model_data_tr, ntransactions = 53674L,
    support = 0.01), .Names = c("data", "ntransactions", "support"
))
)
</code>```

another itemsets is:

```<code>fsets_nonsesmic_test <- new("itemsets"
    , items = new("itemMatrix"
    , data = new("ngCMatrix"
    , i = c(67L, 121L, 74L, 121L, 59L, 121L, 18L, 28L, 121L, 28L, 121L,
18L, 28L)
    , p = c(0L, 2L, 4L, 6L, 9L, 11L, 13L)
    , Dim = c(125L, 6L)
    , Dimnames = list(NULL, NULL)
    , factors = list()
)
    , itemInfo = structure(list(labels = c("SURFSKINTEMP=1", "SURFSKINTEMP=2",
"SURFSKINTEMP=3", "SURFSKINTEMP=4", "SURFSKINTEMP=5", "SURFSKINTEMP=6",
"SURFSKINTEMP=7", "SURFSKINTEMP=8", "SURFSKINTEMP=9", "SURFSKINTEMP=10",
"SURFSKINTEMP=11", "SURFSKINTEMP=12", "SURFSKINTEMP=13", "SURFSKINTEMP=14",
"SURFSKINTEMP=15", "SURFSKINTEMP=16", "SURFAIRTEMP=1", "SURFAIRTEMP=2",
"SURFAIRTEMP=3", "SURFAIRTEMP=4", "SURFAIRTEMP=5", "SURFAIRTEMP=6",
"SURFAIRTEMP=7", "SURFAIRTEMP=8", "SURFAIRTEMP=9", "SURFAIRTEMP=10",
"SURFAIRTEMP=11", "SURFAIRTEMP=12", "TOTH2OVAP=1", "TOTH2OVAP=2",
"TOTH2OVAP=3", "TOTH2OVAP=4", "TOTH2OVAP=5", "TOTH2OVAP=6", "TOTH2OVAP=7",
"TOTH2OVAP=8", "TOTH2OVAP=9", "TOTH2OVAP=10", "TOTH2OVAP=11",
"TOTH2OVAP=12", "TOTH2OVAP=13", "TOTH2OVAP=14", "TOTH2OVAP=15",
"TOTH2OVAP=16", "TOTH2OVAP=17", "TOTO3=1", "TOTO3=2", "TOTO3=3",
"TOTO3=4", "TOTO3=5", "TOTO3=6", "TOTO3=7", "TOTO3=8", "TOTO3=9",
"TOTO3=10", "TOTO3=11", "TOTO3=12", "TOTO3=13", "TOTO3=14", "TOTO3=15",
"TOTO3=16", "TOTO3=17", "TOTCO=1", "TOTCO=2", "TOTCO=3", "TOTCO=4",
"TOTCO=5", "TOTCO=6", "TOTCO=7", "TOTCO=8", "TOTCO=9", "TOTCO=10",
"TOTCO=11", "TOTCO=12", "TOTCO=13", "TOTCO=14", "TOTCO=15", "TOTCH4=1",
"TOTCH4=2", "TOTCH4=3", "TOTCH4=4", "TOTCH4=5", "TOTCH4=6", "TOTCH4=7",
"TOTCH4=8", "TOTCH4=9", "TOTCH4=10", "TOTCH4=11", "TOTCH4=12",
"TOTCH4=13", "TOTCH4=14", "OLR_ARIS=1", "OLR_ARIS=2", "OLR_ARIS=3",
"OLR_ARIS=4", "OLR_ARIS=5", "OLR_ARIS=6", "OLR_ARIS=7", "OLR_ARIS=8",
"OLR_ARIS=9", "OLR_ARIS=10", "CLROLR_ARIS=1", "CLROLR_ARIS=2",
"CLROLR_ARIS=3", "CLROLR_ARIS=4", "CLROLR_ARIS=5", "CLROLR_ARIS=6",
"CLROLR_ARIS=7", "CLROLR_ARIS=8", "CLROLR_ARIS=9", "CLROLR_ARIS=10",
"OLR_NOAA=1", "OLR_NOAA=2", "OLR_NOAA=3", "OLR_NOAA=4", "OLR_NOAA=5",
"OLR_NOAA=6", "OLR_NOAA=7", "OLR_NOAA=8", "OLR_NOAA=9", "OLR_NOAA=10",
"MODIS_LST=1", "MODIS_LST=2", "MODIS_LST=3", "MODIS_LST=4"),
    variables = structure(c(6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
    6L, 6L, 6L, 6L, 6L, 6L, 6L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
    5L, 5L, 5L, 5L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
    9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
    10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 8L, 8L,
    8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 7L, 7L,
    7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 3L, 3L, 3L,
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L,
    2L), .Label = c("CLROLR_ARIS", "MODIS_LST", "OLR_ARIS", "OLR_NOAA",
    "SURFAIRTEMP", "SURFSKINTEMP", "TOTCH4", "TOTCO", "TOTH2OVAP",
    "TOTO3"), class = "factor"), levels = structure(c(1L, 10L,
    11L, 12L, 13L, 14L, 15L, 16L, 17L, 2L, 3L, 4L, 5L, 6L, 7L,
    8L, 1L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 2L, 3L, 4L,
    1L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 2L, 3L, 4L, 5L,
    6L, 7L, 8L, 9L, 1L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L,
    2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 1L, 10L, 11L, 12L, 13L, 14L,
    15L, 16L, 17L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 10L, 11L, 12L,
    13L, 14L, 15L, 16L, 17L, 2L, 3L, 4L, 5L, 6L, 1L, 10L, 11L,
    12L, 13L, 14L, 15L, 16L, 17L, 2L, 1L, 10L, 11L, 12L, 13L,
    14L, 15L, 16L, 17L, 2L, 1L, 10L, 11L, 12L, 13L, 14L, 15L,
    16L, 17L, 2L, 1L, 10L, 11L, 12L), .Label = c("1", "10", "11",
    "12", "13", "14", "15", "16", "17", "2", "3", "4", "5", "6",
    "7", "8", "9"), class = "factor")), .Names = c("labels",
"variables", "levels"), row.names = c(NA, -125L), class = "data.frame")
    , itemsetInfo = structure(list(), .Names = character(0), row.names = integer(0), class = "data.frame")
)
    , tidLists = NULL
    , quality = structure(list(support = c(0.0219276058330541, 0.0226152387334415,
0.024325561329628, 0.0177273513650827, 0.0287360475123675, 0.0185682782241552
), count = c(10013, 10327, 11108, 8095, 13122, 8479)), .Names = c("support",
"count"), row.names = c(NA, 6L), class = "data.frame")
    , info = structure(list(data = nonsesmic_data_tr, ntransactions = 456639L,
    support = 0.01), .Names = c("data", "ntransactions", "support"
))
)
</code>```

答: If the two sets come from transaction data that are compatible (see ? itemCoding) then you can use match to find matching itemsets in the two sets. After that, it should be easy to subtract the support.

Body:
Using arules, I have got two itemsets, and I want to do subtraction between the two different itemsets when having same items.

> inspect(fsets_model_test)
    items                        support    count
[1] {SURFSKINTEMP=6,MODIS_LST=1} 0.01235235 663
[2] {TOTCO=13,MODIS_LST=1}       0.01373104 737
[3] {TOTCO=6,MODIS_LST=1}        0.01393598 748
[4] {TOTO3=15,MODIS_LST=1}       0.01265045 679
[5] {TOTH2OVAP=6,MODIS_LST=1}    0.01548236 831
[6] {TOTH2OVAP=1,MODIS_LST=1}    0.01565004 840
> inspect(fsets_nonsesmic_test)
    items                                   support    count
[1] {TOTCO=6,MODIS_LST=1}                   0.02192761 10013
[2] {TOTCO=13,MODIS_LST=1}                  0.02261524 10327
[3] {TOTO3=15,MODIS_LST=1}                  0.02432556 11108
[4] {SURFAIRTEMP=3,TOTH2OVAP=1,MODIS_LST=1} 0.01772735  8095
[5] {TOTH2OVAP=1,MODIS_LST=1}               0.02873605 13122
[6] {SURFAIRTEMP=3,TOTH2OVAP=1}             0.01856828  8479

you can see that itemsets fsets_model_test and itemsets fsets_nonsesmic_test have same items {TOTO3=15,MODIS_LST=1}

What I want to do is subtract support between two itemsets, in above case is
0.02432556 - 0.01265045 = 0.01167511, and then get a new itemsets.

How to implement this in arules, thanks

following are the example itemsets

one itemsets

fsets_model_test <- new("itemsets"
    , items = new("itemMatrix"
    , data = new("ngCMatrix"
    , i = c(5L, 121L, 74L, 121L, 67L, 121L, 59L, 121L, 33L, 121L, 28L,
121L)
    , p = c(0L, 2L, 4L, 6L, 8L, 10L, 12L)
    , Dim = c(125L, 6L)
    , Dimnames = list(NULL, NULL)
    , factors = list()
)
    , itemInfo = structure(list(labels = c("SURFSKINTEMP=1", "SURFSKINTEMP=2",
"SURFSKINTEMP=3", "SURFSKINTEMP=4", "SURFSKINTEMP=5", "SURFSKINTEMP=6",
"SURFSKINTEMP=7", "SURFSKINTEMP=8", "SURFSKINTEMP=9", "SURFSKINTEMP=10",
"SURFSKINTEMP=11", "SURFSKINTEMP=12", "SURFSKINTEMP=13", "SURFSKINTEMP=14",
"SURFSKINTEMP=15", "SURFSKINTEMP=16", "SURFAIRTEMP=1", "SURFAIRTEMP=2",
"SURFAIRTEMP=3", "SURFAIRTEMP=4", "SURFAIRTEMP=5", "SURFAIRTEMP=6",
"SURFAIRTEMP=7", "SURFAIRTEMP=8", "SURFAIRTEMP=9", "SURFAIRTEMP=10",
"SURFAIRTEMP=11", "SURFAIRTEMP=12", "TOTH2OVAP=1", "TOTH2OVAP=2",
"TOTH2OVAP=3", "TOTH2OVAP=4", "TOTH2OVAP=5", "TOTH2OVAP=6", "TOTH2OVAP=7",
"TOTH2OVAP=8", "TOTH2OVAP=9", "TOTH2OVAP=10", "TOTH2OVAP=11",
"TOTH2OVAP=12", "TOTH2OVAP=13", "TOTH2OVAP=14", "TOTH2OVAP=15",
"TOTH2OVAP=16", "TOTH2OVAP=17", "TOTO3=1", "TOTO3=2", "TOTO3=3",
"TOTO3=4", "TOTO3=5", "TOTO3=6", "TOTO3=7", "TOTO3=8", "TOTO3=9",
"TOTO3=10", "TOTO3=11", "TOTO3=12", "TOTO3=13", "TOTO3=14", "TOTO3=15",
"TOTO3=16", "TOTO3=17", "TOTCO=1", "TOTCO=2", "TOTCO=3", "TOTCO=4",
"TOTCO=5", "TOTCO=6", "TOTCO=7", "TOTCO=8", "TOTCO=9", "TOTCO=10",
"TOTCO=11", "TOTCO=12", "TOTCO=13", "TOTCO=14", "TOTCO=15", "TOTCH4=1",
"TOTCH4=2", "TOTCH4=3", "TOTCH4=4", "TOTCH4=5", "TOTCH4=6", "TOTCH4=7",
"TOTCH4=8", "TOTCH4=9", "TOTCH4=10", "TOTCH4=11", "TOTCH4=12",
"TOTCH4=13", "TOTCH4=14", "OLR_ARIS=1", "OLR_ARIS=2", "OLR_ARIS=3",
"OLR_ARIS=4", "OLR_ARIS=5", "OLR_ARIS=6", "OLR_ARIS=7", "OLR_ARIS=8",
"OLR_ARIS=9", "OLR_ARIS=10", "CLROLR_ARIS=1", "CLROLR_ARIS=2",
"CLROLR_ARIS=3", "CLROLR_ARIS=4", "CLROLR_ARIS=5", "CLROLR_ARIS=6",
"CLROLR_ARIS=7", "CLROLR_ARIS=8", "CLROLR_ARIS=9", "CLROLR_ARIS=10",
"OLR_NOAA=1", "OLR_NOAA=2", "OLR_NOAA=3", "OLR_NOAA=4", "OLR_NOAA=5",
"OLR_NOAA=6", "OLR_NOAA=7", "OLR_NOAA=8", "OLR_NOAA=9", "OLR_NOAA=10",
"MODIS_LST=1", "MODIS_LST=2", "MODIS_LST=3", "MODIS_LST=4"),
    variables = structure(c(6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
    6L, 6L, 6L, 6L, 6L, 6L, 6L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
    5L, 5L, 5L, 5L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
    9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
    10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 8L, 8L,
    8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 7L, 7L,
    7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 3L, 3L, 3L,
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L,
    2L), .Label = c("CLROLR_ARIS", "MODIS_LST", "OLR_ARIS", "OLR_NOAA",
    "SURFAIRTEMP", "SURFSKINTEMP", "TOTCH4", "TOTCO", "TOTH2OVAP",
    "TOTO3"), class = "factor"), levels = structure(c(1L, 10L,
    11L, 12L, 13L, 14L, 15L, 16L, 17L, 2L, 3L, 4L, 5L, 6L, 7L,
    8L, 1L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 2L, 3L, 4L,
    1L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 2L, 3L, 4L, 5L,
    6L, 7L, 8L, 9L, 1L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L,
    2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 1L, 10L, 11L, 12L, 13L, 14L,
    15L, 16L, 17L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 10L, 11L, 12L,
    13L, 14L, 15L, 16L, 17L, 2L, 3L, 4L, 5L, 6L, 1L, 10L, 11L,
    12L, 13L, 14L, 15L, 16L, 17L, 2L, 1L, 10L, 11L, 12L, 13L,
    14L, 15L, 16L, 17L, 2L, 1L, 10L, 11L, 12L, 13L, 14L, 15L,
    16L, 17L, 2L, 1L, 10L, 11L, 12L), .Label = c("1", "10", "11",
    "12", "13", "14", "15", "16", "17", "2", "3", "4", "5", "6",
    "7", "8", "9"), class = "factor")), .Names = c("labels",
"variables", "levels"), row.names = c(NA, -125L), class = "data.frame")
    , itemsetInfo = structure(list(), .Names = character(0), row.names = integer(0), class = "data.frame")
)
    , tidLists = NULL
    , quality = structure(list(support = c(0.0123523493684093, 0.0137310429630734,
0.0139359839028207, 0.0126504452807691, 0.0154823564481872, 0.0156500353988896
), count = c(663, 737, 748, 679, 831, 840)), .Names = c("support",
"count"), row.names = c(NA, 6L), class = "data.frame")
    , info = structure(list(data = model_data_tr, ntransactions = 53674L,
    support = 0.01), .Names = c("data", "ntransactions", "support"
))
)

another itemsets is:

fsets_nonsesmic_test <- new("itemsets"
    , items = new("itemMatrix"
    , data = new("ngCMatrix"
    , i = c(67L, 121L, 74L, 121L, 59L, 121L, 18L, 28L, 121L, 28L, 121L,
18L, 28L)
    , p = c(0L, 2L, 4L, 6L, 9L, 11L, 13L)
    , Dim = c(125L, 6L)
    , Dimnames = list(NULL, NULL)
    , factors = list()
)
    , itemInfo = structure(list(labels = c("SURFSKINTEMP=1", "SURFSKINTEMP=2",
"SURFSKINTEMP=3", "SURFSKINTEMP=4", "SURFSKINTEMP=5", "SURFSKINTEMP=6",
"SURFSKINTEMP=7", "SURFSKINTEMP=8", "SURFSKINTEMP=9", "SURFSKINTEMP=10",
"SURFSKINTEMP=11", "SURFSKINTEMP=12", "SURFSKINTEMP=13", "SURFSKINTEMP=14",
"SURFSKINTEMP=15", "SURFSKINTEMP=16", "SURFAIRTEMP=1", "SURFAIRTEMP=2",
"SURFAIRTEMP=3", "SURFAIRTEMP=4", "SURFAIRTEMP=5", "SURFAIRTEMP=6",
"SURFAIRTEMP=7", "SURFAIRTEMP=8", "SURFAIRTEMP=9", "SURFAIRTEMP=10",
"SURFAIRTEMP=11", "SURFAIRTEMP=12", "TOTH2OVAP=1", "TOTH2OVAP=2",
"TOTH2OVAP=3", "TOTH2OVAP=4", "TOTH2OVAP=5", "TOTH2OVAP=6", "TOTH2OVAP=7",
"TOTH2OVAP=8", "TOTH2OVAP=9", "TOTH2OVAP=10", "TOTH2OVAP=11",
"TOTH2OVAP=12", "TOTH2OVAP=13", "TOTH2OVAP=14", "TOTH2OVAP=15",
"TOTH2OVAP=16", "TOTH2OVAP=17", "TOTO3=1", "TOTO3=2", "TOTO3=3",
"TOTO3=4", "TOTO3=5", "TOTO3=6", "TOTO3=7", "TOTO3=8", "TOTO3=9",
"TOTO3=10", "TOTO3=11", "TOTO3=12", "TOTO3=13", "TOTO3=14", "TOTO3=15",
"TOTO3=16", "TOTO3=17", "TOTCO=1", "TOTCO=2", "TOTCO=3", "TOTCO=4",
"TOTCO=5", "TOTCO=6", "TOTCO=7", "TOTCO=8", "TOTCO=9", "TOTCO=10",
"TOTCO=11", "TOTCO=12", "TOTCO=13", "TOTCO=14", "TOTCO=15", "TOTCH4=1",
"TOTCH4=2", "TOTCH4=3", "TOTCH4=4", "TOTCH4=5", "TOTCH4=6", "TOTCH4=7",
"TOTCH4=8", "TOTCH4=9", "TOTCH4=10", "TOTCH4=11", "TOTCH4=12",
"TOTCH4=13", "TOTCH4=14", "OLR_ARIS=1", "OLR_ARIS=2", "OLR_ARIS=3",
"OLR_ARIS=4", "OLR_ARIS=5", "OLR_ARIS=6", "OLR_ARIS=7", "OLR_ARIS=8",
"OLR_ARIS=9", "OLR_ARIS=10", "CLROLR_ARIS=1", "CLROLR_ARIS=2",
"CLROLR_ARIS=3", "CLROLR_ARIS=4", "CLROLR_ARIS=5", "CLROLR_ARIS=6",
"CLROLR_ARIS=7", "CLROLR_ARIS=8", "CLROLR_ARIS=9", "CLROLR_ARIS=10",
"OLR_NOAA=1", "OLR_NOAA=2", "OLR_NOAA=3", "OLR_NOAA=4", "OLR_NOAA=5",
"OLR_NOAA=6", "OLR_NOAA=7", "OLR_NOAA=8", "OLR_NOAA=9", "OLR_NOAA=10",
"MODIS_LST=1", "MODIS_LST=2", "MODIS_LST=3", "MODIS_LST=4"),
    variables = structure(c(6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
    6L, 6L, 6L, 6L, 6L, 6L, 6L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
    5L, 5L, 5L, 5L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
    9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
    10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 8L, 8L,
    8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 7L, 7L,
    7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 3L, 3L, 3L,
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L,
    2L), .Label = c("CLROLR_ARIS", "MODIS_LST", "OLR_ARIS", "OLR_NOAA",
    "SURFAIRTEMP", "SURFSKINTEMP", "TOTCH4", "TOTCO", "TOTH2OVAP",
    "TOTO3"), class = "factor"), levels = structure(c(1L, 10L,
    11L, 12L, 13L, 14L, 15L, 16L, 17L, 2L, 3L, 4L, 5L, 6L, 7L,
    8L, 1L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 2L, 3L, 4L,
    1L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 2L, 3L, 4L, 5L,
    6L, 7L, 8L, 9L, 1L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L,
    2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 1L, 10L, 11L, 12L, 13L, 14L,
    15L, 16L, 17L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 10L, 11L, 12L,
    13L, 14L, 15L, 16L, 17L, 2L, 3L, 4L, 5L, 6L, 1L, 10L, 11L,
    12L, 13L, 14L, 15L, 16L, 17L, 2L, 1L, 10L, 11L, 12L, 13L,
    14L, 15L, 16L, 17L, 2L, 1L, 10L, 11L, 12L, 13L, 14L, 15L,
    16L, 17L, 2L, 1L, 10L, 11L, 12L), .Label = c("1", "10", "11",
    "12", "13", "14", "15", "16", "17", "2", "3", "4", "5", "6",
    "7", "8", "9"), class = "factor")), .Names = c("labels",
"variables", "levels"), row.names = c(NA, -125L), class = "data.frame")
    , itemsetInfo = structure(list(), .Names = character(0), row.names = integer(0), class = "data.frame")
)
    , tidLists = NULL
    , quality = structure(list(support = c(0.0219276058330541, 0.0226152387334415,
0.024325561329628, 0.0177273513650827, 0.0287360475123675, 0.0185682782241552
), count = c(10013, 10327, 11108, 8095, 13122, 8479)), .Names = c("support",
"count"), row.names = c(NA, 6L), class = "data.frame")
    , info = structure(list(data = nonsesmic_data_tr, ntransactions = 456639L,
    support = 0.01), .Names = c("data", "ntransactions", "support"
))
)


问:
Inputting Array In Multiline Text In Android
I am new to android and am trying to make an app where the user inputs an array in a text box with inputType = textMultiLine. The problem is that I want to make it so that whenever user hits enter, the app takes input of the next array element and not treat the entire text in the textbox as one element. The code is as below :

```<code>    EditText input = findViewById(R.id.inputtext);
    Button show = findViewById(R.id.button);
    TextView output = findViewById(R.id.output);
    String [] name = new String[3];

    for (int i = 0 ; i < 3 ; i++)
    {
        name[i] = input.getText().toString();
        output.setText(name[i]);
    }
</code>```

But whenever i try to take name[1] after hitting enter the app doesnt treat the next line as name[2] but instead treats it as name[1]. For example if type the names john,steve and frank, then i should get an array that is like this :

```<code>name[0] = john
name[1] = steve
name[2] = frank
</code>```

but instead whenever I typejohn,press enter,type steve, press enter and type frank the app treats it as :

```<code>name[0] = john
          steve
          frank
</code>```

also if i set the output to something like this :

```<code>output.setText(name[i] + i)
</code>```

instead of getting an oupt like this :

```<code>john 0
steve 1
frank 2
</code>```

I get an output like this :

```<code>john
steve
frank2
</code>```

Any and all help would be much appreciated.

Thanks

======================================================================================================================================================

EDIT 1

I tried this code but didn't work:

```<code>String name[] = input .getText().toString().split("\\r?\\n");

for (int i = 0 ; i < name.length; i++)
{

    output.setText(name[i]);
}
</code>```

Still get only frank when I input john,steve and frank

答:
try below code</p>

```<code> String name[] = input .getText().toString().split("\\r?\\n");
 String disp="";
 for (int i = 0 ; i < name.length; i++)
    {
        disp += name[i] +"\n";

    }
 output.setText(disp);
</code>```

Body:
I am new to android and am trying to make an app where the user inputs an array in a text box with inputType = textMultiLine. The problem is that I want to make it so that whenever user hits enter, the app takes input of the next array element and not treat the entire text in the textbox as one element. The code is as below :

    EditText input = findViewById(R.id.inputtext);
    Button show = findViewById(R.id.button);
    TextView output = findViewById(R.id.output);
    String [] name = new String[3];

    for (int i = 0 ; i < 3 ; i++)
    {
        name[i] = input.getText().toString();
        output.setText(name[i]);
    }

But whenever i try to take name[1] after hitting enter the app doesnt treat the next line as name[2] but instead treats it as name[1]. For example if type the names john,steve and frank, then i should get an array that is like this :

name[0] = john
name[1] = steve
name[2] = frank

but instead whenever I typejohn,press enter,type steve, press enter and type frank the app treats it as :

name[0] = john
          steve
          frank

also if i set the output to something like this :

output.setText(name[i] + i)

instead of getting an oupt like this :

john 0
steve 1
frank 2

I get an output like this :

john
steve
frank2

Any and all help would be much appreciated.

Thanks

======================================================================================================================================================

EDIT 1

I tried this code but didn't work:

String name[] = input .getText().toString().split("\\r?\\n");

for (int i = 0 ; i < name.length; i++)
{

    output.setText(name[i]);
}

Still get only frank when I input john,steve and frank

Body:
try below code

 String name[] = input .getText().toString().split("\\r?\\n");
 String disp="";
 for (int i = 0 ; i < name.length; i++)
    {
        disp += name[i] +"\n";

    }
 output.setText(disp);


问:
Compiling OpenCV on Windows 7 64bit
I'm trying to get OpenCV working on Windows 7 64bit.

I tried installing the vs2008.exe installer bundle from the OpenCV website but it produced errors when trying to compile, I Google'd these and it appears that installer is no good for 64bit versions of Windows 7, bugger.

I've tried having a crack at compiling using CMake, but really having no luck, does anyone know of a way to get OpenCV installed on here so I can use it in VS2010?

Cheers

答:
For anyone else interested in a guide how to compile OpenCV with TBB support in Visual Studio 2010, I created a video tutorial for it: http://www.youtube.com/watch?v=XeBhwbRoKvk
(although this is for Windows 7 32 bit)</p>

Title: Compiling OpenCV on Windows 7 64bit


问:
How can I pause and resume NSTimer.scheduledTimerWithTimeInterval in swift?
I'm developing a game and I want to create a pause menu. Here is my code:

```<code>self.view?.paused = true
</code>```

but  NSTimer.scheduledTimerWithTimeInterval still running...

```<code> for var i=0; i < rocketCount; i++ {
    var a: NSTimeInterval = 1
    ii += a
    delaysShow = 2.0 + ((stimulus + interStimulus) * ii)
    var time3 = NSTimer.scheduledTimerWithTimeInterval(delaysShow!, target: self, selector: Selector("showRocket:"), userInfo: rocketid[i], repeats: false)
 }
</code>```

I want time3 to pause the timer when player click pause menu and continue run the timer when player come back to the game, but how can I pause NSTimer.scheduledTimerWithTimeInterval? help me please.

答:
Even though the solutions exposed here are good, I thought an important insight was missing. Like a lot of people here explained, timer invalidate() and recreate is the best option. But one could argue that you could do something like this:

```<code>var paused:Bool

func timerAction() {
    if !paused {
        // Do stuff here
    }
}
</code>```

is easier to implement, but it will be less efficient.

For energy impact reasons, Apple promotes avoiding timers whenever possible and to prefer event notifications. If you really need to use a timer, you should implement pauses efficiently by invalidating the current timer. Read recommendations about Timer in the Apple Energy Efficiency Guide here:
https://developer.apple.com/library/content/documentation/Performance/Conceptual/EnergyGuide-iOS/MinimizeTimerUse.html

ContentLicense: CC BY-SA 4.0

Body:
I'm developing a game and I want to create a pause menu. Here is my code:

self.view?.paused = true

but  NSTimer.scheduledTimerWithTimeInterval still running...

 for var i=0; i < rocketCount; i++ {
    var a: NSTimeInterval = 1
    ii += a
    delaysShow = 2.0 + ((stimulus + interStimulus) * ii)
    var time3 = NSTimer.scheduledTimerWithTimeInterval(delaysShow!, target: self, selector: Selector("showRocket:"), userInfo: rocketid[i], repeats: false)
 }

I want time3 to pause the timer when player click pause menu and continue run the timer when player come back to the game, but how can I pause NSTimer.scheduledTimerWithTimeInterval? help me please.

Body:
Even though the solutions exposed here are good, I thought an important insight was missing. Like a lot of people here explained, timer invalidate() and recreate is the best option. But one could argue that you could do something like this:

var paused:Bool

func timerAction() {
    if !paused {
        // Do stuff here
    }
}

is easier to implement, but it will be less efficient.

For energy impact reasons, Apple promotes avoiding timers whenever possible and to prefer event notifications. If you really need to use a timer, you should implement pauses efficiently by invalidating the current timer. Read recommendations about Timer in the Apple Energy Efficiency Guide here:
https://developer.apple.com/library/content/documentation/Performance/Conceptual/EnergyGuide-iOS/MinimizeTimerUse.html


问:
Difference between AUFK-AUFNR and AUFK-KDAUF
There are two fields in the SAP table AUFK, AUFNR and KDAUF, that I cannot differentiate. I searched around in the net, and both are being referred to as "Sales Order Number".

Can somebody kindly explain what the differences are between the two?

答: AUFNR is not the sales order number. Table AUFK stores the internal orders of the CO module, AUFNR is its number, so the internal order number. Internal order is a CO element (like a cost center), you can post on them. KDAUF is the sales order number (you can post sales orders on internal orders, this is why it is there).</p>


问:
Angular 2: Cannot find name 'Params'
When subscribing to the parameters of ActivatedRoute, I get the error Cannot find name 'Params'. From which package do I import it from?

```<code>import { Component, OnInit } from '@angular/core';
import { Recipe } from '../recipe.model';
import { RecipeService } from '../../services/recipe/recipe.service';
import { ActivatedRoute } from '@angular/router';
</code>```

// I'm missing an import here. Just don't know which package to load from.

```<code>@Component({
  selector: 'app-recipe-detail',
  templateUrl: './recipe-detail.component.html',
  styleUrls: ['./recipe-detail.component.css']
})
export class RecipeDetailComponent implements OnInit {
  recipe: Recipe;
  id: number;

  constructor (
    private rService: RecipeService ,
    private ACTIVATED_ROUTE: ActivatedRoute,
  ) {

  }

  ngOnInit() {
    const id = this.ACTIVATED_ROUTE.snapshot.params['id'];

    this.ACTIVATED_ROUTE.params.subscribe(
      ( P: Params ) => { // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< PROBLEM LINE
        this.id = +P['id'];
        this.recipe = this.rService.getRecipe( this.id );
      }
    );
  }

  onAddToShopList(){
    this.rService.addIngredientsToShopList( this.recipe.ingredients );
  }

}
</code>```

I searched the documentation:
https://angular.io/guide/router
I've checked all 25 instances of "Params" on said page.
I've checked all 301 instances of "import" on the same page.
At no point is "Params" ever imported.

This works fine without the import:

```<code> (P)=> {...}
</code>```

This leads to error:

```<code>(P:Params)=>{...} ?
</code>```

The question is about the type of "P" not the type of ACTIVATED_ROUTE.params, which is a Observable<Param>.

答:
Missing Import:</p>

```<code>import { Params } from '@angular/router';
</code>```

Title: Angular 2: Cannot find name 'Params'

Body:
When subscribing to the parameters of ActivatedRoute, I get the error Cannot find name 'Params'. From which package do I import it from?

import { Component, OnInit } from '@angular/core';
import { Recipe } from '../recipe.model';
import { RecipeService } from '../../services/recipe/recipe.service';
import { ActivatedRoute } from '@angular/router';

// I'm missing an import here. Just don't know which package to load from.

@Component({
  selector: 'app-recipe-detail',
  templateUrl: './recipe-detail.component.html',
  styleUrls: ['./recipe-detail.component.css']
})
export class RecipeDetailComponent implements OnInit {
  recipe: Recipe;
  id: number;

  constructor (
    private rService: RecipeService ,
    private ACTIVATED_ROUTE: ActivatedRoute,
  ) {

  }

  ngOnInit() {
    const id = this.ACTIVATED_ROUTE.snapshot.params['id'];

    this.ACTIVATED_ROUTE.params.subscribe(
      ( P: Params ) => { // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< PROBLEM LINE
        this.id = +P['id'];
        this.recipe = this.rService.getRecipe( this.id );
      }
    );
  }

  onAddToShopList(){
    this.rService.addIngredientsToShopList( this.recipe.ingredients );
  }

}

I searched the documentation:
https://angular.io/guide/router
I've checked all 25 instances of "Params" on said page.
I've checked all 301 instances of "import" on the same page.
At no point is "Params" ever imported.

This works fine without the import:

 (P)=> {...}

This leads to error:

(P:Params)=>{...} ?

The question is about the type of "P" not the type of ACTIVATED_ROUTE.params, which is a Observable<Param>.

Body:
Missing Import:

import { Params } from '@angular/router';


问:
Netmask and ip are incompatible in dlink dir-300
I have Dlink Dir-300 wireless router. I have to set a static ip settings there.
I specify Ip as 192.168.242.3 Netmask: 255.255.0.0. When I press enter it says that the ip is invalid. Although such configuration works on another(linksys) router normally.

When setting the static ip I have control only over last 2 bytes, first two are fixed, so we have 192.168.X.X according to our local network structure.

How can this problem be solved?

答: The netmask should be 255.255.255.0.</p>

Body: The netmask should be 255.255.255.0.


问:
Postgres Regex to Return first word before comma and first word after
I am trying to get the first and last name from a column using regex but I'm stumped.

I'm trying:

```<code>select
    substring('SMIRTH JR, DAVID ALLEN', '^[^ ,]+') as namemodified
</code>```

it should return

```<code>SMIRTH, DAVID
</code>```

but it only returns the last name. I can't figure out how to get both.

I also need it to work for:

```<code>SMIRTHJR, DAVID ALLEN
</code>```

since the data isn't very clean. Any ideas?

答:
Use regexp_matches function instead of substring (assuming Postgresql 9.x):

```<code>select
    regexp_matches(regexp_replace('SMIRTHJR, DAVID ALLEN','(JR|SR),', ','),
                   '([^\s,]+).*?(, [^\s,]+) [^\s,]+$') as namemodified
</code>```

The above will return SMIRTH, DAVID for both input strings SMIRTHJR, DAVID ALLEN or SMIRTH JR, DAVID ALLEN

Body:
I am trying to get the first and last name from a column using regex but I'm stumped.

I'm trying:

select
    substring('SMIRTH JR, DAVID ALLEN', '^[^ ,]+') as namemodified

it should return

SMIRTH, DAVID

but it only returns the last name. I can't figure out how to get both.

I also need it to work for:

SMIRTHJR, DAVID ALLEN

since the data isn't very clean. Any ideas?

Body:
Use regexp_matches function instead of substring (assuming Postgresql 9.x):

select
    regexp_matches(regexp_replace('SMIRTHJR, DAVID ALLEN','(JR|SR),', ','),
                   '([^\s,]+).*?(, [^\s,]+) [^\s,]+$') as namemodified

The above will return SMIRTH, DAVID for both input strings SMIRTHJR, DAVID ALLEN or SMIRTH JR, DAVID ALLEN


问:
ld: library not found for -lrt
I am trying to run a project that was made and works for Ubuntu but on Mac OS. And when I am doing the make I got the following error:

```<code>ld: library not found for -lrt
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [consumer] Error 1
make[1]: *** [CMakeFiles/consumer.dir/all] Error 2
make: *** [all] Error 2
</code>```

I can't see any library with that name at thole project.

Can anyone explain what it is and how to solve it?

答:
On old Linux systems, several functions, such as clock_gettime, are documented to need -lrt for old versions of GNU libc. This is no more the case on recent glibc (after 2.17 from 2013).

So you can  remove -lrt  from your Makefile (and remove the thing from your cmake configuration  thing generating it).

BTW, removing -lrt should also fit for recent Linux distributions.

PS. If you are paying support for your Linux system, you should ask your support for advice.

Title: ld: library not found for -lrt

Body:
I am trying to run a project that was made and works for Ubuntu but on Mac OS. And when I am doing the make I got the following error:

ld: library not found for -lrt
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [consumer] Error 1
make[1]: *** [CMakeFiles/consumer.dir/all] Error 2
make: *** [all] Error 2

I can't see any library with that name at thole project.

Can anyone explain what it is and how to solve it?


问:
numpy undefined symbol: PyFPE_jbuf
I am trying to use the One Million Song Dataset, for this i had to install python tables, numpy, cython, hdf5, numexpr, and so.

Yesterday i managed to install all i needed, and after having some troubles with hdf5, i downloaded the precompiled binary packages and saved them in my /bin folder, and the respective libraries in /lib , after that i tested this python script : http://labrosa.ee.columbia.edu/millionsong/sites/default/files/tutorial1.py.txt

and it worked fine, to be clear the way i made it work was to first run the script and start installing the needed dependencies, but today i restarted my laptop and it didn't work, now it throws me this error on the console :

```<code>python2.7 script.py
</code>```

returns :

```<code>import numpy as np # get it at: http://numpy.scipy.org/
from . import random
from .mtrand import *
ImportError: /home/francisco/.local/lib/python2.7/site-packages/numpy/random/mtrand.so: undefined symbol: PyFPE_jbuf
</code>```

seems to me that there is a missing variable in such file, my guess is that the script is looking for the numpy library in the wrong place, since i made so many failed installations maybe i broke something and it only worked out because it was loaded in the temporal memory of the computer.

I tried installing Anaconda, and i created a new environment  and installed the packaged with the anaconda package manager, and even thought i listed all packaged and it returns :

```<code># packages in environment at /home/francisco/anaconda2/envs/Music:
#
biopython                 1.66                np110py27_0
cython                    0.23.4                    <pip>
hdf5                      1.8.15.1                      2
mkl                       11.3.1                        0
numexpr                   2.5                 np110py27_0
numpy                     1.10.4                   py27_1
openssl                   1.0.2g                        0
pillow                    3.1.1                     <pip>
pip                       8.1.1                    py27_0
pytables                  3.2.2               np110py27_1
python                    2.7.11                        0
python-ldap               2.4.25                    <pip>
readline                  6.2                           2
reportlab                 3.3.0                     <pip>
requirements              0.1                       <pip>
setuptools                20.3                     py27_0
sqlite                    3.9.2                         0
tables                    3.2.2                     <pip>
tk                        8.5.18                        0
wheel                     0.29.0                   py27_0
zlib                      1.2.8                         0
</code>```

i still get the same error. I really need help and don't know what else to try. Thanks.

答:
For cython users:

This post was helpful. The post explains, that there is some flag (--with-fpectl), which is either set during the compilation of cpython or not. When a library has been compiled using a cpython without that flag, it is incompatible to a version with that flag being set. This effect does only show up when you use cython, as numpy itself does not use this extension.

As further stated in that post, my Ubuntu 16.04 has been created with this flag and Conda without it. For me, it was specifically the module hmmlearn throwing the undefined symbol error. This must be the case because it was shipped by Ubuntu with the flag being set and not by anaconda. So I uninstalled hmmlearn and manually installed it anew from sourcescode (Anaconda, unfortunately, does not offer hmmlearn). --> Works!

Title: numpy undefined symbol: PyFPE_jbuf

Body:
I am trying to use the One Million Song Dataset, for this i had to install python tables, numpy, cython, hdf5, numexpr, and so.

Yesterday i managed to install all i needed, and after having some troubles with hdf5, i downloaded the precompiled binary packages and saved them in my /bin folder, and the respective libraries in /lib , after that i tested this python script : http://labrosa.ee.columbia.edu/millionsong/sites/default/files/tutorial1.py.txt

and it worked fine, to be clear the way i made it work was to first run the script and start installing the needed dependencies, but today i restarted my laptop and it didn't work, now it throws me this error on the console :

python2.7 script.py

returns :

import numpy as np # get it at: http://numpy.scipy.org/
from . import random
from .mtrand import *
ImportError: /home/francisco/.local/lib/python2.7/site-packages/numpy/random/mtrand.so: undefined symbol: PyFPE_jbuf

seems to me that there is a missing variable in such file, my guess is that the script is looking for the numpy library in the wrong place, since i made so many failed installations maybe i broke something and it only worked out because it was loaded in the temporal memory of the computer.

I tried installing Anaconda, and i created a new environment  and installed the packaged with the anaconda package manager, and even thought i listed all packaged and it returns :

# packages in environment at /home/francisco/anaconda2/envs/Music:
#
biopython                 1.66                np110py27_0
cython                    0.23.4                    <pip>
hdf5                      1.8.15.1                      2
mkl                       11.3.1                        0
numexpr                   2.5                 np110py27_0
numpy                     1.10.4                   py27_1
openssl                   1.0.2g                        0
pillow                    3.1.1                     <pip>
pip                       8.1.1                    py27_0
pytables                  3.2.2               np110py27_1
python                    2.7.11                        0
python-ldap               2.4.25                    <pip>
readline                  6.2                           2
reportlab                 3.3.0                     <pip>
requirements              0.1                       <pip>
setuptools                20.3                     py27_0
sqlite                    3.9.2                         0
tables                    3.2.2                     <pip>
tk                        8.5.18                        0
wheel                     0.29.0                   py27_0
zlib                      1.2.8                         0

i still get the same error. I really need help and don't know what else to try. Thanks.


问:
How to mutate() a list of columns using map2() in dplyr

I recently had to compile a data frame of student scores (one row per student, id column and several integer-valued columns, one per score component). I had to combine a "master" data frame and several "correction" data frames (containing mostly NA and some updates to the master), so that the result contains the maximum values from the master, and all corrections.

I succeeded by copy-pasting a sequence of mutate() calls, which works (see example below), but is not elegant in my opinion. What I would have wanted to do, was instead of copying and pasting, to use something along the lines of map2 and two lists of columns to compare the columns pair-wise. Something like (which obviously does not work as such):

```<code>list_of_cols1 <- list(col1.x, col2.x, col3.x)
list_of_cols2 <- list(col1.y, col2.y, col3.y
map2(list_of_cols1, list_of_cols2, ~ column = pmax(.x, .y, na.rm=T))
</code>```

I can't seem to be able to figure out to do it. My question is: how to specify such lists of columns and mutate them in one map2() call in dplyr pipe, or is it even possible – have I gotten it all wrong?

Minimum working example

```<code>library(tidyverse)

master <- tibble(
  id=c(1,2,3),
  col1=c(1,1,1),
  col2=c(2,2,2),
  col3=c(3,3,3)
)
correction1 <- tibble(
  id=seq(1,3),
  col1=c(NA, NA, 2 ),
  col2=c( 1, NA, 3 ),
  col3=c(NA, NA, NA)
)

result <- reduce(
  # Ultimately there would several correction data frames
  list(master, correction1),
  function(x,y) {
    x <- x %>%
      left_join(
        y,
        by = c("id")
      ) %>%
      # Wish I knew how to do this mutate call with map2
      mutate(
        col1 = pmax(col1.x, col1.y, na.rm=T),
        col2 = pmax(col2.x, col2.y, na.rm=T),
        col3 = pmax(col3.x, col3.y, na.rm=T)
      ) %>%
      select(id, col1:col3)
  }
)
</code>```

The result is

```<code>> result
# A tibble: 3 x 4
     id  col1  col2  col3
  <int> <dbl> <dbl> <dbl>
1     1     1     2     3
2     2     1     2     3
3     3     2     3     3
</code>```

答:
If correction tables will always have the same structure as master, you can do something like the following:

```<code>library(dplyr)
library(purrr)

update_master = function(...){
  map(list(...), as.matrix) %>%
    reduce(pmax, na.rm = TRUE) %>%
    data.frame()
}

update_master(master, correction1)
</code>```

To allow id to take character values, make the following modification:

```<code>update_master = function(x, ...){
  map(list(x, ...), function(x) as.matrix(x[-1])) %>%
    reduce(pmax, na.rm = TRUE) %>%
    data.frame(id = x[[1]], .)
}

update_master(master, correction1)
</code>```

Result:

```<code>  id col1 col2 col3
1  1    1    2    3
2  2    1    2    3
3  3    2    3    3
</code>```

Body:
I recently had to compile a data frame of student scores (one row per student, id column and several integer-valued columns, one per score component). I had to combine a "master" data frame and several "correction" data frames (containing mostly NA and some updates to the master), so that the result contains the maximum values from the master, and all corrections.

I succeeded by copy-pasting a sequence of mutate() calls, which works (see example below), but is not elegant in my opinion. What I would have wanted to do, was instead of copying and pasting, to use something along the lines of map2 and two lists of columns to compare the columns pair-wise. Something like (which obviously does not work as such):

list_of_cols1 <- list(col1.x, col2.x, col3.x)
list_of_cols2 <- list(col1.y, col2.y, col3.y
map2(list_of_cols1, list_of_cols2, ~ column = pmax(.x, .y, na.rm=T))

I can't seem to be able to figure out to do it. My question is: how to specify such lists of columns and mutate them in one map2() call in dplyr pipe, or is it even possible – have I gotten it all wrong?

Minimum working example

library(tidyverse)

master <- tibble(
  id=c(1,2,3),
  col1=c(1,1,1),
  col2=c(2,2,2),
  col3=c(3,3,3)
)
correction1 <- tibble(
  id=seq(1,3),
  col1=c(NA, NA, 2 ),
  col2=c( 1, NA, 3 ),
  col3=c(NA, NA, NA)
)

result <- reduce(
  # Ultimately there would several correction data frames
  list(master, correction1),
  function(x,y) {
    x <- x %>%
      left_join(
        y,
        by = c("id")
      ) %>%
      # Wish I knew how to do this mutate call with map2
      mutate(
        col1 = pmax(col1.x, col1.y, na.rm=T),
        col2 = pmax(col2.x, col2.y, na.rm=T),
        col3 = pmax(col3.x, col3.y, na.rm=T)
      ) %>%
      select(id, col1:col3)
  }
)

The result is

> result
# A tibble: 3 x 4
     id  col1  col2  col3
  <int> <dbl> <dbl> <dbl>
1     1     1     2     3
2     2     1     2     3
3     3     2     3     3

Body:
If correction tables will always have the same structure as master, you can do something like the following:

library(dplyr)
library(purrr)

update_master = function(...){
  map(list(...), as.matrix) %>%
    reduce(pmax, na.rm = TRUE) %>%
    data.frame()
}

update_master(master, correction1)

To allow id to take character values, make the following modification:

update_master = function(x, ...){
  map(list(x, ...), function(x) as.matrix(x[-1])) %>%
    reduce(pmax, na.rm = TRUE) %>%
    data.frame(id = x[[1]], .)
}

update_master(master, correction1)

Result:

  id col1 col2 col3
1  1    1    2    3
2  2    1    2    3
3  3    2    3    3


问:
Is there a packet sniffer that can be limited to one single program?
I've been using Wireshark for a while now to analyze a few programs. Is there a way that I can limit Wireshark to sniff only one program? Or is there another program that does something like this?</p>

答: If you are sniffing a web application, you should try to use HttpFox, which is a Firefox plugin. It only show net traffic from the current website.</p>


问:
understanding a http request and nested function in ajax
I am referencing this code to build a twitch viewer app, which I'm having difficulties in understanding:

$(document).ready(function() {

  let usernames = ["user1", "user2", "user3", "user4"];

  usernames.forEach(function(user) {
    let http = "https://api.twitch.tv/kraken/streams/" + user;

    function getAjax(getdata) {
      $.ajax({
        url: http,
        headers: {
          'Client-ID': 'myclientid'
        },
        success: function(data) {
          getdata(data)
        }
      });
    }
  });
})```

What does 'headers' do exactly? I looked it up on twitch and couldn't find a detailed description. It doesn't look like it gives/adds anything to my http request. Twitch says the header "securely identify my application." but wasn't sure what that mean. I thought if it works similar to an API key it should be included in the request.

What does the 'getdata' function in this code do? does it simply store the data i receive from the ajax request?

答:
1) Headers are included in the request. You should be able to see them in the developer tools; this is what it looks like in Firefox

2) getdata is a callback function that is passed into getAjax by consumers, which can then act on the data as necessary, for example...

getAjax(function(data) {
     // do something with data
   })

Note also, you're redeclaring the function in each iteration of the loop, but not actually calling it anywhere. You probably want something more like this...

```<code>$(document).ready(function() {
  let usernames = ["user1", "user2", "user3", "user4"];

  function getAjax(url, getdata) {
    $.ajax({
      url: url,
      headers: {
        'Client-ID': 'myclientid'
      },
      success: function(data) {
        getdata(data)
      }
    });
  }

  usernames.forEach(function(user) {
    let http = "https://api.twitch.tv/kraken/streams/" + user;
    getAjax(http, function(data) {
      // do something with data
    })
  });
})
</code>```

Body:
I am referencing this code to build a twitch viewer app, which I'm having difficulties in understanding:

$(document).ready(function() {

  let usernames = ["user1", "user2", "user3", "user4"];

  usernames.forEach(function(user) {
    let http = "https://api.twitch.tv/kraken/streams/" + user;

    function getAjax(getdata) {
      $.ajax({
        url: http,
        headers: {
          'Client-ID': 'myclientid'
        },
        success: function(data) {
          getdata(data)
        }
      });
    }
  });
})

What does 'headers' do exactly? I looked it up on twitch and couldn't find a detailed description. It doesn't look like it gives/adds anything to my http request. Twitch says the header "securely identify my application." but wasn't sure what that mean. I thought if it works similar to an API key it should be included in the request.

What does the 'getdata' function in this code do? does it simply store the data i receive from the ajax request?

Body:
1) Headers are included in the request. You should be able to see them in the developer tools; this is what it looks like in Firefox

2) getdata is a callback function that is passed into getAjax by consumers, which can then act on the data as necessary, for example...

getAjax(function(data) {
     // do something with data
   })

Note also, you're redeclaring the function in each iteration of the loop, but not actually calling it anywhere. You probably want something more like this...

$(document).ready(function() {
  let usernames = ["user1", "user2", "user3", "user4"];

  function getAjax(url, getdata) {
    $.ajax({
      url: url,
      headers: {
        'Client-ID': 'myclientid'
      },
      success: function(data) {
        getdata(data)
      }
    });
  }

  usernames.forEach(function(user) {
    let http = "https://api.twitch.tv/kraken/streams/" + user;
    getAjax(http, function(data) {
      // do something with data
    })
  });
})


问:
Brackets [ ] around string with grep and ps - ef
I am trying to get the time of the process start.
Usually I use the brackets on the first letter of the process that I am running.
It takes away the self reporting "grep" in the ps output.

```<code>#!/bin/bash

set -x
restarTXG="sendevent -E FORCE_STARTJOB -J CASPERRT_CD_TXG_DR_STR_PS"
bounceTXG="sendevent -E FORCE_STARTJOB -J CASPERRT_CD_TXG_DR_STP_PS; sleep 10 ; sendevent -E FORCE_STARTJOB -J CASPERRT_CD_TXG_DR_STR_PS"
timeofTXG=$(ps -ef | grep [t]xg | awk '{print $5}' )

if [ -n "$timeofTXG" ] ; then
    printf "%s\n" "The TXG_DR is ON as of $timeofTXG"
else
    printf "%s\n" "'The TXG_DR is OFF"
fi
</code>```

18:40 is the time I run the check script.  17:44 is the time the process started.

```<code>++ ps -ef
++ grep '[t]xg'
++ awk '{print $5}'
+ timeofTXG='17:44
18:40
18:40'
+ '[' -n '17:44
18:40
18:40' ']'
+ printf '%s\n' 'The TXG_DR is ON as of 17:44
18:40
18:40'
The TXG_DR is ON as of 17:44
18:40
18:40
</code>```

I don't really know how the square brackets work.   When I run the ps from the command line, the [] brackets do work -- ps -ef | grep [t]xg | awk '{print $5}'
however in the context of the bash script, they are not working, they are giving me the time of the self reporting grep.
How do the brackets work?  Why do they work on the command line and not in the script?   How do I get rid of the self revealing grep in bash script ?

答:
If you are running awk already you don't need grep, do something like this (which I guess is your intention):

```<code>ps -ef | awk '$8 ~ /txg/ {print $5}'
</code>```

Body:
I am trying to get the time of the process start.
Usually I use the brackets on the first letter of the process that I am running.
It takes away the self reporting "grep" in the ps output.

#!/bin/bash

set -x
restarTXG="sendevent -E FORCE_STARTJOB -J CASPERRT_CD_TXG_DR_STR_PS"
bounceTXG="sendevent -E FORCE_STARTJOB -J CASPERRT_CD_TXG_DR_STP_PS; sleep 10 ; sendevent -E FORCE_STARTJOB -J CASPERRT_CD_TXG_DR_STR_PS"
timeofTXG=$(ps -ef | grep [t]xg | awk '{print $5}' )

if [ -n "$timeofTXG" ] ; then
    printf "%s\n" "The TXG_DR is ON as of $timeofTXG"
else
    printf "%s\n" "'The TXG_DR is OFF"
fi

18:40 is the time I run the check script.  17:44 is the time the process started.

++ ps -ef
++ grep '[t]xg'
++ awk '{print $5}'
+ timeofTXG='17:44
18:40
18:40'
+ '[' -n '17:44
18:40
18:40' ']'
+ printf '%s\n' 'The TXG_DR is ON as of 17:44
18:40
18:40'
The TXG_DR is ON as of 17:44
18:40
18:40

I don't really know how the square brackets work.   When I run the ps from the command line, the [] brackets do work -- ps -ef | grep [t]xg | awk '{print $5}'
however in the context of the bash script, they are not working, they are giving me the time of the self reporting grep.
How do the brackets work?  Why do they work on the command line and not in the script?   How do I get rid of the self revealing grep in bash script ?

Body:
If you are running awk already you don't need grep, do something like this (which I guess is your intention):

ps -ef | awk '$8 ~ /txg/ {print $5}'


问:
Reading JSON String using JSON/Gson
I have the JSON String of the below format which I get as a http request in Java. I need to get the name and values of the below JSON string, but I am not able to get the correct solution.

Can any one tell me how to parse this? Also, let me know if we will be able to format this string because there is no property names from the 3 element.

The string format is

```<code>{

 'appname':'application',
 'Version':'0.1.0',
 'UUID':'300V',
 'WWXY':'310W',
 'ABCD':'270B',
 'YUDE':'280T'

}
</code>```

edit#1 formatted the question.

答:
With which language do you want to do that ?

Here is the solution for PHP :

```<code>$data = json_decode('the json');
</code>```

Title: Reading JSON String using JSON/Gson

Body:
I have the JSON String of the below format which I get as a http request in Java. I need to get the name and values of the below JSON string, but I am not able to get the correct solution.

Can any one tell me how to parse this? Also, let me know if we will be able to format this string because there is no property names from the 3 element.

The string format is

{

 'appname':'application',
 'Version':'0.1.0',
 'UUID':'300V',
 'WWXY':'310W',
 'ABCD':'270B',
 'YUDE':'280T'

}

edit#1 formatted the question.

Body:
With which language do you want to do that ?

Here is the solution for PHP :

$data = json_decode('the json');


问:
Install ShareLatex on a RaspberryPi / no matching manifest for linux/arm in the manifest list entries
I try to install ShareLatex like this:

https://www.ioblogger.de/2017/03/sharelatex-docker-image-einrichtung-unter-debian-8-inkl-aller-texlive-pakete-und-systemd/

But after this command:

docker-compose up

I'll get this error:

$ docker-compose up
Pulling mongo (mongo:latest)...
latest: Pulling from library/mongo
ERROR: no matching manifest for linux/arm in the manifest list entries

答: I found out: ShareLaTex do not run on ARM!</p>


问:
django rest framework abstract class serializer
I have some models like these:

```<code>class TypeBase(models.Model):
    name = models.CharField(max_length=20)
    class Meta:
        abstract=True

class PersonType(TypeBase):
    pass

class CompanyType(TypeBase):
    pass
</code>```

Having this, I want to create just one serializer that holds all these field types (serialization, deserialization, update and save).

To be more specific, I want only one serializer (TypeBaseSerializer) that print the Dropdown on the UI, serialize the json response, deserialize it on post and save it for all my based types.

Something like this:

```<code>class TypeBaseSerializer(serializers.Serializer):
    class Meta:
        model = TypeBase
        fields = ('id', 'name')
</code>```

Is it possible?

答:
Just iterating a bit over @adki's answer:

it is possible to skip model for TypeBaseSerializer;

derived serializers can refer to TypeBaseSerializer.Meta, so you would change them in a single place.

```<code>class TypeBaseSerializer(serializers.Serializer):
    class Meta:
        fields = ('id', 'name', 'created')
        abstract = True

    def func(...):
    # ... some logic

class PersonTypeSerializer(TypeBaseSerializer):
    class Meta:
        model = PersonType
        fields = TypeBaseSerializer.Meta.fields + ('age', 'date_of_birth')

class CompanyTypeSerializer(TypeBaseSerializer):
    class Meta:
        model = CompanyType
        fields = TypeBaseSerializer.Meta.fields
</code>```

Body:
I have some models like these:

class TypeBase(models.Model):
    name = models.CharField(max_length=20)
    class Meta:
        abstract=True

class PersonType(TypeBase):
    pass

class CompanyType(TypeBase):
    pass

Having this, I want to create just one serializer that holds all these field types (serialization, deserialization, update and save).

To be more specific, I want only one serializer (TypeBaseSerializer) that print the Dropdown on the UI, serialize the json response, deserialize it on post and save it for all my based types.

Something like this:

class TypeBaseSerializer(serializers.Serializer):
    class Meta:
        model = TypeBase
        fields = ('id', 'name')

Is it possible?

Body:
Just iterating a bit over @adki's answer:

it is possible to skip model for TypeBaseSerializer;

derived serializers can refer to TypeBaseSerializer.Meta, so you would change them in a single place.

class TypeBaseSerializer(serializers.Serializer):
    class Meta:
        fields = ('id', 'name', 'created')
        abstract = True

    def func(...):
    # ... some logic

class PersonTypeSerializer(TypeBaseSerializer):
    class Meta:
        model = PersonType
        fields = TypeBaseSerializer.Meta.fields + ('age', 'date_of_birth')

class CompanyTypeSerializer(TypeBaseSerializer):
    class Meta:
        model = CompanyType
        fields = TypeBaseSerializer.Meta.fields


问:
How do I create an Excel (.XLS and .XLSX) file in C# without installing Microsoft Office?
How can I create an Excel spreadsheet with C# without requiring Excel to be installed on the machine that's running the code?</p>

答:
One really easy option which is often overlooked is to create a .rdlc report using Microsoft Reporting and export it to excel format. You can design it in visual studio and generate the file using:

```<code>localReport.Render("EXCELOPENXML", null, ((name, ext, encoding, mimeType, willSeek) => stream = new FileStream(name, FileMode.CreateNew)), out warnings);
</code>```

You can also export it do .doc or .pdf, using "WORDOPENXML" and "PDF" respectively, and it's supported on many different platforms such as ASP.NET and SSRS.

It's much easier to make changes in a visual designer where you can see the results, and trust me, once you start grouping data, formatting group headers, adding new sections, you don't want to mess with dozens of XML nodes.

OwnerDisplayName: mistrmark

LastEditorDisplayName: mistrmark

Body:
One really easy option which is often overlooked is to create a .rdlc report using Microsoft Reporting and export it to excel format. You can design it in visual studio and generate the file using:

localReport.Render("EXCELOPENXML", null, ((name, ext, encoding, mimeType, willSeek) => stream = new FileStream(name, FileMode.CreateNew)), out warnings);

You can also export it do .doc or .pdf, using "WORDOPENXML" and "PDF" respectively, and it's supported on many different platforms such as ASP.NET and SSRS.

It's much easier to make changes in a visual designer where you can see the results, and trust me, once you start grouping data, formatting group headers, adding new sections, you don't want to mess with dozens of XML nodes.


问:
Add a delay or sleep to an array of promises in nodejs
I have a promise chain problem I have been grappling with.  I make a call out to an external api that returns me data that I need to process and ingest into a mongo database. I am using nodejs and mongodb with express.  Anyway, the calls to the api are working ok, the problem is that I am making tons of them at once.  I want to slow them down, like make all the calls for one set. Wait a minute. Make all the calls for the next set.  If this was a known amount of sets I would just promise chain them.  I dont know how many sets there are so I am looping through them.  I think the closure is the problem but cant work around it. on to the example code!</p>

```<code>  function readApi(carFactory){
    var promise = new Promise(function(resolve, reject) {
      // call out to api, get set of car data from factory1

      console.log(carFactory);
      if (true) {
        console.log('resolved');
        resolve("Stuff worked!"+carFactory);
      }
      else {
        reject(Error("It broke"));
      }
    });
    return promise;
  }

  function manager(){

    //singular call
    readApi("this is a singular test").then(returnedThing=>{
      console.log(returnedThing); //Stuff worked! this is a singular test
    });

    let dynamicList = ["carFactory1", "carFactory2","carFactory3","carFactory..N"];
    let readApiAction = [];
    dynamicList.forEach(carIter=>{
      readApiAction.push(readApi(carIter));
    });
    //ok so now I got an array of promise objects.
    //I want to call the first one, wait 1 minute and then call the next one.

    //originally I was calling promise.all, but there is no way to get at
    //each promise to pause them out so this code is what I am looking to fix
    let results= Promise.all(readApiAction);
    results.then(data=>{
      data.forEach(resolvedData=>{
        console.log(resolvedData); //Stuff worked carFactory1, etc...
      });
    });

    //singular call with timeout, this does not work, each one called at the same time
    let readApiActionTimeouts = [];
    dynamicList.forEach(carIter=>{
      setTimeout(callingTimeout(carIter), 6000);
    });
  }

  //just a function to call the promise in a timeout
  //this fails with this  - TypeError: "callback" argument must be a function
  function callingTimeout(carIter){
    readApi(carIter).then(returnedThing=>{
      console.log("timeout version"+returnedThing);
    });
  }
</code>```

答:
you get the error : TypeError: "callback" argument must be a function because your callingTimeout returns nothing and setTimeout needs a function as argument, this is how to fixe it :

```<code>    let readApiActionTimeouts = [];
    dynamicList.forEach(carIter=>{
          callingTimeout(carIter)
    });
</code>```

your promise :

```<code>function readApi(carFactory){
    var promise = new Promise(function(resolve, reject) {
       //...
       setTimeout(()=>{
          resolve("Stuff worked!"+carFactory);
       }, 6000);
       //...
    });
    return promise;
  }
</code>```

Body:
I have a promise chain problem I have been grappling with.  I make a call out to an external api that returns me data that I need to process and ingest into a mongo database. I am using nodejs and mongodb with express.  Anyway, the calls to the api are working ok, the problem is that I am making tons of them at once.  I want to slow them down, like make all the calls for one set. Wait a minute. Make all the calls for the next set.  If this was a known amount of sets I would just promise chain them.  I dont know how many sets there are so I am looping through them.  I think the closure is the problem but cant work around it. on to the example code!

  function readApi(carFactory){
    var promise = new Promise(function(resolve, reject) {
      // call out to api, get set of car data from factory1

      console.log(carFactory);
      if (true) {
        console.log('resolved');
        resolve("Stuff worked!"+carFactory);
      }
      else {
        reject(Error("It broke"));
      }
    });
    return promise;
  }

  function manager(){

    //singular call
    readApi("this is a singular test").then(returnedThing=>{
      console.log(returnedThing); //Stuff worked! this is a singular test
    });

    let dynamicList = ["carFactory1", "carFactory2","carFactory3","carFactory..N"];
    let readApiAction = [];
    dynamicList.forEach(carIter=>{
      readApiAction.push(readApi(carIter));
    });
    //ok so now I got an array of promise objects.
    //I want to call the first one, wait 1 minute and then call the next one.

    //originally I was calling promise.all, but there is no way to get at
    //each promise to pause them out so this code is what I am looking to fix
    let results= Promise.all(readApiAction);
    results.then(data=>{
      data.forEach(resolvedData=>{
        console.log(resolvedData); //Stuff worked carFactory1, etc...
      });
    });

    //singular call with timeout, this does not work, each one called at the same time
    let readApiActionTimeouts = [];
    dynamicList.forEach(carIter=>{
      setTimeout(callingTimeout(carIter), 6000);
    });
  }

  //just a function to call the promise in a timeout
  //this fails with this  - TypeError: "callback" argument must be a function
  function callingTimeout(carIter){
    readApi(carIter).then(returnedThing=>{
      console.log("timeout version"+returnedThing);
    });
  }

Body:
you get the error : TypeError: "callback" argument must be a function because your callingTimeout returns nothing and setTimeout needs a function as argument, this is how to fixe it :

    let readApiActionTimeouts = [];
    dynamicList.forEach(carIter=>{
          callingTimeout(carIter)
    });

your promise :

function readApi(carFactory){
    var promise = new Promise(function(resolve, reject) {
       //...
       setTimeout(()=>{
          resolve("Stuff worked!"+carFactory);
       }, 6000);
       //...
    });
    return promise;
  }