问:
RuntimeException (Chromecast)
I try to configure Chromecast but got RuntimeException and don't understant the reason. Here are logs from Fabric:

Fatal Exception: java.lang.RuntimeException: Unable to start activity
  ComponentInfo{... .activity.TVActivityPhone}:
  java.lang.RuntimeException:
  com.google.android.gms.dynamite.DynamiteModule$zza: Remote load
  failed. No local fallback found.
         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2677)
         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2747)
         at android.app.ActivityThread.access$900(ActivityThread.java:187)
         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1584)
         at android.os.Handler.dispatchMessage(Handler.java:111)
         at android.os.Looper.loop(Looper.java:194)
         at android.app.ActivityThread.main(ActivityThread.java:5877)
         at java.lang.reflect.Method.invoke(Method.java)
         at java.lang.reflect.Method.invoke(Method.java:372)
         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815) Caused by java.lang.RuntimeException:
  com.google.android.gms.dynamite.DynamiteModule$zza: Remote load
  failed. No local fallback found.

And here is my code:

```<code>protected void configureCast() {
        mCastContext = CastContext.getSharedInstance(this); // here I've got RuntimeException
        if(mCastContext != null) mCastSession = mCastContext.getSessionManager().getCurrentCastSession();
        mSessionManagerListener = new CastSessionManagerListener(this);
        mSessionManagerListener.setCastConnectionListener(mCastConnectionListener);
    }
</code>```

Here is build.gradle:

```<code>    compile 'com.google.android.gms:play-services-gcm:10.2.0'
    compile 'com.google.android.gms:play-services-analytics:10.2.0'
    compile 'com.google.android.gms:play-services-location:10.2.0'
    compile 'com.google.android.gms:play-services-cast-framework:10.2.0'
</code>```

Any help?

答:
First of all, it's not related to wrong project configuration as described in Why I get this error when on google map "Failed to load DynamiteLoader: java.lang.ClassNotFoundException: Didn't find class?.

One day I got a spike (~1300 crash in 1 day) in crashes in Fabric with
com.google.android.gms.dynamite.DynamiteModule$zza: Remote load failed. No local fallback,
com.google.android.gms.dynamite.DynamiteModule$zzc: No acceptable module found. Local version is 0 and remote version is 0 exceptions.

It wasn't clear to me from the first look why it happened as I didn't ship any update of the application during that period of time. After deeper investigation (few days in total) I have found that the issue is caused by broken compatibility between Google Play Services version and outdated Google Cast SDK.

My Android application used 10.2.4 version of Google Cast SDK and this version is not compatible with some Google Play Services versions.
I have found that 11.3.02 (480-161239932) version of Google Play Service is not compatible with 10.2.4 Google Cast SDK. There are (for sure) other versions of Google Play Services which are not compatible with Google Cast SDK library, but I found just one and it was enough for testing and further fix.

Having 11.3.02 (480-161239932) version of Google Play Services installed on the device my application was crashing immediately upon start. Worth noting, that I have found other applications on my device which were crashing immediately upon start and stack trace was the same.

Fix for the crash

Fix was simple for me - I had to update Google Play Services from 10.2.4 to 11.4.2,
 in particular play-services-cast-framework, play-services-ads, firebase-core, firebase-messaging.

Spikes history in Fabric:

September 25 (~400 crashes), first spike

September 27 (~200 crashes)

September 29 (~140 crashes)

October 8 (~1300 crashes)

After October 8th crash wasn't that critical (~10-20 crashes per day) and no more spikes observed. This means that users updated Google Play Services and application didn't crash anymore on start.

Once I updated the Google Play Services version and users updated to new version of application - crash disappeared (~1-2 crashes per day).

Explanation of why this crash occured

As you may know, Google Play Services are automatically updated in background. This means that one day users can receive update of Google Play Services which is not compatible with Google Cast SDK used in application and application will crash (100%).

From my experience, it happens for Google Cast SDK, but might be the case with other libraries (no proofs).

Application crashes when you are calling any method from Google Cast SDK. I have commented different places in my application which rely on Google Cast SDK and application was always crashing.

Detailed guide

If someone is curious how to mimic this crash, here's detailed guide.

First of all, we need to uninstall existing version of Google Play Services. This can be achieved from "Google Play Services" application info screen

Install 11.3.02 (480-161239932) version of Google Play Services on Android device (apkmirror link).

adb install -r com.google.android.gms_11.3.02_(480-161239932)-11302480_minAPI23(x86,x86_64)(nodpi)_apkmirror.com.apk

Open application and observer application crash when Google Cast SDK accessed.

2nd arrival of the crash

I thought that I have fixed the crash by update Google Play Services, but few weeks after silence I've got notification that crash with the same stacktrace resurfaced.

After some investigation (few days again) I was able to reproduce the issue. And here are the sad news - I can do nothing about this crash :sad_face: or at least I didn't find elegant solution yet.

Good news are that resurfaced crash appearance is very rare (~1-2 crashes per month).

Google Play Services auto-update or force uninstall (less probable) force stops open application to take effect of Play Services update. This is an uncontrollable process, which means that Android OS can install silently Google Play Services at any time. If the user has application open and Google Play Services installation finishes at some point, an application will be killed by the system and user needs to reopen it. When an application is killed by the system, we can see in logs exact the same stacktrace for the crash as we had for the 1st case.
It's hard to reproduce and happened to me only a few times.
But this case is more probably as Google Play Services are getting updates quite often.

Though there's a way to reproduce this crash (less probable in real life) - "removal of Google Play Services updates from device". It produces the same stacktrace.

So basically, we need to start removal of Google Play Services updates and quickly (I mean really quick) open our application. If we succeed, the application will be killed by the system upon start as Google Play Services were removed and system kills the application.

And here's the stacktrace:

```<code>FATAL EXCEPTION: main
Process: XXX, PID: 26149
java.lang.RuntimeException: Unable to start activity ComponentInfo{XXX/XXX.SomeActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class fragment
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2733)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2819)
    at android.app.ActivityThread.-wrap12(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1532)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6321)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
 Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class fragment
 Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class fragment
 Caused by: java.lang.RuntimeException: com.google.android.gms.dynamite.DynamiteModule$zzc: No acceptable module found. Local version is 0 and remote version is 0.
    at com.google.android.gms.internal.zzavl.zzbp(Unknown Source)
    at com.google.android.gms.internal.zzavl.zza(Unknown Source)
    at com.google.android.gms.cast.framework.CastContext.<init>(Unknown Source)
    at com.google.android.gms.cast.framework.CastContext.getSharedInstance(Unknown Source)
    at com.google.android.gms.cast.framework.media.uicontroller.UIMediaController.<init>(Unknown Source)
    at com.google.android.gms.cast.framework.media.widget.MiniControllerFragment.onCreateView(Unknown Source)
    at android.support.v4.app.Fragment.performCreateView(Fragment.java:2343)
    at android.support.v4.app.FragmentManagerImpl.ensureInflatedFragmentView(FragmentManager.java:1645)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1390)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1640)
    at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1896)
    at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3673)
    at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111)
    at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:331)
    at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39)
    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:65)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:777)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
    at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
    at XXX.SomeActivity.setContentView(SomeActivity:XXX)
    at XXX.SomeActivity.onCreate(SomeActivity:XXX)
    at android.app.Activity.performCreate(Activity.java:6760)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
</code>```

Update

There was a Google Play Services 12.0.0 release, which supposes to fix the issue:

Fixed a bug where calling CastContext.getSharedInstance() on devices with out-of-date versions of Google Play services caused a crash. Outdated Google Play services versions still cause the method to fail, so clients should check for an appropriate version.

But in fact, even after updating to 12.0.0 version I'm seeing lots of crashes. Crashes occur when there's an update of Google Play Services is happening on the device.
To workaround this issue, we need to check if Cast API is available by checking if an Exception is not thrown when we call Cast API.

```<code>fun isCastApiAvailable(): Boolean {
    val isCastApiAvailable = isNotTv(context)
            && GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS
    try {
        CastContext.getSharedInstance(context)
    } catch (e: Exception) {
        // track non-fatal
        return false
    }
    return isCastApiAvailable
}
</code>```

This way we prevent the crash. The application might be killed and restarted by the system if Play Services update happens when the application is in the foreground. Alternatively, Cast API related features won't be available (Chromecast icon is not visible).
So we avoid the crash this way and report as non-fatals just to have understanding how often this situation happens.

Title: RuntimeException (Chromecast)

Body:
I try to configure Chromecast but got RuntimeException and don't understant the reason. Here are logs from Fabric:

Fatal Exception: java.lang.RuntimeException: Unable to start activity
  ComponentInfo{... .activity.TVActivityPhone}:
  java.lang.RuntimeException:
  com.google.android.gms.dynamite.DynamiteModule$zza: Remote load
  failed. No local fallback found.
         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2677)
         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2747)
         at android.app.ActivityThread.access$900(ActivityThread.java:187)
         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1584)
         at android.os.Handler.dispatchMessage(Handler.java:111)
         at android.os.Looper.loop(Looper.java:194)
         at android.app.ActivityThread.main(ActivityThread.java:5877)
         at java.lang.reflect.Method.invoke(Method.java)
         at java.lang.reflect.Method.invoke(Method.java:372)
         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815) Caused by java.lang.RuntimeException:
  com.google.android.gms.dynamite.DynamiteModule$zza: Remote load
  failed. No local fallback found.

And here is my code:

protected void configureCast() {
        mCastContext = CastContext.getSharedInstance(this); // here I've got RuntimeException
        if(mCastContext != null) mCastSession = mCastContext.getSessionManager().getCurrentCastSession();
        mSessionManagerListener = new CastSessionManagerListener(this);
        mSessionManagerListener.setCastConnectionListener(mCastConnectionListener);
    }

Here is build.gradle:

    compile 'com.google.android.gms:play-services-gcm:10.2.0'
    compile 'com.google.android.gms:play-services-analytics:10.2.0'
    compile 'com.google.android.gms:play-services-location:10.2.0'
    compile 'com.google.android.gms:play-services-cast-framework:10.2.0'

