问:
Spark connects to database every time I perform a Transformation/Action?
I am running Spark 2.1.0 on Windows 10. I connected to a MySQL database to get data into spark using JDBC. As shown below, whenever I perform an action I get the following warning which makes me wonder that the data is being retrieved from database for every operation.

```<code>scala> val jdbcDF2 = spark.read.jdbc("jdbc:mysql:dbserver", "schema.tablename", connectionProperties)
Wed Mar 29 15:05:23 IST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
jdbcDF2: org.apache.spark.sql.DataFrame = [id: bigint, site: bigint ... 15 more fields]

scala> jdbcDF2.count
Wed Mar 29 15:09:09 IST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
</code>```

If this is the case, is there a way by which I can save the data in a spark local object like a DataFrame so that it doesn't have to connect to database all the time?

I tried to cache the table and it runs successfully but I am unable to use Spark-SQL on the table

```<code>scala> jdbcDF2.cache()
res6: jdbcDF2.type = [id: bigint, site: bigint ... 15 more fields]
scala> val unique = sql("SELECT DISTINCT site FROM jdbcDF2")
org.apache.spark.sql.AnalysisException: Table or view not found: jdbcDF2;
</code>```

答:
You can execute your queries after caching directly on your DataFrame using

val unique = jdbcDF2.selectExpr("count(distinct site)")

or

val unique = jdbcDF2.select("site").distinct.count

or
creating a temporary view from your DataFrame and access it via sqlContext

```<code>jdbcDF2.createOrReplaceTempView("jdbcDF2")
val unique = sql("SELECT DISTINCT site FROM jdbcDF2")
</code>```

Body:
I am running Spark 2.1.0 on Windows 10. I connected to a MySQL database to get data into spark using JDBC. As shown below, whenever I perform an action I get the following warning which makes me wonder that the data is being retrieved from database for every operation.

scala> val jdbcDF2 = spark.read.jdbc("jdbc:mysql:dbserver", "schema.tablename", connectionProperties)
Wed Mar 29 15:05:23 IST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
jdbcDF2: org.apache.spark.sql.DataFrame = [id: bigint, site: bigint ... 15 more fields]

scala> jdbcDF2.count
Wed Mar 29 15:09:09 IST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

If this is the case, is there a way by which I can save the data in a spark local object like a DataFrame so that it doesn't have to connect to database all the time?

I tried to cache the table and it runs successfully but I am unable to use Spark-SQL on the table

scala> jdbcDF2.cache()
res6: jdbcDF2.type = [id: bigint, site: bigint ... 15 more fields]
scala> val unique = sql("SELECT DISTINCT site FROM jdbcDF2")
org.apache.spark.sql.AnalysisException: Table or view not found: jdbcDF2;

Body:
You can execute your queries after caching directly on your DataFrame using

val unique = jdbcDF2.selectExpr("count(distinct site)")

or

val unique = jdbcDF2.select("site").distinct.count

or
creating a temporary view from your DataFrame and access it via sqlContext

jdbcDF2.createOrReplaceTempView("jdbcDF2")
val unique = sql("SELECT DISTINCT site FROM jdbcDF2")


来源: stackexchange

问:
Selenium Chrome Driver » 3.2.0
I am an automation tester using Cucumber, Serenity and Gradle.
I just updated my build.gradle properties file to use [Selenium Chrome Driver » 3.2.0] and ran my login test and found an error that has not occurred in [Selenium Chrome Driver » 3.0.1].

I also get the same error when using 3.1.0
compile group: 'org.seleniumhq.selenium', name: 'selenium-chrome-driver', version: '3.1.0'.

I moved back to version 3.0.1 which works without any issues.
Here is the error message I get:

```<code>net.serenitybdd.core.exceptions.SerenityManagedException: org.openqa.selenium.os.CommandLine.find(Ljava/lang/String;)Ljava/lang/String;
    at net.serenitybdd.core.webdriver.servicepools.DriverServiceExecutable.asAFile(DriverServiceExecutable.java:90)
    at net.serenitybdd.core.webdriver.servicepools.GeckoDriverServiceExecutable.geckoBinaryCalled(GeckoDriverServiceExecutable.java:38)
    at net.serenitybdd.core.webdriver.servicepools.GeckoDriverServiceExecutable.executablePath(GeckoDriverServiceExecutable.java:24)
    at net.serenitybdd.core.webdriver.servicepools.GeckoDriverServiceExecutable.inEnvironment(GeckoDriverServiceExecutable.java:20)
    at net.serenitybdd.core.webdriver.servicepools.GeckoServicePool.configureGeckoDriverBinaries(GeckoServicePool.java:38)
    at net.serenitybdd.core.webdriver.servicepools.GeckoServicePool.<init>(GeckoServicePool.java:29)
    at net.serenitybdd.core.webdriver.driverproviders.FirefoxDriverProvider.<init>(FirefoxDriverProvider.java:29)
    at net.thucydides.core.webdriver.WebDriverFactory.driverProviders(WebDriverFactory.java:102)
    at net.thucydides.core.webdriver.WebDriverFactory.newWebdriverInstance(WebDriverFactory.java:126)
    at net.thucydides.core.webdriver.WebDriverFacade.newDriverInstance(WebDriverFacade.java:144)
    at net.thucydides.core.webdriver.WebDriverFacade.newProxyDriver(WebDriverFacade.java:135)
    at net.thucydides.core.webdriver.WebDriverFacade.getProxiedDriver(WebDriverFacade.java:105)
    at net.thucydides.core.webdriver.WebDriverFacade.openIgnoringHtmlUnitScriptErrors(WebDriverFacade.java:180)
    at net.thucydides.core.webdriver.WebDriverFacade.get(WebDriverFacade.java:175)
    at net.serenitybdd.core.pages.PageObject.openPageAtUrl(PageObject.java:829)
    at net.serenitybdd.core.pages.PageObject.openAt(PageObject.java:782)
    at faa.cucumber.stepLibraries.BaseUserSteps.navigateToTheFaaHomePage(BaseUserSteps.java:60)
    at faa.cucumber.stepLibraries.BaseUserSteps$$EnhancerByCGLIB$$9ba37e92.CGLIB$navigateToTheFaaHomePage$26(<generated>)
    at faa.cucumber.stepLibraries.BaseUserSteps$$EnhancerByCGLIB$$9ba37e92$$FastClassByCGLIB$$7f7ccb1e.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at net.thucydides.core.steps.StepInterceptor.invokeMethod(StepInterceptor.java:372)
    at net.thucydides.core.steps.StepInterceptor.executeTestStepMethod(StepInterceptor.java:357)
    at net.thucydides.core.steps.StepInterceptor.runTestStep(StepInterceptor.java:332)
    at net.thucydides.core.steps.StepInterceptor.testStepResult(StepInterceptor.java:134)
    at net.thucydides.core.steps.StepInterceptor.intercept(StepInterceptor.java:61)
    at faa.cucumber.stepLibraries.BaseUserSteps$$EnhancerByCGLIB$$9ba37e92.navigateToTheFaaHomePage(<generated>)
    at faa.cucumber.maps.NavigationMap.given_welcome(NavigationMap.java:197)
    at ✽.Given i have accessed the welcome page(login.feature:11)
</code>```

答:
I'm not using maven. I'm using Created a gradle project, write cucumber feature files, then write java map, steps and page classes.
I then run my tests using git-bash at the command line.
My tests run and create a serenity report .
Have been doing it this way for 3 years.

Here is part of my build.gradle file to show my current chrome driver.  When I update the driver to 3.2.0, I get that error message as previously posted.

compile group: 'org.seleniumhq.selenium', name: 'selenium-chrome-driver', version: '3.0.1'

ContentLicense: CC BY-SA 3.0

Title: Selenium Chrome Driver » 3.2.0

Body:
I am an automation tester using Cucumber, Serenity and Gradle.
I just updated my build.gradle properties file to use [Selenium Chrome Driver » 3.2.0] and ran my login test and found an error that has not occurred in [Selenium Chrome Driver » 3.0.1].

I also get the same error when using 3.1.0
compile group: 'org.seleniumhq.selenium', name: 'selenium-chrome-driver', version: '3.1.0'.

I moved back to version 3.0.1 which works without any issues.
Here is the error message I get:

net.serenitybdd.core.exceptions.SerenityManagedException: org.openqa.selenium.os.CommandLine.find(Ljava/lang/String;)Ljava/lang/String;
    at net.serenitybdd.core.webdriver.servicepools.DriverServiceExecutable.asAFile(DriverServiceExecutable.java:90)
    at net.serenitybdd.core.webdriver.servicepools.GeckoDriverServiceExecutable.geckoBinaryCalled(GeckoDriverServiceExecutable.java:38)
    at net.serenitybdd.core.webdriver.servicepools.GeckoDriverServiceExecutable.executablePath(GeckoDriverServiceExecutable.java:24)
    at net.serenitybdd.core.webdriver.servicepools.GeckoDriverServiceExecutable.inEnvironment(GeckoDriverServiceExecutable.java:20)
    at net.serenitybdd.core.webdriver.servicepools.GeckoServicePool.configureGeckoDriverBinaries(GeckoServicePool.java:38)
    at net.serenitybdd.core.webdriver.servicepools.GeckoServicePool.<init>(GeckoServicePool.java:29)
    at net.serenitybdd.core.webdriver.driverproviders.FirefoxDriverProvider.<init>(FirefoxDriverProvider.java:29)
    at net.thucydides.core.webdriver.WebDriverFactory.driverProviders(WebDriverFactory.java:102)
    at net.thucydides.core.webdriver.WebDriverFactory.newWebdriverInstance(WebDriverFactory.java:126)
    at net.thucydides.core.webdriver.WebDriverFacade.newDriverInstance(WebDriverFacade.java:144)
    at net.thucydides.core.webdriver.WebDriverFacade.newProxyDriver(WebDriverFacade.java:135)
    at net.thucydides.core.webdriver.WebDriverFacade.getProxiedDriver(WebDriverFacade.java:105)
    at net.thucydides.core.webdriver.WebDriverFacade.openIgnoringHtmlUnitScriptErrors(WebDriverFacade.java:180)
    at net.thucydides.core.webdriver.WebDriverFacade.get(WebDriverFacade.java:175)
    at net.serenitybdd.core.pages.PageObject.openPageAtUrl(PageObject.java:829)
    at net.serenitybdd.core.pages.PageObject.openAt(PageObject.java:782)
    at faa.cucumber.stepLibraries.BaseUserSteps.navigateToTheFaaHomePage(BaseUserSteps.java:60)
    at faa.cucumber.stepLibraries.BaseUserSteps$$EnhancerByCGLIB$$9ba37e92.CGLIB$navigateToTheFaaHomePage$26(<generated>)
    at faa.cucumber.stepLibraries.BaseUserSteps$$EnhancerByCGLIB$$9ba37e92$$FastClassByCGLIB$$7f7ccb1e.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at net.thucydides.core.steps.StepInterceptor.invokeMethod(StepInterceptor.java:372)
    at net.thucydides.core.steps.StepInterceptor.executeTestStepMethod(StepInterceptor.java:357)
    at net.thucydides.core.steps.StepInterceptor.runTestStep(StepInterceptor.java:332)
    at net.thucydides.core.steps.StepInterceptor.testStepResult(StepInterceptor.java:134)
    at net.thucydides.core.steps.StepInterceptor.intercept(StepInterceptor.java:61)
    at faa.cucumber.stepLibraries.BaseUserSteps$$EnhancerByCGLIB$$9ba37e92.navigateToTheFaaHomePage(<generated>)
    at faa.cucumber.maps.NavigationMap.given_welcome(NavigationMap.java:197)
    at ✽.Given i have accessed the welcome page(login.feature:11)


