问:
Update Android Support Library to 23.2.0 cause error: XmlPullParserException Binary XML file line #17<vector> tag requires viewportWidth > 0
I try to update my Support Library up to 23.2.0 and face this error:

```<code>Exception while inflating <vector>
org.xmlpull.v1.XmlPullParserException: Binary XML file line #17<vector> tag requires viewportWidth > 0
at android.support.graphics.drawable.VectorDrawableCompat.updateStateFromTypedArray(VectorDrawableCompat.java:535)
at android.support.graphics.drawable.VectorDrawableCompat.inflate(VectorDrawableCompat.java:472)
at android.support.graphics.drawable.VectorDrawableCompat.createFromXmlInner(VectorDrawableCompat.java:436)
at android.support.v7.widget.AppCompatDrawableManager$VdcInflateDelegate.createFromXmlInner(AppCompatDrawableManager.java:829)
at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:303)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:178)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:173)
at android.support.v7.widget.TintTypedArray.getDrawable(TintTypedArray.java:60)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:254)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:196)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
at com.chotot.vn.v2.activities.MainActivity.onCreate(MainActivity.java:121)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
</code>```

And

```<code>FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.chotot.vn.dev/com.chotot.vn.v2.activities.MainActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class android.support.v7.widget.Toolbar
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class android.support.v7.widget.Toolbar
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
at com.chotot.vn.v2.activities.MainActivity.onCreate(MainActivity.java:121)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
at com.chotot.vn.v2.activities.MainActivity.onCreate(MainActivity.java:121)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID #0x7f020016
at android.content.res.Resources.loadDrawable(Resources.java:2091)
at android.content.res.Resources.getDrawable(Resources.java:695)
at android.support.v7.widget.TintResources.superGetDrawable(TintResources.java:48)
at android.support.v7.widget.AppCompatDrawableManager.onDrawableLoadedFromResources(AppCompatDrawableManager.java:374)
at android.support.v7.widget.TintResources.getDrawable(TintResources.java:44)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:180)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:173)
at android.support.v7.widget.TintTypedArray.getDrawable(TintTypedArray.java:60)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:254)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:196)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
at com.chotot.vn.v2.activities.MainActivity.onCreate(MainActivity.java:121)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #17: invalid drawable tag vector
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:897)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:837)
at android.content.res.Resources.loadDrawable(Resources.java:2087)
at android.content.res.Resources.getDrawable(Resources.java:695)
at android.support.v7.widget.TintResources.superGetDrawable(TintResources.java:48)
at android.support.v7.widget.AppCompatDrawableManager.onDrawableLoadedFromResources(AppCompatDrawableManager.java:374)
at android.support.v7.widget.TintResources.getDrawable(TintResources.java:44)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:180)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:173)
at android.support.v7.widget.TintTypedArray.getDrawable(TintTypedArray.java:60)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:254)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:196)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
at com.chotot.vn.v2.activities.MainActivity.onCreate(MainActivity.java:121)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
</code>```

My activity_main.xml

```<code><?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <fragment
        android:id="@+id/f_actionbar"
        android:name="com.chotot.vn.fragments.ActionBarFragment"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <android.support.v7.widget.Toolbar
        android:id="@+id/main_tool_bar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:layout_alignParentTop="true"
        android:background="@color/action_bar_bg">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <include
                android:id="@+id/main_action_bar_layout"
                layout="@layout/layout_actionbar_custom_search"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:layout_gravity="top" />

            <LinearLayout
                android:id="@+id/main_action_bar_layout_content"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/main_action_bar_layout"
                android:orientation="vertical" />
        </RelativeLayout>
    </android.support.v7.widget.Toolbar>

    <FrameLayout
        android:id="@+id/layout_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/main_tool_bar" />

</RelativeLayout>
</code>```

How can I fix it?

答:
Even though I have support of vector enabled in my gradle and have the latest version of gradle, build tools, support library and Android studio,  I still got the error.

Here a fix for my case:

```<code>AppCompatDrawableManager.get().getDrawable(getContext(), R.drawable.drawable_xyz);
</code>```

to supress the lint warning add this @SuppressLint("RestrictedApi")

Body:
I try to update my Support Library up to 23.2.0 and face this error:

Exception while inflating <vector>
org.xmlpull.v1.XmlPullParserException: Binary XML file line #17<vector> tag requires viewportWidth > 0
at android.support.graphics.drawable.VectorDrawableCompat.updateStateFromTypedArray(VectorDrawableCompat.java:535)
at android.support.graphics.drawable.VectorDrawableCompat.inflate(VectorDrawableCompat.java:472)
at android.support.graphics.drawable.VectorDrawableCompat.createFromXmlInner(VectorDrawableCompat.java:436)
at android.support.v7.widget.AppCompatDrawableManager$VdcInflateDelegate.createFromXmlInner(AppCompatDrawableManager.java:829)
at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:303)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:178)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:173)
at android.support.v7.widget.TintTypedArray.getDrawable(TintTypedArray.java:60)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:254)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:196)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
at com.chotot.vn.v2.activities.MainActivity.onCreate(MainActivity.java:121)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)

And

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.chotot.vn.dev/com.chotot.vn.v2.activities.MainActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class android.support.v7.widget.Toolbar
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class android.support.v7.widget.Toolbar
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
at com.chotot.vn.v2.activities.MainActivity.onCreate(MainActivity.java:121)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
at com.chotot.vn.v2.activities.MainActivity.onCreate(MainActivity.java:121)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID #0x7f020016
at android.content.res.Resources.loadDrawable(Resources.java:2091)
at android.content.res.Resources.getDrawable(Resources.java:695)
at android.support.v7.widget.TintResources.superGetDrawable(TintResources.java:48)
at android.support.v7.widget.AppCompatDrawableManager.onDrawableLoadedFromResources(AppCompatDrawableManager.java:374)
at android.support.v7.widget.TintResources.getDrawable(TintResources.java:44)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:180)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:173)
at android.support.v7.widget.TintTypedArray.getDrawable(TintTypedArray.java:60)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:254)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:196)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
at com.chotot.vn.v2.activities.MainActivity.onCreate(MainActivity.java:121)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #17: invalid drawable tag vector
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:897)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:837)
at android.content.res.Resources.loadDrawable(Resources.java:2087)
at android.content.res.Resources.getDrawable(Resources.java:695)
at android.support.v7.widget.TintResources.superGetDrawable(TintResources.java:48)
at android.support.v7.widget.AppCompatDrawableManager.onDrawableLoadedFromResources(AppCompatDrawableManager.java:374)
at android.support.v7.widget.TintResources.getDrawable(TintResources.java:44)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:180)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:173)
at android.support.v7.widget.TintTypedArray.getDrawable(TintTypedArray.java:60)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:254)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:196)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
at com.chotot.vn.v2.activities.MainActivity.onCreate(MainActivity.java:121)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)

My activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <fragment
        android:id="@+id/f_actionbar"
        android:name="com.chotot.vn.fragments.ActionBarFragment"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <android.support.v7.widget.Toolbar
        android:id="@+id/main_tool_bar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:layout_alignParentTop="true"
        android:background="@color/action_bar_bg">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <include
                android:id="@+id/main_action_bar_layout"
                layout="@layout/layout_actionbar_custom_search"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:layout_gravity="top" />

            <LinearLayout
                android:id="@+id/main_action_bar_layout_content"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/main_action_bar_layout"
                android:orientation="vertical" />
        </RelativeLayout>
    </android.support.v7.widget.Toolbar>

    <FrameLayout
        android:id="@+id/layout_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/main_tool_bar" />

</RelativeLayout>

How can I fix it?

Body:
Even though I have support of vector enabled in my gradle and have the latest version of gradle, build tools, support library and Android studio,  I still got the error.

Here a fix for my case:

AppCompatDrawableManager.get().getDrawable(getContext(), R.drawable.drawable_xyz);

to supress the lint warning add this @SuppressLint("RestrictedApi")


来源: stackexchange

问:
How do I fine-tune regex syntax to parse a tricky dirty text?
I have an OCR'ed .txt file that is a volume with data about book reviews (It's a Book Review Index). I'm attempting to separate authors, titles, and review data. I've been able to cleanly separate authors, but still can't separate titles from review data cleanly. Here is a sample of the .txt file:

MA, Chi-Hua - Huan Chiu Hsin Ying BL - v70 - Jl 1 ’74 - pi 183 c MA, Ching-Hsien - Pei Niang Niang Ti Ku Shih
  BL - v77 - Ja 1 ’81 - p630 MA, Hsin-Teh - Chinese Women In The Great Leap Forward
  Choice - v20 - N ’82 - p396 MA, Huan • The Overall Survey Of The Ocean’s Shores 1433
  Choice - v8 - 0 ’71 - pl074 MA, Huan • Ying-Yai Sheng-Lan AHR - v76 - D ’71 - pl578 GJ - vl37 - Je ’71 - p213 JAS - v31 - N ’71 - pl81 TLS - Je 16 ’72 - p681 MA, Laurence J C - Commercial Development And Urban Change In Sung China 960-1279
  JAS - v31 - Ag ’72 - p928 Pac A - v45 - Summer ’72 - p285 MA, Laurence J C - The Environment JAS - v42 - N ’82 - pl39 MA, Laurence J C - Urban Development In Modern China
  Choice - vl9 - Ja ’82 - p696 JAS - v42 - N 82 - pl39 MA, Nancy Chih - Cook Chinese AB - v45 - My 25 ’70 - pl786 PW - vl97 - Mr 23 ’70 - p38 MA, Nancy Chih • Don’t Lick The Chopsticks CSM - v66 - Ja 10 ’74 - pF2 LJ - v99 - Mr 15 ’74 - p757 MA, Nancy Chih - Mrs. Ma’s Japanese Cooking
  VQR - v58 - Spring ’82 - p68 MA, Tsu Sheng - Microscale Manipulations In Chemistry
  Choice-vl3-N ’76 -pi 164 MA, Tsu Sheng - Organic Functional Group Analysis By Gas Chromatography Choice - vl3 - F ’77 - pl624 r MA, Wei-Yi - A Bibliography Of Chinese-Language Materials On The People's Communes ARBA - vl5 - '84 - p320
  Pac A - v56 - Winter ’83 - p796 MA, Wook - Seoul Ro Kanun Kil BL - v78 - 0 15 '81 - p294 y MA, Y W - Traditional Chinese Stories ANQ - vl8 - 0 ’79 - p30 BF - v4 - Ap 40 '79 - p575 Choice -vl5-Ja ’79 -pl528 HR-v32-Spring'79-pl23 JAS - v38 - Ag '79 - p773 Kliatt - vl3 • Winter '79 - p26 WIT - v53 - Summer '79 - p555 MA, Yun • Shih Ching T'ao Hsing BL - v68 - Ap 1 '72 - p651 MA BRICALL, Josep - Politica Economica De La Generalitat 1936-1939. Vol. 1 WP - v25 - O '72 - pl55 MA COY, Ramelle • Short-Time Compensation
  Choice - v21 - Jl '84 - pl648 Econ Bks - vll - S ’84 - p62 c MA De - The Cowherd And The Weaving Maid
  Cur R - v20 - S '81 -p325 c MA De - Crickets
  Cur R - v20 - S '81 - p325 c MA De - School-Master Dongguo Cur R - v20 - S '81 - p325 c MA De - Thrice Borrowing The Plantain Fan CurR- v20-S ’81 -p325 c MA De - The Wonderful Gourds Cur R - v20 - S '81 - p325 MAACK, Berthold - Preussen JMH - v55 - Mr '83 - p71 r MAACK, Mary N - Libraries In Senegal ARBA - vl3 - '82 - pi53 CRL - v45 - Mr '84-pl52 JAL - v7 - S '81 - p244 JLH - vl9 - Spring ’84 - p315 LJ - vl07 - My 1 ’82 - p865 LQ - v52 - Ap '82-pl75 MAACK, Reinhard • Kontinentaldrift Und Geologie Des Sudatlantischen Ozeans GJ - vl36 - Mr '70 - pl38 MAAG, Russell C - Observe And Understand The Sun
  S&T - v54 - S ’77 - p221 MAAG, Victor - Hiob
  Rel St Rev - vlO - Ap '84 - pi 75 MAAILMA Katettu Poyta