Any help?

Body:
First of all, it's not related to wrong project configuration as described in Why I get this error when on google map "Failed to load DynamiteLoader: java.lang.ClassNotFoundException: Didn't find class?.

One day I got a spike (~1300 crash in 1 day) in crashes in Fabric with
com.google.android.gms.dynamite.DynamiteModule$zza: Remote load failed. No local fallback,
com.google.android.gms.dynamite.DynamiteModule$zzc: No acceptable module found. Local version is 0 and remote version is 0 exceptions.

It wasn't clear to me from the first look why it happened as I didn't ship any update of the application during that period of time. After deeper investigation (few days in total) I have found that the issue is caused by broken compatibility between Google Play Services version and outdated Google Cast SDK.

My Android application used 10.2.4 version of Google Cast SDK and this version is not compatible with some Google Play Services versions.
I have found that 11.3.02 (480-161239932) version of Google Play Service is not compatible with 10.2.4 Google Cast SDK. There are (for sure) other versions of Google Play Services which are not compatible with Google Cast SDK library, but I found just one and it was enough for testing and further fix.

Having 11.3.02 (480-161239932) version of Google Play Services installed on the device my application was crashing immediately upon start. Worth noting, that I have found other applications on my device which were crashing immediately upon start and stack trace was the same.

Fix for the crash

Fix was simple for me - I had to update Google Play Services from 10.2.4 to 11.4.2,
 in particular play-services-cast-framework, play-services-ads, firebase-core, firebase-messaging.

Spikes history in Fabric:

September 25 (~400 crashes), first spike

September 27 (~200 crashes)

September 29 (~140 crashes)

October 8 (~1300 crashes)

After October 8th crash wasn't that critical (~10-20 crashes per day) and no more spikes observed. This means that users updated Google Play Services and application didn't crash anymore on start.

Once I updated the Google Play Services version and users updated to new version of application - crash disappeared (~1-2 crashes per day).

Explanation of why this crash occured

As you may know, Google Play Services are automatically updated in background. This means that one day users can receive update of Google Play Services which is not compatible with Google Cast SDK used in application and application will crash (100%).

From my experience, it happens for Google Cast SDK, but might be the case with other libraries (no proofs).

Application crashes when you are calling any method from Google Cast SDK. I have commented different places in my application which rely on Google Cast SDK and application was always crashing.

Detailed guide

If someone is curious how to mimic this crash, here's detailed guide.

First of all, we need to uninstall existing version of Google Play Services. This can be achieved from "Google Play Services" application info screen

Install 11.3.02 (480-161239932) version of Google Play Services on Android device (apkmirror link).

adb install -r com.google.android.gms_11.3.02_(480-161239932)-11302480_minAPI23(x86,x86_64)(nodpi)_apkmirror.com.apk

Open application and observer application crash when Google Cast SDK accessed.

2nd arrival of the crash

I thought that I have fixed the crash by update Google Play Services, but few weeks after silence I've got notification that crash with the same stacktrace resurfaced.

After some investigation (few days again) I was able to reproduce the issue. And here are the sad news - I can do nothing about this crash :sad_face: or at least I didn't find elegant solution yet.

Good news are that resurfaced crash appearance is very rare (~1-2 crashes per month).

Google Play Services auto-update or force uninstall (less probable) force stops open application to take effect of Play Services update. This is an uncontrollable process, which means that Android OS can install silently Google Play Services at any time. If the user has application open and Google Play Services installation finishes at some point, an application will be killed by the system and user needs to reopen it. When an application is killed by the system, we can see in logs exact the same stacktrace for the crash as we had for the 1st case.
It's hard to reproduce and happened to me only a few times.
But this case is more probably as Google Play Services are getting updates quite often.

Though there's a way to reproduce this crash (less probable in real life) - "removal of Google Play Services updates from device". It produces the same stacktrace.

So basically, we need to start removal of Google Play Services updates and quickly (I mean really quick) open our application. If we succeed, the application will be killed by the system upon start as Google Play Services were removed and system kills the application.

And here's the stacktrace:

FATAL EXCEPTION: main
Process: XXX, PID: 26149
java.lang.RuntimeException: Unable to start activity ComponentInfo{XXX/XXX.SomeActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class fragment
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2733)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2819)
    at android.app.ActivityThread.-wrap12(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1532)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6321)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
 Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class fragment
 Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class fragment
 Caused by: java.lang.RuntimeException: com.google.android.gms.dynamite.DynamiteModule$zzc: No acceptable module found. Local version is 0 and remote version is 0.
    at com.google.android.gms.internal.zzavl.zzbp(Unknown Source)
    at com.google.android.gms.internal.zzavl.zza(Unknown Source)
    at com.google.android.gms.cast.framework.CastContext.<init>(Unknown Source)
    at com.google.android.gms.cast.framework.CastContext.getSharedInstance(Unknown Source)
    at com.google.android.gms.cast.framework.media.uicontroller.UIMediaController.<init>(Unknown Source)
    at com.google.android.gms.cast.framework.media.widget.MiniControllerFragment.onCreateView(Unknown Source)
    at android.support.v4.app.Fragment.performCreateView(Fragment.java:2343)
    at android.support.v4.app.FragmentManagerImpl.ensureInflatedFragmentView(FragmentManager.java:1645)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1390)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1640)
    at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1896)
    at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3673)
    at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111)
    at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:331)
    at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39)
    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:65)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:777)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
    at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
    at XXX.SomeActivity.setContentView(SomeActivity:XXX)
    at XXX.SomeActivity.onCreate(SomeActivity:XXX)
    at android.app.Activity.performCreate(Activity.java:6760)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)

Update

There was a Google Play Services 12.0.0 release, which supposes to fix the issue:

Fixed a bug where calling CastContext.getSharedInstance() on devices with out-of-date versions of Google Play services caused a crash. Outdated Google Play services versions still cause the method to fail, so clients should check for an appropriate version.

But in fact, even after updating to 12.0.0 version I'm seeing lots of crashes. Crashes occur when there's an update of Google Play Services is happening on the device.
To workaround this issue, we need to check if Cast API is available by checking if an Exception is not thrown when we call Cast API.

fun isCastApiAvailable(): Boolean {
    val isCastApiAvailable = isNotTv(context)
            && GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS
    try {
        CastContext.getSharedInstance(context)
    } catch (e: Exception) {
        // track non-fatal
        return false
    }
    return isCastApiAvailable
}

This way we prevent the crash. The application might be killed and restarted by the system if Play Services update happens when the application is in the foreground. Alternatively, Cast API related features won't be available (Chromecast icon is not visible).
So we avoid the crash this way and report as non-fatals just to have understanding how often this situation happens.


来源: stackexchange

问:
Mercurial undoing push to main branch
I accidentally pushed some changes to the main branch which weren't ready, so I immediately did a backout. Later I tried merging new changes from the trunk into my branch, but the merge didn't work very well. In particular, it seemed that it thought the backout meant that I wanted all of my changes undone. Fortunately, none of the files that I had modified were modified by the changes on the main branch, so I could just revert the files to local, but if there had been conflicts, this would have been messy. Was backing out the right thing to do in this situation, or is there something else I could have done to avoid potential conflicts later.</p>

答:
Happened to me too.  In case it helps any one else:
My repository shouldn't have allowed pushes anyway.  Do do that, put in your .hg/hgrc file:

```<code>[hooks]
prechangegroup = false
</code>```

That is, if you want to prevent anyone from pushing into that repository.

ContentLicense: CC BY-SA 2.5

Title: Mercurial undoing push to main branch

Body:
Happened to me too.  In case it helps any one else:
My repository shouldn't have allowed pushes anyway.  Do do that, put in your .hg/hgrc file:

[hooks]
prechangegroup = false

That is, if you want to prevent anyone from pushing into that repository.


问:
Is it possible to forward only part of a path using aws elb?
I am trying to create rules in my ALB so there are parts of the path that I do not forward on to the target.  So for example, my underlying service may accept a call like

GET http://hostname/dogs

But in the ALB I might add a version to the path for routing purposes:

GET http://hostname/v1/dogs

or I could call

GET http://hostname/v2/dogs

Both versions would be running in different target groups.  I was thinking I could then drop the version part off so that my application doesn't have to be concerned with versioning.  However, it's not obvious how I might handle that and it doesn't appear to be possible.

答:
This is not something that is currently supported by Application Load Balancer.

CloudFront, however, has a setting called Origin Path that is prepended to the request URI before sending the request to the origin server -- in this case, the origin ALB -- so you'd set the origin path to /v1 if you wanted example.com/dogs to be sent to the ALB as example.com/v1/dogs.  CloudFront is a CDN but it has a number of other purposes, such as request rewriting -- it's essentially a massive, globally-distributed reverse proxy with a cache, and supports dynamic as well as static content.  More complex rewrites require Lambda@Edge in addition to CloudFront, but prepending a string to certain request path patterns is part of the base feature set.

ContentLicense: CC BY-SA 3.0


问:
Regarding WPF and web development?
i don't know anything about WPF. so a question has come to my mind that when we develop apps in WPF that can be run as web application without changing code. please comment. thanks.</p>

答: Have a look at the XBAP variation of WPF too. See if it fits your need.</p>

Title: Regarding WPF and web development?


问:
What does a tensorflow "op" do?
Below I have created a tf placeholder named "op testing":

```<code>self.center_words = tf.placeholder(tf.int32, shape=[self.batch_size], name='op testing')
print("Extracting the op", self.center_words.op)
</code>```

When I print that self.center_words.op it prints out a structure like this:

```<code>op: "Placeholder"
attr {
  key: "dtype"
  value {
    type: DT_INT32
  }
}
attr {
  key: "shape"
  value {
    shape {
      dim {
        size: 128
      }
    }
  }
}
</code>```

This works for any TensorFlow variable, function output, etc. What is this .op?