问:
Big quantity of data with MySql
i have a question about Mass storage. Actually, i'm working with 5 sensors which sends a lot of datas with a different frequency for each one and i'm using MySQL DATABASE.

so here is my questions:

1) is MySQL the perfect solution.
2) if not, is there a solution to store this big quantity of data in a data base?
3) I'm using Threads in this and i'm using mutexs also, i'm afraid if this can cause problems, Actually,it seems to be.

i hope i will have an answer to this question.

答:
You can store data anywhere, but the data storage structure selection would depends on the use cases (the things, you want to do with the data).

It could be HDFS files, RDBMS, NoSQL DB, etc.

For example your common could be:

1. to save the sensor data very quickly.

2. get the sensor data on the definite date.

Then, you can use MongoDB or Cassandra.

If you want to get deep analytics (to get monthly average sensor data), you definitely should think about another solutions.

As for MySQL, it could also be used for some reasonable big data storage,
as it supports sharding.
 It fits some scenarios well, some not.

But I repeat, all would depend on use cases, i.e. the things you want to do with data.
So you could provide question with more details (define desired use-cases), or ask again.

Title: Big quantity of data with MySql


问:
Passing image to another app for editing/annotate from my App
I am trying to allow my users to edit an image through any annotation app installed in their devices.
For this, I am sending image from my Application to another app for editing and retrieving it back.
I am using the following code in Xamarin.Android -

```<code>                var imgIntent = new Intent (Intent.ActionEdit);

                var imgItem = (File)ImageAdapter.GetItem (p0.ItemId);
                var imgFileName = imgItem.Name;
                AndroidController.Current.SetImgFileName(Activity, imgFileName);
                imgIntent.PutExtra (Intent.ExtraStream,
                    Uri.FromFile (imgItem));
                imgIntent.SetType ("image/*");

                if (Utils.CheckIntentAvailable (Activity, imgIntent)) {
                    StartActivity (imgIntent);
                } else {
                    Toast.MakeText(Activity.ApplicationContext, "xyz", ToastLength.Long).Show();
                }
</code>```

When I select "Skitch", the image is perfectly getting transferred to skitch, and getting back into my app once they share it with my app.

But, When I select "Inkboard" for the same purpose, the Inkboard app Intent triggers, but it doesn't pick the image I sent in Intent Extras.

Can anybody figure out what is happening here ?
Thanks in advance.

答:
note: i donot know anythink about xamarin

according to https://developer.android.com/reference/android/content/Intent.html#ACTION_EDIT the uri to be edited should go into Intent.data.

your code uses Intent.ExtraStream instead which is not standard.

I use this java code to to edit a jpg

```<code>    final Intent imgIntent = new Intent()
            .setAction(Intent.ACTION_EDIT)
            // .putExtra(Intent.EXTRA_STREAM, uri)
            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET)
            .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    // #64 edit allow to modify file
    imgIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
                .addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);

                }
    File file = new File("/sd/path/to/image.jpg");
    final Uri uri = Uri.fromFile(file);
    imgIntent.setData(uri);
    // imgIntent.setDataAndType(uri, "image/*");

    startActivity (imgIntent);
</code>```

note: if you use

```<code>    startActivityForResult(imgIntent);
</code>```

your app get notified, when edit has finished or was canceld via onActivityResult(...)

Body:
I am trying to allow my users to edit an image through any annotation app installed in their devices.
For this, I am sending image from my Application to another app for editing and retrieving it back.
I am using the following code in Xamarin.Android -

                var imgIntent = new Intent (Intent.ActionEdit);

                var imgItem = (File)ImageAdapter.GetItem (p0.ItemId);
                var imgFileName = imgItem.Name;
                AndroidController.Current.SetImgFileName(Activity, imgFileName);
                imgIntent.PutExtra (Intent.ExtraStream,
                    Uri.FromFile (imgItem));
                imgIntent.SetType ("image/*");

                if (Utils.CheckIntentAvailable (Activity, imgIntent)) {
                    StartActivity (imgIntent);
                } else {
                    Toast.MakeText(Activity.ApplicationContext, "xyz", ToastLength.Long).Show();
                }

When I select "Skitch", the image is perfectly getting transferred to skitch, and getting back into my app once they share it with my app.

But, When I select "Inkboard" for the same purpose, the Inkboard app Intent triggers, but it doesn't pick the image I sent in Intent Extras.

Can anybody figure out what is happening here ?
Thanks in advance.

Body:
note: i donot know anythink about xamarin

according to https://developer.android.com/reference/android/content/Intent.html#ACTION_EDIT the uri to be edited should go into Intent.data.

your code uses Intent.ExtraStream instead which is not standard.

I use this java code to to edit a jpg

    final Intent imgIntent = new Intent()
            .setAction(Intent.ACTION_EDIT)
            // .putExtra(Intent.EXTRA_STREAM, uri)
            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET)
            .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    // #64 edit allow to modify file
    imgIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
                .addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);

                }
    File file = new File("/sd/path/to/image.jpg");
    final Uri uri = Uri.fromFile(file);
    imgIntent.setData(uri);
    // imgIntent.setDataAndType(uri, "image/*");

    startActivity (imgIntent);

note: if you use

    startActivityForResult(imgIntent);

your app get notified, when edit has finished or was canceld via onActivityResult(...)


问:
How do I get basic jQuery tabs to work inside a .Net modal popup?
Really simple question: Am I missing something?  Seems like this should be all that is necessary for the basic setup...  currently I'm getting an un-stylized version (i.e. no tabs, just plain text/html).  So they don't look like tabs and when you click them nothing hides/shows as would be expected with tabs. Do I have to manually hook up javascript to show and hide the contents of the tabs or does the framework do this for me?

Update:

So I tested the code out and
  this works fine for basic tabs.
  However, I need to use this inside a
  .Net modal popup using their "Ajax"
  toolkit.  Essentially this is doing a
  postback which I've noticed tends to
  fight with jQuery.  In the past, I've
  used the jQuery live events, but
  I'm not sure what to bind it to...
  Usually you bind to an event on an
  object, like a click handler for a
  button.  Here, I need to attach the
  tab assignment/binding ( using .tabs()
  ) via a live event but I'm not sure
  which one.  I tried binding to the
  document load event but no luck with
  that:

```<code>$(document).live('load', bind_tabs);
</code>```

Any ideas?

Style sheet and Javascript links included on page:

```<code>https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/base/jquery-ui.css
https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js
https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js
</code>```

Added the following line to my stylesheet:

```<code>.ui-tabs .ui-tabs-hide { display: none; }
</code>```

Added the following script to the page:

```<code><script type="text/javascript">
  $(function () {
  $("#tabs2").tabs();
  $("#tabs").tabs();
  });
</script>
</code>```

HTML:

```<code><div id="tabs">
   <ul>
      <li><a href="#tabs-1">Nunc tincidunt</a></li>
      <li><a href="#tabs-2">Proin dolor</a></li>
      <li><a href="#tabs-3">Aenean lacinia</a></li>
   </ul>
   <div id="tabs-1">
      <p>Tab 1 content</p>
   </div>
   <div id="tabs-2">
      <p>Tab 2 content</p>
   </div>
   <div id="tabs-3">
      <p>Tab 3 content</p>
   </div>
</div>
</code>```