And here is a cleaner version, to see better what I'm trying to separate:

MA, Chi-Hua - Huan Chiu Hsin Ying BL - v70 - Jl 1 ’74 - pi 183 c
  MA, Ching-Hsien - Pei Niang Niang Ti Ku Shih BL - v77 - Ja 1 ’81 - p630
  MA, Hsin-Teh - Chinese Women In The Great Leap Forward Choice - v20 - N ’82 - p396
  MA, Huan • The Overall Survey Of The Ocean’s Shores 1433 Choice - v8 - 0 ’71 - pl074
  MA, Huan • Ying-Yai Sheng-Lan AHR - v76 - D ’71 - pl578 GJ - vl37 - Je ’71 - p213 JAS - v31 - N ’71 - pl81 TLS - Je 16 ’72 - p681
  MA, Laurence J C - Commercial Development And Urban Change In Sung China 960-1279 JAS - v31 - Ag ’72 - p928 Pac A - v45 - Summer ’72 - p285
  MA, Laurence J C - The Environment JAS - v42 - N ’82 - pl39
  MA, Laurence J C - Urban Development In Modern China Choice - vl9 - Ja ’82 - p696 JAS - v42 - N 82 - pl39
  MA, Nancy Chih - Cook Chinese AB - v45 - My 25 ’70 - pl786 PW - vl97 - Mr 23 ’70 - p38
  MA, Nancy Chih • Don’t Lick The Chopsticks CSM - v66 - Ja 10 ’74 - pF2 LJ - v99 - Mr 15 ’74 - p757
  MA, Nancy Chih - Mrs. Ma’s Japanese Cooking VQR - v58 - Spring ’82 - p68
  MA, Tsu Sheng - Microscale Manipulations In Chemistry Choice-vl3-N ’76 -pi 164
  MA, Tsu Sheng - Organic Functional Group Analysis By Gas Chromatography Choice - vl3 - F ’77 - pl624 r
  MA, Wei-Yi - A Bibliography Of Chinese-Language Materials On The People's Communes ARBA - vl5 - '84 - p320 Pac A - v56 - Winter ’83 - p796
  MA, Wook - Seoul Ro Kanun Kil BL - v78 - 0 15 '81 - p294 y
  MA, Y W - Traditional Chinese Stories ANQ - vl8 - 0 ’79 - p30 BF - v4 - Ap 40 '79 - p575 Choice -vl5-Ja ’79 -pl528 HR-v32-Spring'79-pl23 JAS - v38 - Ag '79 - p773 Kliatt - vl3 • Winter '79 - p26 WIT - v53 -  Summer '79 - p555
  MA, Yun • Shih Ching T'ao Hsing BL - v68 - Ap 1 '72 - p651
  MA BRICALL, Josep - Politica Economica De La Generalitat 1936-1939. Vol. 1 WP - v25 - O '72 - pl55
  MA COY, Ramelle • Short-Time Compensation Choice - v21 - Jl '84 - pl648 Econ Bks - vll - S ’84 - p62 c
  MA De - The Cowherd And The Weaving Maid Cur R - v20 - S '81 -p325 c
  MA De - Crickets Cur R - v20 - S '81 - p325 c
  MA De - School-Master Dongguo Cur R - v20 - S '81 - p325 c
  MA De - Thrice Borrowing The Plantain Fan CurR- v20-S ’81 -p325 c
  MA De - The Wonderful Gourds Cur R - v20 - S '81 - p325
  MAACK, Berthold - Preussen JMH - v55 - Mr '83 - p71 r

And here's my code:

```<code># read in review volume .txt file
import pandas as pd
import numpy as np
import re

file = '/Users/sinykin/Dropbox/US_LIT_PRODUCTION_DATA/REVIEWS_DATA/BOOK_REVIEWS_INDEX_TEXTS/1965_1984_Vol_5_M-P.txt'

with open(file) as f:
    content = f.readlines()
    content = [x.strip() for x in content]
    content = " ".join(content)

# Get all authors
pattern = r"[A-Z\-]{2,}[\,]+\s[A-Za-z\s\,\(\)\.]+\s[\-\*\•\.\■ ]{1}"
authors = re.findall(pattern, content)

# Now replace all found authors with XXX_XXX
if re.search(pattern, content):
    r = re.compile(pattern)
    content2 = r.sub(r'XXX_XXX', content)

# Now get all the content for each author
content3 = content2.split('XXX_XXX')
bib = content3[1:]

# Now separate reviews from titles
pattern2 = r"\s+(?:([A-Z][a-z][a-z]((?!\s+-|\s+Choice\s*-).)*?\w)(?:\s+-
\s*|\s+(?=Choice\s*-)|\s*$))"
bib2 = "".join(bib)
titles = re.findall(pattern2, bib2)
print (titles[:1000])
</code>```

It's the regex code in pattern2 that I'm struggling with. For example, it currently gives me this, for what should be titles:

[('The Overall Survey Of The Ocean\xe2\x80\x99s Shores 1433', '3'),

  ('Ying-Yai Sheng-Lan AHR', 'H'),

  ('Commercial Development And Urban Change In Sung China 960-1279 JAS', 'A'),

  ('Pac A', ' '),

  ('Summer \xe2\x80\x9972', '7'),

  ('The Environment JAS', 'A'),

  ('Urban Development In Modern China', 'n'),

  ('Cook Chinese AB', 'A'),

  ('Don\xe2\x80\x99t Lick The Chopsticks CSM', 'S'),

  ('Mrs. Ma\xe2\x80\x99s Japanese Cooking VQR', 'Q'),
  ('Spring \xe2\x80\x9982', '8'),

  ('Microscale Manipulations In Chemistry', 'r')

As you can see, I'm getting extra data beyond the end of the titles, esp capital letters that mark abbreviation for reviews.

Can you help me refine my regex to capture just the titles?

答:
You could keep building up on the last positive lookahead, by adding some specific expressions, to screen out the unwanted trailing characters. For example, extending

(?:\s+-\s*|\s+(?=Choice\s*-)|\s*$))

into

(?:\s+-\s*|\s+(?=Choice\s*-)|\s*$|\s+[A-Z]{2,3}|\s+Cur R))

would eliminate the Cur R and code endings (AB, JAS, etc.):

('The Environment', 'n')

  ('Urban Development In Modern China', 'n')

  ('Cook Chinese', 's')

  ('Nancy Chih \xe2\x80\xa2 Don\xe2\x80\x99t Lick The Chopsticks', 'k')

  ('Mrs. Ma\xe2\x80\x99s Japanese Cooking', 'n')

ContentLicense: CC BY-SA 3.0

Body:
I have an OCR'ed .txt file that is a volume with data about book reviews (It's a Book Review Index). I'm attempting to separate authors, titles, and review data. I've been able to cleanly separate authors, but still can't separate titles from review data cleanly. Here is a sample of the .txt file:

MA, Chi-Hua - Huan Chiu Hsin Ying BL - v70 - Jl 1 ’74 - pi 183 c MA, Ching-Hsien - Pei Niang Niang Ti Ku Shih
  BL - v77 - Ja 1 ’81 - p630 MA, Hsin-Teh - Chinese Women In The Great Leap Forward
  Choice - v20 - N ’82 - p396 MA, Huan • The Overall Survey Of The Ocean’s Shores 1433
  Choice - v8 - 0 ’71 - pl074 MA, Huan • Ying-Yai Sheng-Lan AHR - v76 - D ’71 - pl578 GJ - vl37 - Je ’71 - p213 JAS - v31 - N ’71 - pl81 TLS - Je 16 ’72 - p681 MA, Laurence J C - Commercial Development And Urban Change In Sung China 960-1279
  JAS - v31 - Ag ’72 - p928 Pac A - v45 - Summer ’72 - p285 MA, Laurence J C - The Environment JAS - v42 - N ’82 - pl39 MA, Laurence J C - Urban Development In Modern China
  Choice - vl9 - Ja ’82 - p696 JAS - v42 - N 82 - pl39 MA, Nancy Chih - Cook Chinese AB - v45 - My 25 ’70 - pl786 PW - vl97 - Mr 23 ’70 - p38 MA, Nancy Chih • Don’t Lick The Chopsticks CSM - v66 - Ja 10 ’74 - pF2 LJ - v99 - Mr 15 ’74 - p757 MA, Nancy Chih - Mrs. Ma’s Japanese Cooking
  VQR - v58 - Spring ’82 - p68 MA, Tsu Sheng - Microscale Manipulations In Chemistry
  Choice-vl3-N ’76 -pi 164 MA, Tsu Sheng - Organic Functional Group Analysis By Gas Chromatography Choice - vl3 - F ’77 - pl624 r MA, Wei-Yi - A Bibliography Of Chinese-Language Materials On The People's Communes ARBA - vl5 - '84 - p320
  Pac A - v56 - Winter ’83 - p796 MA, Wook - Seoul Ro Kanun Kil BL - v78 - 0 15 '81 - p294 y MA, Y W - Traditional Chinese Stories ANQ - vl8 - 0 ’79 - p30 BF - v4 - Ap 40 '79 - p575 Choice -vl5-Ja ’79 -pl528 HR-v32-Spring'79-pl23 JAS - v38 - Ag '79 - p773 Kliatt - vl3 • Winter '79 - p26 WIT - v53 - Summer '79 - p555 MA, Yun • Shih Ching T'ao Hsing BL - v68 - Ap 1 '72 - p651 MA BRICALL, Josep - Politica Economica De La Generalitat 1936-1939. Vol. 1 WP - v25 - O '72 - pl55 MA COY, Ramelle • Short-Time Compensation
  Choice - v21 - Jl '84 - pl648 Econ Bks - vll - S ’84 - p62 c MA De - The Cowherd And The Weaving Maid
  Cur R - v20 - S '81 -p325 c MA De - Crickets
  Cur R - v20 - S '81 - p325 c MA De - School-Master Dongguo Cur R - v20 - S '81 - p325 c MA De - Thrice Borrowing The Plantain Fan CurR- v20-S ’81 -p325 c MA De - The Wonderful Gourds Cur R - v20 - S '81 - p325 MAACK, Berthold - Preussen JMH - v55 - Mr '83 - p71 r MAACK, Mary N - Libraries In Senegal ARBA - vl3 - '82 - pi53 CRL - v45 - Mr '84-pl52 JAL - v7 - S '81 - p244 JLH - vl9 - Spring ’84 - p315 LJ - vl07 - My 1 ’82 - p865 LQ - v52 - Ap '82-pl75 MAACK, Reinhard • Kontinentaldrift Und Geologie Des Sudatlantischen Ozeans GJ - vl36 - Mr '70 - pl38 MAAG, Russell C - Observe And Understand The Sun
  S&T - v54 - S ’77 - p221 MAAG, Victor - Hiob
  Rel St Rev - vlO - Ap '84 - pi 75 MAAILMA Katettu Poyta

And here is a cleaner version, to see better what I'm trying to separate:

MA, Chi-Hua - Huan Chiu Hsin Ying BL - v70 - Jl 1 ’74 - pi 183 c
  MA, Ching-Hsien - Pei Niang Niang Ti Ku Shih BL - v77 - Ja 1 ’81 - p630
  MA, Hsin-Teh - Chinese Women In The Great Leap Forward Choice - v20 - N ’82 - p396
  MA, Huan • The Overall Survey Of The Ocean’s Shores 1433 Choice - v8 - 0 ’71 - pl074
  MA, Huan • Ying-Yai Sheng-Lan AHR - v76 - D ’71 - pl578 GJ - vl37 - Je ’71 - p213 JAS - v31 - N ’71 - pl81 TLS - Je 16 ’72 - p681
  MA, Laurence J C - Commercial Development And Urban Change In Sung China 960-1279 JAS - v31 - Ag ’72 - p928 Pac A - v45 - Summer ’72 - p285
  MA, Laurence J C - The Environment JAS - v42 - N ’82 - pl39
  MA, Laurence J C - Urban Development In Modern China Choice - vl9 - Ja ’82 - p696 JAS - v42 - N 82 - pl39
  MA, Nancy Chih - Cook Chinese AB - v45 - My 25 ’70 - pl786 PW - vl97 - Mr 23 ’70 - p38
  MA, Nancy Chih • Don’t Lick The Chopsticks CSM - v66 - Ja 10 ’74 - pF2 LJ - v99 - Mr 15 ’74 - p757
  MA, Nancy Chih - Mrs. Ma’s Japanese Cooking VQR - v58 - Spring ’82 - p68
  MA, Tsu Sheng - Microscale Manipulations In Chemistry Choice-vl3-N ’76 -pi 164
  MA, Tsu Sheng - Organic Functional Group Analysis By Gas Chromatography Choice - vl3 - F ’77 - pl624 r
  MA, Wei-Yi - A Bibliography Of Chinese-Language Materials On The People's Communes ARBA - vl5 - '84 - p320 Pac A - v56 - Winter ’83 - p796
  MA, Wook - Seoul Ro Kanun Kil BL - v78 - 0 15 '81 - p294 y
  MA, Y W - Traditional Chinese Stories ANQ - vl8 - 0 ’79 - p30 BF - v4 - Ap 40 '79 - p575 Choice -vl5-Ja ’79 -pl528 HR-v32-Spring'79-pl23 JAS - v38 - Ag '79 - p773 Kliatt - vl3 • Winter '79 - p26 WIT - v53 -  Summer '79 - p555
  MA, Yun • Shih Ching T'ao Hsing BL - v68 - Ap 1 '72 - p651
  MA BRICALL, Josep - Politica Economica De La Generalitat 1936-1939. Vol. 1 WP - v25 - O '72 - pl55
  MA COY, Ramelle • Short-Time Compensation Choice - v21 - Jl '84 - pl648 Econ Bks - vll - S ’84 - p62 c
  MA De - The Cowherd And The Weaving Maid Cur R - v20 - S '81 -p325 c
  MA De - Crickets Cur R - v20 - S '81 - p325 c
  MA De - School-Master Dongguo Cur R - v20 - S '81 - p325 c
  MA De - Thrice Borrowing The Plantain Fan CurR- v20-S ’81 -p325 c
  MA De - The Wonderful Gourds Cur R - v20 - S '81 - p325
  MAACK, Berthold - Preussen JMH - v55 - Mr '83 - p71 r

And here's my code:

# read in review volume .txt file
import pandas as pd
import numpy as np
import re

file = '/Users/sinykin/Dropbox/US_LIT_PRODUCTION_DATA/REVIEWS_DATA/BOOK_REVIEWS_INDEX_TEXTS/1965_1984_Vol_5_M-P.txt'

with open(file) as f:
    content = f.readlines()
    content = [x.strip() for x in content]
    content = " ".join(content)

# Get all authors
pattern = r"[A-Z\-]{2,}[\,]+\s[A-Za-z\s\,\(\)\.]+\s[\-\*\•\.\■ ]{1}"
authors = re.findall(pattern, content)

# Now replace all found authors with XXX_XXX
if re.search(pattern, content):
    r = re.compile(pattern)
    content2 = r.sub(r'XXX_XXX', content)

# Now get all the content for each author
content3 = content2.split('XXX_XXX')
bib = content3[1:]

# Now separate reviews from titles
pattern2 = r"\s+(?:([A-Z][a-z][a-z]((?!\s+-|\s+Choice\s*-).)*?\w)(?:\s+-
\s*|\s+(?=Choice\s*-)|\s*$))"
bib2 = "".join(bib)
titles = re.findall(pattern2, bib2)
print (titles[:1000])

It's the regex code in pattern2 that I'm struggling with. For example, it currently gives me this, for what should be titles:

[('The Overall Survey Of The Ocean\xe2\x80\x99s Shores 1433', '3'),

  ('Ying-Yai Sheng-Lan AHR', 'H'),

  ('Commercial Development And Urban Change In Sung China 960-1279 JAS', 'A'),

  ('Pac A', ' '),

  ('Summer \xe2\x80\x9972', '7'),

  ('The Environment JAS', 'A'),

  ('Urban Development In Modern China', 'n'),

  ('Cook Chinese AB', 'A'),

  ('Don\xe2\x80\x99t Lick The Chopsticks CSM', 'S'),

  ('Mrs. Ma\xe2\x80\x99s Japanese Cooking VQR', 'Q'),
  ('Spring \xe2\x80\x9982', '8'),

  ('Microscale Manipulations In Chemistry', 'r')

As you can see, I'm getting extra data beyond the end of the titles, esp capital letters that mark abbreviation for reviews.

Can you help me refine my regex to capture just the titles?


问:
Android - Send data to the server in every 5 minutes
I have some data in my SQLite database table. When my app starts, I want to send that data to the server every 5 minutes.

When the app is closed, it should stop.

What is the best approach for this?

Should I use Service or IntentService?

Should I use AlarmManager, Handler or any other thing?

I'm aware of my application speed. I don't want to make it slow. What is the effective approach?

答:
As you just want to run your process while the app is foreground, then TimerTask or Handler with conjunction to Message or Runable is good. It won't bother much your app's performance. If you ask about the better one from these two I'll say it's Handler. Check the details here in this answer:

https://stackoverflow.com/a/3975337/4128371

But if you want a really good performance then I'll suggest to go with AlarmManager. Otherwise Handler is a good option.


问:
Delete the last node of a linked list
I am trying to delete the last Node of a linked list,
I have the first element of the list. But the function does not work I would be happy if you could help me

Code -

```<code>void deleteNode(Node* firstNode)
{
    Node* currNode = firstNode;
    while (currNode->next != NULL)
    {
     currNode = currNode->next;
    }
     delete currNode->next;
     currNode->next = NULL;
 }
</code>```

答:
The problem with your code is, at the last instance curNode points to the last node of the list. When you delete the curNode, you will no longer be left with node, ie, the data and next part. So you now you cannot access next part of curNode. This code will lead to runtime error:

```<code>currNode->next = NULL;
</code>```

Instead try this:

If the list contains only one element, then firstNode points to NULL and the only node is deleted. If there are more than two items in your list, your have to iterate to the last second element, set its next value to NULL, and delete the last node with the help of a temp pointer.

```<code>void pop_back(struct node** firstNode)
{
    struct node* p = *firstNode;

    if(p == NULL)
        cout << "List empty." << endl;

    else if(p->next == NULL){
        cout << "Element " << p-> data << " deleted." << endl;
        delete *firstNode;
        *firstNode = NULL;
    }

    else
    {
        while(p->next->next != NULL){
            p= p->next;
        }

    struct node* temp = p-> next;
    p->next = NULL;
    cout << "Element " << temp->data << " deleted." << endl;
    delete temp;
    }
}
</code>```

Title: Delete the last node of a linked list

Body:
I am trying to delete the last Node of a linked list,
I have the first element of the list. But the function does not work I would be happy if you could help me

Code -

void deleteNode(Node* firstNode)
{
    Node* currNode = firstNode;
    while (currNode->next != NULL)
    {
     currNode = currNode->next;
    }
     delete currNode->next;
     currNode->next = NULL;
 }

Body:
The problem with your code is, at the last instance curNode points to the last node of the list. When you delete the curNode, you will no longer be left with node, ie, the data and next part. So you now you cannot access next part of curNode. This code will lead to runtime error:

currNode->next = NULL;

Instead try this:

If the list contains only one element, then firstNode points to NULL and the only node is deleted. If there are more than two items in your list, your have to iterate to the last second element, set its next value to NULL, and delete the last node with the help of a temp pointer.

void pop_back(struct node** firstNode)
{
    struct node* p = *firstNode;

    if(p == NULL)
        cout << "List empty." << endl;

    else if(p->next == NULL){
        cout << "Element " << p-> data << " deleted." << endl;
        delete *firstNode;
        *firstNode = NULL;
    }

    else
    {
        while(p->next->next != NULL){
            p= p->next;
        }

    struct node* temp = p-> next;
    p->next = NULL;
    cout << "Element " << temp->data << " deleted." << endl;
    delete temp;
    }
}


问:
Web frontend plugin for AWS Elasticsearch service
I am using AWS Elasticsearch service (ES version 5.3). What are the web frontend plugin that can be used with AWS-ES?

The AWS ES supported plugins doesn't seem to support any frontend view.

Also, doesn't seem like Elasticsearch-head plugin can't be installed inside the AWS-ES service. Any suggestion?

答:
Use Kibana. Launch a local instance of it or running in ec2.

Or try cloud.elastic.co which has everything OOTB.

Disclaimer: I'm working at elastic.


问:
Write dropdown value to SQL table field
Creating a dropdown into a PHP form where the value of this dropdown should be written to SQL table field.

I'm almost certain the issue is this piece name="txtStatus" value="<?php echo $dataSt['Opt'];?>"> but I can't get it to work.

EDITED
This the code of the edit.php, now I'm able to get the drop-down, down on the page, to work but the values in the $result["Status"] aren't sent to the save.php file and of course neither to the SQL database table field.

```<code><html>
<head>
<title>TEST EDIT</title>
</head>
<style type="text/css">
@import url(http://fonts.googleapis.com/css?family=Roboto:400,500,700,300,100);
body {
  background-color: #576370;
  font-family: "Roboto", helvetica, arial, sans-serif;
  font-size: 16px;
  font-weight: 400;
  text-rendering: optimizeLegibility;
}

div.table-title {
  text-align:center;
  display: block;
  margin: auto;
  width: 100%;
}

.table-title h3 {
   color: #fafafa;
   padding:1px;
   font-size: 25px;
   font-weight: 300;
   font-style:normal;
   font-family: "Roboto", helvetica, arial, sans-serif;
   text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.1);
   text-transform:uppercase;
}

.table-title h2 {
   color: #D8D8D8;
   font-size: 10px;
   font-weight: 50;
   font-style:normal;
   text-transform:uppercase;
}

.table-title h4 {
   color: #F3F781;
   font-size: 10px;
   font-weight: 50;
   font-style:normal;
   text-transform:uppercase;
}

/*** Table Styles **/

.table-fill {
  background: white;
  border-radius:3px;
  border-collapse: collapse;
  height: 15px;
  margin: auto;
  padding:1px;
  width: 100%;
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
  animation: float 8s infinite;
}

th {
  color:#D5DDE5;
  text-align:left;
  background:#1b1e24;
  border-right: 1px solid #343a45;
  font-size:14px;
  font-weight: 50;
  padding:8px;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
  vertical-align:middle;
  width: 100px;
}

th:first-child {
  border-top-left-radius:3px;

}

th:last-child {
  border-top-right-radius:3px;
  border-right:none;
}

tr {
  border-top: 1px solid #C1C3D1;
  border-bottom-: 1px solid #C1C3D1;
  color:#666B85;
  font-size:16px;
  font-weight:normal;
  text-shadow: 0 1px 1px rgba(256, 256, 256, 0.1);
}

tr:hover td {
  background:#4E5066;
  color:#FFFFFF;
  border-top: 0px solid #22262e;
  border-bottom: 0px solid #22262e;
}

tr:first-child {
  border-top:none;
}

tr:last-child {
  border-bottom:none;
}

tr:nth-child(odd) td {
  background:#EBEBEB;
}

tr:nth-child(odd):hover td {
  background:#4E5066;

}

tr:last-child td:first-child {
  border-bottom-left-radius:3px;
}

tr:last-child td:last-child {
  border-bottom-right-radius:3px;
}

td {
  background:#FFFFFF;
  padding:8px;
  vertical-align:middle;
  font-weight:300;
  font-size:14px;
  text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.1);
  border-right: 1px solid #C1C3D1;
}

.show {display:block;}
</style>
</head>
<body>
<div class="table-title">
    <h3>SCANIA FINANCE</h3>
<body>

<?php
   ini_set('display_errors', 1);
   error_reporting(~0);

    $serverName = 'localhost';
    $userName = 'user';
    $userPassword = 'password';
    $dbName = 'AdWorks';

   $strBusinessEntityID = null;

   if(isset($_GET["BusinessEntityID"]))
   {
       $strBusinessEntityID = $_GET["BusinessEntityID"];
   }

   $connectionInfo = array("Database"=>$dbName, "UID"=>$userName, "PWD"=>$userPassword, "MultipleActiveResultSets"=>true);

   $conn = sqlsrv_connect( $serverName, $connectionInfo);

   if( $conn === false ) {
      die( print_r( sqlsrv_errors(), true));
   }

    $stmt = "SELECT * FROM tKelvin32 WHERE BusinessEntityID = ? ";
    $params = array($strBusinessEntityID);

    $query = sqlsrv_query( $conn, $stmt, $params);

    $result = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC);

?>
<form action="save_bck.php" name="frmAdd" method="post">
<table align="center">
  <tr>
    <th width="120">BusinessEntityID</th>
    <td><input type="hidden" name="txtBusinessEntityID" value="<?php echo $result["BusinessEntityID"];?>"><?php echo $result["BusinessEntityID"];?></td>
    </tr>
  <tr>
    <th width="120">FirstName</th>
    <td><input type="hidden" name="txtFirstName" value="<?php echo $result["FirstName"];?>"><?php echo $result["FirstName"];?></td>
    </tr>
  <tr>
    <th width="120">LastName</th>
    <td><input type="hidden" name="txtLastName" size="25" value="<?php echo $result["LastName"];?>"><?php echo $result["LastName"];?></td>
    </tr>
  <tr>
    <th width="120">JobTitle</th>
    <td><input type="hidden" name="txtJobTitle" value="<?php echo $result["JobTitle"];?>"><?php echo $result["JobTitle"];?></td>
    </tr>
  <tr>
    <th width="120">PhoneNumber</th>
    <td><input type="hidden" name="txtPhoneNumber" value="<?php echo $result["PhoneNumber"];?>"><?php echo $result["PhoneNumber"];?></td>
    </tr>
  <tr>
    <th width="120">PhoneNumberType</th>
    <td><input type="hidden" name="txtPhoneNumberType" value="<?php echo $result["PhoneNumberType"];?>"><?php echo $result["PhoneNumberType"];?></td>
    </tr>
    <tr>
    <th width="120">EmailAddress</th>
    <td><input type="hidden" name="txtEmailAddress" value="<?php echo $result["EmailAddress"];?>"><?php echo $result["EmailAddress"];?></td>
    </tr>
    <tr>
    <th width="120">AddressLine1</th>
    <td><input type="hidden" name="txtAddressLine1" value="<?php echo $result["AddressLine1"];?>"><?php echo $result["AddressLine1"];?></td>
    </tr>
    <tr>
    <th width="120">City</th>
    <td><input type="hidden" name="txtCity" value="<?php echo $result["City"];?>"><?php echo $result["City"];?></td>
    </tr>
    <tr>
    <th width="120">PostalCode</th>
    <td><input type="hidden" name="txtPostalCode" value="<?php echo $result["PostalCode"];?>"><?php echo $result["PostalCode"];?></td>
    </tr>
    <tr>
    <th width="120">CountryRegionName</th>
    <td><input type="hidden" name="txtCountryRegionName" value="<?php echo $result["CountryRegionName"];?>"><?php echo $result["CountryRegionName"];?></td>
    </tr>
    <tr>
    <th width="120">Status</th>
    <td>
    <input type="hidden" name="txtStatus" value="<?php echo $result["Status"];?>"><select name="TowerSelect"><option> Choose </option>
    <?php
    //STATUS Query
    $sqlSt = "SELECT DISTINCT Opt FROM StatsOptions ORDER BY Opt";
    $resultSt = sqlsrv_query($conn,$sqlSt) or die("Couldn't execut query");
    while ($dataSt=sqlsrv_fetch_array($resultSt, SQLSRV_FETCH_ASSOC)){
    echo '<option value="'.$dataSt['Opt'].'">';
    echo $dataSt['Opt'];
    echo "</option>";
    }
    ?>
    </select>
    </td>
    </tr>
  </table>
  <input type="submit" name="submit" value="submit">
</form>
<?php
sqlsrv_close($conn);
?>
</body>
</html>
</code>```

答:
Ok, I got it, the issue was not the edit_bck.php code but on the save.php code, I was calling the wrong variable, I was calling the $_POST["txtStatus"] instead of $_POST["Desc"], see following code.

```<code>if( $conn === false ) {
        die( print_r( sqlsrv_errors(), true));
    }

    $sql = "UPDATE tKelvin32 SET
                FirstName = ? ,
                LastName = ? ,
                JobTitle = ? ,
                PhoneNumber = ? ,
                PhoneNumberType = ?,
                EmailAddress = ?,
                AddressLine1 = ?,
                City = ?,
                PostalCode = ?,
                CountryRegionName = ?,
                Status = ?
                WHERE BusinessEntityID = ? ";

    $params = array($_POST["txtFirstName"], $_POST["txtLastName"], $_POST["txtJobTitle"], $_POST["txtPhoneNumber"], $_POST["txtPhoneNumberType"], $_POST["txtEmailAddress"], $_POST["txtAddressLine1"], $_POST["txtCity"], $_POST["txtPostalCode"], $_POST["txtCountryRegionName"], $_POST["Desc"],$_POST["txtBusinessEntityID"]);
</code>```

Title: Write dropdown value to SQL table field

Body:
Creating a dropdown into a PHP form where the value of this dropdown should be written to SQL table field.

I'm almost certain the issue is this piece name="txtStatus" value="<?php echo $dataSt['Opt'];?>"> but I can't get it to work.

EDITED
This the code of the edit.php, now I'm able to get the drop-down, down on the page, to work but the values in the $result["Status"] aren't sent to the save.php file and of course neither to the SQL database table field.

<title>TEST EDIT</title>

SCANIA FINANCE

<?php
   ini_set('display_errors', 1);
   error_reporting(~0);

    $serverName = 'localhost';
    $userName = 'user';
    $userPassword = 'password';
    $dbName = 'AdWorks';

   $strBusinessEntityID = null;

   if(isset($_GET["BusinessEntityID"]))
   {
       $strBusinessEntityID = $_GET["BusinessEntityID"];
   }

   $connectionInfo = array("Database"=>$dbName, "UID"=>$userName, "PWD"=>$userPassword, "MultipleActiveResultSets"=>true);

   $conn = sqlsrv_connect( $serverName, $connectionInfo);

   if( $conn === false ) {
      die( print_r( sqlsrv_errors(), true));
   }

    $stmt = "SELECT * FROM tKelvin32 WHERE BusinessEntityID = ? ";
    $params = array($strBusinessEntityID);

    $query = sqlsrv_query( $conn, $stmt, $params);

    $result = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC);