答:
TensorFlow Operations, also known as Ops, are nodes that
perform computations on or with Tensor objects. After computation, they return zero or
more tensors, which can be used by other Ops later in the graph. To create an Operation,
you call its constructor in Python, which takes in whatever Tensor parameters needed for
its calculation, known as inputs, as well as any additional information needed to properly
create the Op, known as attributes. The Python constructor returns a handle to the
Operation’s output (zero or more Tensor objects), and it is this output which can be passed
on to other Operations or Session.run

ContentLicense: CC BY-SA 4.0

Title: What does a tensorflow "op" do?

Body:
Below I have created a tf placeholder named "op testing":

self.center_words = tf.placeholder(tf.int32, shape=[self.batch_size], name='op testing')
print("Extracting the op", self.center_words.op)

When I print that self.center_words.op it prints out a structure like this:

op: "Placeholder"
attr {
  key: "dtype"
  value {
    type: DT_INT32
  }
}
attr {
  key: "shape"
  value {
    shape {
      dim {
        size: 128
      }
    }
  }
}

This works for any TensorFlow variable, function output, etc. What is this .op?


问:
Google Drive Api Pdf export from Google Doc generate empty response
I'm using the export Google Drive API to retrieve a Google Doc as Pdf: https://developers.google.com/drive/v3/reference/files/export

I'm having the following problem: for documents bigger than a certain size (I don't know exactly the threshold, but it happens even with relatively small files around 1,5 MB) the API return a 200 response code with a blank result (normally it should contains the pdf data as byte stream), as you can see in the following screenshot:

I can successfully export the file via GoogleDrive/GoogleDoc UI  with the "File -> Download as.. -> Pdf" command, despite it takes a bit of time.

Here is the file used for test (1.180 KB exported from Google Doc), I shared it so you can access to try export:
https://docs.google.com/document/d/18Cz7kHfEiDLeTWHyyoOi6U4kFQDMeg0D-CCJzILMMCk/edit?usp=sharing

Here is the (Java) code I'm using to perform the operation:

```<code>@Override
public GoogleDriveDocumentContent downloadFileContentAsPDF(String executionGoogleUser, String fileId) {

    GoogleDriveDocumentContent documentContent = new GoogleDriveDocumentContent();

    String conversionMimeType = "application/pdf";

    try {

        getLogger().info("GDrive APIs - Downloading file content in PDF format ...");

        InputStream gDriveFileData = getDriveService(executionGoogleUser).files()
                .export(fileId, conversionMimeType)
                .executeMediaAsInputStream();

        getLogger().info("GDrive APIs - File content as PDF format downloaded.");

        documentContent.setFileName(null);
        documentContent.setMimeType(conversionMimeType);
        documentContent.setData(gDriveFileData);

    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    return documentContent;

}
</code>```

Does anyone has the same issue and know how to solve it?
The goal is to generate a pdf from a Google Doc.

Thanks

答:
I think you should try using media downloadeder you will have to alter it for Google drive rather than storage service.

```<code>{
    // Create the service using the client credentials.
    var storageService = new StorageService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "APP_NAME_HERE"
        });
    // Get the client request object for the bucket and desired object.
    var getRequest = storageService.Objects.Get("BUCKET_HERE", "OBJECT_HERE");
    using (var fileStream = new System.IO.FileStream(
        "FILE_PATH_HERE",
        System.IO.FileMode.Create,
        System.IO.FileAccess.Write))
    {
        // Add a handler which will be notified on progress changes.
        // It will notify on each chunk download and when the
        // download is completed or failed.
        getRequest.MediaDownloader.ProgressChanged += Download_ProgressChanged;
        getRequest.Download(fileStream);
    }
}

static void Download_ProgressChanged(IDownloadProgress progress)
{
    Console.WriteLine(progress.Status + " " + progress.BytesDownloaded);
}
</code>```

Code ripped from here

Body:
I'm using the export Google Drive API to retrieve a Google Doc as Pdf: https://developers.google.com/drive/v3/reference/files/export

I'm having the following problem: for documents bigger than a certain size (I don't know exactly the threshold, but it happens even with relatively small files around 1,5 MB) the API return a 200 response code with a blank result (normally it should contains the pdf data as byte stream), as you can see in the following screenshot:

I can successfully export the file via GoogleDrive/GoogleDoc UI  with the "File -> Download as.. -> Pdf" command, despite it takes a bit of time.

Here is the file used for test (1.180 KB exported from Google Doc), I shared it so you can access to try export:
https://docs.google.com/document/d/18Cz7kHfEiDLeTWHyyoOi6U4kFQDMeg0D-CCJzILMMCk/edit?usp=sharing

Here is the (Java) code I'm using to perform the operation:

@Override
public GoogleDriveDocumentContent downloadFileContentAsPDF(String executionGoogleUser, String fileId) {

    GoogleDriveDocumentContent documentContent = new GoogleDriveDocumentContent();

    String conversionMimeType = "application/pdf";

    try {

        getLogger().info("GDrive APIs - Downloading file content in PDF format ...");

        InputStream gDriveFileData = getDriveService(executionGoogleUser).files()
                .export(fileId, conversionMimeType)
                .executeMediaAsInputStream();

        getLogger().info("GDrive APIs - File content as PDF format downloaded.");

        documentContent.setFileName(null);
        documentContent.setMimeType(conversionMimeType);
        documentContent.setData(gDriveFileData);

    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    return documentContent;

}

Does anyone has the same issue and know how to solve it?
The goal is to generate a pdf from a Google Doc.

Thanks

Body:
I think you should try using media downloadeder you will have to alter it for Google drive rather than storage service.

{
    // Create the service using the client credentials.
    var storageService = new StorageService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "APP_NAME_HERE"
        });
    // Get the client request object for the bucket and desired object.
    var getRequest = storageService.Objects.Get("BUCKET_HERE", "OBJECT_HERE");
    using (var fileStream = new System.IO.FileStream(
        "FILE_PATH_HERE",
        System.IO.FileMode.Create,
        System.IO.FileAccess.Write))
    {
        // Add a handler which will be notified on progress changes.
        // It will notify on each chunk download and when the
        // download is completed or failed.
        getRequest.MediaDownloader.ProgressChanged += Download_ProgressChanged;
        getRequest.Download(fileStream);
    }
}

static void Download_ProgressChanged(IDownloadProgress progress)
{
    Console.WriteLine(progress.Status + " " + progress.BytesDownloaded);
}

Code ripped from here


答:
If I understand this correctly then one way to do this would be use each row of t1 and find where any row falls within each time range:

```<code>select from t2 where any date within/:value each t1
date                    ccypair mid
-----------------------------------------
2017.10.01T10:01:00.000 EURUSD  0.41239
2017.10.01T10:02:00.000 EURUSD  0.5429457
...
</code>```

Which is the same as yoru example output above, without the afrom and ato columns. In this example within selects all values within a range and any and each-right /: allow you to use multiple ranges. If this does not scale particularly well for you then you can work on each row of t1 individually:

```<code>raze{[x;y]select from x where date within value y}[t2]'[t1]
</code>```

Which should work if the windows do not overlap.

If you need exclusive or then you could try modifying the window times slightly to ensure they are excluded:

```<code>q)select from t2 where any date within/:value each @[t1;`afrom`ato;+;1 -1*00:00:00.001]
date                    ccypair mid
-----------------------------------------
2017.10.01T10:01:00.000 EURUSD  0.41239
2017.10.01T10:02:00.000 EURUSD  0.5429457
...
</code>```

To add the afrom and ato columns to the output you can cross them with the selected rows:

```<code>raze{[x;y]flip[1#'y]cross select from x where date within value[y]+1 -1*00:00:00.001}[t2]'[t1]
afrom                   ato                     date                    ccypair mid
-----------------------------------------------------------------------------------------
2017.10.01T10:00:00.000 2017.10.01T12:00:00.000 2017.10.01T10:01:00.000 EURUSD  0.41239
2017.10.01T10:00:00.000 2017.10.01T12:00:00.000 2017.10.01T10:02:00.000 EURUSD  0.5429457
...
</code>```

Title: Is there a more scalable sub-select alternative to this query?

Body:
I have a large table that contains a date field of type datetime. As part of a function that takes as input two lists of datetime namely a list of afroms and atos I'd like to compute for each of these afrom,ato pairs all the rows of the large table whose date is between them.

I worked out a not very efficient way to do this i.e. it has a serious scalability drawback:

/ t1 contains my afrom,ato pairs
q)t1:([] afrom:`datetime$(2017.10.01T10:00:00.000 2017.10.02T10:00:00.000);ato:`datetime$(2017.10.01T12:00:00.000 2017.10.02T12:00:00.000));
q)t1
afrom                   ato
-----------------------------------------------
2017.10.01T10:00:00.000 2017.10.01T12:00:00.000
2017.10.02T10:00:00.000 2017.10.02T12:00:00.000

/ t2 contains my very very large dataset
q)t2:([] date:`datetime$(2017.10.01T10:01:00.000 2017.10.01T10:02:00.000 2017.10.01T10:03:00.000 2017.10.02T10:01:00.000 2017.10.02T10:02:00.000 2017.10.02T10:03:00.000); ccypair:(3#`EURUSD),(3#`USDCHF); mid:6?1.05);
q)t2
date                    ccypair mid
----------------------------------------------------
2017.10.01T10:01:00.000 EURUSD  0.24256133290473372
2017.10.01T10:02:00.000 EURUSD  0.091602176288142809
2017.10.01T10:03:00.000 EURUSD  0.10756538207642735
2017.10.02T10:01:00.000 USDCHF  0.91046513157198206
2017.10.02T10:02:00.000 USDCHF  0.76424539103172717
2017.10.02T10:03:00.000 USDCHF  0.17090452200500295

Then I can use cross like this:

select from (t1 cross t2) where afrom<date,date<ato

and this produces the correct results:

afrom                   ato                     date                    ccypa..
-----------------------------------------------------------------------------..
2017.10.01T10:00:00.000 2017.10.01T12:00:00.000 2017.10.01T10:01:00.000 EURUS..
2017.10.01T10:00:00.000 2017.10.01T12:00:00.000 2017.10.01T10:02:00.000 EURUS..
2017.10.01T10:00:00.000 2017.10.01T12:00:00.000 2017.10.01T10:03:00.000 EURUS..
2017.10.02T10:00:00.000 2017.10.02T12:00:00.000 2017.10.02T10:01:00.000 USDCH..
2017.10.02T10:00:00.000 2017.10.02T12:00:00.000 2017.10.02T10:02:00.000 USDCH..
2017.10.02T10:00:00.000 2017.10.02T12:00:00.000 2017.10.02T10:03:00.000 USDCH..

However, when I have a large list of afroms and atos the cross will "unnecessarily" expand the potentially large table t2 times the size of t1 and that doesn't scale well.

Is there a better way to do this? e.g. I have tried things like:

select from t2 where (exec afrom from t1)<date,date<(exec ato from t1)
error: `length

I would need to do a loop I guess but not sure how. Subquestion .. is it possible to have a sigle list of interval tuples i.e. intervals(afrom;ato) instead of having separated afroms and atos?

Body:
If I understand this correctly then one way to do this would be use each row of t1 and find where any row falls within each time range:

select from t2 where any date within/:value each t1
date                    ccypair mid
-----------------------------------------
2017.10.01T10:01:00.000 EURUSD  0.41239
2017.10.01T10:02:00.000 EURUSD  0.5429457
...

Which is the same as yoru example output above, without the afrom and ato columns. In this example within selects all values within a range and any and each-right /: allow you to use multiple ranges. If this does not scale particularly well for you then you can work on each row of t1 individually:

raze{[x;y]select from x where date within value y}[t2]'[t1]

Which should work if the windows do not overlap.

If you need exclusive or then you could try modifying the window times slightly to ensure they are excluded:

q)select from t2 where any date within/:value each @[t1;`afrom`ato;+;1 -1*00:00:00.001]
date                    ccypair mid
-----------------------------------------
2017.10.01T10:01:00.000 EURUSD  0.41239
2017.10.01T10:02:00.000 EURUSD  0.5429457
...

To add the afrom and ato columns to the output you can cross them with the selected rows:

raze{[x;y]flip[1#'y]cross select from x where date within value[y]+1 -1*00:00:00.001}[t2]'[t1]
afrom                   ato                     date                    ccypair mid
-----------------------------------------------------------------------------------------
2017.10.01T10:00:00.000 2017.10.01T12:00:00.000 2017.10.01T10:01:00.000 EURUSD  0.41239
2017.10.01T10:00:00.000 2017.10.01T12:00:00.000 2017.10.01T10:02:00.000 EURUSD  0.5429457
...


问:
TypeError: (intermediate value).keys(...).map is not a function
I am getting a strange error, could somebody help me fix this out?

```<code>const myArray = new Array(4)
    .keys()
    .map((v, i) => (
          console.log('print:', v, i)
      )
    )
console.log('myArray print: ', myArray);
</code>```

I am getting this error:

```<code>TypeError: (intermediate value).keys(...).map is not a function
</code>```

update:

i want to use the i to look up some stuff from another existing array.

```<code>const myArray = new Array(4)
    .keys()
    .map((v, i) => ({
      name: i
      })
    )
console.log('myArray print: ', myArray);
</code>```

edit:

this question is not a duplicate, It is trying to iterate over a certain number and create a new object using the iterations.

答:
You can use Array.from to get the expected output:

var myArray = Array.from(Array(4), (value, index) => ({ name: index}));
console.log('myArray print: ', myArray);```

Body:
I am getting a strange error, could somebody help me fix this out?

const myArray = new Array(4)
    .keys()
    .map((v, i) => (
          console.log('print:', v, i)
      )
    )
console.log('myArray print: ', myArray);

I am getting this error:

TypeError: (intermediate value).keys(...).map is not a function

update:

i want to use the i to look up some stuff from another existing array.

const myArray = new Array(4)
    .keys()
    .map((v, i) => ({
      name: i
      })
    )
console.log('myArray print: ', myArray);

edit:

this question is not a duplicate, It is trying to iterate over a certain number and create a new object using the iterations.


问:
General error: 1366 Incorrect string value: '\xD6wn Sm...' for column 'user_agent'
I need to save the user agent of a visiting user.

This is my snippet:

```<code>// User Agent
$ua = $_SERVER['HTTP_USER_AGENT']??'';
$ua_md5 = md5($ua);
// Search if the UA already exists in the user_agents table
$ua_id = $db->query("SELECT id FROM user_agents WHERE md5='".$ua_md5."';")->fetchColumn();

if(!$ua_id) {
    // If it doesn't exist, insert it and get its id
    $db->query("INSERT INTO user_agents (md5, user_agent) VALUES ('$ua_md5', ".$db->quote($ua).")");
    $ua_id = $db->lastInsertId();
}
</code>```