Also noticed on the "theming" documentation on the page (http://jqueryui.com/demos/tabs/#theming) that it states the following. Should I manually put in all those styles (like ui-widget) or rely on the framework to do it?

Sample markup with jQuery UI CSS
  Framework classes

```<code><div class="ui-tabs ui-widget ui-widget-content ui-corner-all" id="tabs">
   <ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
     <li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a href="#tabs-1">Nunc tincidunt</a></li>
      <li class="ui-state-default ui-corner-top"><a href="#tabs-2">Proin dolor</a></li>
   <div class="ui-tabs-panel ui-widget-content ui-corner-bottom" id="tabs-1">
      <p>Tab one content goes here.</p>
   </div>
    ...
</div>
</code>```

Note: This is a sample of markup
  generated by the tabs plugin, not
  markup you should use to create a
  tabs. The only markup needed for that
  is

```<code><div id="tabs">
   <ul>
      <li><a href="#tabs-1">Nunc tincidunt</a></li>
      <li><a href="#tabs-2">Proin dolor</a></li>
      <li><a href="#tabs-3">Aenean lacinia</a></li>
   </ul>
   <div id="tabs-1">
      <p>Tab 1 content</p>
   </div>
   <div id="tabs-2">
      <p>Tab 2 content</p>
   </div>
   <div id="tabs-3">
      <p>Tab 3 content</p>
   </div>
</div>
</code>```

答:
```<code><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js" type="text/javascript"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
</code>```

Try linking to the .css file after the two .js files. I had a similar problem with the jQuery UI datepicker, once I had reordered the list as above it worked fine.

ContentLicense: CC BY-SA 2.5

Body:
Really simple question: Am I missing something?  Seems like this should be all that is necessary for the basic setup...  currently I'm getting an un-stylized version (i.e. no tabs, just plain text/html).  So they don't look like tabs and when you click them nothing hides/shows as would be expected with tabs. Do I have to manually hook up javascript to show and hide the contents of the tabs or does the framework do this for me?

Update:

So I tested the code out and
  this works fine for basic tabs.
  However, I need to use this inside a
  .Net modal popup using their "Ajax"
  toolkit.  Essentially this is doing a
  postback which I've noticed tends to
  fight with jQuery.  In the past, I've
  used the jQuery live events, but
  I'm not sure what to bind it to...
  Usually you bind to an event on an
  object, like a click handler for a
  button.  Here, I need to attach the
  tab assignment/binding ( using .tabs()
  ) via a live event but I'm not sure
  which one.  I tried binding to the
  document load event but no luck with
  that:

$(document).live('load', bind_tabs);

Any ideas?

Style sheet and Javascript links included on page:

https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/base/jquery-ui.css
https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js
https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js

Added the following line to my stylesheet:

.ui-tabs .ui-tabs-hide { display: none; }

Added the following script to the page:

HTML:

Nunc tincidunt

Proin dolor

Aenean lacinia

Tab 1 content

Tab 2 content

Tab 3 content

Also noticed on the "theming" documentation on the page (http://jqueryui.com/demos/tabs/#theming) that it states the following. Should I manually put in all those styles (like ui-widget) or rely on the framework to do it?

Sample markup with jQuery UI CSS
  Framework classes

Nunc tincidunt

Proin dolor

Tab one content goes here.

    ...

Note: This is a sample of markup
  generated by the tabs plugin, not
  markup you should use to create a
  tabs. The only markup needed for that
  is

Nunc tincidunt

Proin dolor

Aenean lacinia

Tab 1 content

Tab 2 content

Tab 3 content

Body:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js" type="text/javascript"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>

Try linking to the .css file after the two .js files. I had a similar problem with the jQuery UI datepicker, once I had reordered the list as above it worked fine.


问:
Set theme color dynamically
I am using themes (dynamically) in my android app, like this:

my_layout.xml (extract):

```<code><TextView
    android:id="@+id/myItem"
    style="?my_item_style" />
</code>```

attrs.xml (extract):

```<code><attr name="my_item_style" format="reference" />
</code>```

themes.xml (extract):

```<code><style name="MainTheme.Blue">
      <item name="my_item_style">@style/my_item_style_blue</item>
</style>

<style name="MainTheme.Green">
      <item name="my_item_style">@style/my_item_style_green<item>
</style>
</code>```

styles.xml (extract):

```<code><style name="my_item_style_blue">
      <item name="android:textColor">@color/my_blue</item>
</style>

<style name="my_item_style_green">
      <item name="android:textColor">@color/my_blue</item>
</style>
</code>```

So, as you can see, I am setting themes dynamically. I am using this class:

```<code>public class ThemeUtils {

  private static int sTheme;
  public final static int THEME_BLUE = 1;
  public final static int THEME_GREEN = 2;

  public static void changeToTheme(MainActivity activity, int theme) {
      sTheme = theme;
      activity.startActivity(new Intent(activity, MyActivity.class));
  }

  public static void onActivityCreateSetTheme(Activity activity)
  {
      switch (sTheme)
      {
          default:
          case THEME_DEFAULT:
          case THEME_BLUE:
              activity.setTheme(R.style.MainTheme_Blue);
              break;
          case THEME_GREEN:
              activity.setTheme(R.style.MainTheme_Green);
              break;
      }
  }
</code>```

}

What I want to know, is there a way how to do this (change theme color) in code? For example, I have following code (extract):

```<code>((TextView) findViewById(R.id.myItem)).setTextColor(R.color.blue);
</code>```

It can be done by some helper method, which would use switch command for available themes and return correct color for a theme. But I would like to know if there is some better, nicer and faster way.

Thanks!

答:
I have finally done it using following method:

```<code>public static int getColor(String colorName) {
    Context ctx = getContext();
    switch (sTheme) {
        default:
        case THEME_DEFAULT:
            return ctx.getResources().getIdentifier("BLUE_" + colorName, "color", ctx.getPackageName());
        case THEME_BLUE:
            return ctx.getResources().getIdentifier("BLUE_" + colorName, "color", ctx.getPackageName());
        case THEME_GREEN:
            return ctx.getResources().getIdentifier("GREEN_" + colorName, "color", ctx.getPackageName());
    }
}
</code>```

This returns color according to my theme (I used prefixes).

Title: Set theme color dynamically

Body:
I am using themes (dynamically) in my android app, like this:

my_layout.xml (extract):

<TextView
    android:id="@+id/myItem"
    style="?my_item_style" />

attrs.xml (extract):

<attr name="my_item_style" format="reference" />

themes.xml (extract):

styles.xml (extract):

So, as you can see, I am setting themes dynamically. I am using this class:

public class ThemeUtils {

  private static int sTheme;
  public final static int THEME_BLUE = 1;
  public final static int THEME_GREEN = 2;

  public static void changeToTheme(MainActivity activity, int theme) {
      sTheme = theme;
      activity.startActivity(new Intent(activity, MyActivity.class));
  }

  public static void onActivityCreateSetTheme(Activity activity)
  {
      switch (sTheme)
      {
          default:
          case THEME_DEFAULT:
          case THEME_BLUE:
              activity.setTheme(R.style.MainTheme_Blue);
              break;
          case THEME_GREEN:
              activity.setTheme(R.style.MainTheme_Green);
              break;
      }
  }

}

What I want to know, is there a way how to do this (change theme color) in code? For example, I have following code (extract):

((TextView) findViewById(R.id.myItem)).setTextColor(R.color.blue);

It can be done by some helper method, which would use switch command for available themes and return correct color for a theme. But I would like to know if there is some better, nicer and faster way.

Thanks!

Body:
I have finally done it using following method:

public static int getColor(String colorName) {
    Context ctx = getContext();
    switch (sTheme) {
        default:
        case THEME_DEFAULT:
            return ctx.getResources().getIdentifier("BLUE_" + colorName, "color", ctx.getPackageName());
        case THEME_BLUE:
            return ctx.getResources().getIdentifier("BLUE_" + colorName, "color", ctx.getPackageName());
        case THEME_GREEN:
            return ctx.getResources().getIdentifier("GREEN_" + colorName, "color", ctx.getPackageName());
    }
}

This returns color according to my theme (I used prefixes).


问:
not enough arguments for format string with bool and list
I'm newbie to python and trying to update one column value (true/false) of all rows (ids provide in list) using IN on list.

My query is like this :

```<code>qry = "Update table Set "\
      "col1 = %s "\
      "where col2 in ( " + ",".join( "%s" for _ in lstIds)
qry += ")"
cursor.execute(qry,(col1Value, lstIds))
</code>```

But I'm getting error

not enough arguments for format string

I've tried different solutions but unable to resolve my issue.
When I change my query this way, it works fine

```<code>qry = "Update table Set "\
  "col1 = 1 "\
  "where col2 in ( " + ",".join( "%s" for _ in lstIds)
qry += ")"
cursor.execute(qry,( lstIds))
</code>```

So I guess issue is in first parameter value but I dont know how to resolve this.

Any kind of help will be appreciated.

答:
You need to include each of the values in lstIds as a separate parameter:

```<code>cursor.execute(qry, (col1Value,) + lstIds)
</code>```

assuming lstIds is a tuple, or

```<code>cursor.execute(qry, [col1Value] + lstIds)
</code>```

if it is a list.

Or you can combine the sequence into one list with the * notation in Python 3.5 and newer:

```<code>cursor.execute(qry, [col1Value, *lstIds])
</code>```

Body:
I'm newbie to python and trying to update one column value (true/false) of all rows (ids provide in list) using IN on list.

My query is like this :

qry = "Update table Set "\
      "col1 = %s "\
      "where col2 in ( " + ",".join( "%s" for _ in lstIds)
qry += ")"
cursor.execute(qry,(col1Value, lstIds))

But I'm getting error

not enough arguments for format string

I've tried different solutions but unable to resolve my issue.
When I change my query this way, it works fine

qry = "Update table Set "\
  "col1 = 1 "\
  "where col2 in ( " + ",".join( "%s" for _ in lstIds)
qry += ")"
cursor.execute(qry,( lstIds))

So I guess issue is in first parameter value but I dont know how to resolve this.

Any kind of help will be appreciated.

Body:
You need to include each of the values in lstIds as a separate parameter:

cursor.execute(qry, (col1Value,) + lstIds)

assuming lstIds is a tuple, or

cursor.execute(qry, [col1Value] + lstIds)

if it is a list.

Or you can combine the sequence into one list with the * notation in Python 3.5 and newer:

cursor.execute(qry, [col1Value, *lstIds])


问:
Apache2 mod_rewrite remote user variable to lowercase
i'm using the mod_auth_kerb module for kerberos authentication in apache.

Usernames have the format "User.Name" like here:

```<code>[authz_core:error]  AH01631: user User.Name: authorization failure for "/site/":
</code>```

I need the full Username in lowercase. The variable is %{LA-U:REMOTE_USER}

How can I rewrite the variable to lowercase with mod_rewrite? Or is there a better way?

Thanks for your help.

答:
you can solve this with a auth_to_local Rule in your Kerberos-configuration like mentioned in http://comp.protocols.kerberos.narkive.com/fzcjz10b/auth-to-local-rule-to-convert-camel-case-principals-to-all-lower-case

[realms]
    REALM.YOUR.TLD = {
     auth_to_local = RULE:[1:$1](.*)s/A/a/g s/B/b/g s/B/b/g s/C/c/g s/D/d/g s/E/e/g s/F/f/g s/G/g/g s/H/h/g s/I/i/g s/J/j/g s/K/k/g s/L/l/g s/M/m/g s/N/n/g s/O/o/g s/P/p/g s/Q/q/g s/R/r/g s/S/s/g s/T/t/g s/U/u/g s/V/v/g s/W/w/g s/X/x/g s/Y/y/g s/Z/z/g

Maybe there's a more efficient regex, but I couldn't find one, because you may only use search/replace syntax.

Another way would be mod_map_user

http://www.perzl.org/aix/index.php?n=Main.ModMapUser

Or you set up SSSD

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/SSSD-Introduction.html

http://www.admin-magazin.de/Das-Heft/2012/03/Der-System-Security-Services-Daemon
(german)

Yours
Tobias

Body:
i'm using the mod_auth_kerb module for kerberos authentication in apache.

Usernames have the format "User.Name" like here:

[authz_core:error]  AH01631: user User.Name: authorization failure for "/site/":

I need the full Username in lowercase. The variable is %{LA-U:REMOTE_USER}

How can I rewrite the variable to lowercase with mod_rewrite? Or is there a better way?

Thanks for your help.


问:
Want to click f12 using jquery
I am working on one project in which I disabled f12 and right click using jquery and its working fine.
Code for it:

```<code>$(document).keydown(function(event){
 if(event.keyCode==123){
  return false;
 }
 else if(event.ctrlKey && event.shiftKey && event.keyCode==73){
    return false;  //Prevent from ctrl+shift+i
 }
});

$(document).on("contextmenu",function(e){
  e.preventDefault();
});
</code>```

Is there any way so that I can click f12 key using jquery.
I want this because I am facing one issue.
eg. If google.com is already opened with insect element and then I load my page then it shows me inspect element. So I want to hide inspect window on page load.

Is there any way???

答:
No it is not possible because f12 is attached with browser and not with page. JavaScript can only make communication with page.

Source: Handling key-press events (F1-F12) using JavaScript and jQuery, cross-browser

Title: Want to click f12 using jquery

Body:
I am working on one project in which I disabled f12 and right click using jquery and its working fine.
Code for it:

$(document).keydown(function(event){
 if(event.keyCode==123){
  return false;
 }
 else if(event.ctrlKey && event.shiftKey && event.keyCode==73){
    return false;  //Prevent from ctrl+shift+i
 }
});

$(document).on("contextmenu",function(e){
  e.preventDefault();
});

Is there any way so that I can click f12 key using jquery.
I want this because I am facing one issue.
eg. If google.com is already opened with insect element and then I load my page then it shows me inspect element. So I want to hide inspect window on page load.

Is there any way???


问:
How to get a sorted subvector out of a sorted vector, fast
I have a data structure like this:

```<code>struct X {
  float value;
  int id;
};
</code>```

a vector of those (size N (think 100000), sorted by value (stays constant during the execution of the program):

```<code>std::vector<X> values;
</code>```

Now, I want to write a function

```<code>void subvector(std::vector<X> const& values,
               std::vector<int> const& ids,
               std::vector<X>& out /*,
               helper data here */);
</code>```

that fills the out parameter with a sorted subset of values, given by the passed ids (size M < N (about 0.8 times N)), fast (memory is not an issue, and this will be done repeatedly, so building lookuptables (the helper data from the function parameters) or something else that is done only once is entirely ok).

My solution so far:

Build lookuptable lut containing id -> offset in values (preparation, so constant runtime)

create std::vector<X> tmp, size N, filled with invalid ids (linear in N)

for each id, copy values[lut[id]] to tmp[lut[id]] (linear in M)

loop over tmp, copying items to out (linear in N)

this is linear in N (as it's bigger than M), but the temporary variable and repeated copying bugs me. Is there a way to do it quicker than this? Note that M will be close to N, so things that are O(M log N) are unfavourable.

Edit: http://ideone.com/xR8Vp is a sample implementation of mentioned algorithm, to make the desired output clear and prove that it's doable in linear time - the question is about the possibility of avoiding the temporary variable or speeding it up in some other way, something that is not linear is not faster :).

答:
If I understood your problem correctly, you actually try to create a linear time sorting algorithm (subject to the input size of numbers M).
That is NOT possible.

Your current approach is to have a sorted list of possible values.
This takes linear time to the number of possible values N (theoretically, given that the map search takes O(1) time).

The best you could do, is to sort the values (you found from the map) with a quick sorting method (O(MlogM) f.e. quicksort, mergesort etc) for small values of M and maybe do that linear search for bigger values of M.
For example, if N is 100000 and M is 100 it is much faster to just use a sorting algorithm.

I hope you can understand what I say. If you still have questions I will try to answer them :)

edit: (comment)
I will further explain what I mean.
Say you know that your numbers will range from 1 to 100.
You have them sorted somewhere (actually they are "naturally" sorted) and you want to get a subset of them in sorted form.
If it would be possible to do it faster than O(N) or O(MlogM), sorting algorithms would just use this method to sort.

F.e. by having the set of numbers {5,10,3,8,9,1,7}, knowing that they are a subset of the sorted set of numbers {1,2,3,4,5,6,7,8,9,10} you still can't sort them faster than O(N) (N = 10) or O(MlogM) (M = 7).

Body:
I have a data structure like this:

struct X {
  float value;
  int id;
};

a vector of those (size N (think 100000), sorted by value (stays constant during the execution of the program):

std::vector<X> values;

Now, I want to write a function

void subvector(std::vector<X> const& values,
               std::vector<int> const& ids,
               std::vector<X>& out /*,
               helper data here */);

that fills the out parameter with a sorted subset of values, given by the passed ids (size M < N (about 0.8 times N)), fast (memory is not an issue, and this will be done repeatedly, so building lookuptables (the helper data from the function parameters) or something else that is done only once is entirely ok).

My solution so far:

Build lookuptable lut containing id -> offset in values (preparation, so constant runtime)

create std::vector<X> tmp, size N, filled with invalid ids (linear in N)

for each id, copy values[lut[id]] to tmp[lut[id]] (linear in M)

loop over tmp, copying items to out (linear in N)

this is linear in N (as it's bigger than M), but the temporary variable and repeated copying bugs me. Is there a way to do it quicker than this? Note that M will be close to N, so things that are O(M log N) are unfavourable.

Edit: http://ideone.com/xR8Vp is a sample implementation of mentioned algorithm, to make the desired output clear and prove that it's doable in linear time - the question is about the possibility of avoiding the temporary variable or speeding it up in some other way, something that is not linear is not faster :).


问:
Negotiating Bluetooth LE ATT MTU on Android and iOS central / peripheral in practice
On Android we have requestMtu and onMtuChanged, which seems to imply that we have to manually negotiate MTU sizes, if both central and peripheral devices are Android based (but I might be wrong and it might be that it happens also automatically upon connection without my intervention).
Documentation for requestMtu talks only about write request (write without response) operation and does not mention notifications, and also says that it is meant for "connection" but does not mention if it's from central or peripheral side.
Thus, it's not clear, which side of the connection can/should use requestMtu and how it affects both notification size and write size?

On iOS, it seems, there is no direct alternative to requestMtu and we have only central.maximumUpdateValueLength (since iOS 7, I guess). Its documentation (on the contrary to the Android one) says that maximumUpdateValueLength is for notification updates only, which implies that it is useful only on the peripheral side, since you send notifications from peripheral to central.
But what about writes? If I'm writing (again without response) to a characteristic from a central to a peripheral, how do I know my batch size to ensure efficient writes?

Considering mixed systems (Android/iOS central/peripheral), it all gets confusing and it is not clear at all which side and when can/should request/react to MTU size negotiation. Is there any document describing ATT MTU exchange options, which correspond to real Android and iOS implementation?

答: According to the BLE standard both sides may exchange MTU. The same MTU applies to both when the device acts as client and server.</p>


问:
BigQuery view as a data source in Google DataStudio
I am getting this error, while trying to use a BigQuery view data source in Google Data Studio:

Error Details: There's a query error. Cannot reference a SQL view in a Legacy SQL query.

So, I checked the view's info and the "Use Legacy SQL" is false:

The view is working fine in BigQuery, but it seems that Google Data Studio is running the query in "Legacy mode" instead of "SQL Standard Dialect mode".  If this is the problem, how can I change this setting in the Data Studio?

Thanks for your help.

答:
You need to use the custom query option for the time being, which lets you specify to use standard SQL. Your query can simply be:

```<code>SELECT * FROM YourViewName;
</code>```

My understanding at the time of this writing is that the Data Studio team is still working on support for data sources created from standard SQL views.

Body:
You need to use the custom query option for the time being, which lets you specify to use standard SQL. Your query can simply be:

SELECT * FROM YourViewName;

My understanding at the time of this writing is that the Data Studio team is still working on support for data sources created from standard SQL views.


问:
How to return only first result hit from Google Drive?
If we want to use Google Drive with GoogleDriva Android API we forst make a query to retrieve all the files that meet our criteria. Multiple file can have the same name as names are not unique identifiers. DriveId's are. But sometimes we are interested only in the latest file. The usual way (from google web site) is something like this.

```<code>void retrieveFiles() {
    SortOrder sortOrder = new SortOrder.Builder()
        .addSortDescending(SortableField.MODIFIED_DATE)
        .build();
    Query query = new Query.Builder()
        .addFilter(Filters.eq(SearchableField.TITLE, filename), "my_filename.txt"))
        .setSortOrder(sortOrder)
        .build();
    MetadataBufferResult mbr = Drive.DriveApi.query(query).await().getMetadataBuffer();

    // Now we can iterate through all the result hits
    Metadata metadata;
    Iterator<Metadata> iterator = mbr.getMetadataBuffer().iterator();
    metadata = iterator.next();  // get the first hit
});
</code>```

This query returns metadata for all files that meet criteria. But, it would be useful to limit the search only to the first file (or arbitrary number of them) since this is teh one we are interested. Sorting enables us to prune the result.
Is there a way to limit the result set to? Somethinh like TOP N ROWS in SQL.

答:
You can set pageSize to limit the number of rows returned to 1.

There is no way to do a group by or a distinct like you would in SQL.  If you have files with the same name your going to get them all.

The only thing I can think of would be to add an orderBy

orderBy  string
A comma-separated list of sort keys. Valid keys are
  'createdTime', 'folder', 'modifiedByMeTime', 'modifiedTime', 'name',
  'quotaBytesUsed', 'recency', 'sharedWithMeTime', 'starred', and
  'viewedByMeTime'. Each key sorts ascending by default, but may be
  reversed with the 'desc' modifier. Example usage:
  ?orderBy=folder,modifiedTime desc,name. Please note that there is a
  current limitation for users with approximately one million files in
  which the requested sort order is ignored.

Then sort by 'modifiedTime' which you appear to be doing already.  You can then then you can just deal with the duplicates locally.

Body:
If we want to use Google Drive with GoogleDriva Android API we forst make a query to retrieve all the files that meet our criteria. Multiple file can have the same name as names are not unique identifiers. DriveId's are. But sometimes we are interested only in the latest file. The usual way (from google web site) is something like this.

void retrieveFiles() {
    SortOrder sortOrder = new SortOrder.Builder()
        .addSortDescending(SortableField.MODIFIED_DATE)
        .build();
    Query query = new Query.Builder()
        .addFilter(Filters.eq(SearchableField.TITLE, filename), "my_filename.txt"))
        .setSortOrder(sortOrder)
        .build();
    MetadataBufferResult mbr = Drive.DriveApi.query(query).await().getMetadataBuffer();

    // Now we can iterate through all the result hits
    Metadata metadata;
    Iterator<Metadata> iterator = mbr.getMetadataBuffer().iterator();
    metadata = iterator.next();  // get the first hit
});

This query returns metadata for all files that meet criteria. But, it would be useful to limit the search only to the first file (or arbitrary number of them) since this is teh one we are interested. Sorting enables us to prune the result.
Is there a way to limit the result set to? Somethinh like TOP N ROWS in SQL.


问:
How to analyse SQL Server error log for shutdown due to issues?
I need to know how to analyze error logs for shutdown due to issues. Is there any article explaining this? If yes kindly share it with me.</p>

答: Can you elaborate on that? If i understood what you are asking, search for SQL Server Extended Events.</p>


问:
Looping over array elements, given an array of arrays' variable names in Bash Script
I have an array containing names of categories

```<code>categories=( categoryA categoryB categoryC )
</code>```

Each category contains multiple products, which is stored in different arrays.

```<code>categoryA=( productA1 productA2 productA3 )
categoryB=( productB1 productB2 productB3 )
categoryC=( productC1 productC2 productC3 )
</code>```

I want to loop over all products, so I wrote this code:

```<code>categories=( categoryA categoryB categoryC )

categoryA=( productA1 productA2 productA3 )
categoryB=( productB1 productB2 productB3 )
categoryC=( productC1 productC2 productC3 )

for category_name in "${categories[@]}"
do
    echo $category_name

    category=${!category_name}
    for product in "${category[@]}"
    do
        echo -e '\t' $product
    done

    echo -e '\n'

done
</code>```

I expected the output to be:

```<code>CategoryA
    ProductA1
    ProductA2
    ProductA3

CategoryB
    ProductB1
    ProductB2
    ProductB3

CategoryC
    ProductC1
    ProductC2
    ProductC3
</code>```

but unfortunately, the output is

```<code>CategoryA
    ProductA1

CategoryB
    ProductB1

CategoryC
    ProductC1
</code>```

How to fix this ?

答:
I already found a solution,

instead of category=${!category_name} ,

I can eval the array eval category=\( \${${category_name}[@]} \)

for those who are interested, here it is:

```<code>for category_name in "${categories[@]}"
do
    echo $category_name

    eval category=\( \${${category_name}[@]} \)
    for product in "${category[@]}"
    do
        echo -e '\t' $product
    done

    echo -e '\n'

done
</code>```

I will leave the question and the answer, for whoever meets the same challenge, and for anyone who has a more elegant solution, or for any objections

UPDATE: For security considerations, check Inian's response, and if you use Bash < 4.3 as I do, check Leon's response as an alternative

Body:
I have an array containing names of categories

categories=( categoryA categoryB categoryC )

Each category contains multiple products, which is stored in different arrays.

categoryA=( productA1 productA2 productA3 )
categoryB=( productB1 productB2 productB3 )
categoryC=( productC1 productC2 productC3 )

I want to loop over all products, so I wrote this code:

categories=( categoryA categoryB categoryC )

categoryA=( productA1 productA2 productA3 )
categoryB=( productB1 productB2 productB3 )
categoryC=( productC1 productC2 productC3 )

for category_name in "${categories[@]}"
do
    echo $category_name

    category=${!category_name}
    for product in "${category[@]}"
    do
        echo -e '\t' $product
    done

    echo -e '\n'

done

I expected the output to be:

CategoryA
    ProductA1
    ProductA2
    ProductA3

CategoryB
    ProductB1
    ProductB2
    ProductB3

CategoryC
    ProductC1
    ProductC2
    ProductC3

but unfortunately, the output is

CategoryA
    ProductA1

CategoryB
    ProductB1

CategoryC
    ProductC1

How to fix this ?

Body:
I already found a solution,

instead of category=${!category_name} ,

I can eval the array eval category=\( \${${category_name}[@]} \)

for those who are interested, here it is:

for category_name in "${categories[@]}"
do
    echo $category_name

    eval category=\( \${${category_name}[@]} \)
    for product in "${category[@]}"
    do
        echo -e '\t' $product
    done

    echo -e '\n'

done

I will leave the question and the answer, for whoever meets the same challenge, and for anyone who has a more elegant solution, or for any objections

UPDATE: For security considerations, check Inian's response, and if you use Bash < 4.3 as I do, check Leon's response as an alternative


问:
My viewDidAppear not called in view controller
It turns out that what I want to do is that when I come from a 3d shortcut, forcing the UITabBarController to choose an index, if I do this in the tab bar viewDidAppear() the problem is that the viewDidAppear() of my main UIViewController Embedded is not called, if I click again on the tab bar item then already if it is called. With the rest of the drivers does not happen, I understand why it is not the one that is first in the list of items in the UITabBarController.

Tab bar controller: (Here it comes)

```<code>override func viewDidAppear(_ animated: Bool) {
    if goTasks {
        self.selectedIndex = 0
    } else if goTodo {
        self.selectedIndex = 2
    } else if goProjects {
        self.selectedIndex = 3
    } else if goSearch {
        self.selectedIndex = 0
    }

}
</code>```

My first UIViewController:
(Not called this method)

```<code>override func viewDidAppear(_ animated: Bool) {
    print("Entry")
}
</code>```

Is the problem override the methods? Any solution?

答:
In your UITabBarController class viewDidAppear func , call it's super class, like this

```<code> override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        if goTasks {
            self.selectedIndex = 0
        } else if goTodo {
            self.selectedIndex = 2
        } else if goProjects {
            self.selectedIndex = 3
        } else if goSearch {
            self.selectedIndex = 0
        }

    }
</code>```

After that, your first viewcontroller will call this method.

```<code>override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    print("Entry")
}
</code>```

Body:
It turns out that what I want to do is that when I come from a 3d shortcut, forcing the UITabBarController to choose an index, if I do this in the tab bar viewDidAppear() the problem is that the viewDidAppear() of my main UIViewController Embedded is not called, if I click again on the tab bar item then already if it is called. With the rest of the drivers does not happen, I understand why it is not the one that is first in the list of items in the UITabBarController.

Tab bar controller: (Here it comes)

override func viewDidAppear(_ animated: Bool) {
    if goTasks {
        self.selectedIndex = 0
    } else if goTodo {
        self.selectedIndex = 2
    } else if goProjects {
        self.selectedIndex = 3
    } else if goSearch {
        self.selectedIndex = 0
    }

}

My first UIViewController:
(Not called this method)

override func viewDidAppear(_ animated: Bool) {
    print("Entry")
}

Is the problem override the methods? Any solution?

Body:
In your UITabBarController class viewDidAppear func , call it's super class, like this

 override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        if goTasks {
            self.selectedIndex = 0
        } else if goTodo {
            self.selectedIndex = 2
        } else if goProjects {
            self.selectedIndex = 3
        } else if goSearch {
            self.selectedIndex = 0
        }

    }

After that, your first viewcontroller will call this method.

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    print("Entry")
}


问:
Django - static/CACHE files not found
I'm using Django 1.10 + uWsgi + nginx.
In Prod mode the static files do not show up, this is what my nginx error-log tells me:

```<code>404   ... static/CACHE/js/e3a6fa7588d1.js" failed (2: No such file or directory),
</code>```

The folder static/CACHE remains empty (so the 404's make sense), but why?
I already set the permissions to 775 for static/CACHE .

nginx conf:

```<code># /etc/nginx/sites/available/mysite_nginx.conf
# the upstream component nginx needs to connect to
upstream bdjango {
   server unix:///tmp/mysite.sock; # for a file socket
}
# configuration of the server
server {
   # the port your site will be served on
   listen 80;

   # the domain name it will serve for
   server_name dev.mysite.com; # substitute your machine's IP address or FQDN
   charset utf-8;

   # max upload size
   client_max_body_size 8M; # adjust to taste

   # Django media
   location /media {
      alias /var/www/mysite/src/media; # your Django project's media files - amend as required
   }
   location /static {
      alias /var/www/mysite/src/static; # your Django project's static files - amend as required
   }
   # Finally, send all non-media requests to the Django server.
   location / {
      uwsgi_pass adjango;
      include /var/www/mysite/src/uwsgi_params; # the uwsgi_params file you installed
   }
}
</code>```

Django settings contains

```<code>PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__) + "../../../")
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
</code>```

So, why are my js/css files not in static/CACHE ?

EDIT:
solved it: uwsgi_pass was pointing at the wrong upstream location (which happened to be a different website):
      uwsgi_pass adjango;

答:
Are you using CACHE?

Have you defiened STATIC_URL and STATIC_ROOT correctly.

Is DEBUG = False?

Are you using any 3rd party tool to cache/pipline your static files?

Title: Django - static/CACHE files not found

Body:
I'm using Django 1.10 + uWsgi + nginx.
In Prod mode the static files do not show up, this is what my nginx error-log tells me:

404   ... static/CACHE/js/e3a6fa7588d1.js" failed (2: No such file or directory),

The folder static/CACHE remains empty (so the 404's make sense), but why?
I already set the permissions to 775 for static/CACHE .

nginx conf:

# /etc/nginx/sites/available/mysite_nginx.conf
# the upstream component nginx needs to connect to
upstream bdjango {
   server unix:///tmp/mysite.sock; # for a file socket
}
# configuration of the server
server {
   # the port your site will be served on
   listen 80;

   # the domain name it will serve for
   server_name dev.mysite.com; # substitute your machine's IP address or FQDN
   charset utf-8;

   # max upload size
   client_max_body_size 8M; # adjust to taste

   # Django media
   location /media {
      alias /var/www/mysite/src/media; # your Django project's media files - amend as required
   }
   location /static {
      alias /var/www/mysite/src/static; # your Django project's static files - amend as required
   }
   # Finally, send all non-media requests to the Django server.
   location / {
      uwsgi_pass adjango;
      include /var/www/mysite/src/uwsgi_params; # the uwsgi_params file you installed
   }
}

Django settings contains

PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__) + "../../../")
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')

So, why are my js/css files not in static/CACHE ?

EDIT:
solved it: uwsgi_pass was pointing at the wrong upstream location (which happened to be a different website):
      uwsgi_pass adjango;


问:
calling nested javascript function in django template
I am new to both Django and Javascript and am having trouble calling a user defined function from within a javascript function in Django template.

I have a javascript block as follows:

```<code>function EditDialog(pk) {
   $.ajax({
       url: "{% url 'populatereviewform' %}",
       method: 'GET',
       data: {
       pk: pk
       },
       success: function(formHtml){
          //Do something
          alert("Success!")
       },
       dataType: 'html'
    });

    // this is my function that I would like to call
    function MyFunc(e, offset) {
       alert("Calling my function")
    }

    // Now I try to call this function from another function
    ("#dialog").submit(function(e)
    {
        this.MyFunc(e, "1");
        return false;
    });
}
</code>```

My question is how can I call this nested function?
In the code above, I am creating a function called MyFunc which I am trying to call from the submit method. However, this comes back with this.MyFunc is not a function.

答:
The this is bound to something else.

Remove this and call your function like this: MyFunc().

Body:
I am new to both Django and Javascript and am having trouble calling a user defined function from within a javascript function in Django template.

I have a javascript block as follows:

function EditDialog(pk) {
   $.ajax({
       url: "{% url 'populatereviewform' %}",
       method: 'GET',
       data: {
       pk: pk
       },
       success: function(formHtml){
          //Do something
          alert("Success!")
       },
       dataType: 'html'
    });

    // this is my function that I would like to call
    function MyFunc(e, offset) {
       alert("Calling my function")
    }

    // Now I try to call this function from another function
    ("#dialog").submit(function(e)
    {
        this.MyFunc(e, "1");
        return false;
    });
}

My question is how can I call this nested function?
In the code above, I am creating a function called MyFunc which I am trying to call from the submit method. However, this comes back with this.MyFunc is not a function.


问:
Div ScrollLeft or Right on each click Jquery
How to scroll a div left or right on each click by 30px?
Pls help

```<code>$(document).ready(function(){
    $("button").click(function(){
        $("div").scrollLeft(30);
    });
});
</code>```

http://jsfiddle.net/stfzy/1835/

答:
Try this one ....</p>

```<code>       $(document).ready(function(){
            var amount=30;
            $("button").on('click', function(){
                $("div").scrollLeft(amount);
                amount += 30;
            });
        });
</code>```

Body:
How to scroll a div left or right on each click by 30px?
Pls help

$(document).ready(function(){
    $("button").click(function(){
        $("div").scrollLeft(30);
    });
});

http://jsfiddle.net/stfzy/1835/

Body:
Try this one ....

       $(document).ready(function(){
            var amount=30;
            $("button").on('click', function(){
                $("div").scrollLeft(amount);
                amount += 30;
            });
        });


问:
examples in the paper Monadic Parse in Haskell
In the paper Monadic Parse in Haskell, the author gives an example about parsing string of simple arithmetics. I tried to expand the term, applied it to "1 + 2", but I'm still confused about the recursive nature of the parsers. That is, the term would be expanded into the following form if I did it correct

```<code>expr = ((digit +++ do {symb "("; n <- expr; symb ")"; return n})
           `chianl1` mulop) `chainl1` addop
</code>```

But after first parsing the digit "1" in the string "1 + 2" by digit and the "+" by addop, why could the parser expr continue to parse following "2"?

Moreover, when I applied term to "1 - 2 * 3 + 4", which is the example given in the paper, I got [(-5,"+ 4")] instead of [(-1, "")]. Is it the the problem with my code? Yet I have checked my code against that in the paper and found no deviation.

Below is my code

```<code>module Parser where

import Prelude hiding (filter)
import Data.Char (isDigit, isSpace, toUpper, ord)

newtype Parser a = Parser {
runParser :: (String -> [(a, String)])
}

instance Monad Parser where
    return a = Parser $ \s -> [(a, s)]
    p >>= f = Parser $ \s ->
        concat [runParser (f a) s' | (a, s') <- runParser p s]

instance Applicative Parser where
    pure a = Parser $ \s -> [(a, s)]
    k <*> m = Parser $ \s ->
         [(f a, s'') |
           (f, s') <- runParser k s,
           (a, s'') <- runParser m s']

instance Functor Parser where
   fmap f p = Parser $ \s ->
            [(f a, s')  | (a, s') <- runParser p s]

applyP :: Parser a -> String -> [(a, String)]
applyP p s = runParser p s

emptyP :: Parser a
emptyP = Parser $ \s -> []

appendP :: Parser a-> Parser a-> Parser a
appendP p q = Parser $ \s ->
   let xs = runParser p s
       ys = runParser q s
    in xs ++ ys

(+++) :: Parser a -> Parser a -> Parser a
p +++ q = Parser $ \s ->
        case (runParser (p `appendP` q) s) of
        []     -> []
        (x:xs) -> return x

item :: Parser Char
item = Parser $ \cs ->
        case cs of
            []     -> []
            (c:cs) -> [(c, cs)]

-- since the function tiem is of type "Parser Char"
-- it can only produce char as a result of computation
filterP :: (Char -> Bool) -> Parser Char
filterP f = item >>= \c -> if f c
          then return c
          else emptyP

-- returns ak result if the prefix char matches
char :: Char -> Parser Char
char c = filterP (\x -> x == c)

-- parses a specific string
string :: String -> Parser String
string [] = return ""  -- why it will be an empty list if "emptyP" is used?
string (x:xs) = do c <- char x
                   cs <- string xs
                   return (c:cs)

many :: Parser a -> Parser [a]
many p = many1 p +++  (return [])

many1 :: Parser a -> Parser [a]
many1 p = do c <- p
             cs <- many p
         return (c:cs)

sepby :: Parser a -> Parser b -> Parser [a]
sepby p sep = sepby1 p sep +++ (return [])

sepby1 :: Parser a -> Parser b -> Parser [a]
sepby1 p sep = do c <- p
                  cs <- many (sep >> p)
               return (c:cs)

chainl :: Parser a -> Parser (a -> a -> a) -> a -> Parser a
chainl p q a = (p `chainl1` q) +++ return a

chainl1 :: Parser a -> Parser (a -> a -> a) -> Parser a
p `chainl1` q = do {a <- p; rest a}
            where rest a = (do  f <- q
                                b <- p
                            return (f a b))
                           +++ return a

space :: Parser String
space = many (filterP isSpace)

-- parse a given value, throw away trailing space
token :: Parser a -> Parser a
token p = do {a <- p; space; return a}

-- parses a given token, throws away trailing space
symb :: String -> Parser String
symb s = token (string s)

-- throw away any prefix space, apply parser
apply :: Parser a -> String -> [(a, String)]
apply p = runParser (do {space; p})

addop :: Parser (Int -> Int -> Int)
addop = do {symb "+"; return (+)} +++ do {symb "-"; return (-)}

mulop :: Parser (Int -> Int -> Int)
mulop = do {symb "*"; return (*)} +++ do {symb "/"; return (div)}

digit = do {x <- token (filterP isDigit); return (ord x - ord '0')}
factor = digit +++ do {symb "("; n <- expr; symb ")"; return n}
term = factor `chainl1` mulop
expr = term `chainl1` addop
</code>```

Thanks a lot!!

答:
In chainl1 you replaced a recursive call to rest by return.

```<code>rest a = do f <- q
            b <- p
            rest (f a b)
         +++ return a
</code>```

Body:
In the paper Monadic Parse in Haskell, the author gives an example about parsing string of simple arithmetics. I tried to expand the term, applied it to "1 + 2", but I'm still confused about the recursive nature of the parsers. That is, the term would be expanded into the following form if I did it correct

expr = ((digit +++ do {symb "("; n <- expr; symb ")"; return n})
           `chianl1` mulop) `chainl1` addop

But after first parsing the digit "1" in the string "1 + 2" by digit and the "+" by addop, why could the parser expr continue to parse following "2"?

Moreover, when I applied term to "1 - 2 * 3 + 4", which is the example given in the paper, I got [(-5,"+ 4")] instead of [(-1, "")]. Is it the the problem with my code? Yet I have checked my code against that in the paper and found no deviation.

Below is my code

module Parser where

import Prelude hiding (filter)
import Data.Char (isDigit, isSpace, toUpper, ord)

newtype Parser a = Parser {
runParser :: (String -> [(a, String)])
}

instance Monad Parser where
    return a = Parser $ \s -> [(a, s)]
    p >>= f = Parser $ \s ->
        concat [runParser (f a) s' | (a, s') <- runParser p s]