?>
<form action="save_bck.php" name="frmAdd" method="post">

    BusinessEntityID
    <input type="hidden" name="txtBusinessEntityID" value="<?php echo $result["BusinessEntityID"];?>"><?php echo $result["BusinessEntityID"];?>

    FirstName
    <input type="hidden" name="txtFirstName" value="<?php echo $result["FirstName"];?>"><?php echo $result["FirstName"];?>

    LastName
    <input type="hidden" name="txtLastName" size="25" value="<?php echo $result["LastName"];?>"><?php echo $result["LastName"];?>

    JobTitle
    <input type="hidden" name="txtJobTitle" value="<?php echo $result["JobTitle"];?>"><?php echo $result["JobTitle"];?>

    PhoneNumber
    <input type="hidden" name="txtPhoneNumber" value="<?php echo $result["PhoneNumber"];?>"><?php echo $result["PhoneNumber"];?>

    PhoneNumberType
    <input type="hidden" name="txtPhoneNumberType" value="<?php echo $result["PhoneNumberType"];?>"><?php echo $result["PhoneNumberType"];?>

    EmailAddress
    <input type="hidden" name="txtEmailAddress" value="<?php echo $result["EmailAddress"];?>"><?php echo $result["EmailAddress"];?>

    AddressLine1
    <input type="hidden" name="txtAddressLine1" value="<?php echo $result["AddressLine1"];?>"><?php echo $result["AddressLine1"];?>

    City
    <input type="hidden" name="txtCity" value="<?php echo $result["City"];?>"><?php echo $result["City"];?>

    PostalCode
    <input type="hidden" name="txtPostalCode" value="<?php echo $result["PostalCode"];?>"><?php echo $result["PostalCode"];?>

    CountryRegionName
    <input type="hidden" name="txtCountryRegionName" value="<?php echo $result["CountryRegionName"];?>"><?php echo $result["CountryRegionName"];?>

    Status

    <input type="hidden" name="txtStatus" value="<?php echo $result["Status"];?>"><select name="TowerSelect"><option> Choose </option>
    <?php
    //STATUS Query
    $sqlSt = "SELECT DISTINCT Opt FROM StatsOptions ORDER BY Opt";
    $resultSt = sqlsrv_query($conn,$sqlSt) or die("Couldn't execut query");
    while ($dataSt=sqlsrv_fetch_array($resultSt, SQLSRV_FETCH_ASSOC)){
    echo '<option value="'.$dataSt['Opt'].'">';
    echo $dataSt['Opt'];
    echo "</option>";
    }
    ?>
    </select>

  <input type="submit" name="submit" value="submit">
</form>
<?php
sqlsrv_close($conn);
?>

Body:
Ok, I got it, the issue was not the edit_bck.php code but on the save.php code, I was calling the wrong variable, I was calling the $_POST["txtStatus"] instead of $_POST["Desc"], see following code.

if( $conn === false ) {
        die( print_r( sqlsrv_errors(), true));
    }

    $sql = "UPDATE tKelvin32 SET
                FirstName = ? ,
                LastName = ? ,
                JobTitle = ? ,
                PhoneNumber = ? ,
                PhoneNumberType = ?,
                EmailAddress = ?,
                AddressLine1 = ?,
                City = ?,
                PostalCode = ?,
                CountryRegionName = ?,
                Status = ?
                WHERE BusinessEntityID = ? ";

    $params = array($_POST["txtFirstName"], $_POST["txtLastName"], $_POST["txtJobTitle"], $_POST["txtPhoneNumber"], $_POST["txtPhoneNumberType"], $_POST["txtEmailAddress"], $_POST["txtAddressLine1"], $_POST["txtCity"], $_POST["txtPostalCode"], $_POST["txtCountryRegionName"], $_POST["Desc"],$_POST["txtBusinessEntityID"]);


问:
Travis-CI: Knitr Not Found in loadVignetteBuilder
I've been using travis-ci successfully so far but I'm having trouble when using travis-ci with R 3.4.0 at the vignette building step with the following error in the "building package" section:

```<code>* installing the package to build vignettes
* creating vignettes ... ERROR
Error in loadVignetteBuilder(vigns$pkgdir) :
  vignette builder 'knitr' not found
Calls: <Anonymous> -> loadVignetteBuilder
Execution halted
</code>```

When I run R-CMD-check locally it passes and I don't get any errors

Here's the current .travis.yml

```<code>language: R
sudo: false
install:
  - R -e "0" --args --bootstrap-packrat
cache:
  directories:
    - $TRAVIS_BUILD_DIR/packrat/src
    - $TRAVIS_BUILD_DIR/packrat/lib
  packages: true

r_packages:
    - covr

after_success:
    - Rscript -e 'library(covr); codecov()'
</code>```

DESCRIPTION has the vignette line in it:

```<code>VignetteBuilder: knitr
</code>```

knitr is also in my packrat.lock file and packrat is used for the build in .travis.yml.

I've tried the following to no avail:

added knitr to the r_packages in .travis.yml

added knitr to the Imports in DESCRIPTION

added r_check_args: "--no-vignettes" to travis.yml in the hopes of skipping the vignette building step.

added packrat call in travis.yml from install to before_install

I'm pretty knew to building R packages, never mind travis-ci so I'm not sure if I understand why the vignette builder would not have access to the knitr package.

Repo: https://github.com/cormac85/datakindr

Travis: https://travis-ci.org/cormac85/datakindr

答:
So in the end I got the build to pass by just removing packrat config from .travis.yml and replacing it with the normal package building config: cache: packages.

The packrat config I used was suggested in the Travis R Documentation and worked well for the rest of the items in the package but it did not work for the loadVignetteBuilder() step during the build.

Body:
I've been using travis-ci successfully so far but I'm having trouble when using travis-ci with R 3.4.0 at the vignette building step with the following error in the "building package" section:

* installing the package to build vignettes
* creating vignettes ... ERROR
Error in loadVignetteBuilder(vigns$pkgdir) :
  vignette builder 'knitr' not found
Calls: <Anonymous> -> loadVignetteBuilder
Execution halted

When I run R-CMD-check locally it passes and I don't get any errors

Here's the current .travis.yml

language: R
sudo: false
install:
  - R -e "0" --args --bootstrap-packrat
cache:
  directories:
    - $TRAVIS_BUILD_DIR/packrat/src
    - $TRAVIS_BUILD_DIR/packrat/lib
  packages: true

r_packages:
    - covr

after_success:
    - Rscript -e 'library(covr); codecov()'

DESCRIPTION has the vignette line in it:

VignetteBuilder: knitr

knitr is also in my packrat.lock file and packrat is used for the build in .travis.yml.

I've tried the following to no avail:

added knitr to the r_packages in .travis.yml

added knitr to the Imports in DESCRIPTION

added r_check_args: "--no-vignettes" to travis.yml in the hopes of skipping the vignette building step.

added packrat call in travis.yml from install to before_install

I'm pretty knew to building R packages, never mind travis-ci so I'm not sure if I understand why the vignette builder would not have access to the knitr package.

Repo: https://github.com/cormac85/datakindr

Travis: https://travis-ci.org/cormac85/datakindr


问:
Read & split multiple column text file into arrays
For a project I'm working on a fairly big animal dataset with up to 14 parameters of data. I was able to read it in and display it as strings using this:

```<code>public static void readIn(String file) throws IOException {

    Scanner scanner = new Scanner(new File(file));
    while (scanner.hasNext()) {
        String[] columns = scanner.nextLine().split("/t");
        String data = columns[columns.length-1];
        System.out.println(data);
    }
}
</code>```

and displaying something like this:

```<code>04:00:01    0.11    0.04    -0.1    1047470 977.91  91.75
04:00:01    0.32    -0.03   -0.07   1047505 977.34  92.91
04:00:01    0.49    -0.03   -0.08   1047493 978.66  92.17
</code>```

But I'm currently having trouble trying to split each column into separate arrays so that I can process the data (e.g. calculating means). Any idea of how I can do this? Any help would be much appreciated.

Edit: thanks, I've found out a solution that works and also lets me choose which channel it reads specifically. I've also decided to store the data as arrays within the class, here's what I have now:

```<code>public static void readChannel(String file, int channel) throws IOException
{
    List<Double> dataArr = new ArrayList<>();
    Scanner scanner = new Scanner(new File(file));
    while (scanner.hasNext()) {
        String[] columns = scanner.nextLine().split("\t");

        for (int i = channel; i < columns.length; i+=(columns.length-channel)) {
            dataArr.add(Double.parseDouble(columns[i]));
            dataArr.toArray();
        }
    }
}
</code>```

