问:
Java Android - finding file extension
So I'm trying to get the extension from a file so that I can compare it to a string to see if the extension matches the extension I want to find. However, at the moment I think I am able to get the extension but then comparing it with the one I want to find is causing my app to crash and close immediately. Also, I want it to be able to cope with files that don't have extensions and just pass them off as files that don't match the wanted file extension. Below is the code snippet that performs this, hopefully someone can explain to me what I'm doing wrong here.

```<code>File directory =  getFilesDir();
File[] listOfFiles = directory.listFiles();
String[] fileArray;
ListView fileList = (ListView) findViewById(R.id.fileList);
fileArray = new String[listOfFiles.length];
for (int i = 0; i < listOfFiles.length; ++i){
    String extension = MimeTypeMap.getFileExtensionFromUrl(listOfFiles[i].getAbsolutePath());
    if (extension.equals("txt")) {
        fileArray[i] = listOfFiles[i].getName();
    }
</code>```

P.S: I'm new to Java and Android Development so please be nice to me. :)

EDIT:

Okay, I'm being asked to post my errors, I don't really know how to post them in a nice way but this is the best I can do.

03-29 15:39:32.437 7671-7671/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_0_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_0_apk.apk@classes.dex) because non-0 exit status
03-29 15:39:32.479 7671-7671/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_1_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_1_apk.apk@classes.dex) because non-0 exit status
03-29 15:39:32.522 7671-7671/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_2_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_2_apk.apk@classes.dex) because non-0 exit status
03-29 15:39:32.571 7671-7671/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_3_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_3_apk.apk@classes.dex) because non-0 exit status
03-29 15:39:32.618 7671-7671/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_4_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_4_apk.apk@classes.dex) because non-0 exit status
03-29 15:39:32.671 7671-7671/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_5_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_5_apk.apk@classes.dex) because non-0 exit status
03-29 15:39:32.724 7671-7671/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_6_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_6_apk.apk@classes.dex) because non-0 exit status
03-29 15:39:32.766 7671-7671/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_7_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_7_apk.apk@classes.dex) because non-0 exit status
03-29 15:39:32.809 7671-7671/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_8_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_8_apk.apk@classes.dex) because non-0 exit status
03-29 15:39:32.884 7671-7671/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_9_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_9_apk.apk@classes.dex) because non-0 exit status
03-29 15:39:32.887 7671-7671/? W/System: ClassLoader referenced unknown path: /data/app/com.removedforprivacy.appname-1/lib/arm64
03-29 15:39:32.894 7671-7671/? I/InstantRun: Starting Instant Run Server for com.removedforprivacy.appname
03-29 15:39:33.061 7671-7671/? I/HwCust: Constructor found for class android.app.HwCustHwWallpaperManagerImpl
03-29 15:39:33.276 7671-7671/? I/HwSecImmHelper: mSecurityInputMethodService is null
03-29 15:39:33.349 7671-7727/? I/OpenGLRenderer: Initialized EGL, version 1.4
03-29 15:39:33.396 7671-7671/? W/art: Before Android 4.1, method int android.support.v7.internal.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
03-29 15:39:34.694 7671-7677/? I/art: Ignoring second debugger -- accepting and dropping

The above is the log from when the app is started. This is before the problem area is loaded. The below is when I press the button that triggers the running of the problem area.

03-29 15:42:50.550 10762-10762/? I/art: Late-enabling -Xcheck:jni
03-29 15:42:50.654 10762-10762/com.removedforprivacy.appname W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_dependencies_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_dependencies_apk.apk@classes.dex) because non-0 exit status
03-29 15:42:50.808 10762-10762/com.removedforprivacy.appname W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_0_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_0_apk.apk@classes.dex) because non-0 exit status
03-29 15:42:50.851 10762-10762/com.removedforprivacy.appname W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_1_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_1_apk.apk@classes.dex) because non-0 exit status
03-29 15:42:50.895 10762-10762/com.removedforprivacy.appname W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_2_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_2_apk.apk@classes.dex) because non-0 exit status
03-29 15:42:50.953 10762-10762/com.removedforprivacy.appname W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_3_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_3_apk.apk@classes.dex) because non-0 exit status
03-29 15:42:51.008 10762-10762/com.removedforprivacy.appname W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_4_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_4_apk.apk@classes.dex) because non-0 exit status
03-29 15:42:51.072 10762-10762/com.removedforprivacy.appname W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_5_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_5_apk.apk@classes.dex) because non-0 exit status
03-29 15:42:51.151 10762-10762/com.removedforprivacy.appname W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_6_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_6_apk.apk@classes.dex) because non-0 exit status
03-29 15:42:51.197 10762-10762/com.removedforprivacy.appname W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_7_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_7_apk.apk@classes.dex) because non-0 exit status
03-29 15:42:51.241 10762-10762/com.removedforprivacy.appname W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_8_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_8_apk.apk@classes.dex) because non-0 exit status
03-29 15:42:51.315 10762-10762/com.removedforprivacy.appname W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_9_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_9_apk.apk@classes.dex) because non-0 exit status
03-29 15:42:51.318 10762-10762/com.removedforprivacy.appname W/System: ClassLoader referenced unknown path: /data/app/com.removedforprivacy.appname-1/lib/arm64
03-29 15:42:51.326 10762-10762/com.removedforprivacy.appname I/InstantRun: Starting Instant Run Server for com.removedforprivacy.appname

One last thing, when I press the button, there is another bit of logs shown which I think is different to the above but it very quickly disappears so I can't copy it in. Hope that helps.

答:
Use ends with to get extension from whole string </p>

```<code>File directory =  getFilesDir();
File[] listOfFiles = directory.listFiles();
String[] fileArray;

fileArray = new String[listOfFiles.length];
 if (listOfFiles != null) {

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

             if (listOfFiles[i].getName().endsWith(".txt")){
                          //Do what ever u want

          }
        }
    }
</code>```

Title: Java Android - finding file extension

Body:
So I'm trying to get the extension from a file so that I can compare it to a string to see if the extension matches the extension I want to find. However, at the moment I think I am able to get the extension but then comparing it with the one I want to find is causing my app to crash and close immediately. Also, I want it to be able to cope with files that don't have extensions and just pass them off as files that don't match the wanted file extension. Below is the code snippet that performs this, hopefully someone can explain to me what I'm doing wrong here.

File directory =  getFilesDir();
File[] listOfFiles = directory.listFiles();
String[] fileArray;
ListView fileList = (ListView) findViewById(R.id.fileList);
fileArray = new String[listOfFiles.length];
for (int i = 0; i < listOfFiles.length; ++i){
    String extension = MimeTypeMap.getFileExtensionFromUrl(listOfFiles[i].getAbsolutePath());
    if (extension.equals("txt")) {
        fileArray[i] = listOfFiles[i].getName();
    }

P.S: I'm new to Java and Android Development so please be nice to me. :)

EDIT:

Okay, I'm being asked to post my errors, I don't really know how to post them in a nice way but this is the best I can do.

03-29 15:39:32.437 7671-7671/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_0_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_0_apk.apk@classes.dex) because non-0 exit status
03-29 15:39:32.479 7671-7671/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_1_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_1_apk.apk@classes.dex) because non-0 exit status
03-29 15:39:32.522 7671-7671/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_2_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_2_apk.apk@classes.dex) because non-0 exit status
03-29 15:39:32.571 7671-7671/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_3_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_3_apk.apk@classes.dex) because non-0 exit status
03-29 15:39:32.618 7671-7671/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_4_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_4_apk.apk@classes.dex) because non-0 exit status
03-29 15:39:32.671 7671-7671/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_5_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_5_apk.apk@classes.dex) because non-0 exit status
03-29 15:39:32.724 7671-7671/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_6_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_6_apk.apk@classes.dex) because non-0 exit status
03-29 15:39:32.766 7671-7671/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_7_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_7_apk.apk@classes.dex) because non-0 exit status
03-29 15:39:32.809 7671-7671/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_8_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_8_apk.apk@classes.dex) because non-0 exit status
03-29 15:39:32.884 7671-7671/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_9_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_9_apk.apk@classes.dex) because non-0 exit status
03-29 15:39:32.887 7671-7671/? W/System: ClassLoader referenced unknown path: /data/app/com.removedforprivacy.appname-1/lib/arm64
03-29 15:39:32.894 7671-7671/? I/InstantRun: Starting Instant Run Server for com.removedforprivacy.appname
03-29 15:39:33.061 7671-7671/? I/HwCust: Constructor found for class android.app.HwCustHwWallpaperManagerImpl
03-29 15:39:33.276 7671-7671/? I/HwSecImmHelper: mSecurityInputMethodService is null
03-29 15:39:33.349 7671-7727/? I/OpenGLRenderer: Initialized EGL, version 1.4
03-29 15:39:33.396 7671-7671/? W/art: Before Android 4.1, method int android.support.v7.internal.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
03-29 15:39:34.694 7671-7677/? I/art: Ignoring second debugger -- accepting and dropping

The above is the log from when the app is started. This is before the problem area is loaded. The below is when I press the button that triggers the running of the problem area.