instance Applicative Parser where
    pure a = Parser $ \s -> [(a, s)]
    k <*> m = Parser $ \s ->
         [(f a, s'') |
           (f, s') <- runParser k s,
           (a, s'') <- runParser m s']

instance Functor Parser where
   fmap f p = Parser $ \s ->
            [(f a, s')  | (a, s') <- runParser p s]

applyP :: Parser a -> String -> [(a, String)]
applyP p s = runParser p s

emptyP :: Parser a
emptyP = Parser $ \s -> []

appendP :: Parser a-> Parser a-> Parser a
appendP p q = Parser $ \s ->
   let xs = runParser p s
       ys = runParser q s
    in xs ++ ys

(+++) :: Parser a -> Parser a -> Parser a
p +++ q = Parser $ \s ->
        case (runParser (p `appendP` q) s) of
        []     -> []
        (x:xs) -> return x

item :: Parser Char
item = Parser $ \cs ->
        case cs of
            []     -> []
            (c:cs) -> [(c, cs)]

-- since the function tiem is of type "Parser Char"
-- it can only produce char as a result of computation
filterP :: (Char -> Bool) -> Parser Char
filterP f = item >>= \c -> if f c
          then return c
          else emptyP

-- returns ak result if the prefix char matches
char :: Char -> Parser Char
char c = filterP (\x -> x == c)

-- parses a specific string
string :: String -> Parser String
string [] = return ""  -- why it will be an empty list if "emptyP" is used?
string (x:xs) = do c <- char x
                   cs <- string xs
                   return (c:cs)

many :: Parser a -> Parser [a]
many p = many1 p +++  (return [])

many1 :: Parser a -> Parser [a]
many1 p = do c <- p
             cs <- many p
         return (c:cs)

sepby :: Parser a -> Parser b -> Parser [a]
sepby p sep = sepby1 p sep +++ (return [])

sepby1 :: Parser a -> Parser b -> Parser [a]
sepby1 p sep = do c <- p
                  cs <- many (sep >> p)
               return (c:cs)

chainl :: Parser a -> Parser (a -> a -> a) -> a -> Parser a
chainl p q a = (p `chainl1` q) +++ return a

chainl1 :: Parser a -> Parser (a -> a -> a) -> Parser a
p `chainl1` q = do {a <- p; rest a}
            where rest a = (do  f <- q
                                b <- p
                            return (f a b))
                           +++ return a

space :: Parser String
space = many (filterP isSpace)

-- parse a given value, throw away trailing space
token :: Parser a -> Parser a
token p = do {a <- p; space; return a}

-- parses a given token, throws away trailing space
symb :: String -> Parser String
symb s = token (string s)

-- throw away any prefix space, apply parser
apply :: Parser a -> String -> [(a, String)]
apply p = runParser (do {space; p})

addop :: Parser (Int -> Int -> Int)
addop = do {symb "+"; return (+)} +++ do {symb "-"; return (-)}

mulop :: Parser (Int -> Int -> Int)
mulop = do {symb "*"; return (*)} +++ do {symb "/"; return (div)}

digit = do {x <- token (filterP isDigit); return (ord x - ord '0')}
factor = digit +++ do {symb "("; n <- expr; symb ")"; return n}
term = factor `chainl1` mulop
expr = term `chainl1` addop

Thanks a lot!!

Body:
In chainl1 you replaced a recursive call to rest by return.

rest a = do f <- q
            b <- p
            rest (f a b)
         +++ return a


问:
SQL Server error conversion failed when converting the varchar value to datatype int
```<code>SELECT
    BG_BUG_ID, BG_SUMMARY, BG_STATUS, BG_USER_14, BG_USER_39,
    BG_USER_03, BG_PROJECT, BG_DETECTED_BY, BG_USER_09
FROM
    QC11_tests_defects_db.td.BUG
WHERE
    BG_BUG_ID IN ('" & Replace(Mid(Tmp_List, 1, Len(Tmp_List) - 1), ";", "',')
</code>```

I get an error :

Conversion failed when converting the varchar value to datatype int

Please I need help :)

答:
The best option is to use Tablue Valued Parameters.

First, you would need to create a table type to use with the procedure:

```<code>create type dbo.Id_udt as table (Id int not null);
go
</code>```

Then, create the procedure:

```<code>create procedure dbo.bug_get_fromlist (
  @Id_udt as dbo.Id_udt readonly
) as
begin;
  set nocount, xact_abort on;

  select bg_bug_id, bg_summary, bg_status, bg_user_14, bg_user_39,
         bg_user_03, bg_project, bg_detected_by, bg_user_09
  from qc11_tests_defects_db.td.bug
  /* or use an inner join */
  where bg_bug_id in (
    select id
    from @Id_udt i
    );

end;
go
</code>```

Table Valued Parameters Reference:

Table-Valued Parameters - msdn

User-Defined Table Types - msdn

SQL Server 2008 Table-Valued Parameters and C# Custom Iterators: A Match Made In Heaven! - Leonard Lobel

Table Value Parameter Use With C# - Jignesh Trivedi

Using Table-Valued Parameters in SQL Server and .NET - Erland Sommarskog

Alternatively, you could split the string and use it like a table.

In SQL Server 2016+ you can use string_split().

In SQL Server pre-2016, using a CSV Splitter table valued function by Jeff Moden and conditional aggregation:

```<code>select bg_bug_id, bg_summary, bg_status, bg_user_14, bg_user_39,
       bg_user_03, bg_project, bg_detected_by, bg_user_09
from qc11_tests_defects_db.td.bug
where bg_bug_id in (
  select s.item
  from dbo.delimitedsplit8K(@tmp_list,';') s
  )
</code>```

splitting strings reference:

Tally OH! An Improved SQL 8K “CSV Splitter” Function - Jeff Moden

Splitting Strings : A Follow-Up - Aaron Bertrand

Split strings the right way – or the next best way - Aaron Bertrand

string_split() in SQL Server 2016 : Follow-Up #1 - Aaron Bertrand

delimitedsplit8K by Jeff Moden.

```<code>create function [dbo].[delimitedsplit8K] (
      @pstring varchar(8000)
    , @pdelimiter char(1)
  )
returns table with schemabinding as
 return
  with e1(N) as (
    select 1 union all select 1 union all select 1 union all
    select 1 union all select 1 union all select 1 union all
    select 1 union all select 1 union all select 1 union all select 1
  )
  , e2(N) as (select 1 from e1 a, e1 b)
  , e4(N) as (select 1 from e2 a, e2 b)
  , ctetally(N) as (
    select top (isnull(datalength(@pstring),0))
      row_number() over (order by (select null)) from e4
  )
  , ctestart(N1) as (
    select 1 union all
    select t.N+1 from ctetally t where substring(@pstring,t.N,1) = @pdelimiter
  )
  , ctelen(N1,L1) as (
    select s.N1,
      isnull(nullif(charindex(@pdelimiter,@pstring,s.N1),0)-s.N1,8000)
    from ctestart s
  )
 select itemnumber = row_number() over(order by l.N1)
      , item       = substring(@pstring, l.N1, l.L1)
   from ctelen l
;
go
</code>```

Body:
SELECT
    BG_BUG_ID, BG_SUMMARY, BG_STATUS, BG_USER_14, BG_USER_39,
    BG_USER_03, BG_PROJECT, BG_DETECTED_BY, BG_USER_09
FROM
    QC11_tests_defects_db.td.BUG
WHERE
    BG_BUG_ID IN ('" & Replace(Mid(Tmp_List, 1, Len(Tmp_List) - 1), ";", "',')

I get an error :

Conversion failed when converting the varchar value to datatype int

Please I need help :)

Body:
The best option is to use Tablue Valued Parameters.

First, you would need to create a table type to use with the procedure:

create type dbo.Id_udt as table (Id int not null);
go

Then, create the procedure:

create procedure dbo.bug_get_fromlist (
  @Id_udt as dbo.Id_udt readonly
) as
begin;
  set nocount, xact_abort on;

  select bg_bug_id, bg_summary, bg_status, bg_user_14, bg_user_39,
         bg_user_03, bg_project, bg_detected_by, bg_user_09
  from qc11_tests_defects_db.td.bug
  /* or use an inner join */
  where bg_bug_id in (
    select id
    from @Id_udt i
    );

end;
go

Table Valued Parameters Reference:

Table-Valued Parameters - msdn

User-Defined Table Types - msdn

SQL Server 2008 Table-Valued Parameters and C# Custom Iterators: A Match Made In Heaven! - Leonard Lobel

Table Value Parameter Use With C# - Jignesh Trivedi

Using Table-Valued Parameters in SQL Server and .NET - Erland Sommarskog

Alternatively, you could split the string and use it like a table.

In SQL Server 2016+ you can use string_split().

In SQL Server pre-2016, using a CSV Splitter table valued function by Jeff Moden and conditional aggregation:

select bg_bug_id, bg_summary, bg_status, bg_user_14, bg_user_39,
       bg_user_03, bg_project, bg_detected_by, bg_user_09
from qc11_tests_defects_db.td.bug
where bg_bug_id in (
  select s.item
  from dbo.delimitedsplit8K(@tmp_list,';') s
  )

splitting strings reference:

Tally OH! An Improved SQL 8K “CSV Splitter” Function - Jeff Moden

Splitting Strings : A Follow-Up - Aaron Bertrand

Split strings the right way – or the next best way - Aaron Bertrand

string_split() in SQL Server 2016 : Follow-Up #1 - Aaron Bertrand

delimitedsplit8K by Jeff Moden.

create function [dbo].[delimitedsplit8K] (
      @pstring varchar(8000)
    , @pdelimiter char(1)
  )
returns table with schemabinding as
 return
  with e1(N) as (
    select 1 union all select 1 union all select 1 union all
    select 1 union all select 1 union all select 1 union all
    select 1 union all select 1 union all select 1 union all select 1
  )
  , e2(N) as (select 1 from e1 a, e1 b)
  , e4(N) as (select 1 from e2 a, e2 b)
  , ctetally(N) as (
    select top (isnull(datalength(@pstring),0))
      row_number() over (order by (select null)) from e4
  )
  , ctestart(N1) as (
    select 1 union all
    select t.N+1 from ctetally t where substring(@pstring,t.N,1) = @pdelimiter
  )
  , ctelen(N1,L1) as (
    select s.N1,
      isnull(nullif(charindex(@pdelimiter,@pstring,s.N1),0)-s.N1,8000)
    from ctestart s
  )
 select itemnumber = row_number() over(order by l.N1)
      , item       = substring(@pstring, l.N1, l.L1)
   from ctelen l
;
go


问:
Python Scrapy only scraping the same elements over and over again
I am trying to learn Scrapy and i'm learning on yelp website
this LINK
But when scrapy runs, it scrapes the same phone, addresses, over and over again instead of scraping different parts. The selector i have used is all the "li" tags that belong to a specific class for each restaurant of the page each li tag contain each restaurant information i have used appropriate selectors but scrapy gives me results repeated form only 2 or 3 restaurants. For some reason Scrapy is using same parts over and over again when it should skip over them as soon as they are completed in the for loop. Here is the code

```<code>    try:
    import scrapy
    from urlparse import urljoin
except ImportError:
    print "\nERROR IMPORTING THE NESSASARY LIBRARIES\n"

#scrapy.optional_features.remove('boto')

url = raw_input('ENTER THE SITE URL : ')

class YelpSpider(scrapy.Spider):
    name = 'yelp spider'
    start_urls = [url]

    def parse(self, response):
        SET_SELECTOR = '.regular-search-result'

        #Going over each li tags containg each resturant belonging to this class

        for yelp in response.css(SET_SELECTOR):

            #getting a slector to get a link to scrape website info from another page
            selector = '.indexed-biz-name a ::attr(href)'

            #getting the complete url joining the extracted part
            momo = urljoin(response.url, yelp.css(selector).extract_first())

            #All the selectors
            name = '.indexed-biz-name a span ::text'
            services = '.category-str-list a ::text'
            address1 = '.neighborhood-str-list ::text'
            address2 = 'address ::text'
            phone = '.biz-phone ::text'

           # extracting them and adding them in a dict
            try:
                add1 = response.css(address1).extract_first().replace('\n','').replace('\n','')
                add2 = response.css(address2).extract_first().replace('\n','').replace('\n','')
                ADDRESS = add1 + ' ' + add2

                pookiebanana = {

                    "PHONE": response.css(phone).extract_first().replace('\n','').replace('\t',''),
                    "NAME": response.css(name).extract_first().replace('\n','').replace('\t',''),
                    "SERVICES": response.css(services).extract_first().replace('\n','').replace('\t',''),
                    "ADDRESS": ADDRESS,
                }
            except:
                pass

            #Opening another page passing the old dict
            Post = scrapy.Request(momo, callback=self.parse_yelp, meta={'item': pookiebanana})

            #yielding the dict with the website scraped
            yield Post

        #Clicking the next button and recursively calling the same function with the same link
        NEXT_PAGE_SELECTOR = '.u-decoration-none.next.pagination-links_anchor  ::attr(href)'
        next_page = response.css(NEXT_PAGE_SELECTOR).extract_first()
        if next_page:
            yield scrapy.Request(
                response.urljoin(next_page),
                callback=self.parse
            )

    def parse_yelp(self, response):
        #Website selector opening a new page from the link we extracted
        WEBSITE_SELECTOR = '.biz-website.js-add-url-tagging a ::text'

        item = response.meta['item']

        #inside the try block extracting the website info and returning the modified dict
        try:
            item['WEBSITE'] = ' '.join(response.css(WEBSITE_SELECTOR).extract_first().split(' '))
        except:
            pass
        return item
</code>```

i have commented in the code extensively about where i did what. What am i doing wrong ?

here is the output csv screenshot this shows the repetitions

HERE is the scrapy scraping output as you can see it scrapes the same thing over and over
What is happening and what am i doing wrong ?

答: I can't test it but inside for yelp loop you should use yelp.css() but you use response.css()

Body:
I am trying to learn Scrapy and i'm learning on yelp website
this LINK
But when scrapy runs, it scrapes the same phone, addresses, over and over again instead of scraping different parts. The selector i have used is all the "li" tags that belong to a specific class for each restaurant of the page each li tag contain each restaurant information i have used appropriate selectors but scrapy gives me results repeated form only 2 or 3 restaurants. For some reason Scrapy is using same parts over and over again when it should skip over them as soon as they are completed in the for loop. Here is the code

    try:
    import scrapy
    from urlparse import urljoin
except ImportError:
    print "\nERROR IMPORTING THE NESSASARY LIBRARIES\n"

#scrapy.optional_features.remove('boto')

url = raw_input('ENTER THE SITE URL : ')

class YelpSpider(scrapy.Spider):
    name = 'yelp spider'
    start_urls = [url]

    def parse(self, response):
        SET_SELECTOR = '.regular-search-result'

        #Going over each li tags containg each resturant belonging to this class

        for yelp in response.css(SET_SELECTOR):

            #getting a slector to get a link to scrape website info from another page
            selector = '.indexed-biz-name a ::attr(href)'

            #getting the complete url joining the extracted part
            momo = urljoin(response.url, yelp.css(selector).extract_first())

            #All the selectors
            name = '.indexed-biz-name a span ::text'
            services = '.category-str-list a ::text'
            address1 = '.neighborhood-str-list ::text'
            address2 = 'address ::text'
            phone = '.biz-phone ::text'

           # extracting them and adding them in a dict
            try:
                add1 = response.css(address1).extract_first().replace('\n','').replace('\n','')
                add2 = response.css(address2).extract_first().replace('\n','').replace('\n','')
                ADDRESS = add1 + ' ' + add2

                pookiebanana = {

                    "PHONE": response.css(phone).extract_first().replace('\n','').replace('\t',''),
                    "NAME": response.css(name).extract_first().replace('\n','').replace('\t',''),
                    "SERVICES": response.css(services).extract_first().replace('\n','').replace('\t',''),
                    "ADDRESS": ADDRESS,
                }
            except:
                pass

            #Opening another page passing the old dict
            Post = scrapy.Request(momo, callback=self.parse_yelp, meta={'item': pookiebanana})

            #yielding the dict with the website scraped
            yield Post

        #Clicking the next button and recursively calling the same function with the same link
        NEXT_PAGE_SELECTOR = '.u-decoration-none.next.pagination-links_anchor  ::attr(href)'
        next_page = response.css(NEXT_PAGE_SELECTOR).extract_first()
        if next_page:
            yield scrapy.Request(
                response.urljoin(next_page),
                callback=self.parse
            )

    def parse_yelp(self, response):
        #Website selector opening a new page from the link we extracted
        WEBSITE_SELECTOR = '.biz-website.js-add-url-tagging a ::text'

        item = response.meta['item']

        #inside the try block extracting the website info and returning the modified dict
        try:
            item['WEBSITE'] = ' '.join(response.css(WEBSITE_SELECTOR).extract_first().split(' '))
        except:
            pass
        return item

i have commented in the code extensively about where i did what. What am i doing wrong ?

here is the output csv screenshot this shows the repetitions

HERE is the scrapy scraping output as you can see it scrapes the same thing over and over
What is happening and what am i doing wrong ?


问:
SSRS- summing from multiple queries/detail rows?
I need to write a SSRS report which pulls data from a datasource multiple times.

One time the flag will be set to 0 and the next time 1. There needs to be a data row which groups by a couple of columns. So far, not a big deal.

The tricky part is that the first query from the datasource has a summary line as does the second query to the same datasource. And then there needs to be a grand total of both at the end, after the results of and totals of the previous queries.

Not sure if I'm expressing myself clearly, but if anyone could help me figure out how to tackle this I would be appreciative.

Currently, I'm thinking about hitting the dataset three times with three different tables accessing it. The first time the flag is sent as a parameter with the value of 0, the second time as 1, and the third time with a null value and it gets back all the results.

This will also prevent me from having to sum up across two tables, which I don't really know how to do either. But that's for a different thread if that's the right solution.

Thanks in advance.

答:
You may get mileage from changing the data source to do the work for you.
i.e. a sql procedure something like

```<code>select col1, col2, col3 into #Result

select 1 as colIndicator, col1, col2, col3 where col3='a value'
union
select 2 as colIndicator, col1, col2, sum(col3) where col3='a value'
union
select 4 as colIndicator, col1, col2, col3 where col3='a differnt value'
union
select 5 as colIndicator, col1, col2, sum(col3) where col3='a differnt value'
union
select 6 as colIndicator, col1, col2, sum(col3)
</code>```

you can then filter the dataset for your display and order by  colIndicator, col1, col2 as required.

Body:
You may get mileage from changing the data source to do the work for you.
i.e. a sql procedure something like

select col1, col2, col3 into #Result

select 1 as colIndicator, col1, col2, col3 where col3='a value'
union
select 2 as colIndicator, col1, col2, sum(col3) where col3='a value'
union
select 4 as colIndicator, col1, col2, col3 where col3='a differnt value'
union
select 5 as colIndicator, col1, col2, sum(col3) where col3='a differnt value'
union
select 6 as colIndicator, col1, col2, sum(col3)

you can then filter the dataset for your display and order by  colIndicator, col1, col2 as required.


问:
The POM for unknown.binary:mysql-connector-java-5.1.23-bin:jar:SNAPSHOT is missing, no dependency information available
Ive been getting the error show in the title when building my project, which i believe is the cause of my errors when trying to run it in tomcat. The POM has been added below.

```<code><?xml version="1.0" encoding="UTF-8"?>
</code>```

http://maven.apache.org/xsd/maven-4.0.0.xsd">
    4.0.0

```<code><artifactId>AuctionWebsiteM</artifactId>
<packaging>war</packaging>
<name>AuctionWebsiteM</name>
<description>An auction website</description>
<version>1.0</version>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.2.RELEASE</version>
</parent>

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>

    <!-- Web -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <!-- Web with Tomcat + Embed -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- JSTL -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>

    <!-- Need this to compile JSP -->
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Need this to compile JSP -->
    <dependency>
        <groupId>org.eclipse.jdt.core.compiler</groupId>
        <artifactId>ecj</artifactId>
        <version>4.6.1</version>
        <scope>provided</scope>
    </dependency>

    <!-- Optional, for bootstrap -->
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>bootstrap</artifactId>
        <version>3.3.7</version>
    </dependency>

            <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>

    </dependency>
             <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-jdbc</artifactId>
            </dependency>

            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-entitymanager</artifactId>
                    <version>5.2.9.Final</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.data</groupId>
                <artifactId>spring-data-commons</artifactId>
            </dependency>
 <dependency>
  <groupId>org.springframework.data</groupId>
  <artifactId>spring-data-jpa</artifactId>
  <type>jar</type>
 </dependency>
        <dependency>
                <groupId>unknown.binary</groupId>
                <artifactId>mysql-connector-java-5.1.23-bin</artifactId>
                <version>SNAPSHOT</version>
        </dependency>
</dependencies>
<build>
    <plugins>
        <!-- Package as an executable jar/war -->
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
    <repositories>
            <repository>
                    <id>unknown-jars-temp-repo</id>
                    <name>A temporary repository created by NetBeans for libraries and jars it could not identify. Please replace the dependencies in this repository with correct ones and delete this repository.</name>
                    <url>file:${project.basedir}/lib</url>
            </repository>
    </repositories>
</code>```

Hopefully there's something simple that i've missed.

答:
Can you modify and include the version information in the dependency information of mysql-connector. like below and try again ,
I am hoping maven is unable to download the mysql-connector jar and you can verify this by checking, the jar into external library section of your IDE, where all the jars download by maven will be shown:-

```<code> <!--Mysql-Connector-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.36</version>
        </dependency>
</code>```

Body:
Ive been getting the error show in the title when building my project, which i believe is the cause of my errors when trying to run it in tomcat. The POM has been added below.

<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd">
    4.0.0

<artifactId>AuctionWebsiteM</artifactId>
<packaging>war</packaging>
<name>AuctionWebsiteM</name>
<description>An auction website</description>
<version>1.0</version>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.2.RELEASE</version>
</parent>

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>

    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.eclipse.jdt.core.compiler</groupId>
        <artifactId>ecj</artifactId>
        <version>4.6.1</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>bootstrap</artifactId>
        <version>3.3.7</version>
    </dependency>

            <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>

    </dependency>
             <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-jdbc</artifactId>
            </dependency>

            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-entitymanager</artifactId>
                    <version>5.2.9.Final</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.data</groupId>
                <artifactId>spring-data-commons</artifactId>
            </dependency>
 <dependency>
  <groupId>org.springframework.data</groupId>
  <artifactId>spring-data-jpa</artifactId>
  <type>jar</type>
 </dependency>
        <dependency>
                <groupId>unknown.binary</groupId>
                <artifactId>mysql-connector-java-5.1.23-bin</artifactId>
                <version>SNAPSHOT</version>
        </dependency>
</dependencies>
<build>
    <plugins>

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
    <repositories>
            <repository>
                    <id>unknown-jars-temp-repo</id>
                    <name>A temporary repository created by NetBeans for libraries and jars it could not identify. Please replace the dependencies in this repository with correct ones and delete this repository.</name>
                    <url>file:${project.basedir}/lib</url>
            </repository>
    </repositories>

Hopefully there's something simple that i've missed.

Body:
Can you modify and include the version information in the dependency information of mysql-connector. like below and try again ,
I am hoping maven is unable to download the mysql-connector jar and you can verify this by checking, the jar into external library section of your IDE, where all the jars download by maven will be shown:-

 <!--Mysql-Connector-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.36</version>
        </dependency>


问:
Putting arrays in a table using PHP
I'm a beginner in PHP and working on an API project which has to get results from a server I connected via API.

I am getting the results, but I would like to have them well arranged in a simple table.

This is what I am getting:

I used the following code:

```<code>$api = new SplynxAPI($api_url, $key, $secret);

$locationsApiUrl = "admin/administration/locations";

echo "```";

echo "List locations\n";
$result = $api->api_call_get($locationsApiUrl);

echo "Result: ";

if ($result) {
  echo "Ok!\n";
  print_r($api->response);
} else {
  echo "Fail! Error code: $api->response_code\n";
  print_r($api->response);
}

echo "\n-------------------------------------------------\n";
```

Kindly assist me on this one.

答:
The following code will render your response in a HTML
.

```<code>$api = new SplynxAPI($api_url, $key, $secret);

$locationsApiUrl = "admin/administration/locations";

$result = $api->api_call_get($locationsApiUrl);

if ($result) {
  echo "<table>";
  foreach($api->response as $row){
    echo sprintf('<tr><td>%s</td><td>%s</td></tr>', $row['id'], $row['name']);
  }
  echo '</table>';
} else {
  echo "Fail! Error code: $api->response_code\n";
  print_r($api->response);
}

echo "\n-------------------------------------------------\n";
</code>```

Title: Putting arrays in a table using PHP

Body:
I'm a beginner in PHP and working on an API project which has to get results from a server I connected via API.

I am getting the results, but I would like to have them well arranged in a simple table.

This is what I am getting:

I used the following code:

$api = new SplynxAPI($api_url, $key, $secret);

$locationsApiUrl = "admin/administration/locations";

echo "
";

echo "List locations\n";
$result = $api->api_call_get($locationsApiUrl);

echo "Result: ";

if ($result) {
  echo "Ok!\n";
  print_r($api->response);
} else {
  echo "Fail! Error code: $api->response_code\n";
  print_r($api->response);
}

echo "\n-------------------------------------------------\n";

Kindly assist me on this one.

Body:
The following code will render your response in a HTML <table>.

$api = new SplynxAPI($api_url, $key, $secret);

$locationsApiUrl = "admin/administration/locations";

$result = $api->api_call_get($locationsApiUrl);

if ($result) {
  echo "<table>";
  foreach($api->response as $row){
    echo sprintf('<tr><td>%s</td><td>%s</td></tr>', $row['id'], $row['name']);
  }
  echo '</table>';
} else {
  echo "Fail! Error code: $api->response_code\n";
  print_r($api->response);
}

echo "\n-------------------------------------------------\n";


问:
How to rename data frame column by taking only the first value of the splitter string
I have the following data frame:

```<code>df <- structure(list(n.foldchange = c(2, 3, 5), s.foldchange = c(4,
0.2, 100.3)), .Names = c("n.foldchange", "s.foldchange"), row.names = c(NA,
-3L), class = "data.frame")
</code>```

Which looks like this:

```<code>  n.foldchange s.foldchange
1            2          4.0
2            3          0.2
3            5        100.3
</code>```

What I want to do is to rename the column by removing the value after ..
Yielding

```<code>             n            s
1            2          4.0
2            3          0.2
3            5        100.3
</code>```

How can I do that? (with tidyverse possible?)

答:
Another solution uses base R functions substring and regexpr.

```<code>names(df) <- substring(names(df), 1, regexpr(".", names(df), fixed=TRUE)-1)

df
  n     s
1 2   4.0
2 3   0.2
3 5 100.3
</code>```

Here, regexpr is used to identify the positions of the first dot in the variable names. This position (minus one) is given to substring which returns a substring of the original variable names starting at the first character and ending right before the first dot.

Body:
I have the following data frame:

df <- structure(list(n.foldchange = c(2, 3, 5), s.foldchange = c(4,
0.2, 100.3)), .Names = c("n.foldchange", "s.foldchange"), row.names = c(NA,
-3L), class = "data.frame")

Which looks like this:

  n.foldchange s.foldchange
1            2          4.0
2            3          0.2
3            5        100.3

What I want to do is to rename the column by removing the value after ..
Yielding

             n            s
1            2          4.0
2            3          0.2
3            5        100.3

How can I do that? (with tidyverse possible?)

Body:
Another solution uses base R functions substring and regexpr.

names(df) <- substring(names(df), 1, regexpr(".", names(df), fixed=TRUE)-1)

df
  n     s
1 2   4.0
2 3   0.2
3 5 100.3

Here, regexpr is used to identify the positions of the first dot in the variable names. This position (minus one) is given to substring which returns a substring of the original variable names starting at the first character and ending right before the first dot.