答:
I think you should split your problem in 2:

File reading:

Your program read each line and save it inside a instance of a class defined by you:

```<code>public class MyData {
    private String time;
    private double percent;
    //... and so on
}
public MyData readLine( String line ) {
    String[] columns = line.split("\t");
    MyData md = new MyData();
    md.setTime( columns[ 0 ] );
    md.setPercent( Double.parseDouble(columns[ 1 ]) );
}
public void readFile( File file ) {
    Scanner scanner = new Scanner(file);
    List<MyData> myList = new ArrayList<>();
    while (scanner.hasNext()) {
        MyData md = readLine( scanner.nextLine() );
        myList.add( md );
    }
}
</code>```

Data processing:

After you processed your file, you can create the method you need to process the data:

```<code>int sum = 0;
for ( MyData md : myList ) {
    sum = sum + md.getValue();
}
</code>```

I hope it help.

Body:
For a project I'm working on a fairly big animal dataset with up to 14 parameters of data. I was able to read it in and display it as strings using this:

public static void readIn(String file) throws IOException {

    Scanner scanner = new Scanner(new File(file));
    while (scanner.hasNext()) {
        String[] columns = scanner.nextLine().split("/t");
        String data = columns[columns.length-1];
        System.out.println(data);
    }
}

and displaying something like this:

04:00:01    0.11    0.04    -0.1    1047470 977.91  91.75
04:00:01    0.32    -0.03   -0.07   1047505 977.34  92.91
04:00:01    0.49    -0.03   -0.08   1047493 978.66  92.17

But I'm currently having trouble trying to split each column into separate arrays so that I can process the data (e.g. calculating means). Any idea of how I can do this? Any help would be much appreciated.

Edit: thanks, I've found out a solution that works and also lets me choose which channel it reads specifically. I've also decided to store the data as arrays within the class, here's what I have now:

public static void readChannel(String file, int channel) throws IOException
{
    List<Double> dataArr = new ArrayList<>();
    Scanner scanner = new Scanner(new File(file));
    while (scanner.hasNext()) {
        String[] columns = scanner.nextLine().split("\t");

        for (int i = channel; i < columns.length; i+=(columns.length-channel)) {
            dataArr.add(Double.parseDouble(columns[i]));
            dataArr.toArray();
        }
    }
}

Body:
I think you should split your problem in 2:

File reading:

Your program read each line and save it inside a instance of a class defined by you:

public class MyData {
    private String time;
    private double percent;
    //... and so on
}
public MyData readLine( String line ) {
    String[] columns = line.split("\t");
    MyData md = new MyData();
    md.setTime( columns[ 0 ] );
    md.setPercent( Double.parseDouble(columns[ 1 ]) );
}
public void readFile( File file ) {
    Scanner scanner = new Scanner(file);
    List<MyData> myList = new ArrayList<>();
    while (scanner.hasNext()) {
        MyData md = readLine( scanner.nextLine() );
        myList.add( md );
    }
}

Data processing:

After you processed your file, you can create the method you need to process the data:

int sum = 0;
for ( MyData md : myList ) {
    sum = sum + md.getValue();
}

I hope it help.


问:
Can't access Wordpress site after IP change
I'm running a multi-site wordpress install on a virtual machine in the cloud. The WP didn't have a domain, I was accessing it purely through IP address. Today, I turned the VM off/on and lo and behold, I got a new IP address. Now, I can't access it.

Whenever, I go to the new IP address, Chrome will spin for a few seconds and then load up the old IP address as the URL and display a message saying the site took too long to respond.

I've already done the following:

Updated IP address in wp-config.php file.

Updated IP address in siteurl and home in wp_3_options, wp_2_options, etc.

Updated IP Address in wp_blogs, wp_site, wp_sitemeta, wp_options.

Renamed plugins folder so they wouldn't reload. I have Wordfence installed and there's a column called wp_home_url that contains the old IP, but it's a BLOB.

Not sure what else to check. Does anyone have any ideas as to how to fix this?

Running WP 4.7 on Ubuntu 16.10.

答: Juan was right, I just needed to clear the browser cache. I followed this article to update the URL on a multisite WP installation; https://wpengine.com/support/how-to-change-a-multi-site-primary-domain. The article didn't mention that the browser cache had to be cleared and that's where I got stuck.</p>


问:
Jquery scroll to top of each section with button press not working
Im trying to animate the scroll to each section on button press. I have done lots of research and came across with this:

```<code>$('ul.nav').find('a').click(function () {
    var $href = $(this).attr('href');
     var $anchor = $('#' + $href).offset();
     $('body').animate({scrollTop: $anchor.top});
     return false;
 });
</code>```

But it's not working. It just scroll without the animation. Can somebody help me please?

My HTML code:

```<code><nav id="nav">
    <ul>
        <li class="current"><a href="index.php">Hlavní stránka</a></li>
        <li><a href="#rooms">Naše pokoje</a></li>
        <li><a href="#prizes">Ceník</a></li>
        <li><a href="#footer">Kontakt</a></li>
    </ul>
</nav>
</code>```

答:
You are looking for</p>

```<code>$('#nav ul li a').click(function () {
    $('html, body').animate({
        scrollTop: $("#myDiv").offset().top
    }, 2000);
});
</code>```

Body:
Im trying to animate the scroll to each section on button press. I have done lots of research and came across with this:

$('ul.nav').find('a').click(function () {
    var $href = $(this).attr('href');
     var $anchor = $('#' + $href).offset();
     $('body').animate({scrollTop: $anchor.top});
     return false;
 });

But it's not working. It just scroll without the animation. Can somebody help me please?

My HTML code:

Hlavní stránka

Naše pokoje

Ceník

Kontakt

Body:
You are looking for

$('#nav ul li a').click(function () {
    $('html, body').animate({
        scrollTop: $("#myDiv").offset().top
    }, 2000);
});


问:
Print feature names for SelectKBest where k value is inside param_grid of GridSearchCV
I tried parameter combinations of k from SelectKBest and n_components of PCA inside the param_grid. I'm able to print the k value and n_components using the code below. I'm posting the entire code, so you understand from which list the features are being taken from

```<code>#THE FIRST FEATURE HAS TO BE THE LABEL

featurelist = ['poi', 'exercised_stock_options', 'expenses', 'from_messages',
           'from_poi_to_this_person', 'from_this_person_to_poi', 'other',
           'restricted_stock', 'salary', 'shared_receipt_with_poi',
           'to_messages', 'total_payments', 'total_stock_value',
           'ratio_from_poi', 'ratio_to_poi']

enronml = pd.DataFrame(enron[['poi', 'exercised_stock_options', 'expenses', 'from_messages',
           'from_poi_to_this_person', 'from_this_person_to_poi', 'other',
           'restricted_stock', 'salary', 'shared_receipt_with_poi',
           'to_messages', 'total_payments', 'total_stock_value',
           'ratio_from_poi', 'ratio_to_poi']].copy())

enronml = enronml.to_dict(orient="index")
dataset = enronml

#featureFormat, takes the dictionary as the dataset, converts the first
feature in featurelist into label

data = featureFormat(dataset, featurelist, sort_keys = True)
labels, features = targetFeatureSplit(data)

from sklearn.cross_validation import train_test_split
from sklearn.naive_bayes import GaussianNB

from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(features, labels,
test_size=0.20, random_state=0)

pca = PCA()
gnba = GaussianNB()
steps = [('scaler', MinMaxScaler()),
     ('best', SelectKBest()),
     ('pca', pca),
     ('gnba', gnba)]

pipeline = Pipeline(steps)

parameters = [
{
'best__k':[3],
'pca__n_components': [1,2]
},
{
'best__k':[4],
'pca__n_components': [1,2,3]
},
{
'best__k':[5],
'pca__n_components': [1,2,3,4]
},
]

cv = StratifiedShuffleSplit(test_size=0.2, random_state=42)
gnbawithpca = GridSearchCV(pipeline, param_grid = parameters, cv=cv,
scoring="f1")
gnbawithpca.fit(X_train,y_train)

means = gnbawithpca.cv_results_['mean_test_score']
stds = gnbawithpca.cv_results_['std_test_score']

for mean, std, params in zip(means, stds,
gnbawithpca.cv_results_['params']):
    print("%0.3f (+/-%0.03f) for %r"
          % (mean, std * 2, params))
</code>```

I'm able to get a result like this

```<code>0.480 (+/-0.510) for {'best__k': 3, 'pca__n_components': 1}
0.534 (+/-0.409) for {'best__k': 3, 'pca__n_components': 2}
0.480 (+/-0.510) for {'best__k': 4, 'pca__n_components': 1}
0.534 (+/-0.409) for {'best__k': 4, 'pca__n_components': 2}
0.565 (+/-0.342) for {'best__k': 4, 'pca__n_components': 3}
0.480 (+/-0.510) for {'best__k': 5, 'pca__n_components': 1}
0.513 (+/-0.404) for {'best__k': 5, 'pca__n_components': 2}
0.473 (+/-0.382) for {'best__k': 5, 'pca__n_components': 3}
0.448 (+/-0.353) for {'best__k': 5, 'pca__n_components': 4}
</code>```

I want to know what features were selected, for example, when best_k = 5, I want to know the names of those 5 features.

答:
RESOLVED

When you define the pipeline, to be used in GridSearchCV, you name each step:

```<code>steps = [('scaler', MinMaxScaler()),
     ('best', SelectKBest()),
     ('pca', pca),
     ('gnba', gnba)]

pipeline = Pipeline(steps)
</code>```

you do that for two reasons:

So you can define the parameters in the parameter grid (the names are required to identify which step you are defining the parameters for).

So you can access the attributes of the step from the GridSearchCV object (this answers your question).

