问:
How to run app with UNNotificationServiceExtension on pre iOS 10?
My app implements the new iOS 10 rich push NotificationService extension.

Everything works as expected on iOS 10, but I also want to support pre iOS 10 devices - of course not rich push, but just regular push. When lowering the deployment target in Xcode to e.g. 8.0 or 9.0 and trying to run on an older simulator or device i get the following errors:

```<code>Simulator: The operation couldn’t be completed. (LaunchServicesError error 0.)
Device: This app contains an app extension that specifies an extension point identifier that is not supported on this version of iOS for the value of the NSExtensionPointIdentifier key in its Info.plist.
</code>```

I couldn't find anything officially by Apple stating that your app will only run on iOS 10+ once you add a Service Extension - can someone confirm that?

答:
change status of frameworks to optional . when it is required some frameworks not work by ios 9.
enter image description here</p>

Body:
My app implements the new iOS 10 rich push NotificationService extension.

Everything works as expected on iOS 10, but I also want to support pre iOS 10 devices - of course not rich push, but just regular push. When lowering the deployment target in Xcode to e.g. 8.0 or 9.0 and trying to run on an older simulator or device i get the following errors:

Simulator: The operation couldn’t be completed. (LaunchServicesError error 0.)
Device: This app contains an app extension that specifies an extension point identifier that is not supported on this version of iOS for the value of the NSExtensionPointIdentifier key in its Info.plist.

I couldn't find anything officially by Apple stating that your app will only run on iOS 10+ once you add a Service Extension - can someone confirm that?


来源: stackexchange

问:
Is there a way to retrieve the view definition from a SQL Server using plain ADO?
I'm successfully extracting column definitions from databases hosted on a SQL server using the ADO Connection OpenSchema() call in its various incarnations so I can programmatically recreate those tables in another SQL database. So far, so good.

The main interaction with the above tables happens using multiple views; while OpenSchema() is able to return the column definitions for the view in the same way that it returns column definitions for a table, a crucial bit of information is missing - which table and column in the underlying tables the column in the view maps to.

I tried to access the SQL command used to create the view using ADOX Catalog Views, but it appears that the OLEDB driver for SQL Server that we're using doesn't support this functionality.

Is there any way to get at this information for the view configuration via ADO, either in a way that states "ColumnX maps to ColumnY in table Z" or in the form of the actual SQL command used to create the view?

答:
Which version of SQL Server?

For SQL Server 2005 and later, you can obtain the SQL script used to create the view like this:

```<code>select definition
from sys.objects     o
join sys.sql_modules m on m.object_id = o.object_id
where o.object_id = object_id( 'dbo.MyView')
  and o.type      = 'V'
</code>```

This returns a single row containing the script used to create/alter the view.

Other columns in the table tell about about options in place at the time the view was compiled.

Caveats

If the view was last modified with ALTER VIEW, then the script will be an ALTER VIEW statement rather than a CREATE VIEW statement.

The script reflects the name as it was created. The only time it gets updated is if you execute ALTER VIEW, or drop and recreate the view with CREATE VIEW. If the view has been renamed (e.g., via sp_rename) or ownership has been transferred to a different schema, the script you get back will reflect the original  CREATE/ALTER VIEW statement: it will not reflect the objects current name.

Some tools truncate the output. For example, the MS-SQL command line tool sqlcmd.exe truncates the data at 255 chars. You can pass the parameter -y N to get the result with N chars.

ContentLicense: CC BY-SA 2.5

Body:
Which version of SQL Server?

For SQL Server 2005 and later, you can obtain the SQL script used to create the view like this:

select definition
from sys.objects     o
join sys.sql_modules m on m.object_id = o.object_id
where o.object_id = object_id( 'dbo.MyView')
  and o.type      = 'V'

This returns a single row containing the script used to create/alter the view.

Other columns in the table tell about about options in place at the time the view was compiled.

Caveats

If the view was last modified with ALTER VIEW, then the script will be an ALTER VIEW statement rather than a CREATE VIEW statement.

The script reflects the name as it was created. The only time it gets updated is if you execute ALTER VIEW, or drop and recreate the view with CREATE VIEW. If the view has been renamed (e.g., via sp_rename) or ownership has been transferred to a different schema, the script you get back will reflect the original  CREATE/ALTER VIEW statement: it will not reflect the objects current name.

Some tools truncate the output. For example, the MS-SQL command line tool sqlcmd.exe truncates the data at 255 chars. You can pass the parameter -y N to get the result with N chars.

ContentLicense: CC BY-SA 3.0


问:
Click on a filename to open in a new tab with Sublime
Often in my personal readme.txt files / log files, I have some references to other .txt files. It can be relative path (..\notes\blah.txt) or absolute path (like on the screenshot below).

Is it possible, for a .txt file, to have this behaviour in Sublime: double-click on a filename to open it in a new tab?

答:
Note: Clickable URLs plugin is not really usable for me, because it parses the whole file, highlights the URLs (thanks to a nice regex), and then listens to CTRL+ALT+ENTER: if more than ~ 500 highlighted items, Sublime Text becomes highly unresponsive.

Here is a working solution.

First put this file lllaunch.py in your user packages (e.g. C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\User\):

```<code>import sublime, sublime_plugin
import subprocess
import webbrowser
import re

BROWSER = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
EDITOR = 'C:\Program Files\Sublime Text 2\sublime_text.exe'

class LllaunchCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        for region in self.view.sel():
            s = self.view.substr(self.view.line(region))
            i = region.begin() - self.view.line(region).begin()

            start = 0
            end = -1
            for j, c in enumerate(s):
                if c == ' ':
                    if j < i:
                        start = j
                    else:
                        end = j
                        break
            word = s[start:end].strip() if end != -1 else s[start:].strip()
            isurl = bool(re.match("\\bhttps?://[-A-Za-z0-9+&@#/%?=~_()|!:,.;']*[-A-Za-z0-9+&@#/%=~_(|]", word))
            if isurl:
                webbrowser.register('mybrowser', None, webbrowser.GenericBrowser(BROWSER))
                webbrowser.get('mybrowser').open(word)
            else:
                s = '"' + s.split('"')[s[:i].count('"')] + '"'

                command = '"%s" %s' % (EDITOR, s)
                subprocess.Popen(command)
</code>```

Then add the following line to C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\User\Default (Windows).sublime-keymap:

```<code>{ "keys": ["ctrl+alt+enter"], "command": "lllaunch" }
</code>```

Restart Sublime Text.

Now:

doing CTRLALTENTER on an URL will open browser.

doing CTRLALTENTER on a filename with quotes (e.g. "C:\test\readme.txt") will edit the file in your favorite editor.

Body:
Note: Clickable URLs plugin is not really usable for me, because it parses the whole file, highlights the URLs (thanks to a nice regex), and then listens to CTRL+ALT+ENTER: if more than ~ 500 highlighted items, Sublime Text becomes highly unresponsive.

Here is a working solution.

First put this file lllaunch.py in your user packages (e.g. C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\User\):

import sublime, sublime_plugin
import subprocess
import webbrowser
import re

BROWSER = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
EDITOR = 'C:\Program Files\Sublime Text 2\sublime_text.exe'

class LllaunchCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        for region in self.view.sel():
            s = self.view.substr(self.view.line(region))
            i = region.begin() - self.view.line(region).begin()

            start = 0
            end = -1
            for j, c in enumerate(s):
                if c == ' ':
                    if j < i:
                        start = j
                    else:
                        end = j
                        break
            word = s[start:end].strip() if end != -1 else s[start:].strip()
            isurl = bool(re.match("\\bhttps?://[-A-Za-z0-9+&@#/%?=~_()|!:,.;']*[-A-Za-z0-9+&@#/%=~_(|]", word))
            if isurl:
                webbrowser.register('mybrowser', None, webbrowser.GenericBrowser(BROWSER))
                webbrowser.get('mybrowser').open(word)
            else:
                s = '"' + s.split('"')[s[:i].count('"')] + '"'

                command = '"%s" %s' % (EDITOR, s)
                subprocess.Popen(command)

Then add the following line to C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\User\Default (Windows).sublime-keymap:

{ "keys": ["ctrl+alt+enter"], "command": "lllaunch" }

Restart Sublime Text.

Now:

doing CTRLALTENTER on an URL will open browser.

doing CTRLALTENTER on a filename with quotes (e.g. "C:\test\readme.txt") will edit the file in your favorite editor.


问:
How to inherit privately from a base class' derivative, but implement public interface of the base class?
Suppose there are two unchangeable classes from a library, A and B, related like here:

```<code>class A
{
public:
    virtual void doCustomThings() = 0;
    virtual void doOtherThings() = 0;
    void doSomething();
private:
    SomeType1 someData;
};

class B : public A
{
public:
    void doCustomThings() override;
    void doOtherThings() override;
    void someUsefulUtility();
private:
    SomeType2 otherData;
};
</code>```

I'm trying to implement the interface of A in terms of the some available in B, so I do:

```<code>class C : public B
{
public:
    void doCustomThings() override; // uses B::someUsefulUtility()
    // leave B::doOtherThings() not overridden
private:
    SomeType3 myData;
};
</code>```

But I don't intend C to be B, i.e. I don't want references to C to be implicitly convertible to B&, although it should be convertible to A&.

First thing coming to mind is to use virtual inheritance, and then inherit public A, private B. But the A and B classes in my case are not editable, and for virtual inheritance to work here I need class B to inherit as public virtual A.

Another idea is to consider composition instead of inheritance. But if I derive from A and have B as a private member, I'll uselessly have A::someData twice, which looks inelegant.

Is there any good way to so something like class C : public A, private B, so that there'd be only one base class A, given the above mentioned constraints?

答:
Yes, only use inheritance for A, use composition for B, and delegate to the B member (not base)

```<code>class C : public A
{
public:
    void doOtherThings() override { myB.doOtherThings(); }

    void doCustomThings() override {
        std::cout<<"C::doCustomThings()\n";
    }
private:
    B myB;
    SomeType3 myData;
};
</code>```

Body:
Suppose there are two unchangeable classes from a library, A and B, related like here:

class A
{
public:
    virtual void doCustomThings() = 0;
    virtual void doOtherThings() = 0;
    void doSomething();
private:
    SomeType1 someData;
};

class B : public A
{
public:
    void doCustomThings() override;
    void doOtherThings() override;
    void someUsefulUtility();
private:
    SomeType2 otherData;
};

I'm trying to implement the interface of A in terms of the some available in B, so I do:

class C : public B
{
public:
    void doCustomThings() override; // uses B::someUsefulUtility()
    // leave B::doOtherThings() not overridden
private:
    SomeType3 myData;
};

But I don't intend C to be B, i.e. I don't want references to C to be implicitly convertible to B&, although it should be convertible to A&.

First thing coming to mind is to use virtual inheritance, and then inherit public A, private B. But the A and B classes in my case are not editable, and for virtual inheritance to work here I need class B to inherit as public virtual A.

Another idea is to consider composition instead of inheritance. But if I derive from A and have B as a private member, I'll uselessly have A::someData twice, which looks inelegant.

Is there any good way to so something like class C : public A, private B, so that there'd be only one base class A, given the above mentioned constraints?

Body:
Yes, only use inheritance for A, use composition for B, and delegate to the B member (not base)

class C : public A
{
public:
    void doOtherThings() override { myB.doOtherThings(); }

    void doCustomThings() override {
        std::cout<<"C::doCustomThings()\n";
    }
private:
    B myB;
    SomeType3 myData;
};


问:
Round Display Picture
Im creating an application which includes the home screen. This will have a biography of the client. Im trying to create a header, which will include the title and a round display image. From the code i used 3 divs, which will hold the wrapper, title and picture. I done the display:flex which will have them in 1 line, and flex:1 to move the image to the right. When doing the radius 50% its squishing the photo . Can you help me out?

Thanks. Heres the code.

.headerOfBio {
  display: flex
}