I use PDO:quote instead of prepared statements only for performance reasons (it's faster and this script runs thousands of times per second).

It happens that some users has this user agent:

Mozilla/5.0 (Linux; Android 5.0; \xD6wn Smart Build/LRX21M) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/37.0.0.0 Mobile Safari/537.36

And the insert fails for this error:

"PHP message: SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xD6wn Sm...' for column 'user_agent' at row 1" while reading response header from upstream

What is the reason and how can it be fixed?

Edit: more debugging found out the $ua value is:

Mozilla/5.0 (Linux; Android 5.0; ÖWN S1 Build/LRX21M) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/37.0.0.0 Mobile Safari/537.36

答:
First of all, when it comes to encoding issues it's always necessary to inspect raw bytes and never rely of the output of some process that renders or interpret the input. In the case of PHP, var_dump() is always a good starting point but you also need to dump to hex or even resort to an hexadecimal editor:

```<code><?php
var_dump(bin2hex($_SERVER['HTTP_USER_AGENT']));
</code>```

My educated guess so far (and I don't believe it's too far from truth) is:

Some Android browser is sending an HTTP header that includes Öwn Smart Build encoded in ISO-8859-1, where Ö aka 'LATIN CAPITAL LETTER O WITH DIAERESIS' (U+00D6) is encoded as D6.

Your app stack is configured for UTF-8 (the sensible choice), where Ö would be encoded as C396.

PHP doesn't know/care, because PHP strings aren't encoding-aware (they're just byte streams).

MySQL is handled D6, being told it's UTF-8 (but it isn't).

Had D6 been a valid UTF-8 (different) character, or part of a (different) multi-byte sequence, insertion would have completed with minor data loss (the original Öwn text would have been lost and replaced by something else). For good or bad, it isn't valid UTF-8, thus MySQL aborts the insertion with the error message you describe.

Why can't MySQL cope with it? Let's check the UTF-8 definition:

```<code>Nr of
Bytes    Byte 1   Byte 2       Byte 3     Byte 4
1      0xxxxxxx
2      110xxxxx   10xxxxxx
3      1110xxxx   10xxxxxx   10xxxxxx
4      11110xxx   10xxxxxx   10xxxxxx   10xxxxxx
</code>```

Original Latin-1 Öw text is encoded as D6 77 which, translated to binary, is:

```<code>11010110 01001101
^^^      ^^
</code>```

In UTF-8, 110… means "Start of 2-byte character". Second byte should then start with 10… but we have 01… instead. Oops!

How can you solve this? It's trickier than it seems. If you could know for sure that input is ISO-8859-1, it's just a straightforward conversion:

```<code><?php
$input = "\xD6wn";
$output = mb_convert_encoding($input, 'UTF-8', 'ISO-8859-1');
var_dump(bin2hex($input), bin2hex($output));
</code>```

```<code>string(6) "d6776e"
string(8) "c396776e"
</code>```

(Online demo)

But, how can you know? I'm not sure if the User-Agent header allows MIME Encoded-Words and, even there, the browser may just send invalid data anyway. Perhaps you can catch the error (MySQL error code 1366 aka ER_TRUNCATED_WRONG_VALUE_FOR_FIELD looks reasonably precise) and try again assuming ISO-8859-1. And it's probably also a good idea to verify that input is valid UTF-8, though it can make processing kind of bothersome:

```<code><?php
$latin1 = "\xD6wn";
$utf8 = "\xc3\x96wn";
var_dump(mb_check_encoding($latin1, 'UTF-8'));
var_dump(mb_check_encoding($utf8, 'UTF-8'));
</code>```

```<code>bool(false)
bool(true)
</code>```

(Online demo)

Body:
I need to save the user agent of a visiting user.

This is my snippet:

// User Agent
$ua = $_SERVER['HTTP_USER_AGENT']??'';
$ua_md5 = md5($ua);
// Search if the UA already exists in the user_agents table
$ua_id = $db->query("SELECT id FROM user_agents WHERE md5='".$ua_md5."';")->fetchColumn();

if(!$ua_id) {
    // If it doesn't exist, insert it and get its id
    $db->query("INSERT INTO user_agents (md5, user_agent) VALUES ('$ua_md5', ".$db->quote($ua).")");
    $ua_id = $db->lastInsertId();
}

I use PDO:quote instead of prepared statements only for performance reasons (it's faster and this script runs thousands of times per second).

It happens that some users has this user agent:

Mozilla/5.0 (Linux; Android 5.0; \xD6wn Smart Build/LRX21M) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/37.0.0.0 Mobile Safari/537.36

And the insert fails for this error:

"PHP message: SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xD6wn Sm...' for column 'user_agent' at row 1" while reading response header from upstream

What is the reason and how can it be fixed?

Edit: more debugging found out the $ua value is:

Mozilla/5.0 (Linux; Android 5.0; ÖWN S1 Build/LRX21M) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/37.0.0.0 Mobile Safari/537.36

Body:
First of all, when it comes to encoding issues it's always necessary to inspect raw bytes and never rely of the output of some process that renders or interpret the input. In the case of PHP, var_dump() is always a good starting point but you also need to dump to hex or even resort to an hexadecimal editor:

<?php
var_dump(bin2hex($_SERVER['HTTP_USER_AGENT']));

My educated guess so far (and I don't believe it's too far from truth) is:

Some Android browser is sending an HTTP header that includes Öwn Smart Build encoded in ISO-8859-1, where Ö aka 'LATIN CAPITAL LETTER O WITH DIAERESIS' (U+00D6) is encoded as D6.

Your app stack is configured for UTF-8 (the sensible choice), where Ö would be encoded as C396.

PHP doesn't know/care, because PHP strings aren't encoding-aware (they're just byte streams).

MySQL is handled D6, being told it's UTF-8 (but it isn't).

Had D6 been a valid UTF-8 (different) character, or part of a (different) multi-byte sequence, insertion would have completed with minor data loss (the original Öwn text would have been lost and replaced by something else). For good or bad, it isn't valid UTF-8, thus MySQL aborts the insertion with the error message you describe.

Why can't MySQL cope with it? Let's check the UTF-8 definition:

Nr of
Bytes    Byte 1   Byte 2       Byte 3     Byte 4
1      0xxxxxxx
2      110xxxxx   10xxxxxx
3      1110xxxx   10xxxxxx   10xxxxxx
4      11110xxx   10xxxxxx   10xxxxxx   10xxxxxx

Original Latin-1 Öw text is encoded as D6 77 which, translated to binary, is:

11010110 01001101
^^^      ^^

In UTF-8, 110… means "Start of 2-byte character". Second byte should then start with 10… but we have 01… instead. Oops!

How can you solve this? It's trickier than it seems. If you could know for sure that input is ISO-8859-1, it's just a straightforward conversion:

<?php
$input = "\xD6wn";
$output = mb_convert_encoding($input, 'UTF-8', 'ISO-8859-1');
var_dump(bin2hex($input), bin2hex($output));

string(6) "d6776e"
string(8) "c396776e"

(Online demo)

But, how can you know? I'm not sure if the User-Agent header allows MIME Encoded-Words and, even there, the browser may just send invalid data anyway. Perhaps you can catch the error (MySQL error code 1366 aka ER_TRUNCATED_WRONG_VALUE_FOR_FIELD looks reasonably precise) and try again assuming ISO-8859-1. And it's probably also a good idea to verify that input is valid UTF-8, though it can make processing kind of bothersome:

<?php
$latin1 = "\xD6wn";
$utf8 = "\xc3\x96wn";
var_dump(mb_check_encoding($latin1, 'UTF-8'));
var_dump(mb_check_encoding($utf8, 'UTF-8'));

bool(false)
bool(true)

(Online demo)


问:
PostgreSQL How to put constraint on column of type arrays
I have two tables in Postgresql.

table_1 contains sources

```<code>Sources
A_src
B_src
C_src
</code>```

table_2 is as follows

```<code>Result;Result_sources
2.3; {A_src;C_src}
43; {B_src;C_src}
11; {A_src;B_src;C_src}
</code>```

How can I write a constraint on table_2.Result_sources which enables its array entries to only come from table_1.Sources column

答:
You cannot do that, and a trigger is no substitute since you cannot avoid race conditions unless you use SERIALIZABLE transactions.

This problem begs for normalization: create a table that implements and m-to-n relationship between table_1 and table_2.

Body:
I have two tables in Postgresql.

table_1 contains sources

Sources
A_src
B_src
C_src

table_2 is as follows

Result;Result_sources
2.3; {A_src;C_src}
43; {B_src;C_src}
11; {A_src;B_src;C_src}

How can I write a constraint on table_2.Result_sources which enables its array entries to only come from table_1.Sources column


问:
Which function does loadingCache call when .refreshAfterWrite() ends?
I am trying to create a cache using Google LoadingCache.

My program uses another rest service. I am wondering if it's possible to configure the cache such that once the .refreshAfterWrite ends it calls the loadAll function.

Essentially I'd like to do something like what appears on number 8 in  this link once the refreshAfterWrite timer ends.
http://www.baeldung.com/guava-cache

Thanks

答:
There is no "refreshAfterWrite timer", nor any other background cleanup work being managed by the Cache - as the docs say:

refreshAfterWrite will make a key eligible for refresh after the specified duration, but a refresh will only be actually initiated when the entry is queried.

If you want to invoke loadAll() after a certain period of time you should schedule a task to do so.


问:
Laravel monthly count record
I want to create monthly statistics using Chartjs by Laravel.

```<code>$monthly_uploaded_product = DB::table('author_product')
         ->select(DB::raw('count(id) as total'), DB::raw('MONTH(created_at) as month'))
         ->groupBy('month')
         ->get();
</code>```

the result of query is:

```<code>[{"total":1,"month":10},{"total":17,"month":11}]
</code>```

the output of code should be like this to be represented in Javascript (Chartjs):

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

I have wrote code to generate the array, but error Undefined offset: 1 :

```<code>$statistics_monthly_product = array();
foreach (range(1, 12) as $month) {
    foreach ($monthly_uploaded_product as $key) {
        if ($statistics_monthly_product[$month] == $key->month){
            $statistics_monthly_product[$month] = $key->total;
        }else{
            $statistics_monthly_product[$month] = 0;
        }
    }
}
</code>```

答:
This code returns your expected array

```<code>$data = [["total" => 1,"month" => 10],["total" => 17,"month" => 11]];
$monthTotals = [];

foreach($data as $item){
    $monthTotals[$item["month"]] = $item["total"];
}

$chartJSCompat = [];
for($i = 0;$i < 12;$i++){
    if(isset($monthTotals[$i+1]))
        $chartJSCompat[$i] = $monthTotals[$i+1];
    else
        $chartJSCompat[$i] = 0;
}

var_dump($chartJSCompat);
</code>```

Title: Laravel monthly count record

Body:
I want to create monthly statistics using Chartjs by Laravel.

$monthly_uploaded_product = DB::table('author_product')
         ->select(DB::raw('count(id) as total'), DB::raw('MONTH(created_at) as month'))
         ->groupBy('month')
         ->get();

the result of query is:

[{"total":1,"month":10},{"total":17,"month":11}]

the output of code should be like this to be represented in Javascript (Chartjs):

[0,0,0,0,0,0,0,0,0,1,17,0]

I have wrote code to generate the array, but error Undefined offset: 1 :

$statistics_monthly_product = array();
foreach (range(1, 12) as $month) {
    foreach ($monthly_uploaded_product as $key) {
        if ($statistics_monthly_product[$month] == $key->month){
            $statistics_monthly_product[$month] = $key->total;
        }else{
            $statistics_monthly_product[$month] = 0;
        }
    }
}

Body:
This code returns your expected array

$data = [["total" => 1,"month" => 10],["total" => 17,"month" => 11]];
$monthTotals = [];

foreach($data as $item){
    $monthTotals[$item["month"]] = $item["total"];
}

$chartJSCompat = [];
for($i = 0;$i < 12;$i++){
    if(isset($monthTotals[$i+1]))
        $chartJSCompat[$i] = $monthTotals[$i+1];
    else
        $chartJSCompat[$i] = 0;
}

var_dump($chartJSCompat);


问:
DefinitelyTyped for systemjs-builder
Is there a DefinitelyTyped for systemjs-builder?
https://github.com/systemjs/builder

Because systemjs.d.ts does not seem to include it, and I get a "cannot find module" error when I try to import it:

```<code>import Builder = require('systemjs-builder');
</code>```

And I couldn't find a systemjs-builder.d.ts file on the internet.

If there isn't a DefinitelyTyped for that library, how can I use it with TypeScript?

Any help will be profoundly appreciated!

答:
To use in typescript you should import as follows:

```<code>import * as Builder from "systemjs-builder";
</code>```

Then you can use

```<code>const builder = new Builder("", "systemjs.config.js");
builder.bundle("file.js", "output.js", {
    format: "cjs",
    minify: true,
    sourceMaps: true,
    mangle: false
});
</code>```

Title: DefinitelyTyped for systemjs-builder

Body:
Is there a DefinitelyTyped for systemjs-builder?
https://github.com/systemjs/builder

Because systemjs.d.ts does not seem to include it, and I get a "cannot find module" error when I try to import it:

import Builder = require('systemjs-builder');

And I couldn't find a systemjs-builder.d.ts file on the internet.

If there isn't a DefinitelyTyped for that library, how can I use it with TypeScript?

Any help will be profoundly appreciated!

Body:
To use in typescript you should import as follows:

import * as Builder from "systemjs-builder";

Then you can use

const builder = new Builder("", "systemjs.config.js");
builder.bundle("file.js", "output.js", {
    format: "cjs",
    minify: true,
    sourceMaps: true,
    mangle: false
});


问:
How to obtain physical screen size in iOS simulator with Unity?
I want to display a different number of elements in a game dependent on the actual size of the device. Not just scale the output and work with the same logical pixels in width and height. 20 elements in a row look huge on an iPad and 30 elements in a row are too small on an iPhone.

I’m using Screen.dpi together with Screen.width and Screen.height to calculate the physical Screen size. Then I decide on a small, medium, or large scenario.

But the iOS simulator gives me a 0 for Screen.dpi. Unfortunately I don’t have all iPads and iPhones available. It worked alright on a physical iPhone 6S+ and iPad Air 2.

Is this a bug in Unity or normal behavior of the simulator?

Is there a better way? Or do I really need to maintain a list of device DPI for every existing model of iPhone and iPad?

Unity 2017.2.0p3; XCode 9.1

答:
If you read the Screen.dpi docs :

This is the actual DPI of the screen attached or physical device
  running the application. May return 0 if unable to determine the
  current DPI.

As simulators are not physical devices, it would return 0 and it is normal behaviour as simulators lack many other physical properties.

You can use Device.generation to detect the target device type. Look at possible values of  DeviceGeneration and set up your elements accordingly by checking against dpi for each device.

You can create your own extension to get dpi which work for simulator as well.

Hope this helps :)


问:
No AndroidManifest.xml found - Xamarin
This is very interesting scenario which i have been facing from last few days.I have a Xamarin project which is using MvvmCross and few 3rd party libraries like RestSharp.
Few days back when i got project code and open it i found it abnormal that project property folder has more then 1 manifest files.When i tried to run project the visual studio was not picking up android manifest file.
I search on internet about this and got few clues.

Every application must have an AndroidManifest.xml file (with precisely that name) in its root directory.

i am posting my file structure image for reference.i have checked my .csproj file it has following code

```<code> <AndroidManifest>Properties\TurboViewerarmAndroidManifest.xml</AndroidManifest>
<ItemGroup>
<Content Include="Properties\TurboViewerarmAndroidManifest.xml">
  <SubType>Designer</SubType>
</Content>
</code>```

As far as my concern if i change the manifest file name to AndroidManifest.xml the project runs fine but the problem occurs when i try to change name of other manifest file to AndroidManifest.xml because we can not have many files with same name in single folder.But for this project all the manifest files will be in same folder but project will not run without changing their name to AndroidManifest.xml.Its like a deadlock.

As i am new to visual studio and xamarin so i might be missing some point that probably will make everything clear.

答:
Just trying to do very same for a white-label app. Visual Studio ignores the AndroidManifest setting so you cannot rename the file (at the moment). This is an already known issue: https://bugzilla.xamarin.com/show_bug.cgi?id=31306

Even a pre-build process doesn't work since it always throws an error that the manifest file is missing (but it's there).