03-29 15:42:50.550 10762-10762/? I/art: Late-enabling -Xcheck:jni
03-29 15:42:50.654 10762-10762/com.removedforprivacy.appname W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_dependencies_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_dependencies_apk.apk@classes.dex) because non-0 exit status
03-29 15:42:50.808 10762-10762/com.removedforprivacy.appname W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_0_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_0_apk.apk@classes.dex) because non-0 exit status
03-29 15:42:50.851 10762-10762/com.removedforprivacy.appname W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_1_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_1_apk.apk@classes.dex) because non-0 exit status
03-29 15:42:50.895 10762-10762/com.removedforprivacy.appname W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_2_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_2_apk.apk@classes.dex) because non-0 exit status
03-29 15:42:50.953 10762-10762/com.removedforprivacy.appname W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_3_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_3_apk.apk@classes.dex) because non-0 exit status
03-29 15:42:51.008 10762-10762/com.removedforprivacy.appname W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_4_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_4_apk.apk@classes.dex) because non-0 exit status
03-29 15:42:51.072 10762-10762/com.removedforprivacy.appname W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_5_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_5_apk.apk@classes.dex) because non-0 exit status
03-29 15:42:51.151 10762-10762/com.removedforprivacy.appname W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_6_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_6_apk.apk@classes.dex) because non-0 exit status
03-29 15:42:51.197 10762-10762/com.removedforprivacy.appname W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_7_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_7_apk.apk@classes.dex) because non-0 exit status
03-29 15:42:51.241 10762-10762/com.removedforprivacy.appname W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_8_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_8_apk.apk@classes.dex) because non-0 exit status
03-29 15:42:51.315 10762-10762/com.removedforprivacy.appname W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.removedforprivacy.appname-1/split_lib_slice_9_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.removedforprivacy.appname-1@split_lib_slice_9_apk.apk@classes.dex) because non-0 exit status
03-29 15:42:51.318 10762-10762/com.removedforprivacy.appname W/System: ClassLoader referenced unknown path: /data/app/com.removedforprivacy.appname-1/lib/arm64
03-29 15:42:51.326 10762-10762/com.removedforprivacy.appname I/InstantRun: Starting Instant Run Server for com.removedforprivacy.appname

One last thing, when I press the button, there is another bit of logs shown which I think is different to the above but it very quickly disappears so I can't copy it in. Hope that helps.

Body:
Use ends with to get extension from whole string

File directory =  getFilesDir();
File[] listOfFiles = directory.listFiles();
String[] fileArray;

fileArray = new String[listOfFiles.length];
 if (listOfFiles != null) {

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

             if (listOfFiles[i].getName().endsWith(".txt")){
                          //Do what ever u want

          }
        }
    }


来源: stackexchange

问:
replacement of ApostropheFilterFactory in solr 5.3.1
I need to remove apostrophe from the words before indexing. For eg I want Bachelor's to become Bachelor . I used solr.ApostropheFilterFactory for that , but I think , this filter got deprecated after solr4 and i am using solr5.
This is how I used it

```<code><analyzer>
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.ApostropheFilterFactory"/>
</analyzer>
</code>```

I have also used StandardFilterFactory

```<code><fieldType name="text" class="solr.TextField">
  <analyzer type="index">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StandardFilterFactory"/>
  </analyzer>
</fieldType>
</code>```

Both these are not working for me. Can Anyone suggest me Anything. Thanks in advance!

答:
Use Word Delimiter Filter

This filter splits tokens at word delimiters.

The rules for determining delimiters are determined as follows:

```<code><fieldType name="text" class="solr.TextField">
  <analyzer>
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.WordDelimiterFilterFactory"/>
  </analyzer>
</fieldType>
</code>```

A change in case within a word: "CamelCase" -> "Camel", "Case". This can be disabled by setting splitOnCaseChange="0".

A transition from alpha to numeric characters or vice versa: "Gonzo5000" -> "Gonzo", "5000" "4500XL" -> "4500", "XL". This can be disabled by setting splitOnNumerics="0".

Non-alphanumeric characters (discarded): "hot-spot" -> "hot", "spot"

A trailing "'s" is removed: "O'Reilly's" -> "O", "Reilly"
Any leading or trailing delimiters are discarded: "--hot-spot--" -> "hot", "spot"

Or

Classic Filter

This filter takes the output of the Classic Tokenizer and strips periods from acronyms and "'s" from possessives.

```<code><fieldType name="text" class="solr.TextField">
  <analyzer>
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.ClassicFilterFactory"/>
  </analyzer>
</fieldType>
</code>```

Note : If you provide type="index" in analyzer tag then analyzer used for index time

ContentLicense: CC BY-SA 3.0

Body:
I need to remove apostrophe from the words before indexing. For eg I want Bachelor's to become Bachelor . I used solr.ApostropheFilterFactory for that , but I think , this filter got deprecated after solr4 and i am using solr5.
This is how I used it

<analyzer>
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.ApostropheFilterFactory"/>
</analyzer>

I have also used StandardFilterFactory

<fieldType name="text" class="solr.TextField">
  <analyzer type="index">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StandardFilterFactory"/>
  </analyzer>
</fieldType>

Both these are not working for me. Can Anyone suggest me Anything. Thanks in advance!

Body:
Use Word Delimiter Filter

This filter splits tokens at word delimiters.

The rules for determining delimiters are determined as follows:

<fieldType name="text" class="solr.TextField">
  <analyzer>
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.WordDelimiterFilterFactory"/>
  </analyzer>
</fieldType>

A change in case within a word: "CamelCase" -> "Camel", "Case". This can be disabled by setting splitOnCaseChange="0".

A transition from alpha to numeric characters or vice versa: "Gonzo5000" -> "Gonzo", "5000" "4500XL" -> "4500", "XL". This can be disabled by setting splitOnNumerics="0".

Non-alphanumeric characters (discarded): "hot-spot" -> "hot", "spot"

A trailing "'s" is removed: "O'Reilly's" -> "O", "Reilly"
Any leading or trailing delimiters are discarded: "--hot-spot--" -> "hot", "spot"

Or

Classic Filter

This filter takes the output of the Classic Tokenizer and strips periods from acronyms and "'s" from possessives.

<fieldType name="text" class="solr.TextField">
  <analyzer>
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.ClassicFilterFactory"/>
  </analyzer>
</fieldType>

Note : If you provide type="index" in analyzer tag then analyzer used for index time


问:
Incrementing from 0 to 100 in assembly language
This is kinda oddball, but I was poking around with the GNU assembler today (I want to be able to at least read the syntax), and was trying to get this little contrived example of mine to work. Namely I just want to go from 0 to 100, printing out numbers all the while. So a few minutes later I come up with this:

```<code># count.s: print the numbers from 0 to 100.
    .text
string: .asciz "%d\n"
    .globl _main

_main:
    movl    $0, %eax # The starting point/current value.
    movl    $100,   %ebx # The ending point.

_loop:
    # Display the current value.
    pushl   %eax
    pushl   $string
    call     _printf
    addl     $8, %esp

    # Check against the ending value.
    cmpl    %eax, %ebx
    je    _end

    # Increment the current value.
    incl    %eax
    jmp _loop

_end:
</code>```

All I get from this is 3 printed over and over again. Like I said, just a little contrived example, so don't worry too much about it, it's not a life or death problem.