.displayPic {
  flex: 1 background-image: url("../images/displayPicture.jpg") border-radius: 50%
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="quote titleBio">
  <div class="headerOfBio">
    <h3>
      MEET THE <span class="diffColor">FOUNDER</span>
    </h3>

    <div class="displayPic">

    </div>
  </div>

</div></code>```

After adding height and width it becomes like this:

答:
Mention width, height for the div holding the image and change border-radius to half of the width/height.</p>

```<code>.displayPic{
    flex: 1
    background-image: url("../images/displayPicture.jpg")
    width: 300px;
    height: 300px;
    border-radius: 150px;
 }
</code>```

Title: Round Display Picture

Body:
Im creating an application which includes the home screen. This will have a biography of the client. Im trying to create a header, which will include the title and a round display image. From the code i used 3 divs, which will hold the wrapper, title and picture. I done the display:flex which will have them in 1 line, and flex:1 to move the image to the right. When doing the radius 50% its squishing the photo . Can you help me out?

Thanks. Heres the code.

.headerOfBio {
  display: flex
}

.displayPic {
  flex: 1 background-image: url("../images/displayPicture.jpg") border-radius: 50%
}

      MEET THE FOUNDER

After adding height and width it becomes like this:

Body:
Mention width, height for the div holding the image and change border-radius to half of the width/height.

.displayPic{
    flex: 1
    background-image: url("../images/displayPicture.jpg")
    width: 300px;
    height: 300px;
    border-radius: 150px;
 }


问:
Bind a function to Bootstrap Modal Cancel
I know we can bind a function to bootstrap modal for close event like this:

```<code>$("#myModal").on('hide.bs.modal', function(){
    //run the script
});
</code>```

I need to know, when the dialog is canceled, but this also is triggered when the dialog is clicked "OK". How can I filter this? I need to know, when the dialog is hidden but not the primary button clicked.

Thankyou.

答:
I suggest you add an ID to the modal close button and use jQuery's click() function to detect when it's clicked.

Here's an example

$('#modal-close-btn').click(function() {
  console.log("MODAL CLOSED");
});```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">
    <!-- Modal content-->
    <div class="modal-content">
      <!-- ... -->
      <div class="modal-footer">
        <button type="button" id="modal-close-btn" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div></code>```

Body:
I know we can bind a function to bootstrap modal for close event like this:

$("#myModal").on('hide.bs.modal', function(){
    //run the script
});

I need to know, when the dialog is canceled, but this also is triggered when the dialog is clicked "OK". How can I filter this? I need to know, when the dialog is hidden but not the primary button clicked.

Thankyou.

Body:
I suggest you add an ID to the modal close button and use jQuery's click() function to detect when it's clicked.

Here's an example

$('#modal-close-btn').click(function() {
  console.log("MODAL CLOSED");
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">
    <!-- Modal content-->
    <div class="modal-content">
      <!-- ... -->
      <div class="modal-footer">
        <button type="button" id="modal-close-btn" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>


问:
Don't drop dimensions when subseting 3-dimensional array
Let A be a 1 x 2 x 2-array:

```<code>> A <- array(0, dim=c(1,2,2))
> A
, , 1

     [,1] [,2]
[1,]    0    0

, , 2

     [,1] [,2]
[1,]    0    0
</code>```

Then A[,,1] is dimensionless:

```<code>> A[,,1]
[1] 0 0
</code>```

I would like to have:

```<code>     [,1] [,2]
[1,]    0    0
</code>```

The drop argument does not yield what I want:

```<code>> A[,,1,drop=FALSE]
, , 1

     [,1] [,2]
[1,]    0    0
</code>```

I find that annoying. And buggy, because R identifies vectors to column matrices, not to row matrices.

Of course I could do matrix(A[,,1], 1, 2). Is there a more convenient way?

答:
Unfortunately, there isn't an easy way around this. With drop = TRUE, any dimension of 1 gets dropped. You can see this if you look at the source for ArraySubset from src/main/subset.c. At the end of the function we see this:

```<code>if (drop)
    DropDims(result);
</code>```

The DropDims function is defined in src/main/array.c. In that function, we see

```<code>n = 0;
for (i = 0; i < ndims; i++)
    if (dim[i] != 1) n++;
</code>```

and elsewhere in the function we see that dimensions of size one get ignored.

It's annoying that R determines the drop behavior from the result. It would be more natural if R only dropped indexed dimensions of length one, so that behavior would be as you expected in this example.

All that being, said, the following is ugly, bug it may work for your use case:

```<code>`dim<-`(A[,,1], dim(A)[-3])
 #>      [,1] [,2]
 #> [1,]    0    0
</code>```

This doesn't generalize very well, but it works if you index by a single coordinate.

Body:
Let A be a 1 x 2 x 2-array:

> A <- array(0, dim=c(1,2,2))
> A
, , 1

     [,1] [,2]
[1,]    0    0

, , 2

     [,1] [,2]
[1,]    0    0

Then A[,,1] is dimensionless:

> A[,,1]
[1] 0 0

I would like to have:

     [,1] [,2]
[1,]    0    0

The drop argument does not yield what I want:

> A[,,1,drop=FALSE]
, , 1

     [,1] [,2]
[1,]    0    0

I find that annoying. And buggy, because R identifies vectors to column matrices, not to row matrices.

Of course I could do matrix(A[,,1], 1, 2). Is there a more convenient way?

Body:
Unfortunately, there isn't an easy way around this. With drop = TRUE, any dimension of 1 gets dropped. You can see this if you look at the source for ArraySubset from src/main/subset.c. At the end of the function we see this:

if (drop)
    DropDims(result);

The DropDims function is defined in src/main/array.c. In that function, we see

n = 0;
for (i = 0; i < ndims; i++)
    if (dim[i] != 1) n++;

and elsewhere in the function we see that dimensions of size one get ignored.

It's annoying that R determines the drop behavior from the result. It would be more natural if R only dropped indexed dimensions of length one, so that behavior would be as you expected in this example.

All that being, said, the following is ugly, bug it may work for your use case:

`dim<-`(A[,,1], dim(A)[-3])
 #>      [,1] [,2]
 #> [1,]    0    0

This doesn't generalize very well, but it works if you index by a single coordinate.


问:
Why i can not set image style height 100% for height as same as div container?
Why i can not set image style height 100% for height as same as div container ?

When i tried to test code it's will be show like this.

https://i.imgur.com/Q1MGP0Z.png

I want to show image like this.

https://i.imgur.com/GeLUUCo.png

with class name img_look style height: 100%; How can i do ?

.li_look{
    padding: 0px;
    margin: 0;
    position: relative;
    width: 25%;
    border-right: 3px solid #fff;
    margin-right: -3px;
    z-index: 11;
    float: left;
    list-style: none;
    color: #333;
    font-size: 19px;
    background: #fff;
}
.div_1{
    float: none;
    margin: 0;
    width: 100%;
    height: 197.207px;
    display: block;
    position: relative;
}
.a_tag{
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    height: 100%;
    margin-left: auto;
    margin-right: auto;
    overflow: hidden;
    display: block;
    cursor: pointer;
}
.div_2{
    transform: translateX(-50%);
    left: 50%;
    top: 0;
    background-color: transparent;
    display: block;
    position: absolute;
}
.img_look{
    height: 100%;
    display: block;
    margin-left: auto;
    margin-right: auto;
    max-width: unset;

}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><ul>
  <li class="li_look">
    <div class="div_1">

        <div class="div_2">
          <img src="https://i2.wp.com/www.thisblogrules.com/wp-content/uploads/2010/02/man-and-bear-bath.jpg?resize=550%2C356" class="img_look">
        </div>

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

答:
I think You Need This https://jsfiddle.net/wqhch5et/ view full screen mode.
You need to change  position: absolute; to   position: fixed; in div_2

.li_look{
    padding: 0px;
    margin: 0;
    position: relative;
    width: 25%;
    border-right: 3px solid #fff;
    margin-right: -3px;
    z-index: 11;
    float: left;
    list-style: none;
    color: #333;
    font-size: 19px;
    background: #fff;
}
.div_1{
    float: none;
    margin: 0;
    width: 100%;
    height: 197.207px;
    display: block;
    position: relative;
}
.a_tag{
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    height: 100%;
    margin-left: auto;
    margin-right: auto;
    overflow: hidden;
    display: block;
    cursor: pointer;
}
.div_2{
    transform: translateX(-50%);
    left: 50%;
    top: 0;
    background-color: transparent;
    display: block;
    position: fixed;
}
.img_look{
    height: 100%;
    display: block;
    margin-left: auto;
    margin-right: auto;
    max-width: unset;

}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><ul>
  <li class="li_look">
    <div class="div_1">

        <div class="div_2">
          <img src="https://i2.wp.com/www.thisblogrules.com/wp-content/uploads/2010/02/man-and-bear-bath.jpg?resize=550%2C356" class="img_look">
        </div>

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

Body:
I think You Need This https://jsfiddle.net/wqhch5et/ view full screen mode.
You need to change  position: absolute; to   position: fixed; in div_2

.li_look{
    padding: 0px;
    margin: 0;
    position: relative;
    width: 25%;
    border-right: 3px solid #fff;
    margin-right: -3px;
    z-index: 11;
    float: left;
    list-style: none;
    color: #333;
    font-size: 19px;
    background: #fff;
}
.div_1{
    float: none;
    margin: 0;
    width: 100%;
    height: 197.207px;
    display: block;
    position: relative;
}
.a_tag{
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    height: 100%;
    margin-left: auto;
    margin-right: auto;
    overflow: hidden;
    display: block;
    cursor: pointer;
}
.div_2{
    transform: translateX(-50%);
    left: 50%;
    top: 0;
    background-color: transparent;
    display: block;
    position: fixed;
}
.img_look{
    height: 100%;
    display: block;
    margin-left: auto;
    margin-right: auto;
    max-width: unset;

}

<ul>
  <li class="li_look">
    <div class="div_1">
      <a href="#" class="a_tag">
        <div class="div_2">
          <img src="https://i2.wp.com/www.thisblogrules.com/wp-content/uploads/2010/02/man-and-bear-bath.jpg?resize=550%2C356" class="img_look">
        </div>
      </a>
    </div>
  </li>
</ul>


问:
OpenSSL unknown protocol error on aws connection
I get:

Excon::Error::Socket (SSL_connect returned=1 errno=0 state=SSLv2/v3
  read server hello A: unknown protocol (OpenSSL::SSL::SSLError))

when trying to upload files to amazon s3 via curl
curl request:

```<code>curl -X PUT http://localhost:3000/api/v1/projects/{:project_id}/upload -F 'files=@file_path.jpg'
</code>```

答: Using of carrierwave-aws gem instead fog resolved this problem</p>

Body:
I get:

Excon::Error::Socket (SSL_connect returned=1 errno=0 state=SSLv2/v3
  read server hello A: unknown protocol (OpenSSL::SSL::SSLError))

when trying to upload files to amazon s3 via curl
curl request:

curl -X PUT http://localhost:3000/api/v1/projects/{:project_id}/upload -F 'files=@file_path.jpg'


问:
Android NDK, two Static Libraries and Linking
I started off creating libraries as shared libraries, but I considered it would be more efficient to create one shared libraries and the rest static. When it was all shared, it compiled and linked fine, but moving to static, I get on linking "undefined reference".

Edit: I build all the libraries in one Android.mk

Android.mk:

```<code>MY_LOCAL_PATH := $(call my-dir)
MY_LOCAL_CFLAGS := -DDEBUG

TARGET_PLATFORM := 'android-4'

LOCAL_PATH := $(MY_LOCAL_PATH)/../../Base

include $(CLEAR_VARS)

LOCAL_MODULE     := Base
LOCAL_SRC_FILES  := <Base src files>
include $(BUILD_STATIC_LIBRARY)

MY_LOCAL_STATIC_LIBRARIES := Base

MY_LOCAL_C_INCLUDES := $(MY_LOCAL_PATH)/../../Base

LOCAL_PATH := $(MY_LOCAL_PATH)/../../Framework

include $(CLEAR_VARS)

LOCAL_MODULE     := Framework
LOCAL_C_INCLUDES := $(MY_LOCAL_C_INCLUDES)
LOCAL_SRC_FILES  := <Framework src files>
LOCAL_CFLAGS := $(MY_LOCAL_CFLAGS)

include $(BUILD_STATIC_LIBRARY)

MY_LOCAL_STATIC_LIBRARIES += Framework

MY_LOCAL_C_INCLUDES += $(MY_LOCAL_PATH)/../../Framework

LOCAL_PATH := $(MY_LOCAL_PATH)/Graphics

include $(CLEAR_VARS)

LOCAL_MODULE    := Graphics
LOCAL_SRC_FILES := <Graphics src files>
LOCAL_EXPORT_LDLIBS := -lGLESv1_CM
LOCAL_CFLAGS := $(MY_LOCAL_CFLAGS)
LOCAL_C_INCLUDES := $(MY_LOCAL_C_INCLUDES)

include $(BUILD_STATIC_LIBRARY)

MY_LOCAL_STATIC_LIBRARIES += Graphics

MY_LOCAL_C_INCLUDES += $(MY_LOCAL_PATH)/Graphics

LOCAL_PATH := $(MY_LOCAL_PATH)/Platform

include $(CLEAR_VARS)

LOCAL_MODULE := Platform
LOCAL_SRC_FILES := <Platform src files>
LOCAL_CFLAGS := $(MY_LOCAL_CFLAGS)
LOCAL_C_INCLUDES := $(MY_LOCAL_C_INCLUDES)

include $(BUILD_STATIC_LIBRARY)

MY_LOCAL_STATIC_LIBRARIES += Platform

MY_LOCAL_C_INCLUDES += $(MY_LOCAL_PATH)/Platform

LOCAL_PATH := $(MY_LOCAL_PATH)

include $(CLEAR_VARS)

LOCAL_MODULE    := Final
LOCAL_SRC_FILES := <Final src files>
LOCAL_STATIC_LIBRARIES := $(MY_LOCAL_STATIC_LIBRARIES)
LOCAL_LDLIBS    := -llog
LOCAL_CFLAGS := $(MY_LOCAL_CFLAGS)
LOCAL_C_INCLUDES := $(MY_LOCAL_C_INCLUDES)

include $(BUILD_SHARED_LIBRARY)
</code>```

Last line of ndk-build V=1 -B:

```<code>SharedLibrary  : libFinal.so
/Users/robbie/Library/Frameworks/Android-NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-g++ -Wl,-soname,libFinal.so -shared --sysroot=/Users/robbie/Library/Frameworks/Android-NDK/platforms/android-4/arch-arm <object files>   /Users/robbie/Documents/Apps/Revolution/Android/obj/local/armeabi/libBase.a /Users/robbie/Documents/Apps/Revolution/Android/obj/local/armeabi/libFramework.a /Users/robbie/Documents/Apps/Revolution/Android/obj/local/armeabi/libGraphics.a /Users/robbie/Documents/Apps/Revolution/Android/obj/local/armeabi/libPlatform.a /Users/robbie/Documents/Apps/Revolution/Android/obj/local/armeabi/libstdc++.a  /Users/robbie/Library/Frameworks/Android-NDK/platforms/android-4/arch-arm/usr/lib/libc.so /Users/robbie/Library/Frameworks/Android-NDK/platforms/android-4/arch-arm/usr/lib/libstdc++.so /Users/robbie/Library/Frameworks/Android-NDK/platforms/android-4/arch-arm/usr/lib/libm.so   -Wl,--no-undefined -Wl,-z,noexecstack -L/Users/robbie/Library/Frameworks/Android-NDK/platforms/android-4/arch-arm/usr/lib -llog -lGLESv1_CM -lstdc++ -Wl,-rpath-link=/Users/robbie/Library/Frameworks/Android-NDK/platforms/android-4/arch-arm/usr/lib -lsupc++ -o /Users/robbie/Documents/Apps/Revolution/Android/obj/local/armeabi/libFinal.so
/Users/robbie/Documents/Apps/Revolution/Android/obj/local/armeabi/libPlatform.a(ATexture.o): In function `ATexture':
/Users/robbie/Documents/Apps/Revolution/Android/jni/SpinTap/ATexture.cpp:9: undefined reference to `TextureRenderer::TextureRenderer(unsigned int)'
/Users/robbie/Documents/Apps/Revolution/Android/jni/SpinTap/ATexture.cpp:9: undefined reference to `TextureRenderer::TextureRenderer(unsigned int)'
</code>```

Edit2: TextureRenderer is in Graphics, which is included.

Does anyone have an idea why it may not be working and how to fix it?

答:
In your Android.mk, make sure you are referencing the static library with the proper call:

```<code>LOCAL_STATIC_LIBRARIES := mystaticlibproj
</code>```

before calling include $(BUILD_SHARED_LIBRARY).

Then, at the end of the file, place the call to import the static lib module

```<code>$(call import-module, mystaticlibproj)
</code>```

If you're still having trouble, post the verbose build log (ndk-build V=1 -B) and your Android.mk

Body:
I started off creating libraries as shared libraries, but I considered it would be more efficient to create one shared libraries and the rest static. When it was all shared, it compiled and linked fine, but moving to static, I get on linking "undefined reference".

Edit: I build all the libraries in one Android.mk

Android.mk:

MY_LOCAL_PATH := $(call my-dir)
MY_LOCAL_CFLAGS := -DDEBUG

TARGET_PLATFORM := 'android-4'

LOCAL_PATH := $(MY_LOCAL_PATH)/../../Base

include $(CLEAR_VARS)

LOCAL_MODULE     := Base
LOCAL_SRC_FILES  := <Base src files>
include $(BUILD_STATIC_LIBRARY)

MY_LOCAL_STATIC_LIBRARIES := Base

MY_LOCAL_C_INCLUDES := $(MY_LOCAL_PATH)/../../Base

LOCAL_PATH := $(MY_LOCAL_PATH)/../../Framework

include $(CLEAR_VARS)

LOCAL_MODULE     := Framework
LOCAL_C_INCLUDES := $(MY_LOCAL_C_INCLUDES)
LOCAL_SRC_FILES  := <Framework src files>
LOCAL_CFLAGS := $(MY_LOCAL_CFLAGS)

include $(BUILD_STATIC_LIBRARY)

MY_LOCAL_STATIC_LIBRARIES += Framework

MY_LOCAL_C_INCLUDES += $(MY_LOCAL_PATH)/../../Framework

LOCAL_PATH := $(MY_LOCAL_PATH)/Graphics

include $(CLEAR_VARS)

LOCAL_MODULE    := Graphics
LOCAL_SRC_FILES := <Graphics src files>
LOCAL_EXPORT_LDLIBS := -lGLESv1_CM
LOCAL_CFLAGS := $(MY_LOCAL_CFLAGS)
LOCAL_C_INCLUDES := $(MY_LOCAL_C_INCLUDES)

include $(BUILD_STATIC_LIBRARY)

MY_LOCAL_STATIC_LIBRARIES += Graphics

MY_LOCAL_C_INCLUDES += $(MY_LOCAL_PATH)/Graphics

LOCAL_PATH := $(MY_LOCAL_PATH)/Platform

include $(CLEAR_VARS)

LOCAL_MODULE := Platform
LOCAL_SRC_FILES := <Platform src files>
LOCAL_CFLAGS := $(MY_LOCAL_CFLAGS)
LOCAL_C_INCLUDES := $(MY_LOCAL_C_INCLUDES)

include $(BUILD_STATIC_LIBRARY)

MY_LOCAL_STATIC_LIBRARIES += Platform

MY_LOCAL_C_INCLUDES += $(MY_LOCAL_PATH)/Platform

LOCAL_PATH := $(MY_LOCAL_PATH)

include $(CLEAR_VARS)

LOCAL_MODULE    := Final
LOCAL_SRC_FILES := <Final src files>
LOCAL_STATIC_LIBRARIES := $(MY_LOCAL_STATIC_LIBRARIES)
LOCAL_LDLIBS    := -llog
LOCAL_CFLAGS := $(MY_LOCAL_CFLAGS)
LOCAL_C_INCLUDES := $(MY_LOCAL_C_INCLUDES)

include $(BUILD_SHARED_LIBRARY)

Last line of ndk-build V=1 -B:

SharedLibrary  : libFinal.so
/Users/robbie/Library/Frameworks/Android-NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-g++ -Wl,-soname,libFinal.so -shared --sysroot=/Users/robbie/Library/Frameworks/Android-NDK/platforms/android-4/arch-arm <object files>   /Users/robbie/Documents/Apps/Revolution/Android/obj/local/armeabi/libBase.a /Users/robbie/Documents/Apps/Revolution/Android/obj/local/armeabi/libFramework.a /Users/robbie/Documents/Apps/Revolution/Android/obj/local/armeabi/libGraphics.a /Users/robbie/Documents/Apps/Revolution/Android/obj/local/armeabi/libPlatform.a /Users/robbie/Documents/Apps/Revolution/Android/obj/local/armeabi/libstdc++.a  /Users/robbie/Library/Frameworks/Android-NDK/platforms/android-4/arch-arm/usr/lib/libc.so /Users/robbie/Library/Frameworks/Android-NDK/platforms/android-4/arch-arm/usr/lib/libstdc++.so /Users/robbie/Library/Frameworks/Android-NDK/platforms/android-4/arch-arm/usr/lib/libm.so   -Wl,--no-undefined -Wl,-z,noexecstack -L/Users/robbie/Library/Frameworks/Android-NDK/platforms/android-4/arch-arm/usr/lib -llog -lGLESv1_CM -lstdc++ -Wl,-rpath-link=/Users/robbie/Library/Frameworks/Android-NDK/platforms/android-4/arch-arm/usr/lib -lsupc++ -o /Users/robbie/Documents/Apps/Revolution/Android/obj/local/armeabi/libFinal.so
/Users/robbie/Documents/Apps/Revolution/Android/obj/local/armeabi/libPlatform.a(ATexture.o): In function `ATexture':
/Users/robbie/Documents/Apps/Revolution/Android/jni/SpinTap/ATexture.cpp:9: undefined reference to `TextureRenderer::TextureRenderer(unsigned int)'
/Users/robbie/Documents/Apps/Revolution/Android/jni/SpinTap/ATexture.cpp:9: undefined reference to `TextureRenderer::TextureRenderer(unsigned int)'

Edit2: TextureRenderer is in Graphics, which is included.

Does anyone have an idea why it may not be working and how to fix it?

Body:
In your Android.mk, make sure you are referencing the static library with the proper call:

LOCAL_STATIC_LIBRARIES := mystaticlibproj

before calling include $(BUILD_SHARED_LIBRARY).

Then, at the end of the file, place the call to import the static lib module

$(call import-module, mystaticlibproj)

If you're still having trouble, post the verbose build log (ndk-build V=1 -B) and your Android.mk


问:
Passing Array as an argument in batch script
I have created an array in batch script as:

```<code>set arr[1]=a
set arr[2]=b
set arr[3]=c
</code>```

Now I want to pass this array as an argument to another batch file
as follows:

```<code>call :processArr.bat arr
</code>```

I need to do this because in actual the value of %%i in arr[%%i] is variable and it can be greater than 9 and with batch file only 9 arguments can be passed

Moreover its ultra essential that the entire array is passed to the batch file processArr.bat at once

Please help

答:
There's no need to pass the variables as script arguments.  When you call processArr.bat, processArr.bat will inherit all the variables defined by the calling script.  Here's a demonstration:

test.bat:

@echo off & setlocal

for /L %%I in (0,1,5) do set /a "arr[%%I] = %%I << 2"

call test2.bat
```

<p><strong>test2.bat:</strong></p>

<pre class="lang-js prettyprint-override"><code>@echo off & setlocal

echo Checking inheritance...
set arr
</code>```

Output:

Checking inheritance...

  arr[0]=0

  arr[1]=4

  arr[2]=8

  arr[3]=12

  arr[4]=16

  arr[5]=20

Body:
I have created an array in batch script as:

set arr[1]=a
set arr[2]=b
set arr[3]=c

Now I want to pass this array as an argument to another batch file
as follows:

call :processArr.bat arr

I need to do this because in actual the value of %%i in arr[%%i] is variable and it can be greater than 9 and with batch file only 9 arguments can be passed

Moreover its ultra essential that the entire array is passed to the batch file processArr.bat at once

Please help

Body:
There's no need to pass the variables as script arguments.  When you call processArr.bat, processArr.bat will inherit all the variables defined by the calling script.  Here's a demonstration:

test.bat:

@echo off & setlocal

for /L %%I in (0,1,5) do set /a "arr[%%I] = %%I << 2"

call test2.bat

test2.bat:

@echo off & setlocal

echo Checking inheritance...
set arr

Output:

Checking inheritance...

  arr[0]=0

  arr[1]=4

  arr[2]=8

  arr[3]=12

  arr[4]=16

  arr[5]=20


问:
Multi threaded slower without mutex when benchmarking (ruby 2.0, rails Rails 4.2.7.1)
I am trying to benchmark the below code and see that the non-threaded version runs faster than the treaded version.

```<code>      puts Benchmark.measure{
        100.times do |i|
          carrier.services.map do |service_obj|
            Thread.new {
              rate << Rate.rate_by_service(service_obj,@package,@from,@to,@credentials)
            }
          end.each(&:join)
        end
      }
</code>```

below are the timings

```<code>#threading
4.940000   0.730000   5.670000 (  5.795008)
4.740000   0.740000   5.480000 (  5.554500)
4.740000   0.730000   5.470000 (  5.436129)
4.840000   0.710000   5.550000 (  5.524418)
4.710000   0.720000   5.430000 (  5.431673)

#no threading
3.640000   0.190000   3.830000 (  3.962347)
3.670000   0.220000   3.890000 (  4.402259)
3.430000   0.200000   3.630000 (  3.780768)
3.480000   0.190000   3.670000 (  3.830547)
3.650000   0.210000   3.860000 (  4.065442)
</code>```

one thing i have observed in the log is when non-threaded version runs, the queries results are returned from cache like below and in threaded version it does not fetch from cache but accessed the DB.

```<code>  CACHE (0.0ms)  SELECT
  CACHE (0.0ms)  SELECT
  CACHE (0.0ms)  SELECT
  CACHE (0.0ms)  SELECT
  CACHE (0.0ms)  SELECT
  CACHE (0.0ms)  SELECT
  CACHE (0.0ms)  SELECT
  CACHE (0.0ms)  SELECT
  CACHE (0.0ms)  SELECT
  CACHE (0.0ms)  SELECT
  CACHE (0.0ms)  SELECT
</code>```

Note: I have removed the actual queries for readability purpose.

Can anyone please explain as to what could be causing the threaded version to run a bit slow than non-threaded

答:
According to Caching with Rails # SQL Caching,

If Rails encounters the same query again for that request, it will use the cached result set as opposed to running the query against the database again... Query caches are created at the start of an action and destroyed at the end of that action and thus persist only for the duration of the action.

ActiveRecord checks out from the pool one connection per thread.

If your Ruby implementation is MRI, then because of the GVL, CPU works are not in parallel.

So when you run the code in single threaded mode inside an action, the query result is cached. When you run the code in multi-threaded mode, each thread acquires its own database connection, and the query result is not cached, so each thread has to access the database, so it could be slow.

Body:
I am trying to benchmark the below code and see that the non-threaded version runs faster than the treaded version.

      puts Benchmark.measure{
        100.times do |i|
          carrier.services.map do |service_obj|
            Thread.new {
              rate << Rate.rate_by_service(service_obj,@package,@from,@to,@credentials)
            }
          end.each(&:join)
        end
      }

below are the timings

#threading
4.940000   0.730000   5.670000 (  5.795008)
4.740000   0.740000   5.480000 (  5.554500)
4.740000   0.730000   5.470000 (  5.436129)
4.840000   0.710000   5.550000 (  5.524418)
4.710000   0.720000   5.430000 (  5.431673)

#no threading
3.640000   0.190000   3.830000 (  3.962347)
3.670000   0.220000   3.890000 (  4.402259)
3.430000   0.200000   3.630000 (  3.780768)
3.480000   0.190000   3.670000 (  3.830547)
3.650000   0.210000   3.860000 (  4.065442)

one thing i have observed in the log is when non-threaded version runs, the queries results are returned from cache like below and in threaded version it does not fetch from cache but accessed the DB.

  CACHE (0.0ms)  SELECT
  CACHE (0.0ms)  SELECT
  CACHE (0.0ms)  SELECT
  CACHE (0.0ms)  SELECT
  CACHE (0.0ms)  SELECT
  CACHE (0.0ms)  SELECT
  CACHE (0.0ms)  SELECT
  CACHE (0.0ms)  SELECT
  CACHE (0.0ms)  SELECT
  CACHE (0.0ms)  SELECT
  CACHE (0.0ms)  SELECT

Note: I have removed the actual queries for readability purpose.

Can anyone please explain as to what could be causing the threaded version to run a bit slow than non-threaded


问:
Can't resolve all parameters fixed using @Injectable AND @Inject?
I've been slowly upgrading to Angular 5. However, a few days ago I started seeing this error from my ApiService:
can't resolve all parameters for ApiService(?)

This only started happening after I added new components (none of which actually use the service in question). Before then, ApiService was working totally fine. My ApiService looks something like this:

```<code>import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
...
@Injectable()
export class ApiService {
    constructor(private http: HttpClient)
}
...
</code>```

My tsconfig.json already has 'emitDecoratorMetadata' set to true. My app.module.ts has ApiService as a provider and imported properly.

However, if I use both @Injectable AND @Inject then it's much happier and compiles properly (I was doing this as a test to see why it was breaking; I know this is something you shouldn't need to do).

Is there another configuration that I might be forgetting? Most of the answers I've found so far have said to include @Injectable() include, emitDecoratorMetadata, or put the service as part of the app.module.ts providers, all of which I've done. Again, ApiService had been working up until I started adding more components.

I'm using webpack-dev-server to run my server. If I use 'ng serve' it works totally fine, which leads me to believe that it might be something wrong in how I'm configuring webpack-dev-server? Was there recently an update that may need me to change my configurations around a little bit?

Thanks for any advice and help!

答:
Aha! 'Uncaught Error: Can't resolve all parameters for' runtime error when upgrading from Angular 4 to 5.0.1

It seems that I just needed to add

```<code>import 'core-js/es6/reflect';
import 'core-js/es7/reflect';
</code>```

to my polyfills.ts. This seems to be a problem specific to upgrading to Angular 5. I hope this helps out anyone else who's had a similar problem!

Body:
I've been slowly upgrading to Angular 5. However, a few days ago I started seeing this error from my ApiService:
can't resolve all parameters for ApiService(?)

This only started happening after I added new components (none of which actually use the service in question). Before then, ApiService was working totally fine. My ApiService looks something like this:

import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
...
@Injectable()
export class ApiService {
    constructor(private http: HttpClient)
}
...

My tsconfig.json already has 'emitDecoratorMetadata' set to true. My app.module.ts has ApiService as a provider and imported properly.

However, if I use both @Injectable AND @Inject then it's much happier and compiles properly (I was doing this as a test to see why it was breaking; I know this is something you shouldn't need to do).

Is there another configuration that I might be forgetting? Most of the answers I've found so far have said to include @Injectable() include, emitDecoratorMetadata, or put the service as part of the app.module.ts providers, all of which I've done. Again, ApiService had been working up until I started adding more components.

I'm using webpack-dev-server to run my server. If I use 'ng serve' it works totally fine, which leads me to believe that it might be something wrong in how I'm configuring webpack-dev-server? Was there recently an update that may need me to change my configurations around a little bit?

Thanks for any advice and help!

Body:
Aha! 'Uncaught Error: Can't resolve all parameters for' runtime error when upgrading from Angular 4 to 5.0.1

It seems that I just needed to add

import 'core-js/es6/reflect';
import 'core-js/es7/reflect';

to my polyfills.ts. This seems to be a problem specific to upgrading to Angular 5. I hope this helps out anyone else who's had a similar problem!


问:
Adding Yogaglo as supported youtube-dl site
I would like to add Yogaglo support for youtube-dl.

I've followed guidance on Github .

And have drafted the following:

```<code># coding: utf-8
from __future__ import unicode_literals

from .common import InfoExtractor

class YogagloIE(InfoExtractor):
 _SIGNIN_URL = 'https://www.yogaglo.com/login'
 _PASSWORD_URL = 'https://www.yogaglo.com/login/password'
 _USER_URL = 'https://www.yogaglo.com/login/user'
 _ACCOUNT_CREDENTIALS_HINT = 'Use --username and --password options to provide yogaglo.com account credentials.'
_NETRC_MACHINE = 'yogaglo'

def _real_initialize(self):
    self._login()

_VALID_URL = r'https?://(?:www\.)?yogaglo\.com/class/(?P<id>[0-9]+)'
_TEST = {
    'url': 'https://www.yogaglo.com/class/7206',
    'md5': 'TODO: md5 sum of the first 10241 bytes of the video file (use --test)',
    'info_dict': {
        'id': '7206',
        'ext': 'mp4',
        'title': 'Have a Great Day!'
        # TODO more properties, either as:
        # * A value
        # * MD5 checksum; start the string with md5:
        # * A regular expression; start the string with re:
        # * Any Python type (for example int or float)
    }
}

def _real_extract(self, url):
    video_id = self._match_id(url)
    webpage = self._download_webpage(url, video_id)
    title = self._html_search_regex(r'<h1>(.+?)</h1>', webpage, 'title')

    return {
        'id': video_id,
        'title': title,
        'description': self._og_search_description(webpage),
        'uploader': self._search_regex(r'<div[^>]+id="uploader"[^>]*>([^<]+)<', webpage, 'uploader', fatal=False),
        # TODO more properties (see youtube_dl/extractor/common.py)
    }
</code>```

I've added yogagloIE to the list of extractors and when I run it I get an error that the URL is not supported. This is really a first draft and any guidance on hoe to improve it and make it work is recommended.

答:
In Python, indentation is significant, so make sure you indent your class correctly.

After that, you must define a _login method or simply leave _real_initialize empty.

With that being implemented, the extractor will be called (although of course it's not functional yet):

```<code>$ youtube-dl test:yogaglo
[TestURL] Test URL: https://www.yogaglo.com/class/7206
[Yogaglo] 7206: Downloading webpage
ERROR: Unable to extract title; please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see  https://yt-dl.org/update  on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.
</code>```

You can pull this working state with the following command (maybe git stash everything beforehand, and rename your old yogaglo.py file to something else):

```<code>git pull https://github.com/phihag/youtube-dl.git yogaglo
</code>```

Body:
I would like to add Yogaglo support for youtube-dl.

I've followed guidance on Github .

And have drafted the following:

# coding: utf-8
from __future__ import unicode_literals

from .common import InfoExtractor

class YogagloIE(InfoExtractor):
 _SIGNIN_URL = 'https://www.yogaglo.com/login'
 _PASSWORD_URL = 'https://www.yogaglo.com/login/password'
 _USER_URL = 'https://www.yogaglo.com/login/user'
 _ACCOUNT_CREDENTIALS_HINT = 'Use --username and --password options to provide yogaglo.com account credentials.'
_NETRC_MACHINE = 'yogaglo'

def _real_initialize(self):
    self._login()

_VALID_URL = r'https?://(?:www\.)?yogaglo\.com/class/(?P<id>[0-9]+)'
_TEST = {
    'url': 'https://www.yogaglo.com/class/7206',
    'md5': 'TODO: md5 sum of the first 10241 bytes of the video file (use --test)',
    'info_dict': {
        'id': '7206',
        'ext': 'mp4',
        'title': 'Have a Great Day!'
        # TODO more properties, either as:
        # * A value
        # * MD5 checksum; start the string with md5:
        # * A regular expression; start the string with re:
        # * Any Python type (for example int or float)
    }
}

def _real_extract(self, url):
    video_id = self._match_id(url)
    webpage = self._download_webpage(url, video_id)
    title = self._html_search_regex(r'
(.+?)
', webpage, 'title')

    return {
        'id': video_id,
        'title': title,
        'description': self._og_search_description(webpage),
        'uploader': self._search_regex(r'
]+id="uploader"[^>]*>([^<]+)<', webpage, 'uploader', fatal=False),
        # TODO more properties (see youtube_dl/extractor/common.py)
    }

I've added yogagloIE to the list of extractors and when I run it I get an error that the URL is not supported. This is really a first draft and any guidance on hoe to improve it and make it work is recommended.

Body:
In Python, indentation is significant, so make sure you indent your class correctly.

After that, you must define a _login method or simply leave _real_initialize empty.

With that being implemented, the extractor will be called (although of course it's not functional yet):

$ youtube-dl test:yogaglo
[TestURL] Test URL: https://www.yogaglo.com/class/7206
[Yogaglo] 7206: Downloading webpage
ERROR: Unable to extract title; please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see  https://yt-dl.org/update  on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.

You can pull this working state with the following command (maybe git stash everything beforehand, and rename your old yogaglo.py file to something else):

git pull https://github.com/phihag/youtube-dl.git yogaglo

OwnerDisplayName: anon


问:
Measuring/Monitoring response time of each execution of a sql
In Oracle 11g, I want to monitor the response time of a specific sql (I know the sql_id of the sql). Meaning, I want to know the response time of the sql every time it is executed. I would "turn it on" for some time and then would like to see a data something like:

For sql_id 'abcdefg', following were the execution time (in ms)
10
12
10
13
10
10
10
240
230
10
9
12
…
…

We can ignore the exact format I would like to see the output, but is there any way for me to monitor such that I can get the response time for every execution for my sql?

Thanks.

答:
Firstly, you should trace your sql (assume sql_id:6b0z40gs9m759):

```<code>SQL> ALTER SESSION SET sql_trace=TRUE;

SQL> ALTER SESSION SET EVENTS 'trace[rdbms.SQL_Optimizer.*][sql:6b0z40gs9m759]';
[ SQL> ALTER SYSTEM SET EVENTS 'sql_trace [sql:&&sql_id] bind=true, wait=true'; ] -- or use this as alternative.

SQL> ALTER SESSION SET TRACEFILE_IDENTIFIER = "TrcSqlParag"; -- adds this text to your trace file and makes it more recognizable by you.

SQL> SHOW PARAMETER user_dump_dest -- trace files are produced in this directory

-- For 11g DB, you may easily query v$diag_info view to see your file destination :
SQL> SELECT value FROM   v$diag_info WHERE  name = 'Default Trace File';

-- You can identify the trace file for a specific session using the V$SESSION and V$PROCESS views :
SQL> SELECT p.tracefile FROM v$session s JOIN v$process p ON s.paddr = p.addr WHERE  s.sid = &ses_id;

-- You may finish tracing whenever you want :
SQL> ALTER SESSION SET sql_trace=FALSE;
</code>```

Let's have such a dump file :

```<code>/u01/app/oracle/admin/MYDB11G/udump/mydb11g_ora_TrcSqlParag.trc
</code>```

The trace file is not easy to read, we need tkprof utility to read it from OS :

```<code>$ cd /u01/app/oracle/admin/MYDB11G/udump/
$ tkprof mydb11g_ora_TrcSqlParag.trc TrcSqlParag_Translated1.txt explain=<username>/<pwd>@mydb11g table=sys.plan_table sys=no waits=yes
</code>```

Body:
Firstly, you should trace your sql (assume sql_id:6b0z40gs9m759):

SQL> ALTER SESSION SET sql_trace=TRUE;

SQL> ALTER SESSION SET EVENTS 'trace[rdbms.SQL_Optimizer.*][sql:6b0z40gs9m759]';
[ SQL> ALTER SYSTEM SET EVENTS 'sql_trace [sql:&&sql_id] bind=true, wait=true'; ] -- or use this as alternative.

SQL> ALTER SESSION SET TRACEFILE_IDENTIFIER = "TrcSqlParag"; -- adds this text to your trace file and makes it more recognizable by you.

SQL> SHOW PARAMETER user_dump_dest -- trace files are produced in this directory

-- For 11g DB, you may easily query v$diag_info view to see your file destination :
SQL> SELECT value FROM   v$diag_info WHERE  name = 'Default Trace File';

-- You can identify the trace file for a specific session using the V$SESSION and V$PROCESS views :
SQL> SELECT p.tracefile FROM v$session s JOIN v$process p ON s.paddr = p.addr WHERE  s.sid = &ses_id;

-- You may finish tracing whenever you want :
SQL> ALTER SESSION SET sql_trace=FALSE;

Let's have such a dump file :

/u01/app/oracle/admin/MYDB11G/udump/mydb11g_ora_TrcSqlParag.trc

The trace file is not easy to read, we need tkprof utility to read it from OS :

$ cd /u01/app/oracle/admin/MYDB11G/udump/
$ tkprof mydb11g_ora_TrcSqlParag.trc TrcSqlParag_Translated1.txt explain=<username>/<pwd>@mydb11g table=sys.plan_table sys=no waits=yes


问:
How to programmatically trigger keyboard events in Monaco Editor
In writing a generative test suite for code editors, I'm trying to programmatically call the event handlers that handle KeyboardEvent's in Monaco.
Making a new KeyboardEvent({...}) and dispatching it on the textarea, or root editor element didn't work.

For example, how could we transition the editor through the following states:

Paste "abc" => abc|

Move Cursor by -1 => ab|c

Delete once => a|c

Type "x" => ax|c

答:
Try</p>

```<code>editor.trigger(monaco.KeyMod.CtrlCmd + monaco.KeyCode.KEY_P, 'type', { text: 'some text' });
</code>```

Body:
Try

editor.trigger(monaco.KeyMod.CtrlCmd + monaco.KeyCode.KEY_P, 'type', { text: 'some text' });


问:
NixOS - Module imports with arguments
Let's say I have my NixOS configuration.nix set up as follows:

```<code>{config, pkgs, ...}:
{
  services.openssh.enable = true;
}
</code>```

I now want to have a second file called networking.nix which sets my hostname based on an argument.

```<code>{config, pkgs, hostname, ...}:
{
  networking.hostName = hostname
}
</code>```

Is this possible? How can I include the file. I already tried doing it by using imports = [ ./networking.nix { hostname = "helloworld"; } ]; but that didn't work.

Thanks.

答:
A 'NixOS configuration file' is simply a module that doesn't define options, so there is really no distinction. A configuration.nix file is just a module, and typically it does not define any options, so it can be written in the abbreviated form.

Defining options is the normal way for NixOS modules to pass information around, so that's the most idiomatic way to go about.

However, if you really must, for some very special reason, because you're doing very unusual things with NixOS, you can put arbitrary functions in imports. But you shouldn't, because it doesn't work well with the module system's custom error messages and potentially other aspects that rely on knowing where a module is defined. If you do so, do make sure it is an actual function. In your case, that would imply modifying the first line of networking.nix to make it a curried function:

```<code>hostname: {config, pkgs, ...}:
</code>```

Not very pretty in my opinion. Although it is very explicit about what is going on, it deviates from what is to be expected of a NixOS module.

Title: NixOS - Module imports with arguments

Body:
Let's say I have my NixOS configuration.nix set up as follows:

{config, pkgs, ...}:
{
  services.openssh.enable = true;
}

I now want to have a second file called networking.nix which sets my hostname based on an argument.

{config, pkgs, hostname, ...}:
{
  networking.hostName = hostname
}

Is this possible? How can I include the file. I already tried doing it by using imports = [ ./networking.nix { hostname = "helloworld"; } ]; but that didn't work.

Thanks.

Body:
A 'NixOS configuration file' is simply a module that doesn't define options, so there is really no distinction. A configuration.nix file is just a module, and typically it does not define any options, so it can be written in the abbreviated form.

Defining options is the normal way for NixOS modules to pass information around, so that's the most idiomatic way to go about.

However, if you really must, for some very special reason, because you're doing very unusual things with NixOS, you can put arbitrary functions in imports. But you shouldn't, because it doesn't work well with the module system's custom error messages and potentially other aspects that rely on knowing where a module is defined. If you do so, do make sure it is an actual function. In your case, that would imply modifying the first line of networking.nix to make it a curried function:

hostname: {config, pkgs, ...}:

Not very pretty in my opinion. Although it is very explicit about what is going on, it deviates from what is to be expected of a NixOS module.

ContentLicense: CC BY-SA 4.0


问:
How to set up a cron job via PHP (not CPanel)?
How to set up a cron job via PHP (not CPanel)?</p>

答:
There is an embargo on the use of PHP to edit crontabs which has been in place since 2004. You may not be allowed to do this if you live outside of the United States, check with your local government agency.

But seriously, you could always call "crontab -" with a system call. If you need to do this for some user other than the webserver, you'll need some ssh or sudo magic. But it all seems like a bad idea.


问:
VueJS Single File Component with typescript: Unable to find module stuff.vue
I have a simple project structure:

/src/app2/main.ts
/src/app2/components/lib.ts
/src/app2/components/stuff.vue

With webpack, vue-loader, and ts-loader.

main.ts has:

```<code>import Vue = require('vue');
import  Component from './components/lib'

new Vue({
  el: '#app2'

});
</code>```

When trying to build this with 1 webpack entry for /src/app2/main.ts, the error generated is:

```<code>ERROR in C:\temp\vuetest2\proj\src\app2\components\lib.ts
(2,25): error TS2307: Cannot find module './stuff.vue'.

ERROR in ./src/app2/main.ts
Module not found: Error: Can't resolve './components/lib' in 'C:\temp\vuetest2\proj\src\app2'
 @ ./src/app2/main.ts 3:12-39
</code>```

If I change the entry point to src/app2/components/lib.ts, it will build.  I'm at a loss as to why main.ts won't build.

Contents of lib.ts:

```<code>import Vue = require('vue');
import Stuff  = require('./stuff.vue');

let o = {
   Stuff
}

let componentLibrary = {
  components: o,
  registerExternal: function(v:any) {
    for(var k in o) {
        v.component(o[k].name, o[k]);
    }
  },
  registerInternal: function() {
    for(var k in o) {
        Vue.component(o[k].name, o[k]);
    }
  }
}

export default componentLibrary;
</code>```

Stuff.vue is just a simple single file vue component.

Body:
I have a simple project structure:

/src/app2/main.ts
/src/app2/components/lib.ts
/src/app2/components/stuff.vue

With webpack, vue-loader, and ts-loader.

main.ts has:

import Vue = require('vue');
import  Component from './components/lib'

new Vue({
  el: '#app2'

});

When trying to build this with 1 webpack entry for /src/app2/main.ts, the error generated is:

ERROR in C:\temp\vuetest2\proj\src\app2\components\lib.ts
(2,25): error TS2307: Cannot find module './stuff.vue'.

ERROR in ./src/app2/main.ts
Module not found: Error: Can't resolve './components/lib' in 'C:\temp\vuetest2\proj\src\app2'
 @ ./src/app2/main.ts 3:12-39

If I change the entry point to src/app2/components/lib.ts, it will build.  I'm at a loss as to why main.ts won't build.

Contents of lib.ts:

import Vue = require('vue');
import Stuff  = require('./stuff.vue');

let o = {
   Stuff
}

let componentLibrary = {
  components: o,
  registerExternal: function(v:any) {
    for(var k in o) {
        v.component(o[k].name, o[k]);
    }
  },
  registerInternal: function() {
    for(var k in o) {
        Vue.component(o[k].name, o[k]);
    }
  }
}

export default componentLibrary;

Stuff.vue is just a simple single file vue component.

Body:
You can reference on this PR on github. Actually that's not a bug, just a usage problem.

I assume that you want to write SFC with <script lang="ts">, <script lang="tsx">, *.ts for utils functions & classes, and *.tsx for functional pure component.

ts-loader accpets only *.ts or *.tsx files to compile (otherwise it would cause an error that file not found). So ts-loader has two options: appendTsSuffixTo and appendTsxSuffixTo. These two options accept an array of regexp to match which files you want to compile. (Here we give ts-loader the *.vue files that already processed by vue-loader to compile).

I assume that you use *.ts.vue for <script lang="ts"> SFC vue file while *.tsx.vue for <script lang="tsx"> SFC vue file. ts-loader should be configured as below:

  {
    test: /\.tsx?$/,
    use: [
      {
        loader: 'babel-loader'
      },
      {
        loader: 'ts-loader',
        options: {
          appendTsSuffixTo: [/\.ts\.vue$/],
          appendTsxSuffixTo: [/\.tsx\.vue$/]
        }
      }
    ],
    exclude: /node_modules/
  },

This means, normal *.ts and *.tsx files pass to ts-loader will transpiled and then be sent to babel-loader for further compile. And other files end with .ts.vue will be suffixed .ts as *.ts.vue.ts, and end with .tsx.vue to be *.tsx.vue.tsx. These files all passed from vue-loader. Remember ts-loader only accept .ts and .tsx files.

But vue-loader is not smart enough, <script lang="xxx"> will trigger vue-loader append xxx-loader for further compile, and <script lang="tsx"> will make vue-loader append tsx-loader, which is not exist in the world.

Fortunately we can configure vue-loader's options:

  const loaders = {}
  loaders.tsx = ['babel-loader', 'ts-loader']
  loaders.ts = loaders.tsx
  {
    test: /\.vue$/,
    loader: 'vue-loader',
    options: { loaders }
  },

After that webpack config is completed. For tsx support, you should install some JSX types and write a related .d.ts file

You can check this repo on github for more details.

Good luck!


问:
SQL Query calculating the average of an average
I read through several posts on similar issues to this, and cannot seem to find the correct solution. I have tried adding the calculation to several parts of the query, without success. I am sure I am missing something simple.

I work at a mine and I was asked to accomplish the following:

They want to know which trucks was more than 5 % below the average payload of all the other trucks average payload over the past 3 days. It also needs to exclude any trucks that had less than 10 loads

There are 3 tables:

hist_loads (Gives payload and a lot of other information)

hist_exproot (Gives information related to dates, need this to give
a readable date)

hist_eqmtlist (Need this to determine the specific truck models, as
not all truck models must be included)

All of the above tables are joined together by a column called "shiftindex")

Below is my Query:

```<code>    IF OBJECT_ID ('tempdb.dbo.#pave') IS NOT NULL DROP TABLE dbo.#pave;
IF OBJECT_ID ('tempdb.dbo.#pfinal') IS NOT NULL DROP TABLE dbo.#pfinal;

select
    shiftdate
    ,truck
    ,AVG(measureton) as measureton
    ,COUNT(excav) as loads
into #pfinal
from hist_loads as hl
inner join hist_exproot as he on
he.shiftindex = hl.shiftindex
inner join hist_eqmtlist as heq on
heq.shiftindex = hl.shiftindex and
hl.truck = heq.eqmtid
where hl.shiftindex between
                            (select min(shiftindex)
                            from hist_exproot
                            where datepart(year,shiftdate) = datepart(year, getdate()-3)
                            and datepart(month,shiftdate) = datepart(month, getdate()-3)
                            and datepart(day,shiftdate) = datepart(day, getdate()-3))
        and
                            (select max(shiftindex)
                            from hist_exproot
                            where datepart(year,shiftdate) = datepart(year, getdate()-1)
                            and datepart(month,shiftdate) = datepart(month, getdate()-1)
                            and datepart(day,shiftdate) = datepart(day, getdate()-1))

and eqmttype in ('Euclid EH4500','Euclid EH4500-W','Euclid EH4500-HW')
and expit like 1
and measureton not like 0

group by eqmttype, truck, shiftdate
having COUNT(excav) > 10

select
    shiftdate
    ,AVG(measureton) as measureton
    ,COUNT(excav) as loads
into #pave
from hist_loads as hl
inner join hist_exproot as he on
he.shiftindex = hl.shiftindex
inner join hist_eqmtlist as heq on
heq.shiftindex = hl.shiftindex and
hl.truck = heq.eqmtid
where hl.shiftindex between
                            (select min(shiftindex)
                            from hist_exproot
                            where datepart(year,shiftdate) = datepart(year, getdate()-3)
                            and datepart(month,shiftdate) = datepart(month, getdate()-3)
                            and datepart(day,shiftdate) = datepart(day, getdate()-3))
        and
                            (select max(shiftindex)
                            from hist_exproot
                            where datepart(year,shiftdate) = datepart(year, getdate()-1)
                            and datepart(month,shiftdate) = datepart(month, getdate()-1)
                            and datepart(day,shiftdate) = datepart(day, getdate()-1))

and eqmttype in ('Euclid EH4500','Euclid EH4500-W','Euclid EH4500-HW')
and measureton not like 0

group by eqmttype, shiftdate
having COUNT(excav) > 10

select ave.shiftdate, ave.measureton, final.truck
from #pave as ave
left join #pfinal as final on
ave.shiftdate = final.shiftdate
where final.measureton < ave.measureton
order by truck
</code>```

My Result:

```<code>shiftdate           measureton         truck
2017-12-03 00:00:00 230.444365964912    DT01
2017-12-02 00:00:00 231.123014419048    DT04
2017-12-02 00:00:00 231.123014419048    DT07
2017-12-03 00:00:00 230.444365964912    DT07
2017-12-04 00:00:00 226.141955641026    DT07
2017-12-04 00:00:00 226.141955641026    DT10
2017-12-02 00:00:00 231.123014419048    DT13
2017-12-03 00:00:00 230.444365964912    DT14
2017-12-02 00:00:00 231.123014419048    DT15
2017-12-03 00:00:00 230.444365964912    DT17
2017-12-04 00:00:00 226.141955641026    DT17
2017-12-03 00:00:00 230.444365964912    DT20
2017-12-04 00:00:00 226.141955641026    DT20
2017-12-02 00:00:00 231.123014419048    DT22
2017-12-04 00:00:00 226.141955641026    DT24
2017-12-02 00:00:00 231.123014419048    DT25
2017-12-02 00:00:00 231.123014419048    DT27
2017-12-03 00:00:00 230.444365964912    DT27
2017-12-04 00:00:00 226.141955641026    DT28
2017-12-02 00:00:00 231.123014419048    DT30
2017-12-02 00:00:00 231.123014419048    DT31
2017-12-03 00:00:00 230.444365964912    DT31
2017-12-04 00:00:00 226.141955641026    DT32
</code>```

But I only need the trucks that were more than 5% under the average payload. The above result seems to be all of the trucks average payload over the past 3 days. And there also seem to be some repetition between 3 numbers.

Any help would be appreciated.

答:
It looks like you were pretty close... Can't confirm without your actual data, but lets see if this simplified query will work for you...

The first query, I have pre-computed just gathers data based on the date-only field without having to break down the year/month/day individually.

GetDate() by itself will return the current date AND time.  To get just the date, I am running CONVERT(date, getdate()), so 2017-12-05 08:22:15 am is stripped to just 2017-12-05.  Also, by doing dateadd() -3 days will bring this down to 2017-12-02.  The where clause is now >= '2017-12-02' AND LESS than '2017-12-05' which is inclusive of '2017-12-04 at 11:59:59 pm' getting the ENTIRE 12-04 day covering your entire 3 days requested.

You originally had the count > 10 but said to discard any that had LESS than 10 trips, so I changed to >= 10.  Your other criteria left as-is.

So at the end of this first query into the temp table give only the activity for the 3 days in question for the trucks qualified and gets the average per each truck.

```<code>SELECT
      shiftdate,
      truck,
      AVG(measureton) as measureton,
      COUNT(excav) as loads
   into
      #pTruckAvgs
   from
      hist_loads as hl
         inner join hist_exproot as he
            ON hl.shiftindex = he.shiftindex
         inner join hist_eqmtlist as heq
            ON hl.shiftindex = heq.shiftindex
            and hl.truck = heq.eqmtid
   where
          hl.shiftindex >= DateAdd( day, -3, CONVERT(date, getdate()) )
      and hl.shiftindex < CONVERT(date, getdate())
      and eqmttype in ('Euclid EH4500','Euclid EH4500-W','Euclid EH4500-HW')
      and expit like 1
      and measureton not like 0
   group by
      eqmttype,
      truck,
      shiftdate
   having
      COUNT(excav) >= 10;
</code>```

Now, you have a temp table of all trucks and their respective averages.  You don't need to requery again based on the dates and such, just grab the averages from this temp table ( via the QualAvgs result alias).  Here, you were looking for 5% less than the average, so I am taking the average * .95 and getting all truck averages that were LESS than the 95% of all averages.  Drop the temp table when finished.

```<code>select
      TA.*,
      QualAvgs.AllAvg
    from
       #pTruckAvgs TA,
       ( select AVG(measureton) as AllAvg
            from #pTruckAvgs ) QualAvgs
    where
       TA.measureTon < ( QualAvgs.AllAvg * .95);

drop table #pTruckAvgs;
</code>```

Now final thought... For the average on a per-day-basis might need a slight shift... For example, if bad weather, or other unforeseen restrictions making every truck slow on a single day, you might want.

```<code>select
      TA.*,
      QualAvgs.AllAvg
    from
       #pTruckAvgs TA,
       ( select shiftdate,
                 AVG(measureton) as AllAvg
            from #pTruckAvgs
            group by shiftdate ) QualAvgs
    where
           TA.measureTon < ( QualAvgs.AllAvg * .95)
       AND TA.ShiftDate = QualAvgs.ShiftDate;
</code>```

Body:
I read through several posts on similar issues to this, and cannot seem to find the correct solution. I have tried adding the calculation to several parts of the query, without success. I am sure I am missing something simple.

I work at a mine and I was asked to accomplish the following:

They want to know which trucks was more than 5 % below the average payload of all the other trucks average payload over the past 3 days. It also needs to exclude any trucks that had less than 10 loads

There are 3 tables:

hist_loads (Gives payload and a lot of other information)

hist_exproot (Gives information related to dates, need this to give
a readable date)

hist_eqmtlist (Need this to determine the specific truck models, as
not all truck models must be included)

All of the above tables are joined together by a column called "shiftindex")

Below is my Query:

    IF OBJECT_ID ('tempdb.dbo.#pave') IS NOT NULL DROP TABLE dbo.#pave;
IF OBJECT_ID ('tempdb.dbo.#pfinal') IS NOT NULL DROP TABLE dbo.#pfinal;

select
    shiftdate
    ,truck
    ,AVG(measureton) as measureton
    ,COUNT(excav) as loads
into #pfinal
from hist_loads as hl
inner join hist_exproot as he on
he.shiftindex = hl.shiftindex
inner join hist_eqmtlist as heq on
heq.shiftindex = hl.shiftindex and
hl.truck = heq.eqmtid
where hl.shiftindex between
                            (select min(shiftindex)
                            from hist_exproot
                            where datepart(year,shiftdate) = datepart(year, getdate()-3)
                            and datepart(month,shiftdate) = datepart(month, getdate()-3)
                            and datepart(day,shiftdate) = datepart(day, getdate()-3))
        and
                            (select max(shiftindex)
                            from hist_exproot
                            where datepart(year,shiftdate) = datepart(year, getdate()-1)
                            and datepart(month,shiftdate) = datepart(month, getdate()-1)
                            and datepart(day,shiftdate) = datepart(day, getdate()-1))

and eqmttype in ('Euclid EH4500','Euclid EH4500-W','Euclid EH4500-HW')
and expit like 1
and measureton not like 0

group by eqmttype, truck, shiftdate
having COUNT(excav) > 10

select
    shiftdate
    ,AVG(measureton) as measureton
    ,COUNT(excav) as loads
into #pave
from hist_loads as hl
inner join hist_exproot as he on
he.shiftindex = hl.shiftindex
inner join hist_eqmtlist as heq on
heq.shiftindex = hl.shiftindex and
hl.truck = heq.eqmtid
where hl.shiftindex between
                            (select min(shiftindex)
                            from hist_exproot
                            where datepart(year,shiftdate) = datepart(year, getdate()-3)
                            and datepart(month,shiftdate) = datepart(month, getdate()-3)
                            and datepart(day,shiftdate) = datepart(day, getdate()-3))
        and
                            (select max(shiftindex)
                            from hist_exproot
                            where datepart(year,shiftdate) = datepart(year, getdate()-1)
                            and datepart(month,shiftdate) = datepart(month, getdate()-1)
                            and datepart(day,shiftdate) = datepart(day, getdate()-1))

and eqmttype in ('Euclid EH4500','Euclid EH4500-W','Euclid EH4500-HW')
and measureton not like 0

group by eqmttype, shiftdate
having COUNT(excav) > 10

select ave.shiftdate, ave.measureton, final.truck
from #pave as ave
left join #pfinal as final on
ave.shiftdate = final.shiftdate
where final.measureton < ave.measureton
order by truck

My Result:

shiftdate           measureton         truck
2017-12-03 00:00:00 230.444365964912    DT01
2017-12-02 00:00:00 231.123014419048    DT04
2017-12-02 00:00:00 231.123014419048    DT07
2017-12-03 00:00:00 230.444365964912    DT07
2017-12-04 00:00:00 226.141955641026    DT07
2017-12-04 00:00:00 226.141955641026    DT10
2017-12-02 00:00:00 231.123014419048    DT13
2017-12-03 00:00:00 230.444365964912    DT14
2017-12-02 00:00:00 231.123014419048    DT15
2017-12-03 00:00:00 230.444365964912    DT17
2017-12-04 00:00:00 226.141955641026    DT17
2017-12-03 00:00:00 230.444365964912    DT20
2017-12-04 00:00:00 226.141955641026    DT20
2017-12-02 00:00:00 231.123014419048    DT22
2017-12-04 00:00:00 226.141955641026    DT24
2017-12-02 00:00:00 231.123014419048    DT25
2017-12-02 00:00:00 231.123014419048    DT27
2017-12-03 00:00:00 230.444365964912    DT27
2017-12-04 00:00:00 226.141955641026    DT28
2017-12-02 00:00:00 231.123014419048    DT30
2017-12-02 00:00:00 231.123014419048    DT31
2017-12-03 00:00:00 230.444365964912    DT31
2017-12-04 00:00:00 226.141955641026    DT32

But I only need the trucks that were more than 5% under the average payload. The above result seems to be all of the trucks average payload over the past 3 days. And there also seem to be some repetition between 3 numbers.

Any help would be appreciated.

Body:
It looks like you were pretty close... Can't confirm without your actual data, but lets see if this simplified query will work for you...

The first query, I have pre-computed just gathers data based on the date-only field without having to break down the year/month/day individually.

GetDate() by itself will return the current date AND time.  To get just the date, I am running CONVERT(date, getdate()), so 2017-12-05 08:22:15 am is stripped to just 2017-12-05.  Also, by doing dateadd() -3 days will bring this down to 2017-12-02.  The where clause is now >= '2017-12-02' AND LESS than '2017-12-05' which is inclusive of '2017-12-04 at 11:59:59 pm' getting the ENTIRE 12-04 day covering your entire 3 days requested.

You originally had the count > 10 but said to discard any that had LESS than 10 trips, so I changed to >= 10.  Your other criteria left as-is.

So at the end of this first query into the temp table give only the activity for the 3 days in question for the trucks qualified and gets the average per each truck.

SELECT
      shiftdate,
      truck,
      AVG(measureton) as measureton,
      COUNT(excav) as loads
   into
      #pTruckAvgs
   from
      hist_loads as hl
         inner join hist_exproot as he
            ON hl.shiftindex = he.shiftindex
         inner join hist_eqmtlist as heq
            ON hl.shiftindex = heq.shiftindex
            and hl.truck = heq.eqmtid
   where
          hl.shiftindex >= DateAdd( day, -3, CONVERT(date, getdate()) )
      and hl.shiftindex < CONVERT(date, getdate())
      and eqmttype in ('Euclid EH4500','Euclid EH4500-W','Euclid EH4500-HW')
      and expit like 1
      and measureton not like 0
   group by
      eqmttype,
      truck,
      shiftdate
   having
      COUNT(excav) >= 10;

Now, you have a temp table of all trucks and their respective averages.  You don't need to requery again based on the dates and such, just grab the averages from this temp table ( via the QualAvgs result alias).  Here, you were looking for 5% less than the average, so I am taking the average * .95 and getting all truck averages that were LESS than the 95% of all averages.  Drop the temp table when finished.

select
      TA.*,
      QualAvgs.AllAvg
    from
       #pTruckAvgs TA,
       ( select AVG(measureton) as AllAvg
            from #pTruckAvgs ) QualAvgs
    where
       TA.measureTon < ( QualAvgs.AllAvg * .95);

drop table #pTruckAvgs;

Now final thought... For the average on a per-day-basis might need a slight shift... For example, if bad weather, or other unforeseen restrictions making every truck slow on a single day, you might want.

select
      TA.*,
      QualAvgs.AllAvg
    from
       #pTruckAvgs TA,
       ( select shiftdate,
                 AVG(measureton) as AllAvg
            from #pTruckAvgs
            group by shiftdate ) QualAvgs
    where
           TA.measureTon < ( QualAvgs.AllAvg * .95)
       AND TA.ShiftDate = QualAvgs.ShiftDate;


问:
IndexedDB Query in Mobile Web
I use 'IndexedDB' in Mobile Web.
I want query like SQL syntax.
For example...

```<code>SELECT * FROM TABLE WHERE (X1 >= 1.1 AND Y1 <= 5.1) OR (X2 >= 1.2 AND Y2 <= 5.2)
</code>```

Is this possible?

答:
You can use the JsStore for executing Sql query in indexeddb. It provides sql like api like - select, update, where, in , like etc.

So the code for above query in JsStore will be -

```<code>var Connection = new JsStore.Instance();
Connection.openDb('Database_name');
Connection.select({
    From: "TABLE",
    Where: {
        X1: {
            '>=': 1.1
        },
        Y1: {
            '<=': 5.1
        },
        Or: {
            X2: {
                '>=': 1.2
            },
            Y2: {
                '<=': 5.2
            }
        }
    },
    OnSuccess: function (results) {
        console.log(results);
    },
    OnError: function (error) {
        console.log(error);
    }
});
</code>```

You can execute almost all type of sql query using jsstore. For more take a look here - http://jsstore.net/

Title: IndexedDB Query in Mobile Web

Body:
I use 'IndexedDB' in Mobile Web.
I want query like SQL syntax.
For example...

SELECT * FROM TABLE WHERE (X1 >= 1.1 AND Y1 <= 5.1) OR (X2 >= 1.2 AND Y2 <= 5.2)

Is this possible?

Body:
You can use the JsStore for executing Sql query in indexeddb. It provides sql like api like - select, update, where, in , like etc.

So the code for above query in JsStore will be -

var Connection = new JsStore.Instance();
Connection.openDb('Database_name');
Connection.select({
    From: "TABLE",
    Where: {
        X1: {
            '>=': 1.1
        },
        Y1: {
            '<=': 5.1
        },
        Or: {
            X2: {
                '>=': 1.2
            },
            Y2: {
                '<=': 5.2
            }
        }
    },
    OnSuccess: function (results) {
        console.log(results);
    },
    OnError: function (error) {
        console.log(error);
    }
});

You can execute almost all type of sql query using jsstore. For more take a look here - http://jsstore.net/


问:
How to group 2 groups into 1 group in Extjs grid?
I have this grid and would like to group 2 groups into a single group based on the status. Basically I want to put together "Cheched-In" and "Ready for MA" into a single group. Thanks a lot for the help!

Here's the working code: FIDDLE

```<code>Ext.create('Ext.grid.Panel', {
title: 'Employees',
store: store,
 columns: [
  { text: 'Box', dataIndex: 'box', width: 50 },
  { text: 'Name', dataIndex: 'name', flex: 2 },
  { text: 'Status', dataIndex: 'status', flex: 1 }
],
features: [{ftype:'grouping'}],
renderTo: Ext.getBody()
});
</code>```

答:
You can try to have a different field for grouping, try this</p>

```<code>function addGroupField(data) {
  return data.map(function(row) {
    return {
      box: row.box,
      name: row.name,
      status: row.status,
      groupedStatus: [
        'Checked-In',
        'Ready for MA'
      ].indexOf(row.status) > -1 ? 'Checked-In & Ready for MA' : row.status,
    }
  });
}

var data = addGroupField([
  { box: '', name: 'Brady, Marsha',status: 'Checked-In' },
  { box: 'MA', name: 'Dwight, Schrute', status: 'With MA' },
  { box: 'MA', name: 'Jim, Halpert', status: 'With MA' },
  { box: 'MA', name: 'Mike, Brown', status: 'With MA' },
  { box: 'MA', name: 'Steve, Smith', status: 'With MA' },
  { box: 'MA', name: 'Lori, Morrison', status: 'With MA' },
  { box: 'MA', name: 'Mary, Loson', status: 'With MA' },
  { box: 'MA', name: 'Junior, Meloni', status: 'With MA' },
  { box: 'MA', name: 'Jim, Halpert', status: 'With MA' },
  { box: '', name: 'Kevin, Malone', status: 'Checked-In' },
  { box: '', name: 'Angela, Martin', status: 'Checked-In' },
  { box: '2', name: 'Jim, Halpert', status: 'Ready for MA' },
  { box: '2', name: 'Kevin, Malone', status: 'Ready for MA' },
  { box: '2', name: 'Angela, Martin', status: 'Ready for MA' }
]);

var store = Ext.create('Ext.data.Store', {
  fields: ['name', 'seniority', 'department'],
  groupField: 'groupedStatus',
  data: data
});

Ext.onReady(function() {
  Ext.create('Ext.grid.Panel', {
    title: 'Employees',
    store: store,
    columns: [
      { text: 'Box', dataIndex: 'box', width: 50 },
      { text: 'Name', dataIndex: 'name', flex: 2 },
      { text: 'Status', dataIndex: 'status', flex: 1 }
    ],
    features: [{ftype:'grouping'}],
    renderTo: Ext.getBody()
  });
});
</code>```

Body:
I have this grid and would like to group 2 groups into a single group based on the status. Basically I want to put together "Cheched-In" and "Ready for MA" into a single group. Thanks a lot for the help!

Here's the working code: FIDDLE

Ext.create('Ext.grid.Panel', {
title: 'Employees',
store: store,
 columns: [
  { text: 'Box', dataIndex: 'box', width: 50 },
  { text: 'Name', dataIndex: 'name', flex: 2 },
  { text: 'Status', dataIndex: 'status', flex: 1 }
],
features: [{ftype:'grouping'}],
renderTo: Ext.getBody()
});

Body:
You can try to have a different field for grouping, try this

function addGroupField(data) {
  return data.map(function(row) {
    return {
      box: row.box,
      name: row.name,
      status: row.status,
      groupedStatus: [
        'Checked-In',
        'Ready for MA'
      ].indexOf(row.status) > -1 ? 'Checked-In & Ready for MA' : row.status,
    }
  });
}

var data = addGroupField([
  { box: '', name: 'Brady, Marsha',status: 'Checked-In' },
  { box: 'MA', name: 'Dwight, Schrute', status: 'With MA' },
  { box: 'MA', name: 'Jim, Halpert', status: 'With MA' },
  { box: 'MA', name: 'Mike, Brown', status: 'With MA' },
  { box: 'MA', name: 'Steve, Smith', status: 'With MA' },
  { box: 'MA', name: 'Lori, Morrison', status: 'With MA' },
  { box: 'MA', name: 'Mary, Loson', status: 'With MA' },
  { box: 'MA', name: 'Junior, Meloni', status: 'With MA' },
  { box: 'MA', name: 'Jim, Halpert', status: 'With MA' },
  { box: '', name: 'Kevin, Malone', status: 'Checked-In' },
  { box: '', name: 'Angela, Martin', status: 'Checked-In' },
  { box: '2', name: 'Jim, Halpert', status: 'Ready for MA' },
  { box: '2', name: 'Kevin, Malone', status: 'Ready for MA' },
  { box: '2', name: 'Angela, Martin', status: 'Ready for MA' }
]);

var store = Ext.create('Ext.data.Store', {
  fields: ['name', 'seniority', 'department'],
  groupField: 'groupedStatus',
  data: data
});

Ext.onReady(function() {
  Ext.create('Ext.grid.Panel', {
    title: 'Employees',
    store: store,
    columns: [
      { text: 'Box', dataIndex: 'box', width: 50 },
      { text: 'Name', dataIndex: 'name', flex: 2 },
      { text: 'Status', dataIndex: 'status', flex: 1 }
    ],
    features: [{ftype:'grouping'}],
    renderTo: Ext.getBody()
  });
});


问:
Algorithm for generating triangle meshes from vertex array
Let's say I have a set of points in 3D. The points are uniformly spaced on the x and y axes. So one can think of the points as a function z = f(x,y). As an example, x can be from {0,1,2} and y can be {0,1,2}, giving us a total of nine 3D points on a square grid. I am trying to implement a simple algorithm to generate a triangle mesh of these points, given their  coordinates. I do not know much aboout mesh generation, but I do know that my points are evenly spaced in the x and y dimensions on a grid. So if my points were of the form:

0 0 0

0 5 0

0 0 0

Where the row number represents the y coordinate and the column number represents the x coordinate, and the value represents the z coordinate. This set of points should generate a triangular mesh that looks like a square base pyramid where the peak of the pyramid is at (1,1,5). I am looking for a simple  algorithm that I could code up that would generate such a mesh, given the specifics of this problem.

I have heard of Delaunay triangulation, but am not sure if it is applicable to this problem. Thanks.

答: A very easy solution is to consider the four vertices of every mesh and create two triangles, using a diagonal and the four sides.


问:
How to use template helpers in meteor js?
I am working on a project which needs to get parameters from url and insert it in mongodb.I i am using the below code,which is working but still some silly issues is causing a problem.
Below is the main.js code:

```<code>import { Template } from 'meteor/templating';
import { Dbs } from '../lib/collects.js';
import './main.html';

Router.route('/temp1/:ppid', function () {
this.render('temp1', {
data: function ()
{
var rpms = this.params.query.rpms;
return Dbs.findOne({patient_id:this.params.ppid});
}
});
});

Template.temp1.helpers({
  'tempr': function() {
    var p=Router.current().params.ppid;
    var path1=Router.current().params.query.path;
    var doc_id1 =Router.current().params.query.docid;
    var temp1 = Router.current().params.query.temp;
    var age1 = Router.current().params.query.age;
    var gender1= Router.current().params.query.gender;
    var height1= Router.current().params.query.height;
    var weight1= Router.current().params.query.weight;
    var tempr= Router.current().params.query.tempr;
 Meteor.call('dbs.update',p,doc_id1,path1,temp1,age1,gender1,height1,weight1,tempr);
 }
});

Below is main.html code:
<head>
  <title>project1</title>

   <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>

<body>
  <nav class="#c5cae9 indigo lighten-4">
  <div class="container">
  <div class="nav-wrapper">
   <a href="#" class="brand-logo">A3RMT</a>
   <ul id="nav-mobile" class="right hide-on-med-and-down">
</ul>
</div>
</div>
</nav>
<div class="row">
<div class="col s2">
</div>
</div>
</body>

<template name="a3">
<div class="row">
      <div class="col s2">
        <h4 class="black-text text-darken-4">INFORMATION</h4>
      <table class="centered">
      <form class="sub">
       <tr>
        <td><th>Doc_ID</th>{{doc_id}}</td>
        <td><th>tempr</th>{{tempr}}</td>
        <td><th>temp</th>{{temp}}</td>
      </tr>

      <tr>
        <td><th>Path</th>{{path}}</td>
        <td><th>age</th>{{age}}</td>
        <td><th>gender</th>{{gendert}}</td>
        <td><th>weight</th>{{weight}}</td>
        <td><th>Height</th>{{height}}</td>
      </tr>
</form></table></div></div>

</template>
</code>```

The above code is working fine but the only issue is  with line of code:"'tempr': function()".When i insert new parameters from url,its values are stored in database and even updated when i do update but it does not display value of "tempr" from database.And if i change 'tempr':function() to 'abc':function() i am not able to update nor insert anything into database. I am not understanding what am i suppose to use

```<code>Template.temp1.helpers({
      'tempr': function() {
</code>```

please anyone help me with this issue.How do i use template helpers
what do i need to specify at the place of "tempr" in
Template.temp1.helpers({'tempr': function()

答:
The helper is used to work with data and supply it to the html dynamically. The template runs multiple times when the page loads. In your case, the dbs.update will be called many times over and over when the page loads. Ideally, any method call should be present in events. Eg. when you submit the form, update the db. If you want the update to happen each time the page loads, then have it put in the onRendered() method.

Probable solution:

```<code>Templates.<<template_name>>.events({

// on submit of a form or something similar

    var p=Router.current().params.ppid;
    var path1=Router.current().params.query.path;
    var doc_id1 =Router.current().params.query.docid;
    var temp1 = Router.current().params.query.temp;
    var age1 = Router.current().params.query.age;
    var gender1= Router.current().params.query.gender;
    var height1= Router.current().params.query.height;
    var weight1= Router.current().params.query.weight;
    var tempr= Router.current().params.query.tempr;
 Meteor.call('dbs.update',p,doc_id1,path1,temp1,age1,gender1,height1,weight1,tempr);

})
</code>```

Body:
I am working on a project which needs to get parameters from url and insert it in mongodb.I i am using the below code,which is working but still some silly issues is causing a problem.
Below is the main.js code:

import { Template } from 'meteor/templating';
import { Dbs } from '../lib/collects.js';
import './main.html';

Router.route('/temp1/:ppid', function () {
this.render('temp1', {
data: function ()
{
var rpms = this.params.query.rpms;
return Dbs.findOne({patient_id:this.params.ppid});
}
});
});

Template.temp1.helpers({
  'tempr': function() {
    var p=Router.current().params.ppid;
    var path1=Router.current().params.query.path;
    var doc_id1 =Router.current().params.query.docid;
    var temp1 = Router.current().params.query.temp;
    var age1 = Router.current().params.query.age;
    var gender1= Router.current().params.query.gender;
    var height1= Router.current().params.query.height;
    var weight1= Router.current().params.query.weight;
    var tempr= Router.current().params.query.tempr;
 Meteor.call('dbs.update',p,doc_id1,path1,temp1,age1,gender1,height1,weight1,tempr);
 }
});

Below is main.html code:

  <title>project1</title>

   <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

   A3RMT

<template name="a3">

INFORMATION

      <form class="sub">

        Doc_ID	{{doc_id}}
        tempr	{{tempr}}
        temp	{{temp}}

        Path	{{path}}
        age	{{age}}
        gender	{{gendert}}
        weight	{{weight}}
        Height	{{height}}

</form>

</template>

The above code is working fine but the only issue is  with line of code:"'tempr': function()".When i insert new parameters from url,its values are stored in database and even updated when i do update but it does not display value of "tempr" from database.And if i change 'tempr':function() to 'abc':function() i am not able to update nor insert anything into database. I am not understanding what am i suppose to use

Template.temp1.helpers({
      'tempr': function() {

please anyone help me with this issue.How do i use template helpers
what do i need to specify at the place of "tempr" in
Template.temp1.helpers({'tempr': function()

Body:
The helper is used to work with data and supply it to the html dynamically. The template runs multiple times when the page loads. In your case, the dbs.update will be called many times over and over when the page loads. Ideally, any method call should be present in events. Eg. when you submit the form, update the db. If you want the update to happen each time the page loads, then have it put in the onRendered() method.

Probable solution:

Templates.<<template_name>>.events({

// on submit of a form or something similar

    var p=Router.current().params.ppid;
    var path1=Router.current().params.query.path;
    var doc_id1 =Router.current().params.query.docid;
    var temp1 = Router.current().params.query.temp;
    var age1 = Router.current().params.query.age;
    var gender1= Router.current().params.query.gender;
    var height1= Router.current().params.query.height;
    var weight1= Router.current().params.query.weight;
    var tempr= Router.current().params.query.tempr;
 Meteor.call('dbs.update',p,doc_id1,path1,temp1,age1,gender1,height1,weight1,tempr);

})


问:
How to define a before_action callback in application controller only for devise_controllers and activeadmin controllers?
I need to implement a before_action callback in my application controller only for activeadmin and devise controllers. For devise controllers I can do something like:

```<code>before_action :some_callback, if: :devise_controller?
</code>```

How can I do the same for activeadmin controllers? I tried to make a method like:

```<code>def active_admin_controller?
 if params[:controller] =~ /^admin\//i
   true
 end
end
</code>```

but it doesn't work. Any ideas on how to reach the desired result? Thanks ahead.

答:
I've found the solution, just had to put the conditions into an array:

```<code>before_action :some_callback, unless: [:devise_controller?, :active_admin_controller?]
</code>```

also, changed active_admin_controller? method:

```<code>def active_admin_controller?
  if request.filtered_parameters['controller'] =~ /^admin\//i
    true
  else
    false
  end
end
</code>```

Body:
I need to implement a before_action callback in my application controller only for activeadmin and devise controllers. For devise controllers I can do something like:

before_action :some_callback, if: :devise_controller?

How can I do the same for activeadmin controllers? I tried to make a method like:

def active_admin_controller?
 if params[:controller] =~ /^admin\//i
   true
 end
end

but it doesn't work. Any ideas on how to reach the desired result? Thanks ahead.

Body:
I've found the solution, just had to put the conditions into an array:

before_action :some_callback, unless: [:devise_controller?, :active_admin_controller?]

also, changed active_admin_controller? method:

def active_admin_controller?
  if request.filtered_parameters['controller'] =~ /^admin\//i
    true
  else
    false
  end
end


问:
Query to list users having same profile from two tables
```<code>Table 1 : dbt_m_user (user_id, user_name, email_id, . . . . . )

Table 2 : dbt_m_user_profile (user_id, profile_id, . . . . .)
</code>```

I have e-mail id of an user who has particular profile (role).
Now I need names of users who are having same access profile.

I could get the results from below, but it looks very raw and doesn't seem to be elegant one, considering that there are only 2 tables.

```<code>  select user_name from dbt_m_user where user_id in (
  select user_id from dbt_m_user_profile where profile_id in (
  select profile_id from dbt_m_user_profile where user_id in (
  select user_id from  dbt_m_user where Email_Id = 'snehal.masne@db.com' )))
</code>```

Can this be improvised by using special clauses/joins ?

答:
Following query should work:</p>

```<code>select t1.user_name
from dbt_m_user_profile t1
inner join dbt_m_user t2
on t2.user_id = t1.user_id
where t2.profile_id in (select t1.profile_id
                       from dbt_m_user_profile t1
                       inner join (select * from dbt_m_user
                                   where t1.email_id = 'snehal.masne@db.com'
                                  ) t2
                       on t2.user_id = t1.user_id
                       )
;
</code>```

Body:
Table 1 : dbt_m_user (user_id, user_name, email_id, . . . . . )

Table 2 : dbt_m_user_profile (user_id, profile_id, . . . . .)

I have e-mail id of an user who has particular profile (role).
Now I need names of users who are having same access profile.

I could get the results from below, but it looks very raw and doesn't seem to be elegant one, considering that there are only 2 tables.

  select user_name from dbt_m_user where user_id in (
  select user_id from dbt_m_user_profile where profile_id in (
  select profile_id from dbt_m_user_profile where user_id in (
  select user_id from  dbt_m_user where Email_Id = 'snehal.masne@db.com' )))

Can this be improvised by using special clauses/joins ?

Body:
Following query should work:

select t1.user_name
from dbt_m_user_profile t1
inner join dbt_m_user t2
on t2.user_id = t1.user_id
where t2.profile_id in (select t1.profile_id
                       from dbt_m_user_profile t1
                       inner join (select * from dbt_m_user
                                   where t1.email_id = 'snehal.masne@db.com'
                                  ) t2
                       on t2.user_id = t1.user_id
                       )
;