My solution for now: rename the manifest before building the project manually.

Title: No AndroidManifest.xml found - Xamarin

Body:
This is very interesting scenario which i have been facing from last few days.I have a Xamarin project which is using MvvmCross and few 3rd party libraries like RestSharp.
Few days back when i got project code and open it i found it abnormal that project property folder has more then 1 manifest files.When i tried to run project the visual studio was not picking up android manifest file.
I search on internet about this and got few clues.

Every application must have an AndroidManifest.xml file (with precisely that name) in its root directory.

i am posting my file structure image for reference.i have checked my .csproj file it has following code

 <AndroidManifest>Properties\TurboViewerarmAndroidManifest.xml</AndroidManifest>
<ItemGroup>
<Content Include="Properties\TurboViewerarmAndroidManifest.xml">
  <SubType>Designer</SubType>
</Content>

As far as my concern if i change the manifest file name to AndroidManifest.xml the project runs fine but the problem occurs when i try to change name of other manifest file to AndroidManifest.xml because we can not have many files with same name in single folder.But for this project all the manifest files will be in same folder but project will not run without changing their name to AndroidManifest.xml.Its like a deadlock.

As i am new to visual studio and xamarin so i might be missing some point that probably will make everything clear.


问:
Python read CSV to string conversion
I have a CSV with following values

```<code>ID, Value
1, a
2, b
3, c
</code>```

How can I convert this csv to following string using Python

```<code>[('ID', 'Value'), (1, 'a'), (2, 'b'), (3, 'c')]
</code>```

I was trying with the following code

```<code>with open('sample.csv', 'rb') as csvfile:
    reader = csv.reader(csvfile, delimiter=' ', quotechar='|')
    for row in reader:
        data = ', '.join(row)
        rows.append(data)
print rows
</code>```

Am getting following output only

```<code>["'ID','Value'", "1,'a'", "2,'b'", "3,'c'"]
</code>```

答:
To produce the list [('ID', 'Value'), (1, 'a'), (2, 'b'), (3, 'c')] from that CSV data you need to convert the number strings to integer. Here's one way to do that in Python 2.

```<code>import csv

data = []
with open('sample.csv', 'rb') as csvfile:
    reader = csv.reader(csvfile, skipinitialspace=True)
    data.append(tuple(next(reader)))
    for num, val in reader:
        data.append((int(num), val))

print data
</code>```

output

```<code>[('ID', 'Value'), (1, 'a'), (2, 'b'), (3, 'c')]
</code>```

The csv.reader yields each row of the CSV data as a list. We need to extract the items from that list and convert the 1st one to an int. And then we can pack the two items into a tuple and append it to the data list. However, the header line contains two strings, so we don't want to perform that conversion on the header line.

This code:

```<code>data.append(tuple(next(reader)))
</code>```

gets the header line and just converts it to a tuple and appends the result to our data list.

Note that the Python 2 csv module requires you to open the file in 'rb' mode, but in Python 3 you need to open the file in 'r' mode. Please see the respective module docs for further details. Apart from that, and using the print function instead of the print statement, no other changes are needed to run the above code on Python 3.

Title: Python read CSV to string conversion

Body:
I have a CSV with following values

ID, Value
1, a
2, b
3, c

How can I convert this csv to following string using Python

[('ID', 'Value'), (1, 'a'), (2, 'b'), (3, 'c')]

I was trying with the following code

with open('sample.csv', 'rb') as csvfile:
    reader = csv.reader(csvfile, delimiter=' ', quotechar='|')
    for row in reader:
        data = ', '.join(row)
        rows.append(data)
print rows

Am getting following output only

["'ID','Value'", "1,'a'", "2,'b'", "3,'c'"]

Body:
To produce the list [('ID', 'Value'), (1, 'a'), (2, 'b'), (3, 'c')] from that CSV data you need to convert the number strings to integer. Here's one way to do that in Python 2.

import csv

data = []
with open('sample.csv', 'rb') as csvfile:
    reader = csv.reader(csvfile, skipinitialspace=True)
    data.append(tuple(next(reader)))
    for num, val in reader:
        data.append((int(num), val))

print data

output

[('ID', 'Value'), (1, 'a'), (2, 'b'), (3, 'c')]

The csv.reader yields each row of the CSV data as a list. We need to extract the items from that list and convert the 1st one to an int. And then we can pack the two items into a tuple and append it to the data list. However, the header line contains two strings, so we don't want to perform that conversion on the header line.

This code:

data.append(tuple(next(reader)))

gets the header line and just converts it to a tuple and appends the result to our data list.

Note that the Python 2 csv module requires you to open the file in 'rb' mode, but in Python 3 you need to open the file in 'r' mode. Please see the respective module docs for further details. Apart from that, and using the print function instead of the print statement, no other changes are needed to run the above code on Python 3.


问:
Open PDF in a new tab using dompdf
Im trying to generate pdf using dompdf, how can I open the pdf in a new tab in a browser? Like, I Click A link for the PDF and it should open in a new tab, not save it automatically. I want to give the user a choice to save the file after seeing it first. how do i do that? </p>

<p>whenever i use $pdf->output at the end of the file, it does not change a thing, the file is still downloaded automatically.
please help. thanks. </p>

答:
I don't know if you got, but if you use false in this line:

```<code>$dompdf-> stream("pasta/doc/relatorio.pdf", array("Attachment" => false));
</code>```

You can see the pdf in the browser.

Title: Open PDF in a new tab using dompdf

Body:
Im trying to generate pdf using dompdf, how can I open the pdf in a new tab in a browser? Like, I Click A link for the PDF and it should open in a new tab, not save it automatically. I want to give the user a choice to save the file after seeing it first. how do i do that?

whenever i use $pdf->output at the end of the file, it does not change a thing, the file is still downloaded automatically.
please help. thanks.

Body:
I don't know if you got, but if you use false in this line:

$dompdf-> stream("pasta/doc/relatorio.pdf", array("Attachment" => false));

You can see the pdf in the browser.


问:
Load MovieClip inline in TextField
I want to load a MovieClip inside a TextField inline with the text.

The TextField documentation says "HTML text that you assign to a text field can contain embedded media (movie clips, SWF files, GIF files, PNG files, and JPEG files)."

How can this be done with MovieClips? There must be a listener we can override.

source: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/text/TextField.html

答: no you cannot do this in flash. you can only load images in a textfield.</p>

Title: Load MovieClip inline in TextField


问:
Signature error while connecting to s3 bucket via sparklyr
I am encountering an error when I  try to connect to a s3 bucket from R studio using sparklyr. The s3 bucket is in the eu-central-1(Frankfurt) region. Spark version - 2.1.0 , Hadoop 2.7. I am getting a 403 response code with signature mismatch error. However,  when I try to get an s3a bucket instead however I get a 400 response code. Any word on alternative methods to connect to s3 buckets via spark in R studio, is also appreciated. The connection to s3 works fine without Spark.

Here is the code,

```<code>   # install.packages("devtools")
# devtools::install_github("rstudio/sparklyr")
library(sparklyr)
library(dplyr)
sc <- spark_connect(master = "local")
spark_disconnect(sc)
config <- spark_config()
library(sparklyr)
library(dplyr)
# config$sparklyr.defaultPackages <- "org.apache.hadoop:hadoop-aws:2.7.3"
# config$spark.executor.memory <- "4g"
sc <- spark_connect(master = "local",config = config)

ctx <- sparklyr::spark_context(sc)
jsc <- invoke_static(
sc,
"org.apache.spark.api.java.JavaSparkContext",
"fromSparkContext",
ctx
)

hconf <- jsc %>% invoke("hadoopConfiguration")
hconf %>% invoke("set","fs.s3.access.key", "xx")
hconf %>% invoke("set","fs.s3.secret.key", "xx")
#hconf %>% invoke("set","com.amazonaws.services.s3.enableV4", "true")
test <- spark_read_csv(sc, "test", "s3://********.csv")
</code>```