(The formatting's a little messed up, but nothing major).

答:
You can safely use registers that are "callee-saved" without having to save them yourself. On x86 these are edi, esi, and ebx; other architectures have more.

These are documented in the ABI references: http://math-atlas.sourceforge.net/devel/assembly/

OwnerDisplayName: Bernard

ContentLicense: CC BY-SA 2.5

Body:
This is kinda oddball, but I was poking around with the GNU assembler today (I want to be able to at least read the syntax), and was trying to get this little contrived example of mine to work. Namely I just want to go from 0 to 100, printing out numbers all the while. So a few minutes later I come up with this:

# count.s: print the numbers from 0 to 100.
    .text
string: .asciz "%d\n"
    .globl _main

_main:
    movl    $0, %eax # The starting point/current value.
    movl    $100,   %ebx # The ending point.

_loop:
    # Display the current value.
    pushl   %eax
    pushl   $string
    call     _printf
    addl     $8, %esp

    # Check against the ending value.
    cmpl    %eax, %ebx
    je    _end

    # Increment the current value.
    incl    %eax
    jmp _loop

_end:

All I get from this is 3 printed over and over again. Like I said, just a little contrived example, so don't worry too much about it, it's not a life or death problem.

(The formatting's a little messed up, but nothing major).

LastEditorDisplayName: Bernard

OwnerDisplayName: alex strange


问:
Is there any reason to ditch javascript flash embedding methods in 2011?
The benefits of embedding flash with JS to my knowledge:

ability to query navigator object and see what flash versions are installed, possibly branch out on that and feed different content based on this

consistent method of attaching flash, as the script keeps the markup and usually you just need to specify the src, flashvars, dimensions

save time by relying on helper utilities to embed the swf and not worry about intricate details

ability to provide consistent fallback if embedding multiple objects per site.

The disadvantages:

devices with no flash but JS enabled will completely fail

people get lazy and don't provide fallback content

code is a mess if it needs to be cross-browser compatible. there are various bugs with common embed ( even youtube's ) and the "best" cross-browser seems to be nesting an object in an object per this. I realize though, I can use a server-side method and define the embedding code once and change it in one area, but this makes it not embeddable/usable in CMS textareas.

The pros seem to outweigh the cons. I haven't really worked enough with mobile content to get an accurate opinion. Can anyone think of reasons why/why not?

答:
I don't see a good reason to ditch JS flash embedding. SWFObject is pretty ubiquitous these days (pseudo-standard even!), and even Adobe recommends using it.

It makes sticky things like handling player version requirements and allowing the user to update their Flash plugin easy and straight forward.

SWFObject aside, it's my opinion that being able to use client side logic to embed content for any plugin will always be the way to go; it affords more opportunity to read into your user's environment, and deliver the appropriate content.

I suppose an argument can be made that it adds yet another requirement on the client side to deliver your content, but I think the vast majority of user's will have JS enabled... especially the users who are willing to consume Flash media.

Hope that helps :)


问:
Python's tab spacing
So I have a program that prints out two "fish" per line, and the distance between two fish is a tab character "\t", the output looks like this:

My question is, you see, for example, Theodore is longer than Marge, and they all have a "\t" character after them. So why is Simon and Maggie aligned? And why are Homer and Maude the position they are at? I'm suspecting that there are some invisible gridding? I'm using pycharm

Thank you very much!

答:
I'm suspecting that there are some invisible gridding?

That's exactly what tabs do, move the cursor position to the next available tab stop, which are basically gridlines. Tabstops are usually given every 4th or 8th column.

So when you are printing the \t tab at column 5 in a 8th-column tab stop configuration, the next tab stop column would be at position 8. But if your text so far brought you to column 8, then the next stop would be at column 16. Where the next set of characters are printed depends then on how far the preceding text has taken you so far.

Don't use tabs if you need exact control over the output columns. Use string formatting with minimal field sizes to format your data.

```<code>'<>< {:30} <>< {:30}'.format(
    '({}, {})'.format(vara, varb),
    '({}, {})'.format(varc, vard))
</code>```

Now the output string will take at least 30 characters for the each field, adding spaces to make up the difference.

Title: Python's tab spacing

Body:
I'm suspecting that there are some invisible gridding?

That's exactly what tabs do, move the cursor position to the next available tab stop, which are basically gridlines. Tabstops are usually given every 4th or 8th column.

So when you are printing the \t tab at column 5 in a 8th-column tab stop configuration, the next tab stop column would be at position 8. But if your text so far brought you to column 8, then the next stop would be at column 16. Where the next set of characters are printed depends then on how far the preceding text has taken you so far.

Don't use tabs if you need exact control over the output columns. Use string formatting with minimal field sizes to format your data.

'<>< {:30} <>< {:30}'.format(
    '({}, {})'.format(vara, varb),
    '({}, {})'.format(varc, vard))

Now the output string will take at least 30 characters for the each field, adding spaces to make up the difference.


问:
Best practices of handling HTTP response with scala
I have ServerA which exposes an API method for a client, which looks like this:

```<code>def methodExposed()= Action.async(json) { req =>

    val reqAsModel = request.body.extractOpt[ClientRequestModel]

    reqAsModel match {
      case Some(clientRequest) =>
        myApiService
          .doSomething(clientRequest.someList)
          .map(res => ???)
      case None =>
        Future.successful(BadRequest("could not extract request"))
    }
  }
</code>```

So, I have a case class for the client request and if I cannot extract it from the request body, then I return a BadRequest with the message and otherwise I call an internal apiService to perform some action with this request.

doSomething performs an API call to ServerB that can return 3 possible responses:

200 status

400 status with body that I need to extract to a case class

500 status

doSomething looks like this:

```<code>def doSomething(list: List[String]) = {
    wSClient.url(url).withHeaders(("Content-Type", "application/json")).post(write(list)).map { response =>
      response.status match {
        case Status.BAD_REQUEST =>
          parse(response.body).extract[ServiceBResponse]
        case Status.INTERNAL_SERVER_ERROR =>
          val ex = new RuntimeException(s"ServiceB Failed with status: ${response.status} body: ${response.body}")
          throw ex
      }
    }
  }
</code>```

Now I have two issues:

Since the 200 returns with no body and 400 has a body, I don't know what should be the return type of doSomething

How should I handle this in the controller and return the response to the client properly in methodExposed?

答:
If 400 is a common expected error, I think the type Future[Either[Your400CaseClass, Unit]] makes sense. In terms of how methodExposed returns the result to the client depends on your business logic:

Is the underlying 400 something the client should be informed of? If methodExposed should return a 500 to the client when doSomething encounters a 400

Otherwise you can propagate the error to the client. Depending on the business logic, you may or may not want to transform your case class into another form, and potentially with a different http code.

You should throw an exception (using Future.failed) if doSomething returns 500 (or more generally, any unexpected http code).

(Lastly, I hope you're not using 500 to communicate a 'normal' error like validation / authentication error. 5xx code should only be used for exceptional and unrecoverable errors. Most http clients I know will throw an exception immediately when a 5xx is encountered, which means the user won't get the chance to handle it)

Body:
I have ServerA which exposes an API method for a client, which looks like this:

def methodExposed()= Action.async(json) { req =>

    val reqAsModel = request.body.extractOpt[ClientRequestModel]

    reqAsModel match {
      case Some(clientRequest) =>
        myApiService
          .doSomething(clientRequest.someList)
          .map(res => ???)
      case None =>
        Future.successful(BadRequest("could not extract request"))
    }
  }

So, I have a case class for the client request and if I cannot extract it from the request body, then I return a BadRequest with the message and otherwise I call an internal apiService to perform some action with this request.

doSomething performs an API call to ServerB that can return 3 possible responses:

200 status

400 status with body that I need to extract to a case class

500 status

doSomething looks like this:

def doSomething(list: List[String]) = {
    wSClient.url(url).withHeaders(("Content-Type", "application/json")).post(write(list)).map { response =>
      response.status match {
        case Status.BAD_REQUEST =>
          parse(response.body).extract[ServiceBResponse]
        case Status.INTERNAL_SERVER_ERROR =>
          val ex = new RuntimeException(s"ServiceB Failed with status: ${response.status} body: ${response.body}")
          throw ex
      }
    }
  }

Now I have two issues:

Since the 200 returns with no body and 400 has a body, I don't know what should be the return type of doSomething

How should I handle this in the controller and return the response to the client properly in methodExposed?


问:
Bootstrap integration into a php website
I am a beginner in PHP. I have tried developing a website in PHP through tutorials but no I am struck with a problem.

The problem is how can I integrate bootstrap into my website so that it can be compatible through other devices like phones and tablets and also how to integrate paytm into my payment page ?

答:
Check here :
http://getbootstrap.com/getting-started/

Call all bootstrap files in a php file, and include this file in all your pages.

If you have good skills in PHP, you should create templates. Some informations:
https://www.smashingmagazine.com/2011/10/getting-started-with-php-templating/


问:
Is it possible to map a button and/or a system event to launch an android application?
Good evening I am considering creating an application on the android platform and I want to know if it is possible to launch an application based on a particular system event, like pressing and holding a specific button for a period of time (i.e. 3 secs and launch application)?</p>

答: Inside an activity it's easy, use the Event Handlers combined with the KeyEvent class and launch your preferred activity with an intent.</p>


问:
What is a typical use-case for PersistentView in Akka?
Here http://doc.akka.io/docs/akka/current/scala/persistence.html is written:

PersistentView: A view is a persistent, stateful actor that receives
  journaled messages that have been written by another persistent actor.
  A view itself does not journal new messages, instead, it updates
  internal state only from a persistent actor's replicated message
  stream.

What is a typical use-case for PersistentView ?

How is it different from Akka Streams / RX?

It looks pretty similar to me.

答:
You might find it useful if you're designing your application based on CQRS. CQRS fits well with event-sourced systems as can be seen in the blog post.

While you might use PersistentActor actors to update the state of your application - this is the command side / model, PersistentView actors come in handy when you want to display the data, so on the query side.

An example would be storing data about bank accounts. In a traditional model you would probably have all CRUD operations under some repository. A really basic transformation in this model would be to use the PersistentActor for the CUD bit and PersistentView for the R bit. The nice thing is that you decouple the command part which updates the state from the query side.

As for the last question, akka-persistence and akka-streams are made for different purposes. As a matter of fact akka-persistence-query-experimental actually is built using akka-streams to provide different sources. An example is actually here. Note that PersistentView is deprecated in the latest version and it's recommended to use PersistenceQuery.


问:
APEX 5 call modal page from JavaScript
I work on APEX 5 aplication and want to call Modal Page from Interactive Report. Source of Report looks like

```<code>select rid, rname, '<div onclick="clickDay('||rid||')">' || day || '</div>'
from ...
</code>```

and clickDay function placed in Header Text looks like

```<code>    <script type="text/javascript">
  function clickDay(rid){
      window.open("f?p=&APP_ID.:13:&SESSION.::NO::P13_RID:" + rid + ,"Details","dialogWidth:1000px;dialogHeight:600px");
  }
</script>
</code>```

But when I click on IR cell get new page with error
This page can’t be displayed
and url looks like javascript:apex.navigation.dialog('f?p=105:13:9389034907255::NO::P13_RID, ...

What I do wrong?

答:
I think you are mixing two different things. You are trying to open a page as a pop up window which is similar to APEX Page Mode, Non Modal Dialog. Modal Dialog is different from pop up window, it is embedded inside current page instance. Here is help text from APEX on different page mode,

Normal The page is presented as a normal Application Express application page.

Modal Dialog The page is presented as a modal dialog. A modal dialog is an overlay window positioned within the viewport, which
  remains active and focused until the end user dismisses (closes) it.
  The underlying page is grayed out and the end user is prevented from
  interacting with the rest of the page until the dialog is closed.

Non-Modal Dialog The page is presented as a non-modal dialog. A non-modal dialog is an overlay window positioned within the viewport,
  where the end user can interact with the dialog, and content on the
  page that launched the dialog. A non-modal dialog can be used when the
  requested information is not essential to continue, work can continue
  elsewhere while the window is still open.

Title: APEX 5 call modal page from JavaScript

Body:
I work on APEX 5 aplication and want to call Modal Page from Interactive Report. Source of Report looks like

select rid, rname, '
' || day || '
'
from ...

and clickDay function placed in Header Text looks like

But when I click on IR cell get new page with error
This page can’t be displayed
and url looks like javascript:apex.navigation.dialog('f?p=105:13:9389034907255::NO::P13_RID, ...

What I do wrong?


问:
how to reference plan variables in bamboo with my selenium webdriver(java) file
I have selenium driver script

```<code>this.browsername = System.getenv("browsername");
tags.add(this.browsername);
this.browserversion = System.getenv("browserversion");
tags.add(this.browserversion);
</code>```

but when i add variables from task configuration with 'variable name', 'value'
and execute the script , it returns NULL, no value is passed to above mentioned variables through bamboo.

答: Bamboo adds "bamboo_" prefix to variables, try it. Or modify your java class and print all environment variables to see what is exported</p>

Body:
I have selenium driver script

this.browsername = System.getenv("browsername");
tags.add(this.browsername);
this.browserversion = System.getenv("browserversion");
tags.add(this.browserversion);

but when i add variables from task configuration with 'variable name', 'value'
and execute the script , it returns NULL, no value is passed to above mentioned variables through bamboo.


问:
primefaces autocomplete when cleared field giving previuos results of page on clicking submit button
I am using an autocomplete tag of prime faces which retrieves results from a database.

The problem is that when I submit the form leaving the autocomplete field empty the results I get on the page are those of the previous request (the previously selected autocomplete value) - it only gets cleared when I refresh the page.

I want that on each submit, without refreshing the browser page, if i clear out the value in the field using backspaces and submit the form it should give the correct result for this particular instance, not previous one.

I am also using some textfields in the jsf page form but those don't have this problem.
Can anyone offer guidance as to how this problem can be corrected?

EDITED:
Code:

```<code><h:form>
  <h:dataTable id="Ressult" value="#{input.searchResults}" var="r">
    <h:column>#{r.ID}</h:column>
    <h:column>#{r.Name}</h:column>
  </h:dataTable>
  <tr>
    <td>Current Education Level</td>
    <td>
      <h:panelGrid styleClass="text-box">
        <p:autoComplete id="education" value="#{input.education}"
        completeMethod="#{input.getautocomplete}" var="a"
        itemLabel="#{a.Name}" itemValue="#{a}"
        converter="edConverter" forceSelection="true" />
        <p:column>#{a.Name} - #{a.id}</p:column>
      </h:panelGrid>
    </td>
  </tr>
  <tr>
    <td>City</td>
    <td>
      <h:selectOneMenu id="txtCity" styleClass="select-field"
      value="#{input.cityId}">
        <f:selectItem itemLabel=" Please Select" itemValue="0">
        </f:selectItem>
        <f:selectItems value="#{input.cities}"></f:selectItems>
      </h:selectOneMenu>
    </td>
  </tr>
  <tr>
    <td>Name of Person</td>
    <td>
      <h:inputText id="txtName" value="#{input.nameOfPerson}"
      styleClass="text-box"></h:inputText>
    </td>
  </tr>
  <h:commandButton id="btnSearch" value="Search"
  action="#{input.searching}">
    <f:ajax execute="@form" render="Ressult"></f:ajax>
  </h:commandButton>
</h:form>
</code>```

And here is the bean code:

```<code>public class Input
{
    private Education education;
    private List<SelectItem> cities;
    private Integer cityId;
    private String nameOfPerson;
    private List<Results> searchResults;
    //getters and setters

    public String searching()
    {
         searchResults=dao.getSearchResults(cityId,education,nameOfPerson);
         return "success";
    }

    public void autocomplete(String query)
    {
        //AUTOCOMPLTE lIST CODE HERE
    }
}
</code>```

By update, if you mean new results to be shown when new items selected, then yes - the form should be updated but autocomplete somehow takes the previously selected value and shows results according to that. At least until I refresh the page - only then is autocomplete's previous is removed.

答:
Just process event to server. Works with forceselection="true"</p>

```<code><p:ajax event="itemUnselect" global="false" />
</code>```

Body:
I am using an autocomplete tag of prime faces which retrieves results from a database.

The problem is that when I submit the form leaving the autocomplete field empty the results I get on the page are those of the previous request (the previously selected autocomplete value) - it only gets cleared when I refresh the page.

I want that on each submit, without refreshing the browser page, if i clear out the value in the field using backspaces and submit the form it should give the correct result for this particular instance, not previous one.

I am also using some textfields in the jsf page form but those don't have this problem.
Can anyone offer guidance as to how this problem can be corrected?

EDITED:
Code:

<h:form>
  <h:dataTable id="Ressult" value="#{input.searchResults}" var="r">
    <h:column>#{r.ID}</h:column>
    <h:column>#{r.Name}</h:column>
  </h:dataTable>

    Current Education Level

      <h:panelGrid styleClass="text-box">

#{a.Name} - #{a.id}

      </h:panelGrid>

    City

      <h:selectOneMenu id="txtCity" styleClass="select-field"
      value="#{input.cityId}">
        <f:selectItem itemLabel=" Please Select" itemValue="0">
        </f:selectItem>
        <f:selectItems value="#{input.cities}"></f:selectItems>
      </h:selectOneMenu>

    Name of Person

      <h:inputText id="txtName" value="#{input.nameOfPerson}"
      styleClass="text-box"></h:inputText>

  <h:commandButton id="btnSearch" value="Search"
  action="#{input.searching}">
    <f:ajax execute="@form" render="Ressult"></f:ajax>
  </h:commandButton>
</h:form>

And here is the bean code:

public class Input
{
    private Education education;
    private List<SelectItem> cities;
    private Integer cityId;
    private String nameOfPerson;
    private List<Results> searchResults;
    //getters and setters

    public String searching()
    {
         searchResults=dao.getSearchResults(cityId,education,nameOfPerson);
         return "success";
    }

    public void autocomplete(String query)
    {
        //AUTOCOMPLTE lIST CODE HERE
    }
}

By update, if you mean new results to be shown when new items selected, then yes - the form should be updated but autocomplete somehow takes the previously selected value and shows results according to that. At least until I refresh the page - only then is autocomplete's previous is removed.

Body:
Just process event to server. Works with forceselection="true"

<p:ajax event="itemUnselect" global="false" />


问:
MS Access currentdb.excute has different result than Docmd.RunSQL
I use VBA to run an INSERT INTO ... SELECT... SQL query with Currentdb.Execute command. However, I have trouble with the result. There are some rows missing the data.

The result is correct when using Docmd.RunSQL with the same SQL, but I don't want the warning message for inserting data into the table.

I also tried using only the SELECT... with Currentdb.Execute and print the result on the debug window. The result is correct, no missing data.

Here's my code:

```<code>strsql = strsql & "INSERT INTO tempLineItems (OrderNo, PositionNo, PartNo, [Description], PlannedDeliveryDate, Qty, Unit, Price, Curr, txta, LineItemText, Discount, Tax) "
strsql = strsql & "SELECT dbo_ttdsls041600.t_orno, dbo_ttdsls041600.t_pono, dbo_ttdsls041600.t_item, IIF(dbo_ttipcs021600.t_dsca is null,dbo_ttiitm001600.t_dsca,dbo_ttipcs021600.t_dsca) AS t_dsca, dbo_ttdsls041600.t_ddta, dbo_ttdsls041600.t_oqua, dbo_ttdsls041600.t_cups, dbo_ttdsls041600.t_pric, dbo_ttdsls040600.t_ccur, dbo_ttdsls041600.t_txta, Null AS LineItemText, dbo_ttdsls041600.t_disc_1, dbo_ttdsls041600.t_cvat "
strsql = strsql & "FROM dbo_ttdsls040600 INNER JOIN ((dbo_ttipcs021600 RIGHT JOIN dbo_ttdsls041600 ON (dbo_ttipcs021600.t_item = dbo_ttdsls041600.t_item) AND (dbo_ttipcs021600.t_cprj = dbo_ttdsls041600.t_cprj)) LEFT JOIN dbo_ttiitm001600 ON dbo_ttdsls041600.t_item = dbo_ttiitm001600.t_item) ON dbo_ttdsls040600.t_orno = dbo_ttdsls041600.t_orno "
strsql = strsql & "WHERE (((dbo_ttdsls041600.t_orno)=" & Me.txtSalesOrderNo.Value & ") AND ((dbo_ttdsls041600.t_pono)>0)) "
strsql = strsql & "ORDER BY dbo_ttdsls041600.t_pono;"
</code>```

The problem is on the

```<code>IIF(dbo_ttipcs021600.t_dsca is null,dbo_ttiitm001600.t_dsca,dbo_ttipcs021600.t_dsca) AS t_dsca
</code>```

I used ISNULL() function, and it has the same result as using Is Null

3/28/2017 Update:
Those tables are linked tables from the SQL Server. I created local tables based on a subset data of those linked ones, and there's no missing data at all.

答:
I'm just curious about this problem, so I did a different approach by using multiple layer of queries.

```<code>strsql = strsql & "INSERT INTO tempLineItems (OrderNo, PositionNo, PartNo, Description, PlannedDeliveryDate, Qty, Unit, Price, Curr, txta, LineItemText, Discount, Tax) "
strsql = strsql & "SELECT SO1.t_orno, SO1.t_pono, SO1.t_item, nz(SO1.t_dsca, dbo_ttiitm001600.t_dsca) AS t_dsca, SO1.t_ddta, SO1.t_oqua, SO1.t_cups, SO1.t_pric, SO1.t_ccur, SO1.t_txta, Null AS LineItemText, SO1.t_disc_1, SO1.t_cvat "
strsql = strsql & "FROM (SELECT SO.t_orno, SO.t_ccur, SO.t_pono, SO.t_item, SO.t_oqua, SO.t_pric, SO.t_cups, SO.t_ddta, SO.t_txta, SO.t_disc_1, SO.t_cvat, dbo_ttipcs021600.t_dsca "
strsql = strsql & "FROM (SELECT dbo_ttdsls040600.t_orno, dbo_ttdsls040600.t_ccur, dbo_ttdsls041600.t_pono, dbo_ttdsls041600.t_item, dbo_ttdsls041600.t_pric, dbo_ttdsls041600.t_cups, dbo_ttdsls041600.t_ddta, dbo_ttdsls041600.t_cprj, dbo_ttdsls041600.t_txta, dbo_ttdsls041600.t_disc_1, dbo_ttdsls041600.t_cvat, dbo_ttdsls041600.t_oqua "
strsql = strsql & "FROM dbo_ttdsls041600 INNER JOIN dbo_ttdsls040600 ON dbo_ttdsls041600.t_orno = dbo_ttdsls040600.t_orno "
strsql = strsql & "WHERE (((dbo_ttdsls040600.t_orno)=" & Me.txtSalesOrderNo & "))) SO "
strsql = strsql & "LEFT JOIN dbo_ttipcs021600 ON dbo_ttipcs021600.t_cprj = SO.t_cprj AND dbo_ttipcs021600.t_item = SO.t_item)  AS SO1 LEFT JOIN dbo_ttiitm001600 ON dbo_ttiitm001600.t_item = SO1.t_item "
strsql = strsql & "ORDER BY SO1.t_pono;"
</code>```

And this works!! I guess there's some issue in Access internally.

Body:
I use VBA to run an INSERT INTO ... SELECT... SQL query with Currentdb.Execute command. However, I have trouble with the result. There are some rows missing the data.

The result is correct when using Docmd.RunSQL with the same SQL, but I don't want the warning message for inserting data into the table.

I also tried using only the SELECT... with Currentdb.Execute and print the result on the debug window. The result is correct, no missing data.

Here's my code:

strsql = strsql & "INSERT INTO tempLineItems (OrderNo, PositionNo, PartNo, [Description], PlannedDeliveryDate, Qty, Unit, Price, Curr, txta, LineItemText, Discount, Tax) "
strsql = strsql & "SELECT dbo_ttdsls041600.t_orno, dbo_ttdsls041600.t_pono, dbo_ttdsls041600.t_item, IIF(dbo_ttipcs021600.t_dsca is null,dbo_ttiitm001600.t_dsca,dbo_ttipcs021600.t_dsca) AS t_dsca, dbo_ttdsls041600.t_ddta, dbo_ttdsls041600.t_oqua, dbo_ttdsls041600.t_cups, dbo_ttdsls041600.t_pric, dbo_ttdsls040600.t_ccur, dbo_ttdsls041600.t_txta, Null AS LineItemText, dbo_ttdsls041600.t_disc_1, dbo_ttdsls041600.t_cvat "
strsql = strsql & "FROM dbo_ttdsls040600 INNER JOIN ((dbo_ttipcs021600 RIGHT JOIN dbo_ttdsls041600 ON (dbo_ttipcs021600.t_item = dbo_ttdsls041600.t_item) AND (dbo_ttipcs021600.t_cprj = dbo_ttdsls041600.t_cprj)) LEFT JOIN dbo_ttiitm001600 ON dbo_ttdsls041600.t_item = dbo_ttiitm001600.t_item) ON dbo_ttdsls040600.t_orno = dbo_ttdsls041600.t_orno "
strsql = strsql & "WHERE (((dbo_ttdsls041600.t_orno)=" & Me.txtSalesOrderNo.Value & ") AND ((dbo_ttdsls041600.t_pono)>0)) "
strsql = strsql & "ORDER BY dbo_ttdsls041600.t_pono;"

The problem is on the

IIF(dbo_ttipcs021600.t_dsca is null,dbo_ttiitm001600.t_dsca,dbo_ttipcs021600.t_dsca) AS t_dsca

I used ISNULL() function, and it has the same result as using Is Null

3/28/2017 Update:
Those tables are linked tables from the SQL Server. I created local tables based on a subset data of those linked ones, and there's no missing data at all.

Body:
I'm just curious about this problem, so I did a different approach by using multiple layer of queries.

strsql = strsql & "INSERT INTO tempLineItems (OrderNo, PositionNo, PartNo, Description, PlannedDeliveryDate, Qty, Unit, Price, Curr, txta, LineItemText, Discount, Tax) "
strsql = strsql & "SELECT SO1.t_orno, SO1.t_pono, SO1.t_item, nz(SO1.t_dsca, dbo_ttiitm001600.t_dsca) AS t_dsca, SO1.t_ddta, SO1.t_oqua, SO1.t_cups, SO1.t_pric, SO1.t_ccur, SO1.t_txta, Null AS LineItemText, SO1.t_disc_1, SO1.t_cvat "
strsql = strsql & "FROM (SELECT SO.t_orno, SO.t_ccur, SO.t_pono, SO.t_item, SO.t_oqua, SO.t_pric, SO.t_cups, SO.t_ddta, SO.t_txta, SO.t_disc_1, SO.t_cvat, dbo_ttipcs021600.t_dsca "
strsql = strsql & "FROM (SELECT dbo_ttdsls040600.t_orno, dbo_ttdsls040600.t_ccur, dbo_ttdsls041600.t_pono, dbo_ttdsls041600.t_item, dbo_ttdsls041600.t_pric, dbo_ttdsls041600.t_cups, dbo_ttdsls041600.t_ddta, dbo_ttdsls041600.t_cprj, dbo_ttdsls041600.t_txta, dbo_ttdsls041600.t_disc_1, dbo_ttdsls041600.t_cvat, dbo_ttdsls041600.t_oqua "
strsql = strsql & "FROM dbo_ttdsls041600 INNER JOIN dbo_ttdsls040600 ON dbo_ttdsls041600.t_orno = dbo_ttdsls040600.t_orno "
strsql = strsql & "WHERE (((dbo_ttdsls040600.t_orno)=" & Me.txtSalesOrderNo & "))) SO "
strsql = strsql & "LEFT JOIN dbo_ttipcs021600 ON dbo_ttipcs021600.t_cprj = SO.t_cprj AND dbo_ttipcs021600.t_item = SO.t_item)  AS SO1 LEFT JOIN dbo_ttiitm001600 ON dbo_ttiitm001600.t_item = SO1.t_item "
strsql = strsql & "ORDER BY SO1.t_pono;"

And this works!! I guess there's some issue in Access internally.


问:
Powershell 2.0 Savefiledialog style
I have a powershell 2.0 GUI that has a SaveFileDialog box that does not look like windows 7 save file dialog that is used for my other MS Office windows 7 applications - the powershell dialog contains a vertical toolbar, called the Places Bar, and looks like an older version of windows. How can I make the save file dialog in my powershell GUI look like the other windows 7 application save file dialogs?</p>

答:
Original post below

Windows will fall back to the old style Windows GUI as you're using PowerShell 2.0, because, by default, PowerShell 2.0 loads .Net 2.0.

$PSVersionTable in PowerShell 2.0

```<code>Name                           Value
----                           -----
CLRVersion                     2.0.50727.5485
BuildVersion                   6.1.7601.17514
PSVersion                      2.0
WSManStackVersion              2.0
PSCompatibleVersions           {1.0, 2.0}
SerializationVersion           1.1.0.1
PSRemotingProtocolVersion      2.1
</code>```

$PSVersionTable in PowerShell 4

```<code>Name                           Value
----                           -----
PSVersion                      4.0
WSManStackVersion              3.0
SerializationVersion           1.1.0.1
CLRVersion                     4.0.30319.42000
BuildVersion                   6.3.9600.16406
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion      2.2
</code>```

If you have .net CLR version 3.5 or above installed, you can coerce PowerShell 2.0 into loading a newer CLR version than 2.0, which will then give you the newer style file dialog.

Save the code below into a batch file (e.g. WindowsPowerShell3.5.cmd) where 3.5 is the CLR version you wish to load with PowerShell. Then run the batch file to launch PowerShell. Change powershell.exe to powershell_ise.exe to apply this to a PowerShell ISE session.

```<code>@echo off
:: http://stackoverflow.com/questions/7308586/using-batch-echo-with-special-characters
if exist %~dp0powershell.exe.activation_config goto :run
echo.^<?xml version="1.0" encoding="utf-8" ?^>                 > %~dp0powershell.exe.activation_config
echo.^<configuration^>                                        >> %~dp0powershell.exe.activation_config
echo.  ^<startup useLegacyV2RuntimeActivationPolicy="true"^>  >> %~dp0powershell.exe.activation_config
echo.    ^<supportedRuntime version="v3.5"/^>                 >> %~dp0powershell.exe.activation_config
echo.  ^</startup^>                                           >> %~dp0powershell.exe.activation_config
echo.^</configuration^>                                       >> %~dp0powershell.exe.activation_config
:run
:: point COMPLUS_ApplicationMigrationRuntimeActivationConfigPath to the directory that this cmd file lives in
:: and the directory contains a powershell.exe.activation_config file which matches the executable name powershell.exe
set COMPLUS_ApplicationMigrationRuntimeActivationConfigPath=%~dp0
%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe %*
set COMPLUS_ApplicationMigrationRuntimeActivationConfigPath=
</code>```

Original post

Try the code below, which is based on example code from Microsoft:

WPF

```<code>Add-Type -AssemblyName PresentationFramework

$dlg = New-Object 'Microsoft.Win32.SaveFileDialog'
$dlg.FileName = "Document" # Default file name
$dlg.DefaultExt = ".txt" # Default file extension
$dlg.Filter = "Text documents (.txt)|*.txt" # Filter files by extension

# Show save file dialog box
$result = $dlg.ShowDialog()

# Process save file dialog box results
if ($result) {
  # Save document
  $filename = $dlg.FileName;
}
</code>```

I'm guessing you have code using System.Windows.Forms, similar to the code below:

Windows Forms

```<code>[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.forms")
$dlg = New-Object System.Windows.Forms.SaveFileDialog
$dlg.FileName = "Document" # Default file name
$dlg.DefaultExt = ".txt" # Default file extension
$dlg.Filter = "Text documents (.txt)|*.txt" # Filter files by extension

# Show save file dialog box
$result = $dlg.ShowDialog()

# Process save file dialog box results
if ($result) {
  # Save document
  $filename = $dlg.FileName
}
</code>```

Title: Powershell 2.0 Savefiledialog style

Body:
Original post below

Windows will fall back to the old style Windows GUI as you're using PowerShell 2.0, because, by default, PowerShell 2.0 loads .Net 2.0.

$PSVersionTable in PowerShell 2.0

Name                           Value
----                           -----
CLRVersion                     2.0.50727.5485
BuildVersion                   6.1.7601.17514
PSVersion                      2.0
WSManStackVersion              2.0
PSCompatibleVersions           {1.0, 2.0}
SerializationVersion           1.1.0.1
PSRemotingProtocolVersion      2.1

$PSVersionTable in PowerShell 4

Name                           Value
----                           -----
PSVersion                      4.0
WSManStackVersion              3.0
SerializationVersion           1.1.0.1
CLRVersion                     4.0.30319.42000
BuildVersion                   6.3.9600.16406
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion      2.2

If you have .net CLR version 3.5 or above installed, you can coerce PowerShell 2.0 into loading a newer CLR version than 2.0, which will then give you the newer style file dialog.

Save the code below into a batch file (e.g. WindowsPowerShell3.5.cmd) where 3.5 is the CLR version you wish to load with PowerShell. Then run the batch file to launch PowerShell. Change powershell.exe to powershell_ise.exe to apply this to a PowerShell ISE session.

@echo off
:: http://stackoverflow.com/questions/7308586/using-batch-echo-with-special-characters
if exist %~dp0powershell.exe.activation_config goto :run
echo.^<?xml version="1.0" encoding="utf-8" ?^>                 > %~dp0powershell.exe.activation_config
echo.^<configuration^>                                        >> %~dp0powershell.exe.activation_config
echo.  ^<startup useLegacyV2RuntimeActivationPolicy="true"^>  >> %~dp0powershell.exe.activation_config
echo.    ^<supportedRuntime version="v3.5"/^>                 >> %~dp0powershell.exe.activation_config
echo.  ^</startup^>                                           >> %~dp0powershell.exe.activation_config
echo.^</configuration^>                                       >> %~dp0powershell.exe.activation_config
:run
:: point COMPLUS_ApplicationMigrationRuntimeActivationConfigPath to the directory that this cmd file lives in
:: and the directory contains a powershell.exe.activation_config file which matches the executable name powershell.exe
set COMPLUS_ApplicationMigrationRuntimeActivationConfigPath=%~dp0
%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe %*
set COMPLUS_ApplicationMigrationRuntimeActivationConfigPath=

Original post

Try the code below, which is based on example code from Microsoft:

WPF

Add-Type -AssemblyName PresentationFramework

$dlg = New-Object 'Microsoft.Win32.SaveFileDialog'
$dlg.FileName = "Document" # Default file name
$dlg.DefaultExt = ".txt" # Default file extension
$dlg.Filter = "Text documents (.txt)|*.txt" # Filter files by extension

# Show save file dialog box
$result = $dlg.ShowDialog()

# Process save file dialog box results
if ($result) {
  # Save document
  $filename = $dlg.FileName;
}

I'm guessing you have code using System.Windows.Forms, similar to the code below:

Windows Forms

[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.forms")
$dlg = New-Object System.Windows.Forms.SaveFileDialog
$dlg.FileName = "Document" # Default file name
$dlg.DefaultExt = ".txt" # Default file extension
$dlg.Filter = "Text documents (.txt)|*.txt" # Filter files by extension

# Show save file dialog box
$result = $dlg.ShowDialog()

# Process save file dialog box results
if ($result) {
  # Save document
  $filename = $dlg.FileName
}


问:
How to set HTML elements into session grails
In my grails application I need to set html tags to the session. For example

```<code>session.setAttribute("message","<font color=\"green\">Successfully Processed</font>")
</code>```

but when I am fetching the value from the GSP (like ${session.message}) the opening and closing tags get changed to <
So the whole text gets printed as such. Why?

答:
This is due to encoding. The documentation explains the details and why. In your case you want to use raw like this:

${raw(session.message)}

Body:
In my grails application I need to set html tags to the session. For example

session.setAttribute("message","Successfully Processed")

but when I am fetching the value from the GSP (like ${session.message}) the opening and closing tags get changed to <
So the whole text gets printed as such. Why?


问:
How to trigger a click on another app from Swift?
I want to open an app which contains buttons that I want to trigger a click. The app will then open a browser page when done, which I want to close. I want to automate the whole thing. I know to invoke the app and send system event for key press using AppleScript. But how to do that using Swift. I can open the app, but how to make the button click? Is Swift the wrong tool for UI automation?

I am intending to run the swift program as a script #!/usr/bin/swift.

答:
I'm inclined to say it isnt doable with swift on osx - and that is more because of osx than swift.

anyway. there are no public 'native' straight-forward APIs for it and while it might be doable with the accessibility API that'd be a major pain.

I'd recommend you go with AppleScript (Sure, your swift 'app' could trigger a lot of AppleScript to do all the heavy lifting (like you said) but then .. kinda useless to start out with swift anyay, eh? ;)))


问:
Validating user entry matches mixed case requirements
I am trying to figure out how to test for mixed case or change the user input to mixed case.

Currently my code consists of:

```<code>$Type = Read-Host 'Enter MY, OLD, NEWTest, Old_Tests'
</code>```

However, I need to validate that the user entered in the exact case, and if they didn't change the case to the correct case.  I have reviewed so many different questions on here and other websites, but none seem to really talk about validating mixed case in a way I can understand.

Validate User Entry

Regex to match mixed case words

Validating String User Entry

How to check if a string is all upper case (lower case) characters?

Learn Powershell | Achieve More

How To Validate Parameters in PowerShell

$args in powershell

I am not asking anyone to write code for me. I am asking for some sample code that I can gain an understanding on how to validate and change the entries.

答:
PowerShell performs case-insensitive comparisons by default, so to answer the first part of your question you need to do a case-sensitive comparison which is -ceq.

```<code>$Type = Read-Host 'Enter MY, OLD, NEWTest, Old_Tests'
($Type -ceq 'MY' -or  $Type -ceq 'OLD' -or  $Type -ceq 'NEWTest' -or  $Type -ceq 'Old_Tests')
</code>```

Although a simpler solution to that is to use case-sensitive contains -ccontains:

```<code>('MY', 'OLD', 'NEWTest', 'Old_Tests' -ccontains $Type)
</code>```

Here's one way you might correct the case:

```<code>$Type = Read-Host 'Enter MY, OLD, NEWTest, Old_Tests'

If ('MY', 'OLD', 'NEWTest', 'Old_Tests'  -cnotcontains $Type){

    If ('MY', 'OLD', 'NEWTest', 'Old_Tests' -contains $Type){
        $TextInfo = (Get-Culture).TextInfo

        $Type = Switch ($Type) {
            {$_ -in 'MY','OLD'} { $Type.ToUpper() }
            'NEWTest'           { $Type.Substring(0,4).ToUpper() + $Type.Substring(4,3).ToLower() }
            'Old_Tests'         { $TextInfo.ToTitleCase($Type) }
        }
    } Else {
        Write-Warning 'You didnt enter one of: MY, OLD, NEWTest, Old_Tests'
    }
}

Write-Output $Type
</code>```

Explanation:

First we test if the case is correct for the four permitted words (-cnotcontains Case Sensitive Not Contains), if it is we do nothing. If the case is not correct, then we test the text is correct (without caring about case sensitivity -contains).

If the text is correct then we use Switch statement to deal with the different scenarios that we want to adapt the case for:

The first switch test matches the first two words and simply uppercases them with the ToUpper() string method.

The second switch test uses the string method SubString to get a subset of the string starting from the first character (0) and taking 4 characters in length. We uppercase this with ToUpper then we add on the next 3 characters of the string, starting at the 4th character, which we force in to lower case with ToLower().

The final switch test we handle with a .NET method taken from the get-culture cmdlet which allows us to Title Case a string (make the first letter of each word uppercase).

If the inputted text didn't match one of the options we use write-warning (may require PowerShell 4 or above, if you don't have this change it to write-host) to print a warning to the console.

Finally whatever was entered we send to stdout with Write-Output.

Body:
I am trying to figure out how to test for mixed case or change the user input to mixed case.

Currently my code consists of:

$Type = Read-Host 'Enter MY, OLD, NEWTest, Old_Tests'

However, I need to validate that the user entered in the exact case, and if they didn't change the case to the correct case.  I have reviewed so many different questions on here and other websites, but none seem to really talk about validating mixed case in a way I can understand.

Validate User Entry

Regex to match mixed case words

Validating String User Entry

How to check if a string is all upper case (lower case) characters?

Learn Powershell | Achieve More

How To Validate Parameters in PowerShell

$args in powershell

I am not asking anyone to write code for me. I am asking for some sample code that I can gain an understanding on how to validate and change the entries.

Body:
PowerShell performs case-insensitive comparisons by default, so to answer the first part of your question you need to do a case-sensitive comparison which is -ceq.

$Type = Read-Host 'Enter MY, OLD, NEWTest, Old_Tests'
($Type -ceq 'MY' -or  $Type -ceq 'OLD' -or  $Type -ceq 'NEWTest' -or  $Type -ceq 'Old_Tests')

Although a simpler solution to that is to use case-sensitive contains -ccontains:

('MY', 'OLD', 'NEWTest', 'Old_Tests' -ccontains $Type)

Here's one way you might correct the case:

$Type = Read-Host 'Enter MY, OLD, NEWTest, Old_Tests'

If ('MY', 'OLD', 'NEWTest', 'Old_Tests'  -cnotcontains $Type){

    If ('MY', 'OLD', 'NEWTest', 'Old_Tests' -contains $Type){
        $TextInfo = (Get-Culture).TextInfo

        $Type = Switch ($Type) {
            {$_ -in 'MY','OLD'} { $Type.ToUpper() }
            'NEWTest'           { $Type.Substring(0,4).ToUpper() + $Type.Substring(4,3).ToLower() }
            'Old_Tests'         { $TextInfo.ToTitleCase($Type) }
        }
    } Else {
        Write-Warning 'You didnt enter one of: MY, OLD, NEWTest, Old_Tests'
    }
}

Write-Output $Type

Explanation:

First we test if the case is correct for the four permitted words (-cnotcontains Case Sensitive Not Contains), if it is we do nothing. If the case is not correct, then we test the text is correct (without caring about case sensitivity -contains).

If the text is correct then we use Switch statement to deal with the different scenarios that we want to adapt the case for:

The first switch test matches the first two words and simply uppercases them with the ToUpper() string method.

The second switch test uses the string method SubString to get a subset of the string starting from the first character (0) and taking 4 characters in length. We uppercase this with ToUpper then we add on the next 3 characters of the string, starting at the 4th character, which we force in to lower case with ToLower().

The final switch test we handle with a .NET method taken from the get-culture cmdlet which allows us to Title Case a string (make the first letter of each word uppercase).

If the inputted text didn't match one of the options we use write-warning (may require PowerShell 4 or above, if you don't have this change it to write-host) to print a warning to the console.

Finally whatever was entered we send to stdout with Write-Output.


问:
Microsoft JDBC and Datetime2 - rounding issue
From our application we create a java.sql.Timestamp like this:

```<code>Timestamp currentTimeStamp = new Timestamp(System.currentTimeMillis());
currentTimeStamp.setNanos((int) (System.nanoTime() % 1000000000));
</code>```

And then use this as column value in a distributed transaction against a DB2 and MSSQL.

DB2 strips off the digits it cannot use and stores the remaining.

MSSQL rounds the digits and stores the value.

The problem then becomes that the timestamp value is different in the two databases even though they both have the same fraction digits of 6.

Example reproduced using pure T-SQL:

```<code>DECLARE @t TABLE(x DATETIME2(6))
INSERT @t SELECT '2017-03-28 14:00:59.4106489'
SELECT x FROM @t
</code>```

Result:
2017-03-28 14:00:59.410649

Expected:
2017-03-28 14:00:59.410648

答:
It sounds like you need to create a Timestamp value that SQL Server won't round, thereby ensuring that the values will be the same in both databases. One approach would be to use a utility function like

private static Timestamp truncatedTimestamp(Timestamp ts, int precision) {
    return Timestamp.valueOf(ts.toString().substring(0, precision + 20));
}
```

to truncate the Timestamp value at the specified precision (6, in your case).

Body:
From our application we create a java.sql.Timestamp like this:

Timestamp currentTimeStamp = new Timestamp(System.currentTimeMillis());
currentTimeStamp.setNanos((int) (System.nanoTime() % 1000000000));

And then use this as column value in a distributed transaction against a DB2 and MSSQL.

DB2 strips off the digits it cannot use and stores the remaining.

MSSQL rounds the digits and stores the value.

The problem then becomes that the timestamp value is different in the two databases even though they both have the same fraction digits of 6.

Example reproduced using pure T-SQL:

DECLARE @t TABLE(x DATETIME2(6))
INSERT @t SELECT '2017-03-28 14:00:59.4106489'
SELECT x FROM @t

Result:
2017-03-28 14:00:59.410649

Expected:
2017-03-28 14:00:59.410648

Body:
It sounds like you need to create a Timestamp value that SQL Server won't round, thereby ensuring that the values will be the same in both databases. One approach would be to use a utility function like

private static Timestamp truncatedTimestamp(Timestamp ts, int precision) {
    return Timestamp.valueOf(ts.toString().substring(0, precision + 20));
}

to truncate the Timestamp value at the specified precision (6, in your case).


问:
Fortran 77 conversion to C++
I have a Fortran 77 application that uses Common declarations to "share" memory variables.  Back in the day, when memory was expensive and hard to come by this was the way around it.

The equipment being controlled sets status flags.  These flags reside in these Common variables.

Any suggestions on how to implement the Common functionality in c++?

A class perhaps, with all the common variables being public.  Thus any program instantiating that class will have access to the contents of the Common variables.

Are there any tutorials/guidelines for converting Fortran to C or C++?

Thanks

答:
Apropos to my comment on Alexandros' answer the "natural" transliteration is to include everything in the common blocks as class statics in the c++ code. The result will not be good c++ code, but it would give a place to start refactoring.

That said, I would usually try to interface a c++ front end to the existing fortran back end first, and then start the translation process if it still seems like a good idea.

Title: Fortran 77 conversion to C++


问:
Bootstrap - Auto expanding container, row & row columns' width with content
I have following html:

```<code><div class="container">
 <div class="row">
    <div class="col-md-6">
        <ul>
            <li>Long Content 1<li>
        </ul>
    </div>
    <div class="col-md-6">
        <ul>
            <li>Long Content 2<li>
        </ul>
    </div>
 </div>
</div>
</code>```

I will be adding dynamic content into each ul element. I want col-md-* elements and their parents to expand  themselves horizontally with the content, even if they horizontally overflow the screen window. I don't mind horizontal scrolling on the screen. How can I achieve this?

答:
I have been playing around with this a bit. I ended up with this: JSFiddle. I didn t manage to get bootstrap loaded properly so I added in some css to replicate the bootstrap .col-md-6 behavior. I basically added white-space: nowrap to the li-items. And also enabled vertical scrolling on the divs. I figured that would be about what you wanted to do.

html

```<code><div class="container">
 <div class="row">
    <div class="col-md-6 scrollbox">
        <ul>
            <li>Long Content 1 nkjdfhkjfh dskjfhdkjs hkjdsh fkjdshkjf hdkjshf kjh fkdsk fjhkj dhfkjshfkj das fdkjsfkjdsfkj hks fkadsj f last word<li>
        </ul>
    </div>
    <div class="col-md-6 scrollbox">
        <ul>
            <li>Long Content 2<li>
        </ul>
    </div>
 </div>
</div>
</code>```

css

```<code>li{
 white-space: nowrap;
}
/*col-md-6 code is to simulate bootstrap*/
.col-md-6{
  width: 50%;
  float: left;
}
.scrollbox{
  background-color: rgb(200,200,220);
  overflow-x: auto;
  overflow-y: auto;
}
</code>```

Body:
I have following html:

Long Content 1

Long Content 2

I will be adding dynamic content into each ul element. I want col-md-* elements and their parents to expand  themselves horizontally with the content, even if they horizontally overflow the screen window. I don't mind horizontal scrolling on the screen. How can I achieve this?

Body:
I have been playing around with this a bit. I ended up with this: JSFiddle. I didn t manage to get bootstrap loaded properly so I added in some css to replicate the bootstrap .col-md-6 behavior. I basically added white-space: nowrap to the li-items. And also enabled vertical scrolling on the divs. I figured that would be about what you wanted to do.

html

<div class="container">
 <div class="row">
    <div class="col-md-6 scrollbox">
        <ul>
            <li>Long Content 1 nkjdfhkjfh dskjfhdkjs hkjdsh fkjdshkjf hdkjshf kjh fkdsk fjhkj dhfkjshfkj das fdkjsfkjdsfkj hks fkadsj f last word<li>
        </ul>
    </div>
    <div class="col-md-6 scrollbox">
        <ul>
            <li>Long Content 2<li>
        </ul>
    </div>
 </div>
</div>

css

li{
 white-space: nowrap;
}
/*col-md-6 code is to simulate bootstrap*/
.col-md-6{
  width: 50%;
  float: left;
}
.scrollbox{
  background-color: rgb(200,200,220);
  overflow-x: auto;
  overflow-y: auto;
}


问:
DOM class injection in PHP

idea

Via jQuery, I was able to mark all :first-child and :last-child elements in document (well, almost all :)) with class first which could I later style (i.e. first li in ul#navigation would be easily adressable as ul#navigation .first).

I used following code:

```<code>  var $f = $('*:first-child')
      $f.addClass('first');
  var $l = $('body *:last-child')
      $l.addClass('last');
</code>```

example

http://jsbin.com/ikuca/3

Example is already here - it's not the way to do it however, it's just an idea prototyped in other, for me at the moment easier language.

question

Now, my question is if it's possible to do the same via php, so non-JS users/gadgets could have the same effects and additional styling and also it would be less overkill on browser.

So, is it possible to capture output, parse it as html and inject this class easily in php?

clarification

I'm quite aware of output buffering, just haven't done much stuff with it - also, i'm not sure about modificating output string in php as parsed dom (without regex) - and how tough on server it'll be - with caching of course, so this whole stuff will run once until the page will be edited again.

答:
You could even use the same CSS selectors by using some of the libraries mentioned here.
I read that the phpQuery library even has the same :first-child pseudo-class you need.

I sincerely hope you plan on using caching or else your CPU usage will go up 100% with a few request.

Title: DOM class injection in PHP

Body:
idea

Via jQuery, I was able to mark all :first-child and :last-child elements in document (well, almost all :)) with class first which could I later style (i.e. first li in ul#navigation would be easily adressable as ul#navigation .first).

I used following code:

  var $f = $('*:first-child')
      $f.addClass('first');
  var $l = $('body *:last-child')
      $l.addClass('last');

example

http://jsbin.com/ikuca/3

Example is already here - it's not the way to do it however, it's just an idea prototyped in other, for me at the moment easier language.

question

Now, my question is if it's possible to do the same via php, so non-JS users/gadgets could have the same effects and additional styling and also it would be less overkill on browser.

So, is it possible to capture output, parse it as html and inject this class easily in php?

clarification

I'm quite aware of output buffering, just haven't done much stuff with it - also, i'm not sure about modificating output string in php as parsed dom (without regex) - and how tough on server it'll be - with caching of course, so this whole stuff will run once until the page will be edited again.


问:
POST request with CSRF works in Postman but fails in cURL
I make a POST request to REST API to upload a file. In Postman everything works fine. I add Basic authorization and custom CSRF (XSRF) token which I get from the server.

I want to make the same using cURL. I copied the code from Postman, and it does not seem to work.
I believe that the error is related to CSRF because if I turn off CSRF on server and make the same cURL call without CSRF token, everything works fine.

Now some more details:
That's what the command for cURL which Postman gives:

```<code>curl -X POST -H "XSRF: 79f51981-8e85-4e26-be1b-bf63aed92a42" -H "Authorization: Basic bbhjbjb=" -H "Cache-Control: no-cache" -H "Postman-Token: 76a7a43b-f407-15a2-aaff-5242b44d0f47" -H "Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW" -F "package=@C:\Downloads\hello-world.zip" "http://host:port/api/import"
</code>```

And that's the reply I get with --verbose

timeout on name lookup is not supported

Trying ::1...

Connected to localhost (::1) port 7777 (#0)

POST /api/import HTTP/1.1

Host: localhost:7777

User-Agent: curl/7.47.1

Accept: /

XSRF: 79f51981-8e85-4e26-be1b-bf63aed92a42

Authorization: Basic bbhjbjb=

Cache-Control: no-cache

Postman-Token: 76a7a43b-f407-15a2-aaff-5242b44d0f47

Content-Length: 31281

Expect: 100-continue

Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW;
  boundary=------------------------742d3475ac5f6aba

< HTTP/1.1 302 Found

< Set-Cookie: JSESSIONID=1qfjmbntrthxll;Path=/api < Expires: Thu, 01 Jan 1970 00:00:00 GMT

< Set-Cookie: XSRF=b29bd143-cc80-49ad-b495-711125678o;Path=/;Expires=Thu, 15-Dec-2016 10:28:46 GMT

< XSRF: b29bd143-cc80-49ad-b495-711125678o < Location:

http://localhost:7777/api/login/error.jsp?errorMessage=Access Denied

< Content-Length: 0

< Server: Jetty(9.2.17.v20160517)

HTTP error before end of send, stop sending

Closing connection 0

I am probably missing something very obvious here, but don't know what yet.
Looks like I am redirected to login page, not being authenticated correctly, but do not know why (I do send XSRF in cURL). I tried also adding sessionid in cURL - also didn't work.

Any ideas and directions about where to search would be very appreciated!!!

答:
As mentioned in this post, add following option

```<code>--cookie "csrftoken=XXXXXX;sessionid=YYYYYYY"
</code>```

along with

```<code>-H "X-CSRFToken: XXXXX"
</code>```

Body:
I make a POST request to REST API to upload a file. In Postman everything works fine. I add Basic authorization and custom CSRF (XSRF) token which I get from the server.

I want to make the same using cURL. I copied the code from Postman, and it does not seem to work.
I believe that the error is related to CSRF because if I turn off CSRF on server and make the same cURL call without CSRF token, everything works fine.

Now some more details:
That's what the command for cURL which Postman gives:

curl -X POST -H "XSRF: 79f51981-8e85-4e26-be1b-bf63aed92a42" -H "Authorization: Basic bbhjbjb=" -H "Cache-Control: no-cache" -H "Postman-Token: 76a7a43b-f407-15a2-aaff-5242b44d0f47" -H "Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW" -F "package=@C:\Downloads\hello-world.zip" "http://host:port/api/import"

And that's the reply I get with --verbose

timeout on name lookup is not supported

Trying ::1...

Connected to localhost (::1) port 7777 (#0)

POST /api/import HTTP/1.1

Host: localhost:7777

User-Agent: curl/7.47.1

Accept: /

XSRF: 79f51981-8e85-4e26-be1b-bf63aed92a42

Authorization: Basic bbhjbjb=

Cache-Control: no-cache

Postman-Token: 76a7a43b-f407-15a2-aaff-5242b44d0f47

Content-Length: 31281

Expect: 100-continue

Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW;
  boundary=------------------------742d3475ac5f6aba

< HTTP/1.1 302 Found

< Set-Cookie: JSESSIONID=1qfjmbntrthxll;Path=/api < Expires: Thu, 01 Jan 1970 00:00:00 GMT

< Set-Cookie: XSRF=b29bd143-cc80-49ad-b495-711125678o;Path=/;Expires=Thu, 15-Dec-2016 10:28:46 GMT

< XSRF: b29bd143-cc80-49ad-b495-711125678o < Location:

http://localhost:7777/api/login/error.jsp?errorMessage=Access Denied

< Content-Length: 0

< Server: Jetty(9.2.17.v20160517)

HTTP error before end of send, stop sending

Closing connection 0

I am probably missing something very obvious here, but don't know what yet.
Looks like I am redirected to login page, not being authenticated correctly, but do not know why (I do send XSRF in cURL). I tried also adding sessionid in cURL - also didn't work.

Any ideas and directions about where to search would be very appreciated!!!

Body:
As mentioned in this post, add following option

--cookie "csrftoken=XXXXXX;sessionid=YYYYYYY"

along with

-H "X-CSRFToken: XXXXX"


问:
How to prevent select value to reset on form submit?
In the view,

```<code><select id="gender" ng-model="gender">
     <option value=''>Gender?</option>
     <option value="female" >Female</option>
     <option value="male" >Male</option>
     <option value="other" >Other</option>
</select>
<input type="hidden" name="gender" value="{{gender}}">
</code>```

On submit error, the submitted value is retrived and put as the select value,

```<code>var theValue = "<?php echo set_value('gender');?>";
var e = document.getElementById("gender");
e.value = theValue;
</code>```

On submitting the incomplete form, the select should retain the post value, and momentarily it does, but resets again. How do I prevent the select to reset and keep the value?

答:
First, try to always use an object on your ng-model directives, something like:

```<code>ng-model="form.gender"
</code>```

This is best described here:
If you are not using a .(dot) in your AngularJS models you are doing it wrong?

On the response all you need to do is set the form.gender attribute and the two-way-binding of AngularJS will take care of the rest.

Try using the ng-init directive to get values from PHP and use them on your AngularJS controller like:

```<code>ng-init="initGender('<?php echo set_value('gender'); ?>')"
</code>```

and then inside your AngularJS controller:

```<code>$scope.form = {};
$scope.initGender = function(gender) {
    $scope.form.gender = gender;
};
</code>```

Body:
In the view,

<select id="gender" ng-model="gender">
     <option value=''>Gender?</option>
     <option value="female" >Female</option>
     <option value="male" >Male</option>
     <option value="other" >Other</option>
</select>
<input type="hidden" name="gender" value="{{gender}}">

On submit error, the submitted value is retrived and put as the select value,

var theValue = "<?php echo set_value('gender');?>";
var e = document.getElementById("gender");
e.value = theValue;

On submitting the incomplete form, the select should retain the post value, and momentarily it does, but resets again. How do I prevent the select to reset and keep the value?

Body:
First, try to always use an object on your ng-model directives, something like:

ng-model="form.gender"

This is best described here:
If you are not using a .(dot) in your AngularJS models you are doing it wrong?

On the response all you need to do is set the form.gender attribute and the two-way-binding of AngularJS will take care of the rest.

Try using the ng-init directive to get values from PHP and use them on your AngularJS controller like:

ng-init="initGender('<?php echo set_value('gender'); ?>')"

and then inside your AngularJS controller:

$scope.form = {};
$scope.initGender = function(gender) {
    $scope.form.gender = gender;
};