```<code>skb_step = gnbawithpca.best_estimator_.named_steps['best']

# Get SelectKBest scores, rounded to 2 decimal places, name them "feature_scores"

feature_scores = ['%.2f' % elem for elem in skb_step.scores_ ]

# Get SelectKBest pvalues, rounded to 3 decimal places, name them "feature_scores_pvalues"

feature_scores_pvalues = ['%.3f' % elem for elem in  skb_step.pvalues_
]

# Get SelectKBest feature names, whose indices are stored in 'skb_step.get_support',

# create a tuple of feature names, scores and pvalues, name it "features_selected_tuple"

features_selected_tuple=[(featurelist[i+1], feature_scores[i],
feature_scores_pvalues[i]) for i in skb_step.get_support(indices=True)]

# Sort the tuple by score, in reverse order

features_selected_tuple = sorted(features_selected_tuple, key=lambda
feature: float(feature[1]) , reverse=True)

# Print

print ' '
print 'Selected Features, Scores, P-Values'
print features_selected_tuple
</code>```

Body:
I tried parameter combinations of k from SelectKBest and n_components of PCA inside the param_grid. I'm able to print the k value and n_components using the code below. I'm posting the entire code, so you understand from which list the features are being taken from

#THE FIRST FEATURE HAS TO BE THE LABEL

featurelist = ['poi', 'exercised_stock_options', 'expenses', 'from_messages',
           'from_poi_to_this_person', 'from_this_person_to_poi', 'other',
           'restricted_stock', 'salary', 'shared_receipt_with_poi',
           'to_messages', 'total_payments', 'total_stock_value',
           'ratio_from_poi', 'ratio_to_poi']

enronml = pd.DataFrame(enron[['poi', 'exercised_stock_options', 'expenses', 'from_messages',
           'from_poi_to_this_person', 'from_this_person_to_poi', 'other',
           'restricted_stock', 'salary', 'shared_receipt_with_poi',
           'to_messages', 'total_payments', 'total_stock_value',
           'ratio_from_poi', 'ratio_to_poi']].copy())

enronml = enronml.to_dict(orient="index")
dataset = enronml

#featureFormat, takes the dictionary as the dataset, converts the first
feature in featurelist into label

data = featureFormat(dataset, featurelist, sort_keys = True)
labels, features = targetFeatureSplit(data)

from sklearn.cross_validation import train_test_split
from sklearn.naive_bayes import GaussianNB

from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(features, labels,
test_size=0.20, random_state=0)

pca = PCA()
gnba = GaussianNB()
steps = [('scaler', MinMaxScaler()),
     ('best', SelectKBest()),
     ('pca', pca),
     ('gnba', gnba)]

pipeline = Pipeline(steps)

parameters = [
{
'best__k':[3],
'pca__n_components': [1,2]
},
{
'best__k':[4],
'pca__n_components': [1,2,3]
},
{
'best__k':[5],
'pca__n_components': [1,2,3,4]
},
]

cv = StratifiedShuffleSplit(test_size=0.2, random_state=42)
gnbawithpca = GridSearchCV(pipeline, param_grid = parameters, cv=cv,
scoring="f1")
gnbawithpca.fit(X_train,y_train)

means = gnbawithpca.cv_results_['mean_test_score']
stds = gnbawithpca.cv_results_['std_test_score']

for mean, std, params in zip(means, stds,
gnbawithpca.cv_results_['params']):
    print("%0.3f (+/-%0.03f) for %r"
          % (mean, std * 2, params))

I'm able to get a result like this

0.480 (+/-0.510) for {'best__k': 3, 'pca__n_components': 1}
0.534 (+/-0.409) for {'best__k': 3, 'pca__n_components': 2}
0.480 (+/-0.510) for {'best__k': 4, 'pca__n_components': 1}
0.534 (+/-0.409) for {'best__k': 4, 'pca__n_components': 2}
0.565 (+/-0.342) for {'best__k': 4, 'pca__n_components': 3}
0.480 (+/-0.510) for {'best__k': 5, 'pca__n_components': 1}
0.513 (+/-0.404) for {'best__k': 5, 'pca__n_components': 2}
0.473 (+/-0.382) for {'best__k': 5, 'pca__n_components': 3}
0.448 (+/-0.353) for {'best__k': 5, 'pca__n_components': 4}

I want to know what features were selected, for example, when best_k = 5, I want to know the names of those 5 features.

Body:
RESOLVED

When you define the pipeline, to be used in GridSearchCV, you name each step:

steps = [('scaler', MinMaxScaler()),
     ('best', SelectKBest()),
     ('pca', pca),
     ('gnba', gnba)]

pipeline = Pipeline(steps)

you do that for two reasons:

So you can define the parameters in the parameter grid (the names are required to identify which step you are defining the parameters for).

So you can access the attributes of the step from the GridSearchCV object (this answers your question).

skb_step = gnbawithpca.best_estimator_.named_steps['best']

# Get SelectKBest scores, rounded to 2 decimal places, name them "feature_scores"

feature_scores = ['%.2f' % elem for elem in skb_step.scores_ ]

# Get SelectKBest pvalues, rounded to 3 decimal places, name them "feature_scores_pvalues"

feature_scores_pvalues = ['%.3f' % elem for elem in  skb_step.pvalues_
]

# Get SelectKBest feature names, whose indices are stored in 'skb_step.get_support',

# create a tuple of feature names, scores and pvalues, name it "features_selected_tuple"

features_selected_tuple=[(featurelist[i+1], feature_scores[i],
feature_scores_pvalues[i]) for i in skb_step.get_support(indices=True)]

# Sort the tuple by score, in reverse order

features_selected_tuple = sorted(features_selected_tuple, key=lambda
feature: float(feature[1]) , reverse=True)

# Print

print ' '
print 'Selected Features, Scores, P-Values'
print features_selected_tuple


问:
How to fix: Error CREATEing SolrCore 'gettingstarted': Unable to create core
I'm getting this error when I try to create a new core in solr.

```<code>root@ubuntu:/opt/solr# bin/solr create -c gettingstarted -n data_driven_schema_configs

Setup new core instance directory:
/var/solr/data/gettingstarted

Creating new core 'gettingstarted' using command:
http://localhost:8983/solr/admin/cores?action=CREATE&name=gettingstarted&instanceDir=gettingstarted

Failed to create core 'gettingstarted' due to: Error CREATEing SolrCore 'gettingstarted': Unable to create core [gettingstarted] Caused by: /var/solr/data/gettingstarted/data
</code>```

Also, if I try to create alternatively, It gives me same error:

```<code>root@ubuntu:/opt/solr# bin/solr create -c mycore

Setup new core instance directory:
/var/solr/data/mycore

Creating new core 'mycore' using command:
http://localhost:8983/solr/admin/cores?action=CREATE&name=mycore&instanceDir=mycore

Failed to create core 'mycore' due to: Error CREATEing SolrCore 'mycore': Unable to create core [mycore] Caused by: /var/solr/data/mycore/data
</code>```

In browser, when I try to access solr admin panel, it displays a notification like:

```<code>SolrCore Initialization Failures

opt/solr/example/exampledocs/*.xml: org.apache.solr.common.SolrException:org.apache.solr.common.SolrException: /var/solr/data/opt/solr/example/exampledocs/*.xml/data
</code>```

snapshot is attached.

答:
I found this as the solution:

```<code>sudo su - solr -c "/opt/solr/bin/solr create -c mycore"
</code>```

More information here: https://www.howtoforge.com/tutorial/how-to-install-and-configure-solr-on-ubuntu-1604/

Body:
I'm getting this error when I try to create a new core in solr.

root@ubuntu:/opt/solr# bin/solr create -c gettingstarted -n data_driven_schema_configs

Setup new core instance directory:
/var/solr/data/gettingstarted

Creating new core 'gettingstarted' using command:
http://localhost:8983/solr/admin/cores?action=CREATE&name=gettingstarted&instanceDir=gettingstarted

Failed to create core 'gettingstarted' due to: Error CREATEing SolrCore 'gettingstarted': Unable to create core [gettingstarted] Caused by: /var/solr/data/gettingstarted/data

Also, if I try to create alternatively, It gives me same error:

root@ubuntu:/opt/solr# bin/solr create -c mycore

Setup new core instance directory:
/var/solr/data/mycore

Creating new core 'mycore' using command:
http://localhost:8983/solr/admin/cores?action=CREATE&name=mycore&instanceDir=mycore

Failed to create core 'mycore' due to: Error CREATEing SolrCore 'mycore': Unable to create core [mycore] Caused by: /var/solr/data/mycore/data

In browser, when I try to access solr admin panel, it displays a notification like:

SolrCore Initialization Failures