Error: org.apache.hadoop.fs.s3.S3Exception: org.jets3t.service.S3ServiceException: Service Error Message. -- ResponseCode: 403, ResponseStatus: Forbidden, XML Error Message: <?xml version="1.0" encoding="UTF-8"?><Error>SignatureDoesNotMatch<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message><AWSAccessKeyId>AKIAJ3ZD2ZEISKNQMSGQ</AWSAccessKeyId><StringToSign>AWS4-HMAC-SHA25620171129T123633Z20171129/eu-central-1/s3/aws4_request555016eca303c98732f51adcaaa83eac7368fb75f59eaa9f59116684b9030ee0</StringToSign><SignatureProvided>bf703f56827aa0f04aab3fa6a1e2aa277117344cdbfc3f4f3e51895ce62af826</SignatureProvided><StringToSignBytes>41 57 53 34 2d 48 4d 41 43 2d 53 48 41 32 35 36 0a 32 30 31 37 31 31 32 39 54 31 32 33 36 33 33 5a 0a 32 30 31 37 31 31 32 39 2f 65 75 2d 63 65 6e 74 72 61 6c 2d 31 2f 73 33 2f 61 77 73 34 5f 72 65 71 75 65 73 74 0a 35 35 35 30 31 36 65 63 61 33 30 33 63 39 38 37 33 32 66 35 31... <truncated>
    at org.apache.hadoop.fs.s3.Jets3tFileSystemStore.get(Jets3tFileSystemStore.java:175)
    at org.apache.hadoop.fs.s3.Jets3tFileSystemStore.retrieveINode(Jets3tFileSystemStore.java:221)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:191)
    at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:102)
    at com.sun.proxy.$Proxy23.retrieveINode(Unknown Source)
    at org.apache.hadoop.fs.s3.S3FileSystem.getFileStatus(S3FileSystem.java:340)
    at org.apache.hadoop.fs.FileSystem.exists(FileSystem.java:1426)
    at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$14.apply(DataSource.scala:381)
    at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$14.apply(DataSource.scala:370)
    at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:241)
    at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:241)
    at scala.collection.immutable.List.foreach(List.scala:381)
    at scala.collection.TraversableLike$class.flatMap(TraversableLike.scala:241)
    at scala.collection.immutable.List.flatMap(List.scala:344)
    at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:370)
    at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:152)
    at org.apache.spark.sql.DataFrameReader.csv(DataFrameReader.scala:415)
    at org.apache.spark.sql.DataFrameReader.csv(DataFrameReader.scala:352)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sparklyr.Invoke$.invoke(invoke.scala:102)
    at sparklyr.StreamHandler$.handleMethodCall(stream.scala:97)
    at sparklyr.StreamHandler$.read(stream.scala:62)
    at sparklyr.BackendHandler.channelRead0(handler.scala:52)
    at sparklyr.BackendHandler.channelRead0(handler.scala:14)
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:367)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:353)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:346)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:367)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:353)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:346)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:367)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:353)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:346)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:367)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:353)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:652)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:575)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:489)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:451)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)
    at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
    at java.lang.Thread.run(Thread.java:748)
Caused by: org.jets3t.service.S3ServiceException: Service Error Message. -- ResponseCode: 403, ResponseStatus: Forbidden, XML Error Message: <?xml version="1.0" encoding="UTF-8"?><Error>SignatureDoesNotMatch<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message><AWSAccessKeyId>AKIAJ3ZD2ZEISKNQMSGQ</AWSAccessKeyId><StringToSign>AWS4-HMAC-SHA25620171129T123633Z20171129/eu-central-1/s3/aws4_request555016eca303
```

答:
If you are using Amazon's own EMR then you need to look at their docs.

If you are using Apache's own artifacts, then you need to switch off s3 to the s3a filesystem connector, then enable

Set the  JVM system property com.amazonaws.services.s3.enableV4 to true

Set the endpoint fs.s3a.endpoint to the endpoint of the specific store you want to talk to see the list.

If things don't work you get a fairly generic "400 bad request" message, which isn't that useful in working out why things are wrong. Start with getting things to work with a bucket in s3 US east (s3a://landsat-pds) is one to try listing, then move to the bucket in the v4 region.

Body:
I am encountering an error when I  try to connect to a s3 bucket from R studio using sparklyr. The s3 bucket is in the eu-central-1(Frankfurt) region. Spark version - 2.1.0 , Hadoop 2.7. I am getting a 403 response code with signature mismatch error. However,  when I try to get an s3a bucket instead however I get a 400 response code. Any word on alternative methods to connect to s3 buckets via spark in R studio, is also appreciated. The connection to s3 works fine without Spark.

Here is the code,

   # install.packages("devtools")
# devtools::install_github("rstudio/sparklyr")
library(sparklyr)
library(dplyr)
sc <- spark_connect(master = "local")
spark_disconnect(sc)
config <- spark_config()
library(sparklyr)
library(dplyr)
# config$sparklyr.defaultPackages <- "org.apache.hadoop:hadoop-aws:2.7.3"
# config$spark.executor.memory <- "4g"
sc <- spark_connect(master = "local",config = config)

ctx <- sparklyr::spark_context(sc)
jsc <- invoke_static(
sc,
"org.apache.spark.api.java.JavaSparkContext",
"fromSparkContext",
ctx
)

hconf <- jsc %>% invoke("hadoopConfiguration")
hconf %>% invoke("set","fs.s3.access.key", "xx")
hconf %>% invoke("set","fs.s3.secret.key", "xx")
#hconf %>% invoke("set","com.amazonaws.services.s3.enableV4", "true")
test <- spark_read_csv(sc, "test", "s3://********.csv")

Error: org.apache.hadoop.fs.s3.S3Exception: org.jets3t.service.S3ServiceException: Service Error Message. -- ResponseCode: 403, ResponseStatus: Forbidden, XML Error Message: <?xml version="1.0" encoding="UTF-8"?><Error>SignatureDoesNotMatch<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message><AWSAccessKeyId>AKIAJ3ZD2ZEISKNQMSGQ</AWSAccessKeyId><StringToSign>AWS4-HMAC-SHA25620171129T123633Z20171129/eu-central-1/s3/aws4_request555016eca303c98732f51adcaaa83eac7368fb75f59eaa9f59116684b9030ee0</StringToSign><SignatureProvided>bf703f56827aa0f04aab3fa6a1e2aa277117344cdbfc3f4f3e51895ce62af826</SignatureProvided><StringToSignBytes>41 57 53 34 2d 48 4d 41 43 2d 53 48 41 32 35 36 0a 32 30 31 37 31 31 32 39 54 31 32 33 36 33 33 5a 0a 32 30 31 37 31 31 32 39 2f 65 75 2d 63 65 6e 74 72 61 6c 2d 31 2f 73 33 2f 61 77 73 34 5f 72 65 71 75 65 73 74 0a 35 35 35 30 31 36 65 63 61 33 30 33 63 39 38 37 33 32 66 35 31... <truncated>
    at org.apache.hadoop.fs.s3.Jets3tFileSystemStore.get(Jets3tFileSystemStore.java:175)
    at org.apache.hadoop.fs.s3.Jets3tFileSystemStore.retrieveINode(Jets3tFileSystemStore.java:221)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:191)
    at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:102)
    at com.sun.proxy.$Proxy23.retrieveINode(Unknown Source)
    at org.apache.hadoop.fs.s3.S3FileSystem.getFileStatus(S3FileSystem.java:340)
    at org.apache.hadoop.fs.FileSystem.exists(FileSystem.java:1426)
    at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$14.apply(DataSource.scala:381)
    at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$14.apply(DataSource.scala:370)
    at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:241)
    at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:241)
    at scala.collection.immutable.List.foreach(List.scala:381)
    at scala.collection.TraversableLike$class.flatMap(TraversableLike.scala:241)
    at scala.collection.immutable.List.flatMap(List.scala:344)
    at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:370)
    at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:152)
    at org.apache.spark.sql.DataFrameReader.csv(DataFrameReader.scala:415)
    at org.apache.spark.sql.DataFrameReader.csv(DataFrameReader.scala:352)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sparklyr.Invoke$.invoke(invoke.scala:102)
    at sparklyr.StreamHandler$.handleMethodCall(stream.scala:97)
    at sparklyr.StreamHandler$.read(stream.scala:62)
    at sparklyr.BackendHandler.channelRead0(handler.scala:52)
    at sparklyr.BackendHandler.channelRead0(handler.scala:14)
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:367)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:353)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:346)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:367)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:353)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:346)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:367)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:353)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:346)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:367)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:353)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:652)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:575)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:489)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:451)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)
    at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
    at java.lang.Thread.run(Thread.java:748)
Caused by: org.jets3t.service.S3ServiceException: Service Error Message. -- ResponseCode: 403, ResponseStatus: Forbidden, XML Error Message: <?xml version="1.0" encoding="UTF-8"?><Error>SignatureDoesNotMatch<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message><AWSAccessKeyId>AKIAJ3ZD2ZEISKNQMSGQ</AWSAccessKeyId><StringToSign>AWS4-HMAC-SHA25620171129T123633Z20171129/eu-central-1/s3/aws4_request555016eca303


问:
Dsplay the coupon code in an opencart product page
Please help me to display the coupon code or coupon name in opencart 2.1.0.1 product page. For the promotion of products I need to display the coupons or promo code in the product page of opencart 2.1.0.1. </p>

答: I think this will be hard coded, you will have to add a method to the copoun model which will take the product_id and return the copouns related to this product_id, then in the product controller you will need to call this method and list the copouns in a data variable, then in the product view you need to show them in the desired place.</p>


问:
ASP.NET MVC - Full text search on shared hosting
We are developing a Q&A site for a client with very limited budget. Site will be developed in ASP.NET MVC 3, and client will have an option to switch between SQL Express and SQL CE.

We would like to have some full text search functionality but don't know what would be the best for this scenario. So far we've seen SOLR and Lucene.NET, but the most likely site will be hosted on some shared hosting so we have to take that into account.

Any help would be greatly appreciated!

答: IMHO bin deployed Lucene.NET is the way to go. You just might need to modify it so that it stores the index in a folder you have write access.


问:
How to integrate Google Cast v3 with ExoPlayer v2?
How to fully integrate Google Cast v3 with ExoPlayer v2? The activity will contain a FrameLayout with a com.google.android.exoplayer2.ui.SimpleExoPlayerView in it. The Google tutorial only covers integration with VideoView.

答:
Google Cast SDK is independent of Local Player, you can use ExoPlayer or MediaPlayer ( VideoView )

Once your APP has an active session, place the url in MediaInfo

```<code>val movieMetadata = MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE)

movieMetadata.putString(MediaMetadata.KEY_TITLE, "Title")
movieMetadata.putString(MediaMetadata.KEY_SUBTITLE, "Sub")

val mediaLoadOptions =  MediaInfo.Builder( < URL > )
     .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
     .setContentType(< Content Type of Media>)
     .setMetadata(movieMetadata)
     .setStreamDuration(<Media Duration >)
     .build()

mCastSession.remoteMediaClient.load(buildMediaInfo(url), mediaLoadOptions)
</code>```

If you need to stream a local media, you will need to stream it for yourself, using NanoHttpd or another of your choice, and also implement a Cast Receiver

Body:
Google Cast SDK is independent of Local Player, you can use ExoPlayer or MediaPlayer ( VideoView )

Once your APP has an active session, place the url in MediaInfo

val movieMetadata = MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE)

movieMetadata.putString(MediaMetadata.KEY_TITLE, "Title")
movieMetadata.putString(MediaMetadata.KEY_SUBTITLE, "Sub")

val mediaLoadOptions =  MediaInfo.Builder( < URL > )
     .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
     .setContentType(< Content Type of Media>)
     .setMetadata(movieMetadata)
     .setStreamDuration(<Media Duration >)
     .build()

mCastSession.remoteMediaClient.load(buildMediaInfo(url), mediaLoadOptions)

If you need to stream a local media, you will need to stream it for yourself, using NanoHttpd or another of your choice, and also implement a Cast Receiver


问:
Using Windows DLL from Linux
We need to interface to 3rd party app, but company behind the app doesn't disclose message protocol and provides only Windows DLL to interface to.

Our application is Linux-based so I cannot directly communicate with DLL. I couldn't find any existing solution so I'm considering writing socket-based bridge between Linux and Windows, however I'm sure it is not such a unique problem and somebody should have done it before.

Are you aware of any solution that allows to call Windows DDL functions from C app on Linux? It can use Wine or separate Windows PC - doesn't matter.

Many thanks in advance.

答:
I wrote a small Python module for calling into Windows DLLs from Python on Linux. It is based on IPC between a regular Linux/Unix Python process and a Wine-based Python process. Because I have needed it in too many different use-cases / scenarios myself, I designed it as a "generic" ctypes module drop-in replacement, which does most of the required plumbing automatically in the background.

Example: Assume you're in Python on Linux, you have Wine installed, and you want to call into msvcrt.dll (the Microsoft C runtime library). You can do the following:

from zugbruecke import ctypes
dll_pow = ctypes.cdll.msvcrt.pow
dll_pow.argtypes = (ctypes.c_double, ctypes.c_double)
dll_pow.restype = ctypes.c_double
print('You should expect "1024.0" to show up here: "%.1f".' % dll_pow(2.0, 10.0))
```

Source code (LGPL), PyPI package & documentation.

It's still a bit rough around the edges (i.e. alpha and insecure), but it does handle most types of parameters (including pointers).

OwnerDisplayName: qrdl

Title: Using Windows DLL from Linux

Body:
I wrote a small Python module for calling into Windows DLLs from Python on Linux. It is based on IPC between a regular Linux/Unix Python process and a Wine-based Python process. Because I have needed it in too many different use-cases / scenarios myself, I designed it as a "generic" ctypes module drop-in replacement, which does most of the required plumbing automatically in the background.

Example: Assume you're in Python on Linux, you have Wine installed, and you want to call into msvcrt.dll (the Microsoft C runtime library). You can do the following:

from zugbruecke import ctypes
dll_pow = ctypes.cdll.msvcrt.pow
dll_pow.argtypes = (ctypes.c_double, ctypes.c_double)
dll_pow.restype = ctypes.c_double
print('You should expect "1024.0" to show up here: "%.1f".' % dll_pow(2.0, 10.0))

Source code (LGPL), PyPI package & documentation.

It's still a bit rough around the edges (i.e. alpha and insecure), but it does handle most types of parameters (including pointers).


问:
Symfony3 and login redirection
User tries open url
http://example.com/page1?param=value
default authentication redirects to
http://example.com/login
after success login it redirects to
http://example.com/page1?param=value
this one is ok.

Question is, how\where (what should i redefine and where) can I redirect to http://example.com/login?param=value. I need manual (my custom class) of redirection for login form (I want edit url).

答:
Hate symfony, anyway solution found:

```<code>namespace some\lib;

class AuthenticationListener
{
    /**
     * Change some data in response before it fires up.
     *
     * @param FilterResponseEvent $event
     */
    public function onResponse(FilterResponseEvent $event)
    {
        $response = $event->getResponse();

        if ($response instanceof RedirectResponse) {
            /** @var RedirectResponse $response */
            $parsedUrl = parse_url($response->getTargetUrl());

            if (!empty($parsedUrl['path'])) {
                $matchedRoute = $this->router->match($parsedUrl['path']);

                if (!empty($matchedRoute['_route']) && $matchedRoute['_route'] == 'login') {
                    $layout = $event->getRequest()->query->get('layout');

                    if ($layout) {
                        $response = $event->getResponse(); // response that should be fired up (redirect to url)

                        $responseUrl = $response->getTargetUrl();
                        $responseUrl .= is_int(strpos('?', $responseUrl)) // add layout to redirect url
                            ? '&layout=' . $layout
                            : '?layout=' . $layout;

                        $response->setTargetUrl($responseUrl);
                    }
                }
            }
        }
    }
// ... other code
</code>```

Add to services.yml:

```<code>auth_listener:
    class: \some\lig\AuthenticationListener
    arguments: [] # inject yours
    tags:
        # some other definitions
        - { name: kernel.event_listener, event: kernel.response, method: onResponse }
</code>```

Only this way (afaik) we can add params from prev. url (target) to next url (redirect to login).

So we catch RedirectResponse and check it on kernel level.

Title: Symfony3 and login redirection

Body:
Hate symfony, anyway solution found:

namespace some\lib;

class AuthenticationListener
{
    /**
     * Change some data in response before it fires up.
     *
     * @param FilterResponseEvent $event
     */
    public function onResponse(FilterResponseEvent $event)
    {
        $response = $event->getResponse();

        if ($response instanceof RedirectResponse) {
            /** @var RedirectResponse $response */
            $parsedUrl = parse_url($response->getTargetUrl());

            if (!empty($parsedUrl['path'])) {
                $matchedRoute = $this->router->match($parsedUrl['path']);

                if (!empty($matchedRoute['_route']) && $matchedRoute['_route'] == 'login') {
                    $layout = $event->getRequest()->query->get('layout');

                    if ($layout) {
                        $response = $event->getResponse(); // response that should be fired up (redirect to url)

                        $responseUrl = $response->getTargetUrl();
                        $responseUrl .= is_int(strpos('?', $responseUrl)) // add layout to redirect url
                            ? '&layout=' . $layout
                            : '?layout=' . $layout;

                        $response->setTargetUrl($responseUrl);
                    }
                }
            }
        }
    }
// ... other code

Add to services.yml:

auth_listener:
    class: \some\lig\AuthenticationListener
    arguments: [] # inject yours
    tags:
        # some other definitions
        - { name: kernel.event_listener, event: kernel.response, method: onResponse }

Only this way (afaik) we can add params from prev. url (target) to next url (redirect to login).

So we catch RedirectResponse and check it on kernel level.


问:
postgresql case inside function doesn't trigger
So, i have a couple of functions inside my db.

One function needs to run when the data in a specific table is older than 5 minutes.

I've tried doing it with:

```<code>PERFORM case when now() - '5 minutes'::interval > (select end_time from x order by end_route desc limit 1) then update_x() else null end;
</code>```

When i run the command as a regular select query, it runs OK. But when i put that inside another function (The one being called, returns updated table that is no older than 5 minutes), it never runs. Also, if i just put update_x(), then it runs OK (but every time the function is called).

Does anyone have any idea on how i could fix this?
One idea is to just set a cron to run the function every 5 mins independently, but i'd rather the server is idle since the function is quite resource intensive, and it doesn't get called that often.

I'm on version 8.4(Due to my ISP, so can't change, though i am considering moving to VPS, so if this is something that would work on 9.5 and newer, i can wait).

答:
I'm not sure why, but once i moved the boolean up one level it started working.
So now instead of having perform case query inside function, i'm sending boolean to the function, and performing the check in a view above this function.

```<code>CREATE VIEW x_view AS select * from get_x((clock_timestamp() - '5 minutes'::interval)::timestamp > (select end_route from gps_skole2 order by end_route desc limit 1));
</code>```

And inside the function:

```<code>PERFORM case when $1 then update_x() else null end;
</code>```

Body:
So, i have a couple of functions inside my db.

One function needs to run when the data in a specific table is older than 5 minutes.

I've tried doing it with:

PERFORM case when now() - '5 minutes'::interval > (select end_time from x order by end_route desc limit 1) then update_x() else null end;

When i run the command as a regular select query, it runs OK. But when i put that inside another function (The one being called, returns updated table that is no older than 5 minutes), it never runs. Also, if i just put update_x(), then it runs OK (but every time the function is called).

Does anyone have any idea on how i could fix this?
One idea is to just set a cron to run the function every 5 mins independently, but i'd rather the server is idle since the function is quite resource intensive, and it doesn't get called that often.

I'm on version 8.4(Due to my ISP, so can't change, though i am considering moving to VPS, so if this is something that would work on 9.5 and newer, i can wait).

Body:
I'm not sure why, but once i moved the boolean up one level it started working.
So now instead of having perform case query inside function, i'm sending boolean to the function, and performing the check in a view above this function.

CREATE VIEW x_view AS select * from get_x((clock_timestamp() - '5 minutes'::interval)::timestamp > (select end_route from gps_skole2 order by end_route desc limit 1));

And inside the function:

PERFORM case when $1 then update_x() else null end;