opt/solr/example/exampledocs/*.xml: org.apache.solr.common.SolrException:org.apache.solr.common.SolrException: /var/solr/data/opt/solr/example/exampledocs/*.xml/data

snapshot is attached.

Body:
I found this as the solution:

sudo su - solr -c "/opt/solr/bin/solr create -c mycore"

More information here: https://www.howtoforge.com/tutorial/how-to-install-and-configure-solr-on-ubuntu-1604/


答:
You just used a wrong selector...

Try with this:

```<code>$('#nav ul li a').click(function(e) {

    // Get the href
    var $href = $(this).attr('href');

    // Animate only if the href contains the # character.
    if($href.substr(0,1) == "#"){}
      e.preventDefault();

      // Here, the # sign is already present.
      var $anchor = $($href).offset();
      $('body').animate({scrollTop: $anchor.top},1000);  // Set a delay here, in milliseconds.
    }
});
</code>```

And I would use preventDefault() instead of return false;

EDITED to care about the first anchor which looks like to be a "real" link to trigger a page load.

Title: Jquery scroll to top of each section with button press not working

Body:
You just used a wrong selector...

Try with this:

$('#nav ul li a').click(function(e) {

    // Get the href
    var $href = $(this).attr('href');

    // Animate only if the href contains the # character.
    if($href.substr(0,1) == "#"){}
      e.preventDefault();

      // Here, the # sign is already present.
      var $anchor = $($href).offset();
      $('body').animate({scrollTop: $anchor.top},1000);  // Set a delay here, in milliseconds.
    }
});

And I would use preventDefault() instead of return false;

EDITED to care about the first anchor which looks like to be a "real" link to trigger a page load.


问:
Scilab plotting functions with if
I have a problen in scilab
How can I plot functions containing if and < like

```<code>function y = alpha(t)
   if (t < 227.8) then
       y = 0.75;
   elseif (t < 300) then
       y = 2.8 - 0.009 .* t;
   else
       y = 0.1;
   end
endfunction
</code>```

and

```<code>function [r]=minus_alpha(t)
    r = 1 - alpha(t)
endfunction
</code>```

When I use

```<code>x = linspace(0,300)
plot(x, alpha(x))
</code>```

I got the error message

```<code>WARNING: Transposing row vector X to get compatible dimensions
plot2d: falsche Größe für Eingangsargument: inkompatible Größen.
Error 999 : in plot2d called by plot
</code>```

Sorry for german mix. Thank you.

答:
You can avoid explicit loop and be more efficient using the followin code </p>

```<code>function y = alpha(t)
   y=0.1*ones(t);
   y(t<227.8)=0.75;
   i=t>=227.8&t<300;
   y(i)=2.8 - 0.009 .* t(i);
endfunction
</code>```

Title: Scilab plotting functions with if

Body:
I have a problen in scilab
How can I plot functions containing if and < like

function y = alpha(t)
   if (t < 227.8) then
       y = 0.75;
   elseif (t < 300) then
       y = 2.8 - 0.009 .* t;
   else
       y = 0.1;
   end
endfunction

and

function [r]=minus_alpha(t)
    r = 1 - alpha(t)
endfunction

When I use

x = linspace(0,300)
plot(x, alpha(x))

I got the error message

WARNING: Transposing row vector X to get compatible dimensions
plot2d: falsche Größe für Eingangsargument: inkompatible Größen.
Error 999 : in plot2d called by plot

Sorry for german mix. Thank you.

Body:
You can avoid explicit loop and be more efficient using the followin code

function y = alpha(t)
   y=0.1*ones(t);
   y(t<227.8)=0.75;
   i=t>=227.8&t<300;
   y(i)=2.8 - 0.009 .* t(i);
endfunction


问:
jasperserver 6.3.0 report url generation
I'm developing a web application using java, primefaces and bootsfaces. I want to integrate jasperserver for report generation, so I installed Jasperserver 6.3.0 on Tomcat 8.5. I created report and report unit on repository, added a button on my xhtml page binded to a method which returns report url:

```<code>http://localhost:9000/jasperserver/flow.html?_flowId=viewReportFlow&ParentFolderUri=/CUSTOMER_FOLDER&reportUnit=/CUSTOMER_FOLDER/REPORT_UNIT_NAME&j_username=jasperadmin&j_password=jasperadmin&docHeaderId=91&output=pdf
</code>```

This url opens jasperserver web interface but it shows a dialog with report parameter filled.

Where is the problem?

答:
It's always a bit confusing if questions are answered in the comments section, so let me repeat the answer given by @xc93hil themselves:

The intermediate dialog was shown because the parameter "always prompt" was activated. Unflagging it in the JasperServer web interface solved the problem.

Body:
I'm developing a web application using java, primefaces and bootsfaces. I want to integrate jasperserver for report generation, so I installed Jasperserver 6.3.0 on Tomcat 8.5. I created report and report unit on repository, added a button on my xhtml page binded to a method which returns report url:

http://localhost:9000/jasperserver/flow.html?_flowId=viewReportFlow&ParentFolderUri=/CUSTOMER_FOLDER&reportUnit=/CUSTOMER_FOLDER/REPORT_UNIT_NAME&j_username=jasperadmin&j_password=jasperadmin&docHeaderId=91&output=pdf

This url opens jasperserver web interface but it shows a dialog with report parameter filled.

Where is the problem?


问:
Inserting unknown number of rows into a MySQL database
I'm writing an online application form and one of the pieces of data I'm trying to collect is the users education history; school name, school city, years they were there and achievements while there.  This data could be collected for anywhere between zero to about four different schools and the user will be dynamically adding more fields if required.

My question is how would this be captured within the database since I don't know how many schools the user will be adding?  Can it be done in one table, or do I need to create multiple tables and capture the education data in a separate table?

Any help or pointers would be greatly appreciated.

Thanks.

答:
You need separate tables. One with a row per person, and another with a row per school. Schools can be related to people using either a personID in the school table, or an additional table representing the "person attended school" relationship.

Any association of one entity (person) with multiple other entities (schools) requires more than one table.A general rule to follow is one table per "entity", plus additional tables for many-to-many relationships.

ContentLicense: CC BY-SA 2.5


问:
Expand DIV to its UL content
I have a div container and a ul within it. I want that the div be expanded to its content ul. I've tried everything I found (overflow:hidden, clearfix etc ...), but nothing worked.

UPDATE: originally this is a slider with a crossfade effect, where the images are overlapped with each other. So, the solution which causes that the images will be in a column (same left, but different top values) doesn't good for me.
Please, show me the pure HTML/CSS solution, without JS.

.slider {
  position: relative;
  padding: 0;
  margin: 0 auto;
  border: 1px solid black;
}

.slider img {
  max-width: 100%;
  display: block;
}

ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

li {
  position: absolute;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="slider" style="max-width: 880px;">
  <ul>
    <li><img src="https://placeimg.com/400/200/any" style="width:100%"></li>
    <li><img src="https://placeimg.com/400/200/tech" style="width:100%"></li>
    <li><img src="https://placeimg.com/400/200/animals" style="width:100%"></li>
  </ul>
</div></code>```

答:
Use following css:

```<code>.slider {
  width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
    border: 1px solid black;
}

ul {
   list-style: none;
    height: 100%;
    width: 500%;
    overflow: hidden;
    position: relative;
    left: 0px;
}

li {
    width: 20%;
    float: left;
    position: relative;
}
</code>```

For creating pure CSS slider check this:
http://www.blogohblog.com/cool-slider-css3-html/

Title: Expand DIV to its UL content

Body:
Use following css:

.slider {
  width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
    border: 1px solid black;
}

ul {
   list-style: none;
    height: 100%;
    width: 500%;
    overflow: hidden;
    position: relative;
    left: 0px;
}

li {
    width: 20%;
    float: left;
    position: relative;
}

For creating pure CSS slider check this:
http://www.blogohblog.com/cool-slider-css3-html/


问:
What is the `__identify__` route that Capybara looks for?
When I disable Webmock or VCR I get the following error in my Rspec tests. Apparently it's looking for an /__identify__ route.

```<code>          WebMock::NetConnectNotAllowedError:
        Real HTTP connections are disabled. Unregistered request: GET http://127.0.0.1:51768/__identify__ with headers {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}
</code>```

A bit of googling shows that this is something specific to Capybara, but I wasn't able to find out what exactly it's trying to do and why it might need to be stubbed.

Thanks!

答: You shouldn't be stubbing it - you should be allowing it (like all requests to your app).  Its a route added via middleware Capybara installs when it starts up the "server" thread running your app. Capybara needs it to know the app has started up and is ready to go.</p>

Body:
When I disable Webmock or VCR I get the following error in my Rspec tests. Apparently it's looking for an /__identify__ route.

          WebMock::NetConnectNotAllowedError:
        Real HTTP connections are disabled. Unregistered request: GET http://127.0.0.1:51768/__identify__ with headers {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}

A bit of googling shows that this is something specific to Capybara, but I wasn't able to find out what exactly it's trying to do and why it might need to be stubbed.

Thanks!


问:
How can I accept TCP-connections at the same <ip:port> in many threads?
How can I accept TCP-connections at the same ip:port in many threads in one process on Linux (kernel 3.16)?

Can I use for this one socket-acceptor per thread (i.e. 4 socket-acceptors in 4 threads)?

I.e. every thread has its own acceptor socket with the same ip_addr:port, instead of one acceptor socket shared for all threads.

Should I use SO_REUSEPORT and SO_REUSEADDR for this?

答:
I did the exact same thing when writing my server.  You have a main method that accepts incoming connections to the machine, and threads to handle each connection.  Every time a new machine connects to the server, a new connection object is created. From your main method, you have to spawn a new thread for every connection, and pass that connection object as a parameter to the thread.  For example here's an abstraction:

```<code>void acceptConnections()
{
    while(true)
    {
        connection = socket.accept()
        createNewThread(threadMethod, connection)
    }
}
</code>```

In the thread you spawned you can receive data from the connection object just like normal.  I cannot give more detail without knowing what language you are working in

Body:
I did the exact same thing when writing my server.  You have a main method that accepts incoming connections to the machine, and threads to handle each connection.  Every time a new machine connects to the server, a new connection object is created. From your main method, you have to spawn a new thread for every connection, and pass that connection object as a parameter to the thread.  For example here's an abstraction:

void acceptConnections()
{
    while(true)
    {
        connection = socket.accept()
        createNewThread(threadMethod, connection)
    }
}

In the thread you spawned you can receive data from the connection object just like normal.  I cannot give more detail without knowing what language you are working in


问:
Variable not defined error, and if statement doesn't execute
I'm trying to code horoscope that comes after the user input the birth month and day.

```<code>print("To figure out your horoscope, enter the following questions")
month = int(input("what month were you born(january,december,august: "))
days = int(input("what day were you born(2,4,12: "))
if month == 'december':

    astro_sign = 'Sagittarius are nice people' if (day < 22) else 'Capricon are adventurous'
print(astro_sign)
</code>```

However, every time I execute the code, it gives me an error:

```<code>print(astro_sign)
NameError: name 'astro_sign' is not defined
</code>```

Currently, I only put one month which is 12 and day is below 22, later on when one piece of this code works, I'm going to add more months. Can anyone please help me?

答:
```<code>print("Please enter your birthday")

month = int(input("month: "))

day = int(input("day: "))

if month == '12':

      print('Sagittarius are nice people')

if day < 22:

      print('Capricon are adventurous')
</code>```

see if this actually works for you (Tell me if I got it all wrong please)

Body:
I'm trying to code horoscope that comes after the user input the birth month and day.

print("To figure out your horoscope, enter the following questions")
month = int(input("what month were you born(january,december,august: "))
days = int(input("what day were you born(2,4,12: "))
if month == 'december':

    astro_sign = 'Sagittarius are nice people' if (day < 22) else 'Capricon are adventurous'
print(astro_sign)

However, every time I execute the code, it gives me an error:

print(astro_sign)
NameError: name 'astro_sign' is not defined

Currently, I only put one month which is 12 and day is below 22, later on when one piece of this code works, I'm going to add more months. Can anyone please help me?

Body:
print("Please enter your birthday")

month = int(input("month: "))

day = int(input("day: "))

if month == '12':

      print('Sagittarius are nice people')

if day < 22:

      print('Capricon are adventurous')

see if this actually works for you (Tell me if I got it all wrong please)