Tuesday 31 July 2018

Covering 2D plots with 3D surface in python

I am attempting to take many xz plots, each at various y values, and overlay a surface. I have seen many examples of how to plot 3D surfaces in python, but aside from this post, nothing seems to match my inquiry very closely.

The image of what I need to do is shown below (Note: ignore the "constant x" - this is due to a more complicated variable layout than I explained here):

Magnitude vs. Frequency

My code is as follows, and simply takes data and plots each of the individual Magnitude vs. Frequency plots (xz plots):

import numpy as np
import glob, os
import codecs
import re
import matplotlib.pyplot as plt
#-------------------------------------------------------------------------                   
os.chdir('C:/Users/elarrick/Desktop/201807161056')
dataFolders = glob.glob('./*.ltda')

dataLines = []
freq = []
OpenLoopMag = []
OpenLoopPhase = []
for item in dataFolders:
    name, ext = os.path.splitext(item)
    if ext == '.ltda':
        print item
        dataLines = []
        f = codecs.open(item, encoding='utf-8')
        for line in f:
            if '<p>' in line:
                dataLines.append(line)      #All lines with <p> are an entry in dataLines
        #print "\n\n", dataLines
        #break
        for item in dataLines:
            item = re.sub("<p>", "", item)
            item = re.sub("True</p>", "", item)
            item = item.replace(",", "")
            splitItem = item.split()
            #print splitItem
            freq.append(float(splitItem[0]))
            OpenLoopMag.append(float(splitItem[1]))
            OpenLoopPhase.append(float(splitItem[2]))
        print "Frequencies: ", freq
        print "\n\n\n\n\n\nOpenLoopMag: ", OpenLoopMag
#   This is where I will make the plots for each x,y position
        name = name.strip(".\\")
        name = name.replace("-","NEG")
        plt.semilogx(freq, OpenLoopMag)
        #plt.plot(freq, OpenLoopMag)
        plt.xlabel("Frequency, (Hz)")
        plt.ylabel("Magnitude")
        plt.title("{0}".format(name))
        plt.xlim([20,2000])
        #plt.ylim([-43.2,10.9])
        ticks = [20,40,70,100,200,400,700,1000,2000]
        plt.xticks(ticks,ticks)
        plt.savefig("plot_{0}.png".format(name))

#________ Clear the values for the next data folder_______#            
        freq = []
        OpenLoopMag = []
        OpenLoopPhase = []
        break
    else:
        print "Something went wrong - check ColorMap.py"
        sys.exit()

The next thing I need is to grab each plot, find the y value at which the data was taken, and plot along a y axis (shown coming out of the page in the previous picture). Can you help me do that?

Edit: Using Jacob Madsen's code shown below, I get the following graph.

Edit Inclusion



from Covering 2D plots with 3D surface in python

javax.net.ssl.SSLHandshakeException: java.lang.IllegalArgumentException: Invalid input to toASCII: ip_nbae7bac35.kodrive.xyz

Is there a workaround for this exception? looking at this issue on github it sounds like it might be an android bug, something about the hostname having an underscore character or something.

This is the stack trace:

javax.net.ssl.SSLHandshakeException: java.lang.IllegalArgumentException: Invalid input to toASCII: ip_nbae7bac35.kodrive.xyz
        at com.android.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(ConscryptFileDescriptorSocket.java:219)
        at okhttp3.internal.connection.RealConnection.connectTls(RealConnection.java:318)
        at okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.java:282)
        at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:167)
        at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:257)
        at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135)
        at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114)
        at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
        at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
        at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
        at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
        at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
        at okhttp3.RealCall.execute(RealCall.java:77)



from javax.net.ssl.SSLHandshakeException: java.lang.IllegalArgumentException: Invalid input to toASCII: ip_nbae7bac35.kodrive.xyz

Django Rest Framework - passing Model data through a function, then posting output in a separate field in the same model

(Django 2.0, Python 3.6, Django Rest Framework 3.8)

I'm trying to fill the calendarydays field in the model below:

Model

class Bookings(models.Model):
    booked_trainer = models.ForeignKey(TrainerProfile, on_delete=models.CASCADE)
    booked_client = models.ForeignKey(ClientProfile, on_delete=models.CASCADE)
    trainer_availability_only = models.ForeignKey(Availability, on_delete=models.CASCADE)
    calendarydays = models.CharField(max_length=300, blank=True, null=True)

    PENDING = 'PENDING'
    CONFIRMED = 'CONFIRMED'
    CANCELED = 'CANCELED'

    STATUS_CHOICES = (
        (PENDING, 'Pending'),
        (CONFIRMED, 'Confirmed'),
        (CANCELED, 'Canceled')
    )


    booked_status = models.CharField(
        max_length = 9,
        choices = STATUS_CHOICES,
        default = 'Pending'
    )

    def __str__(self):
        return str(self.trainer_availability_only)

Now, I have a function that takes values from trainer_availability_only and converts those values to a list of datetime strings, the returned output would look like this:

{'calendarydays': ['2018-07-23 01:00:00', '2018-07-23 02:00:00', '2018-07-23 03:00:00', '2018-07-30 01:00:00', '2018-07-30 02:00:00', '2018-07-30 03:00:00', '2018-08-06 01:00:00', '2018-08-06 02:00:00', '2018-08-06 03:00:00', '2018-08-13 01:00:00', '2018-08-13 02:00:00', '2018-08-13 03:00:00', '2018-08-20 01:00:00', '2018-08-20 02:00:00', '2018-08-20 03:00:00']}

Problem

How can I fill the calendarydays field with the function output for a user to select from a dropdown, and where should I implement this logic (in my view or the serializer)? My main point of confusion is that, because my function depends on data from trainer_availability_only, I don't want to create a separate model/table for this information (as that would seem too repetitive). I also don't fully understand where in my serializers or views I can implement some sort of dropdown for a User to choose a single calendarydays value for (like I would be able to for a ForeignKey or OneToOneField for example).

Details for the other models aren't really relevant to the question, except trainer_availability_only, which basically gives the user a dropdown selection that would look like this:

('Monday','12:00 am - 1:00 am')
('Wednesday','4:00 pm - 5:00 pm')
etc.

Any help is greatly appreciated.



from Django Rest Framework - passing Model data through a function, then posting output in a separate field in the same model

How to add javascript function in webview and call it later from html

I am adding a javascript function in webview like this (Kotlin)

val webView = findViewById(R.id.webview) as WebView
webView.getSettings().setJavaScriptEnabled(true)
webView.addJavascriptInterface(this, "android")
webView.getSettings().setBuiltInZoomControls(false)
webView.loadUrl(url)

webView.webViewClient = object : WebViewClient() {
        override fun onPageFinished(view: WebView, url: String) {
            super.onPageFinished(view, url)
            webView.loadUrl("javascript:(function captchaResponse (token){" +
                            "      android.reCaptchaCallbackInAndroid(token);" +
                            "    })()")
        }
    }

Function works fine but the problem is that it runs immediately when I add it in webview. I only want to include it as Javascript function and it should be called only from html (When user will fill the recaptcha). How can I do that?



from How to add javascript function in webview and call it later from html

Why this numba code is 6x slower than numpy code?

Is there any reason why the following code run in 2s,

def euclidean_distance_square(x1, x2):
    return -2*np.dot(x1, x2.T) + np.expand_dims(np.sum(np.square(x1), axis=1), axis=1) + np.sum(np.square(x2), axis=1)

while the following numba code run in 12s?

@jit(nopython=True)
def euclidean_distance_square(x1, x2):
   return -2*np.dot(x1, x2.T) + np.expand_dims(np.sum(np.square(x1), axis=1), axis=1) + np.sum(np.square(x2), axis=1)

My x1 is a matrix of dimension (1, 512) and x2 is a matrix of dimension (3000000, 512). It is quite weird that numba can be so much slower. Am I using it wrong?

I really need to speed this up because I need to run this function 3 million times and 2s is still way too slow.

I need to run this on CPU because as you can see the dimension of x2 is so huge, it cannot be loaded onto a GPU (or at least my GPU), not enough memory.



from Why this numba code is 6x slower than numpy code?

Vertical side nav bar - Angular 4 & Bootstrap 3

I have installed bootstrap 3 into my angular 4 project using the npm installer. I have a basic site done up and am trying to get an dynamic sideNav bar that will toggle in and out.

I have seen some examples online however they do not seem to work whether it be a never version of bootstrap or compatibility issues with angular.

Does anyone have any recommendations for a the navigation bar that I could use in this instance?

The HTML in my app.component.html:

    <!-- Sidebar -->

<nav class="navbar navbar-inverse navbar-fixed-left" id="sidebar-wrapper" role="navigation">
    <ul class="nav sidebar-nav">
        <li class="sidebar-brand">
            <a href="#">
                Brand
            </a>
        </li>
        <li>
            <a href="#">Home</a>
        </li>
        <li>
            <a href="#">About</a>
        </li>
        <li>
            <a href="#">Events</a>
        </li>
        <li>
            <a href="#">Team</a>
        </li>
        <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                Works <span class="caret"></span>
            </a>
            <ul class="dropdown-menu" role="menu">
                <li><a href="#">About</a></li>
                <li><a href="#">Services</a></li>
                <li><a href="#">Clients</a></li>
                <li><a href="#">Contact</a></li>
            </ul>
        </li>
        <li>
            <a href="#">Services</a>
        </li>
        <li>
            <a href="#">Contact</a>
        </li>
    </ul>
</nav>



from Vertical side nav bar - Angular 4 & Bootstrap 3

Where is php7.0-fpm.sock located

I have a simple project with directory structure

I am setting up nginx config for my drupal site, and for the fastcgi_pass I have been using 127.0.0.1:9000 but I want to use a unix socket as suggested in this conf:

 # PHP 7 socket location.
   fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;

but I can't find php/php7.0-fpm.sock;

I have the following path in my centos distro

/var/run/php-fpm/php-fpm.pid



from Where is php7.0-fpm.sock located

Unwanted React Component rerender?

So this is a form where the user can add sections to add a question (to build a quiz) and I notice that when I fill in the Answer Choices and put a file in my dropZone (drop works but doesn't update correctly, you can ignore this) the Answer Choices and dropZone rerender and the fields like refresh and become empty.

I am not entirely sure why this is happening, i have tried looking at similar issues but I couldn't get it to work. Here is my CodeSandbox with my App.

I am thinking that it may be the addQuestion function in my Questions component. Here's the code for that:

  addQuestion = question => {
    questionIdx++;
    var newQuestion = { uniqueId: uuid(), question: "" }
    this.setState(prevState => ({
      questions: [...prevState.questions, newQuestion]
    }));
    return { questions: newQuestion }
  };

I am new to React and Js so any tips/explanations will do loads of help. Thanks!



from Unwanted React Component rerender?

ESRI Maps setting MapView.extent cuts off top and bottom of extent in display

I have an ESRI map that I initialize with a given extent. When I draw the map with its initial extent, the extent of what is actually displayed is cut off by about 5-10%, so some features on my FeatureLayers lie outside the initial view. It seems like the map is trying to form a "best fit" zoom level to match the requested extent to the map size, but in this case, the best fit leaves the top and bottom of the view cropped off.

I created a demo to show this behavior:

const map = new EsriMap({
  basemap: 'topo',
});
const extent = {
  spatialReference: {
    latestWkid: 3857,
    wkid: 102100,
  },
  xmin: -8418477.75984,
  ymin: 5691645.413467902,
  xmax: -8413622.645963104,
  ymax: 5694628.596517603,
};

const mapView = new EsriMapView({
  container: document.querySelector('#viewDiv'),
  extent,
  map,
});

const geometry = new EsriPolygon({
  rings: [
    [extent.xmax, extent.ymax],
    [extent.xmax, extent.ymin],
    [extent.xmin, extent.ymin],
    [extent.xmin, extent.ymax],
    [extent.xmax, extent.ymax],
  ],
  spatialReference: extent.spatialReference,
});

const symbol = {
  type: 'simple-line',
  color: [255, 0, 0],
  width: 2,
};

const graphic = new EsriGraphic({
  geometry,
  symbol,
});

mapView.graphics.add(graphic);

See live at https://codepen.io/asgallant/pen/rrWmLW. The red box is the requested extent. If you change the height of the map's container, the map changes its initial zoom level at certain break points.

I would like to configure the map to always choose a default zoom level that fully encapsulates the requested extent, so no features are cut off. I know I can just set the zoom level to whatever I want, but I have hundreds of different maps, requiring different zoom levels to achieve the stated goal. Does anyone know how to accomplish this?



from ESRI Maps setting MapView.extent cuts off top and bottom of extent in display

Angular 6 providedin doesn't work -> StaticInjectorError

I'm trying to use 'providedin' feature in Angular but receive the error "StaticInjectorError(AppModule)[DashboardComponent -> DashboardService]:"

@Injectable({
  providedIn: DashboardModule
})
export class DashboardService {
  getContent() {
    return 'Dashboard Service works!!!';
  }
}

Full demo https://stackblitz.com/edit/angular-kbkjet Thanks for you effort!



from Angular 6 providedin doesn't work -> StaticInjectorError

How do I detect an increase in movement then a sudden stop using the device's accelerometer?

I'm trying to detect a motion that you would get from bumping two phones with each other.

My question is, is an accelerometer the right sensor for this?

If so, how would I implement it?

Otherwise, what sensor should I use and in what way should I use it?

According to the guide at https://developer.android.com/guide/topics/sensors/sensors_overview, TYPE_LINEAR_ACCELERATION seems like the right one to use, however I can't figure out how to use it.



from How do I detect an increase in movement then a sudden stop using the device's accelerometer?

Can't see or download OTA app from iPad in devices in Xcode

Our customer installs the iOS app via OTA on their iPads. Before, we would be able to download the apps from the iPads for debugging purposes and to extract the CoreData sqlite databases, from within the "Devices and Simulators" in Xcode.

However, this does not seem to be possible anymore since our app is not visible in the "Installed Apps" section. We are trying to this from the same mac where the app/ipa was originally build, so all certificates and provisioning profiles are there.

We are using Xcode 9.4.1 on MacOS High Sierra 10.13.6 and the iPads are iPad4 with iOS 11.4.1. I can't say for sure when this has stopped working, but I suspect it was after the last Xcode/iOS upgrade.

Is anyone experiencing the same problems?

Clarification: we have no trouble downloading the apps via OTA to the iPads and the apps are working as expected.



from Can't see or download OTA app from iPad in devices in Xcode

HTML5 audio on IOS: how can currentTime be less than initial value?

I have to play a short fragment of bigger audio. I use currentTime to set starting point in time, and timeupdate event to stop audio when required.

I noticed that on few early timeupdate events sometimes currentTime is less than its initial value, despite there is (obviously) no "rewind" actions.

Here is code example:

var start = 1;
var end = 1.3;
var audio = document.getElementById('audio');
audio.addEventListener('timeupdate', function () {
   console.log(audio.currentTime);
   if (audio.currentTime < start || audio.currentTime > end) {
      audio.pause();
   }
});
audio.currentTime = start;
audio.play();

For example, output of console log can be this:

1
0.85
0.85
1
1.02
...

Here's an example.

Tested on iPad with iOS 11.4.1. This problem appears only on very short time ranges ~0.3sec.



from HTML5 audio on IOS: how can currentTime be less than initial value?

Nodejs pdfkit Measurement Unit

What is the Measurement Unit used in pdfkit (node js)??

Is it centimetre, millimetre, inch any idea ??

Like we use doc.text(20, 20, 'Message') what is 20(x) and 20(x) stands for.

Can I change it to any familiar format like cm, mm, inch?????



from Nodejs pdfkit Measurement Unit

Simulation of t copula in Python

I am trying to simulate a t-copula using Python, but my code yields strange results (is not well-behaving):

I followed the approach suggested by Demarta & McNeil (2004) in "The t Copula and Related Copulas", which states:

t copula simulation

By intuition, I know that the higher the degrees of freedom parameter, the more the t copula should resemble the Gaussian one (and hence the lower the tail dependency). However, given that I sample from scipy.stats.invgamma.rvs or alternatively from scipy.stats.chi2.rvs, yields higher values for my parameter s the higher my parameter df. This does not made any sense, as I found multiple papers stating that for df--> inf, t-copula --> Gaussian copula.

Here is my code, what am I doing wrong? (I'm a beginner in Python fyi).

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.stats import invgamma, chi2, t

#Define number of sampling points
n_samples = 1000
df = 10

calib_correl_matrix = np.array([[1,0.8,],[0.8,1]]) #I just took a bivariate correlation matrix here
mu = np.zeros(len(calib_correl_matrix))
s = chi2.rvs(df)
#s = invgamma.pdf(df/2,df/2) 
Z = np.random.multivariate_normal(mu, calib_correl_matrix,n_samples)
X = np.sqrt(df/s)*Z #chi-square method
#X = np.sqrt(s)*Z #inverse gamma method

U = t.cdf(X,df)

My outcomes behave exactly oppisite to what I am (should be) expecting: Higher df create much higher tail-dependency, here also visually:

 U_pd = pd.DataFrame(U)
 fig = plt.gcf()
 fig.set_size_inches(14.5, 10.5)
 pd.plotting.scatter_matrix(U_pd, figsize=(14,10), diagonal = 'kde')
 plt.show()

df=4: scatter_plot

df=100: enter image description here

It gets especially worse when using the invgamma.rvs directly, even though they should yield the same. For dfs>=30 I often receive a ValueError ("ValueError: array must not contain infs or NaNs")

Thank you very much for your help, much appreciated!



from Simulation of t copula in Python

'import quandl' produces 'Process finished with exit code -1073741819 (0xC0000005)'

Here is my entire program:

import quandl

print("Hello World");

which results in:

Process finished with exit code -1073741819 (0xC0000005)

In the first place I imported Quandl, but then I received:

ModuleNotFoundError: No module named 'Quandl'

and then I googled it and read a suggetstion to change the name to quandl.

I have installed the package in the project intercepter, there it's named Quandl though. Anyway it looks like at least with lower case it passes the compilation.

I run my program on Windows 10. My Python version is 3.7. I use PyCharm.

If I try to import a different package, then it works. Quandl is the problematic one.



from 'import quandl' produces 'Process finished with exit code -1073741819 (0xC0000005)'

Python Cantera MassFlowController won't extract mass from reactor

I am trying to build a hydrogen tank model (liquid-vapour) that includes heat addition over time through the tank walls, a venting valve that is activated at a given pressure and a constant fuel cell supply that is activated after a dormancy time.

H2 tank

When I run the time integration, after some time (18000 sec in the code below), the MassFlowController mass flow is changed automatically, but it won't export any mass from the tank. Cantera is throwing an error shortly after that.

This is a sample code:

import cantera as ct

""" Variables """
Tint = 20.24 #K
Tamb = 293.0 #K
Rho = 44.623  #kg/m3
TankVolume = 7.04 #m3
TankArea = 20.0 # m2
TankU = 0.36
Pvent = 7.0 #bar
Psupply = 2.0 #bar
msupply = 0.005 #kg/s
DormTime = 5.0 #hrs
TotTime = 10.0 #hrs

""" Tank Reactor """
LH2 = ct.Hydrogen()
LH2.TD = Tint, Rho
LR = ct.Reactor(contents=LH2)
LR.volume = TankVolume

""" Air as the ambient medium """
air = ct.Solution('air.cti')
air.TP = Tamb, ct.one_atm
Rin = ct.Reservoir(air)

""" Air as the medium for extraction. Set the outlet pressure to Pvent """
extr = ct.Solution('air.cti')
extr.TP = Tamb, Pvent * ct.one_atm
Rout = ct.Reservoir(extr)

""" Fuel cell reactor. Does not operate as FC """
FCH2 = ct.Hydrogen()
FCH2.TP = Tamb, Psupply * ct.one_atm
Rextr = ct.Reservoir(FCH2)

""" Tank wall for the heat addition """
TW1 = ct.Wall(LR, Rin, A=TankArea, U=0.36)

""" Initiate the supply if there is no dormancy time """
if DormTime != 0.0:
    FCVLV = ct.MassFlowController(LR,Rextr,mdot=0.0)
    MassOn = False
else:
    FCVLV = ct.MassFlowController(LR,Rextr,mdot=msupply)
    MassOn = True

""" Valve for venting the H2 to the atmosphere if the pressure reached Pvent """
VVLV = ct.Valve(LR, Rout, K=1.0)

""" Reactor network for the tank """
network = ct.ReactorNet([LR])

""" Time integartion """
t = 0.0
dt = 60.0

print('{:>6s} {:>12s} {:>6s} {:>5s} {:>9s} {:>7s} {:>7s} {:>8s} {:>8s}'.format(
        'Time', 'Press', 'Temp', 'VapFr', 'Mass', 'Vol', 'Dens', 'H2FC', 'H2Vent'))

print('{:6.0f} {:12.2f} {:6.2f} {:5.3f} {:9.3f} {:7.2f} {:7.3f} {:8.6f} {:8.6f}'.format(
          t, LR.thermo.P, LR.thermo.T, LR.thermo.X, LR.get_state()[0], 
          LR.get_state()[1], LR.thermo.density_mass, FCVLV.mdot(t), VVLV.mdot(t)))

while t < 60.0*60*TotTime:
    if LR.thermo.density_mass < 0.1: #Safety
        break

    t += dt

    """ Initiate the FC mass flow after the dormancy time """
    if t>= 60.0*60.0*DormTime and not MassOn:
        if LR.thermo.P < Psupply:
            print('WARNING: Pressure in tank lower than FC supply pressure. Supply will stay closed')
        else:
            FCVLV.set_mass_flow_rate(msupply)
            MassOn = True

    network.advance(t)

    print('{:6.0f} {:12.2f} {:6.2f} {:5.3f} {:9.3f} {:7.2f} {:7.3f} {:8.6f} {:8.6f}'.format(
          t, LR.thermo.P, LR.thermo.T, LR.thermo.X, LR.get_state()[0], 
          LR.get_state()[1], LR.thermo.density_mass, FCVLV.mdot(t), VVLV.mdot(t)))

Which gives me the below behaviour, up to the point of crashing, which I think is the point that cantera tries to actually take mass out of the tank (see below why). Notice that the mass flow is on, but the mass of H2 is not reducing.

H2Time

The model won't crash if I reduce the dormancy time, but it still shows the same behaviour before it starts reducing the H2 mass in the tank (that's possibly the crash cause above). I suspect that it doesn't have to do with the H2 physics, because I get the same error (below) at different pressures.

CanteraError thrown by CVodesIntegrator::integrate: CVodes error encountered. Error code: -3 At t = 18483.3 and h = 0.00100341, the error test failed repeatedly or with |h| = hmin. Exceptions caught during RHS evaluation: density must be positive Components with largest weighted error estimates: 0: -15.9704 2: 15.9166 1: 0 3: 0

Is this a bug of the Cantera MassFlowController or am I missing anything here?



from Python Cantera MassFlowController won't extract mass from reactor

Why Firebase stops syncing when local date of device is changed explicitly?

When I change my Phone's Local Date setting by 1 or more months and then after restarting my android app which uses Firebase real time database, it doesn't load the data from database and keeps on loading forever. Why does this happen? Does Firebase checks the local time of device before fetching the data?

This is onCreate() MainActivity of Android App

After changing the date (by 10 or more days) in settings and then closing and reopening the app, the progress bar never gets invisible. Not even the onCancelled function get called.

    final ProgressBar progressBar = findViewById(R.id.progress_bar);
    final TextView textView = findViewById(R.id.textView);
    progressBar.setVisibility(View.VISIBLE);

    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference myRef = database.getReference("message");
    myRef.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            String value = dataSnapshot.getValue(String.class);
            textView.setText(value);
            progressBar.setVisibility(View.INVISIBLE);
        }

        @Override
        public void onCancelled(DatabaseError error) {
            progressBar.setVisibility(View.INVISIBLE);
        }
    });`

App level gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.akzarma.testapplication"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.google.firebase:firebase-database:11.8.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

apply plugin: 'com.google.gms.google-services'

This is the Github repo link for this project: https://github.com/akzarma/testApp



from Why Firebase stops syncing when local date of device is changed explicitly?

.net core Application is run with different port with electron.net with cross platrom

I've developed an application using .NET Core and Electron.NET and created one login form.

For login, I have created separate web API project and call the login API on login button click.

When I call API from an application, Its give an error about "Cross-Origin", so I need to register an IP Address and Port in that API but right now I am facing an issue like .net core application is run on the different-different port each time.

While call sign-in in API from the window environment it gives me below port:8001

While calling the same API from the Ubuntu it gives me port 35941.

So now I am facing an issue like, we have the different project for web API and it allows us to call web API on the specific port but due to each time different port generated by the electron.net, we can not call the web API in CORS(cross-origin) and it throws an error.

So anyone please help me for how to opt-out with this situation.



from .net core Application is run with different port with electron.net with cross platrom

How to keep state of page submitted through Turbolinks with Rails 5 + jQuery

I'm trying to show/hide a section when another element is clicked. Pretty simple stuff, and I got it to work fine. The problem is: this is a todo list; tasks are created and checked through Ajax (with Turbolinks, data remote etc), and when this happens, the show/hide action stops working until I manually reload the page again. It also loses track of the state of whether the section is hidden or not, even when I use localStorage, like so:

$(document).ready(function(){
    if (localStorage.getItem("revealed?") === "true") {
      $('#completed').removeClass('hide');
    } else {
      $('#completed').addClass('hide');
    }

    $('#show_completed').click(function(){
      if (localStorage.getItem("revealed?") === "false") {
        $('#completed').removeClass('hide');
        localStorage.setItem("revealed?", "true");
      } else {
        $('#completed').addClass('hide');
        localStorage.setItem("revealed?", "false");
      }
    });

});

I've tried every solution on the JS side that I could think of, and everything works to some extent, but they all still break when a task is submitted automatically.

I'm stumped. Is it some kind of behind-the-scenes interference between jQuery and Turbolinks? What am I missing?



from How to keep state of page submitted through Turbolinks with Rails 5 + jQuery

Android Navigation Architecture Component - Nav Drawer Icons

I'm currently using the Android Architecture Component's Navigation, but I'm running into an issue with my Navigation Drawer. It shows the hamburger menu when at my starting destination, but other Fragments are showing the up arrow. I believe I've setup my navigation_graph incorrectly.

navigation.graph.xml

<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    app:startDestination="@id/nav_home">

    <!-- Start at HomeFragment -->
    <fragment
        android:id="@+id/nav_home"
        android:name=".HomeFragment"
        android:label="@string/home">

        <!-- Navigate to the Search -->
        <action
            android:id="@+id/action_nav_home_to_nav_search"
            app:destination="@id/nav_search" />
    </fragment>


    <fragment
        android:id="@+id/nav_settings"
        android:name=".SettingsFragment"
        android:label="@string/settings">

        <!-- Navigate to the Search -->
        <action
            android:id="@+id/action_nav_settings_to_nav_search"
            app:destination="@id/nav_search" />
    </fragment>



    <fragment
        android:id="@+id/nav_search"
        android:name=".SearchFragment"
        android:label="@string/search" />

</navigation>

I feel like HomeFragment and SettingsFragment should be related somehow but I'm not sure how to define that.

And then within MainActivity, I just set it up like this.

navController = findNavController(R.id.mainNavigationFragment)
setupActionBarWithNavController(this, navController, drawer_layout)

Thanks.



from Android Navigation Architecture Component - Nav Drawer Icons

Bagplot implementation in Swift

I'm trying to approximate GPS coordinates from n different locations.

I read here that using a bagplot would be a good idea: https://gis.stackexchange.com/questions/161838/approximating-gps-coordinates-for-a-point-from-n-expected-locations

I'm trying to implement this in Swift and can't seem to figure out an easy way to do so.



from Bagplot implementation in Swift

Vue.js keyup events and v-model length on Android not working as expected

On Android the length of v-model is returning 0 on keyup unless its a number or the space bar key. Does anyone know why that is and how to make it fire the keyup event no matter what key it is and get the length? Here is a cleaned up version of what I have:

<template>
  <div class="typeahead">
    <input
      v-model="query"
      v-on:keyup="suggestTerms"
      >
  </div>
</template>

<script>
export default {
  data () {
    return {
      query: '',
    }
  },
  methods: {
    suggestTerms () {
      console.log('query length = ' + this.query.length);
    }
  }
}
</script>

P.S. This works on every browser and device except Android.



from Vue.js keyup events and v-model length on Android not working as expected

editing the ckeditor config.js has no impact

I changed my CKeditor config.js file to include all the buttons possible to this:

CKEDITOR.editorConfig = function( config ) {
    config.toolbarGroups = [
        { name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
        { name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
        { name: 'editing', groups: [ 'find', 'selection', 'spellchecker', 'editing' ] },
        { name: 'forms', groups: [ 'forms' ] },
        '/',
        { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
        { name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi', 'paragraph' ] },
        { name: 'links', groups: [ 'links' ] },
        { name: 'insert', groups: [ 'insert' ] },
        '/',
        { name: 'styles', groups: [ 'styles' ] },
        { name: 'colors', groups: [ 'colors' ] },
        { name: 'tools', groups: [ 'tools' ] },
        { name: 'others', groups: [ 'others' ] },
        { name: 'about', groups: [ 'about' ] }
    ];
};

This config was generated using the CKeditor config generator tool.

After the change was deployed to my server and the page was refreshed using incognito mode in chrome non of the buttons changed.

If i add this code directly in my admin.master then the new button does show.

<script>
        jQuery(function() {
            CKEDITOR.config.extraPlugins = 'justify';
        });
    </script>

Is it possible that i am not using the config.js at all?



from editing the ckeditor config.js has no impact

MP3 (MPEG I) chunk decoder for Python

I've been searching for a few days and trying many different libraries including PyDub, python_mp3_decoder (segmentation faults), pymad, but have had basically no luck in finding a library for Python that would allow me to decode a MP3 Stream (from a internet radio; icecast) on the fly and treat it like microphone input (e.g. PyAudio stream).

I am trying to get a stream of decoded audio to use with PyAudio for an acoustic fingerprinting project. The other catch is I cannot use PyMedia which has been suggest here on stackoverflow before since it is not supported on the Mac, nor has it been updated in more than 12 years.

Any input on how I could decode a MP3 Stream in real time in python would be much appreciated! Thanks!



from MP3 (MPEG I) chunk decoder for Python

Showing cropped image in bokeh

I am showing a picture in a figure in bokeh and am using the BoxSelectTool in order to draw a rectangle.

box_select = BoxSelectTool(callback=callback)

p2 = figure(x_range=(0,700), y_range=(0,500),plot_width=1100,plot_height=1100,tools=[box_select])
p2.image_url( url='url',
         x=1, y=1, w=700, h=500, anchor="bottom_left",source=im_src)

rect_source = ColumnDataSource(data=dict(x=[], y=[], width=[], height=[]))
callback = CustomJS(args=dict(rect_source=rect_source), code="""
    // get data source from Callback args
    var data = rect_source.data;

    /// get BoxSelectTool dimensions from cb_data parameter of Callback
    var geometry = cb_data['geometry'];

    /// calculate Rect attributes
    var width = geometry['x1'] - geometry['x0'];
    var height = geometry['y1'] - geometry['y0'];
    var x = geometry['x0'] + width/2;
    var y = geometry['y0'] + height/2;

    /// update data source with new Rect attributes
    data['x'].push(x);
    data['y'].push(y);
    data['width'].push(width);
    data['height'].push(height);

    rect_source.data = data;
    rect_source.change.emit();
'''

Now i want to show that image region as cropped in a new smaller figure, after the rectangle is drawn, without clicking a button or anything:

d2 = figure(x_range=(0,200), y_range=(0,100),plot_width=200,plot_height=100)
d2.image( image='image',
         x=1, y=1, dw=100, dh=100, source=img, palette="Viridis256")

img = ColumnDataSource( data=dict(image=[]))

So i need something like this in JS:

tmp_im = cv2.imread('static/0' + str(pos1.loc[ind, "picture"].values[0]) + '.jpg')
tmp_im = tmp_im[geometry['y0']:geometry['y1'],geometry['x0']:geometry['x1']]
tmp_im = cv2.cvtColor(tmp_im, cv2.COLOR_BGR2GRAY)
img.data = dict(image=[tmp_im])

How can I do that in JS + bokeh?



from Showing cropped image in bokeh

How to add javascript function in webview and call it later from html

I am adding a javascript function in webview like this (Kotlin)

val webView = findViewById(R.id.webview) as WebView
webView.getSettings().setJavaScriptEnabled(true)
webView.addJavascriptInterface(this, "android")
webView.getSettings().setBuiltInZoomControls(false)
webView.loadUrl(url)

webView.webViewClient = object : WebViewClient() {
        override fun onPageFinished(view: WebView, url: String) {
            super.onPageFinished(view, url)
            webView.loadUrl("javascript:(function captchaResponse (token){" +
                            "      android.reCaptchaCallbackInAndroid(token);" +
                            "    })()")
        }
    }

Function works fine but the problem is that it runs immediately when I add it in webview. I only want to include it as Javascript function and it should be called only from html (When user will fill the recaptcha). How can I do that?



from How to add javascript function in webview and call it later from html

React - Highlighting text inside of dangerouslySetHTML for given Xpath

Stuck for days with the following challenge:

The goal is to highlight several parts of a text that is rendered in a "dangerouslySetInnerHTML".

The text object that should be rendered includes the full html of the text content and an array of annotations, in which each annotation contains a string of the text part that should be highlighted and the X-Path (ranges).

{
 content: "<div><p>Hello world!</p><p>Another paragraph.</p></div>",
 annotations: [
   {ranges: [{start: '/p[1]', startOffset: 0, end: '/p[1]', endOffset: 12}]}
 ],
 quote: "Hello world!"
}

This is the simplified JSX:

render () {
    return (
      <div className="textcontainer">
       <p className="textcontent" dangerouslySetInnerHTML= />    
      </div>            
   )
  }

Is it possible to do this without jquery?

I found this answer on that topic Highlighting when HTML and Xpath is given

Though I couldn't make it work. Sorry, React JS newbie here. Thanks so much for helping out. Any help really appreciated.



from React - Highlighting text inside of dangerouslySetHTML for given Xpath

MongoDB CursorNotFound Error on collection.find() for a few hundred small records

I'm running on Mongo 3.6.6 (on a small Mongo Atlas cluster, not sharded) using the native Node JS driver (v. 3.0.10)

My code looks like this:

const records = await collection.find({
  userId: ObjectId(userId),
  status: 'completed',
  lastUpdated: {
    $exists: true,
    $gte: '2018-06-10T21:24:12.000Z'
  }
}).toArray();

I'm seeing this error occasionally:

{
  "name": "MongoError",
  "message": "cursor id 16621292331349 not found",
  "ok": 0,
  "errmsg": "cursor id 16621292331349 not found",
  "code": 43,
  "codeName": "CursorNotFound",
  "operationTime": "6581469650867978275",
  "$clusterTime": {
    "clusterTime": "6581469650867978275",
    "signature": {
      "hash": "aWuGeAxOib4XWr1AOoowQL8yBmQ=",
      "keyId": "6547661618229018626"
    }
  }
}

This is happening for queries that return a few hundred records at most. The records are a few hundred bytes each.

I looked online for what the issue might be but most of what I found is talking about cursor timeouts for very large operations that take longer than 10 minutes to complete. I can't tell exactly how long the failed queries took from my logs, but it's at most two seconds (probably much, much shorter than that).

I tested running the query with the same values as one that errored out and the execution time from explain was just a few milliseconds:

"executionStats" : {
    "executionSuccess" : true, 
    "nReturned" : NumberInt(248), 
    "executionTimeMillis" : NumberInt(3), 
    "totalKeysExamined" : NumberInt(741), 
    "totalDocsExamined" : NumberInt(741), 
    "executionStages" : {...}
    }, 
    "allPlansExecution" : []
    ]
} 

Any ideas? Could intermittent network latency cause this error? How would I mitigate that? Thanks



from MongoDB CursorNotFound Error on collection.find() for a few hundred small records

coca pod Chart not appearing (Swift4)

My chart is not displaying any bars using this bar graph. I have successfully imported the charts cocoa pod. There are currently no run time errors. The only thing that is being displayed in the graph is the description label.

    import UIKit
import Charts
class ViewController: UIViewController {


@IBOutlet var lineChartVIew: BarChartView!
var days: [String]!


override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    days = ["Monday","Tuesday","life"]
    let task = [1.0,4.0,3.0]
    setChart(dataPoints: days, values: task)
}

func setChart(dataPoints : [String], values : [Double]){
    lineChartVIew.noDataText = "Nothining to display"

    var dataEntries : [BarChartDataEntry] = []
    var counter = 0.0

    for i in 0..<dataPoints.count {
        counter += 1
        let dataEntery = BarChartDataEntry(x: values[i], y: counter)
        dataEntries.append(dataEntery)
    }

    let ChartDataSet = BarChartDataSet(values: dataEntries, label: "Time")
    let chartData = BarChartData()
    lineChartVIew.data = chartData
    ChartDataSet.colors = ChartColorTemplates.colorful()

    lineChartVIew.animate(xAxisDuration: 2.0, yAxisDuration: 2.0)
}}

enter image description here



from coca pod Chart not appearing (Swift4)

java.lang.IllegalStateException: YouTubeServiceEntity not initialized with YouTubeThumbnailView

I am using youtube api in my android app to load thumbnails for videos in my RecyclerView. Following is my implementation in side my adapter:

private final Map<YouTubeThumbnailView, YouTubeThumbnailLoader> thumbnailViewToLoaderMap;

This holds the loaders for the YouTubeThumbnailView for each adapter element. This is the code we use for initialisation of the YouTubeThumbnailLoader(s):

    YouTubeThumbnailLoader loader = thumbnailViewToLoaderMap.get(holder.thumbnail);
                final String videoId = Utils.getYoutubeIdFromUrl(m.getYoutubeUrl());
                holder.thumbnail.setTag(videoId);
                if(loader != null) {
                     loader.setVideo(videoId);
                    }
                }

When initialising the elements of the ViewHolder, I initialise the thumbnail loaders as follows:

private void setupYoutubeThumbnail() {
            thumbnail.initialize(RiyazApplication.applicationInstance
                            .getString(R.string.youtube_api_developer_key),
                    thumbnailListener);
            thumbnail.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(v.getTag() != null && itemClickListener != null) {
                        itemClickListener.onClickVideo(mList.get(getAdapterPosition()));
                    }
                }
            });

and the code for releasing the thumbnail loaders is as follows:

public void releaseThumbnailLoaders() {
        final Set<YouTubeThumbnailView> keysSet = thumbnailViewToLoaderMap.keySet();
        for(YouTubeThumbnailView view: keysSet) {
            final YouTubeThumbnailLoader loader = thumbnailViewToLoaderMap.get(view);
            if(loader != null) {
                loader.release();
            }
        }
        thumbnailViewToLoaderMap.clear();
    }

In my crashalytics, I am getting the following exception:

Fatal Exception: java.lang.IllegalStateException: YouTubeServiceEntity not initialized
       at android.os.Parcel.readException(Parcel.java:1497)
       at android.os.Parcel.readException(Parcel.java:1443)
       at com.google.android.youtube.player.internal.l$a$a.a(Unknown Source)
       at com.google.android.youtube.player.internal.o.a(Unknown Source)
       at com.google.android.youtube.player.internal.p.(Unknown Source)
       at com.google.android.youtube.player.internal.ac.a(Unknown Source)
       at com.google.android.youtube.player.YouTubeThumbnailView$a.a(Unknown Source)
       at com.google.android.youtube.player.internal.r.g(Unknown Source)
       at com.google.android.youtube.player.internal.r$c.a(Unknown Source)
       at com.google.android.youtube.player.internal.r$b.a(Unknown Source)
       at com.google.android.youtube.player.internal.r$a.handleMessage(Unknown Source)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:136)
       at android.app.ActivityThread.main(ActivityThread.java:5052)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
       at dalvik.system.NativeStart.main(NativeStart.java)

I am not sure, why am I getting this. Can anyone please help?



from java.lang.IllegalStateException: YouTubeServiceEntity not initialized with YouTubeThumbnailView

Monday 30 July 2018

Allow access of application based on ip, or proxy network coverage

I have a reader application and we are customizing the reader to a certain institution to allow the user to use the application and read from its content. I have to verify whether he is under a certain proxy coverage and that he is logged in to that proxy.

I personally have very little experience with networking and proxy, therefore I would like to ask, whether this is doable and if so, what is the best way to approach it?

In case this is doable will Apple accept it and how can Apple team test the functionality?

I have come over this solution, but I'm not sure if this is what I need: How can I get the username for a proxy host from KeyChain?

Your guidance would be much appreciated.



from Allow access of application based on ip, or proxy network coverage

How to get a final URL after t.co redirects in WKWebView

I know that I can generally get the current URL of WKWebView by using the URL property. However I have discovered that when there is a redirect, it will not give me the proper URL.

For example, if I go to http://twitter.com and then click on a link to some other company (ex: http://mycompany.com), then I see a t.co/XXX URL which eventually redirects me to mycompany.com.

However, when I look at WKWebView's URL property, I am seeing "t.co" instead of "mycompany.com".

Strangely, I am never seeing didReceiveServerRedirectForProvisionalNavigation:... called, and when I check URL at didStartProvisionalNavigation:... and decidePolicyForNavigationAction:... I just see the "t.co" URL instead of the "mycompany.com" one.

Also, I will need to know the domain in order to make some adjustments to the body, so I am not sure if I can use JS here.

Please let me know if you have any ideas.

UPDATE: I realized this only happens when I use a custom URL scheme set via setURLSchemeHandler:, which I had omitted from the question originally since I didn't think it was related.

After some playing around, I was able to get things working with the following change in willPerformHTTPRedirection:...:

NSMutableURLRequest *newRequest = 
[NSMutableURLRequest requestWithURL:request.URL];

dispatch_async(dispatch_get_main_queue(), ^{
    [_webView loadRequest:newRequest];
});

 completionHandler(nil);

UPDATE: This has a serious drawback because URLs that are not for the main frame will come into willPerformHTTPRedirection:..., and if the request is re-loaded for all of these the page gets messed up.

I need a way to determine if the URL is from the main frame and only do the reload for those.



from How to get a final URL after t.co redirects in WKWebView

Google Analytics using React Web / Cordova

I have made an app using React (Web) and bundled it using Cordova.

I am using a plugin called 'react-ga' for tracking Google Analytics.

I initialise react-ga when the app is run using:

ReactGA.initialize('my-ga-uid', { debug: true, cookieDomain: 'auto' })

And create an event using something like:

ReactGA.event({
  category: 'Test',
  action: 'Test button pressed event.'
})

or,

ReactGA.set({ location.pathname })
ReactGA.pageview(location.pathname)

The analytics work fine in the browser and on dev builds, however when I bundle a build for iOS or Android, the analytics don't seem to be tracked?

Is there something wrong with my code? Do I need to initialise something else? Do I need a cordova plugin instead (although I want analytics to still work in a web browser)?



from Google Analytics using React Web / Cordova

Using React within a dynamically loaded es module

I have been loading a native ES Module which can be simplified to src/test.tsx:

export default class Test {
    constructor() {
        console.log('loaded');
    }
}

I can load this in my browser and initialize it great, a la:

import('http://127.0.0.1:8085/').then(m => { 
  const instance = new m.default();
});

However.. if I want to add any external dependency, in this case React, I can't seem to figure out how to target es6 and also bundle React, with tsc. So my dist file contains import React from 'react'; for which the browser has no idea how to resolve, and produces:

(index):1 Uncaught (in promise) TypeError: Failed to resolve module specifier "react". Relative references must start with either "/", "./", or "../".

My tsconfig looks like:

{
    "compilerOptions": {
        "baseUrl": ".",
        "rootDir": "src",
        "module": "es6",
        "target": "es2015",
        "lib": ["es6", "dom"],
        "declaration": true,
        "jsx": "react",
        "outDir": "dist",
        "strict": true,
        "noImplicitAny": false,
        "allowSyntheticDefaultImports": true,
        "esModuleInterop": true,
        "experimentalDecorators": true,
        "moduleResolution": "node",
        "skipLibCheck": true
    },
    "include": ["./src/**/*"]
}

Running node v9.5.0, typescript v2.9.2

I have also attempted to use webpack to bundle everything but cannot figure out how to produce a dynamically importable module that way



from Using React within a dynamically loaded es module

PHP MSSQL num_rows() not working with sqlsrv driver in Codeigniter

I'm getting the following error on a simple query that's supposed to return a number of rows:

Type: Error

Message: Call to a member function num_rows() on boolean

Filename: /var/www/cfc-dev/docroot/project/system/database/DB_query_builder.php

Line Number: 1428

I'm using Codeigniter 3.1.9. I recently started using PHP7.2 and also sqlsrv driver to connect to a MSSQL database.

In some other post, someone mentioned that scrollable should be set to an option different than SQLSRV_CURSOR_FORWARD so I dump the value of $this->scrollable in sqlsrv_driver.php and found out that its value is buffered

/**
     * Execute the query
     *
     * @param   string  $sql    an SQL query
     * @return  resource
     */
    protected function _execute($sql)
    {
        echo $this->scrollable; die();
        return ($this->scrollable === FALSE OR $this->is_write_type($sql))
            ? sqlsrv_query($this->conn_id, $sql)
            : sqlsrv_query($this->conn_id, $sql, NULL, array('Scrollable' => $this->scrollable));
    }

Not quite sure why it's failing. Any other queries that don't include num_rows() are fine so far. Thanks.



from PHP MSSQL num_rows() not working with sqlsrv driver in Codeigniter

Extract features from reddish videos

I have some videos like this video. I want to extract the feature from these videos. Each video has a level value(like 25.1 mmol/L). After extracting the feature I want to apply Machine Learning methods to estimate the glucose level.

Questions are:

  • Which Image processing techniques will be appropriate for extracting feature?
  • How can extract features with image processing techniques? (For convenient, please share a sample code)
  • How can I apply Deep Learning to estimate glucose level?


from Extract features from reddish videos

router animations not preserving height while animating

in my angular project I added router animations and they work fine except for a major lag which in my view is caused by the viewport loosing it's height: 100% css setting durring the animation keyframes.

as a result it first starts by drawing a scrunched-down version of the current view to replace the current view, animate that switching to a scrunched up view of the component coming into view, then redraw the new view it just loaded with it's actual height value, and it tries to do all that within a couple milliseconds.

If the views each have a hard-coded height (for example : height: 200px, in which case it doesn't depend on the parent to know what it'll look like in the end.), then the animation doesn't lag because then it only has to draw the "sliding to right" frames of the view it currently has + the view it's loading.

so it's really the height property being lost that's causing the lag.

the thing is I need the 100% height as I use that to obtain a content that resizes dynamically if the content above the router-outlet changes size.

how do I get to keep both height: 100% and router-animations?



from router animations not preserving height while animating

UIPageViewController transitionCoordinator

Is it possible to get hold of the transitionCoordinator of a UIPageViewController?

Every time I try to get it it's nil. Does it even use one?

If not, is there a non-hacky way of responding to the progress of a scroll between pages?

(hacky = iterating subviews to get scroll view and becoming scroll view delegate. This isn't ideal because of the "magic" that UIPageViewController does with its scroll view)

Thanks



from UIPageViewController transitionCoordinator

Getting random crashes while pushing to another view controller

I am getting random crashes while pushing to another view controller.
 
 It was too difficult to find out such a crash, we spent the almost 2-3 days to solve this issue. seems like the crash was due to the one extra view outlet got connected to the main view in the storyboard. Which created the nil reference for some objects of the view controller and applications crashes.
 But something surprising to us that how Xcode allowing me to connect the two outlets to the main view. I have again tried connecting the same but this time it is not allowing me to connect.  Attaching the screenshot for the same.
 
 Any kind of help/explanation is appreciated.enter image description here



from Getting random crashes while pushing to another view controller

HTML5 audio on IOS: currentTime less than initial value

I have to play specific short piece from source audio using "currentTime" for setting start time and "timeupdate" event to stop audio at special moment.

And I noticed, that on few early timeupdate events currentTime can become less than it's initial value, despite there is no "rewind" actions. Here is code example:

var start = 1;
var end = 1.3;
var audio = document.getElementById('audio');
audio.addEventListener('timeupdate', function () {
   console.log(audio.currentTime);
   if (audio.currentTime < start || audio.currentTime > end) {
      audio.pause();
   }
});
audio.currentTime = start;
audio.play();

For example, output of console log can be this:

1
0.85
0.85
1
1.02
...

More demonstrative example: https://jsfiddle.net/threisdd/tz0cys2a/1/

Tested on iPad with iOS 11.4.1. This problem appears only on very short time ranges ~0.3sec.



from HTML5 audio on IOS: currentTime less than initial value

How to pass Array Parameters in Soap Request

Issue get due to could not pass correct String[] parameters in Soap Request as require in .Net Webservice

public void SoapKsop2_Api_Call(){

    SoapObject request = new SoapObject(namespace, methodName);    
    request.addProperty("Name", "Mr.Abc");

    String[] sqlPar =  new String[2];
    sqlPar[0] = "@FLAG";
    sqlPar[1] = "@RDeviNo";

    String[] sqlVal =  new String[2];
    sqlVal[0] = "RDevice";
    sqlVal[1]  = "123546";

    PropertyInfo PrfsqlParaName = getProperty(namespace,"sqlParaName",sqlPar);
    PropertyInfo sqlParaValue = getProperty(namespace,"sqlParaValue",sqlVal);

    request.addProperty(PrfsqlParaName);
    request.addProperty(sqlParaValue);

    int TimeOutInSeconds = 1000;

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;

    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = new HttpTransportSE(url,TimeOutInSeconds * 1000);


    androidHttpTransport.call(soapAction, envelope);

    Log.d("test", "request: " + androidHttpTransport.requestDump);
    Log.d("test", "response: " + androidHttpTransport.responseDump);

    SoapObject result = (SoapObject)envelope.getResponse();
    String result  = result.getProperty(0).toString();

}

private PropertyInfo getProperty(String NAMESPACE,String name, String[] val) {

    PropertyInfo info = new PropertyInfo();
    info.name = name;
    info.namespace = NAMESPACE;

    //VECTOR_CLASS
    info.type = PropertyInfo.VECTOR_CLASS;


    Vector<String> vct = new Vector<String>();
    for (int i = 0; i < val.length; i++)
        vct.add(val[i]);
    info.setValue(vct);

    return info;
}

Error:

SoapFault - faultcode: 'soap:Server' faultstring: 'Server was unable to process request. ---> System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object.
    at DmlCall.Save_Edit_Delete(String ProcName, String[] sqlParaName, String[] sqlParaValue) in Web Service line 36
    --- End of inner exception stack trace ---' faultactor: 'null' detail: org.kxml2.kdom.Node@16ba69a



from How to pass Array Parameters in Soap Request

How do you load an alternate jquery in a webpack module?

I need to load alternate versions of jQuery other than the one in my node_modules. I have a local copy of the script but I am unable to get it to load in my webpack app.ts. I have removed the global jQuery and resolve path for node_modules in my webpack config since I do not want the version from node_modules. However I can't figure out how I can pass the loaded jquery to the scripts that require it.

I have multiple entry points (app.ts) each which needs to be able to load a different jquery so I can not define jquery in the webpack config as I would like to use the same config for processing all my entry points.

app.ts

import jquery from '../../../js/jquery-3.3.1.js';

// tried this but didn't help
// window.$ = jquery;
// window.jquery = jquery;

// these two require jquery but fail, it only works if I add back in
// the webpack config to find jquery in node_modules which is what I 
// don't want. popper.js has the same issue as jquery.
import '../../../js/popper-1.12.9.min.js';
import '../../../js/bootstrap-4.0.0.js';
import './js/jquery.matchHeight-min.js';

...



from How do you load an alternate jquery in a webpack module?

Multi-language elastic search mapping setup

I have documents stored in MongoDB like so:

const demoArticle = {
  created: new Date(),
  title: [{
    language: 'english',
    value: 'This is the english title'
  }, {
    language: 'dutch',
    value: 'Dit is de nederlandse titel'
  }]
}

I want to add analyzers to specific languages, which is normally specified like so:

"mappings": {
   "article": {
      "properties": {
         "created": {
            "type": "date"
         },
         "title.value": {
           "type": "text",
           "analyzer": "english"
         }
      }
   }
}

The problem is however: depending on the language set on the child level, it should have an analyzer set according to that same language.

I've stumbled upon Dynamic Templates in ElasticSearch but I was not quite convinced this is suited for this use-case.

Any suggestions?



from Multi-language elastic search mapping setup

Spring mvc multiple file upload while working on WebSphere Liberty

I am running into strange problem while trying to upload multiple files using ajax. why we are using Ajax to upload multiple file ? Because user wants to review all the files which he/she is trying to upload to server. what mean by review is, user should be allowed to delete file before uploading to server.

What i tried so far?

JSP

<form id="form1" method="post" action="uploadMultipleFiles" enctype="multipart/form-data">
  <!-- File input -->    
  <input name="file" id="files" type="file"  multiple="multiple"/><br/>
  <button value="Submit" onclick="uploadFiles()" >Upload</button><i>upload</i>
</form>

JS

function uploadFiles(){
  var files = $("#files").prop("files");
  var oMyForm = new FormData();   
  oMyForm.append("file", files[0]);  //currently trying with only one file
      $.ajax({
            url:  'uploadMultipleFiles',
            data: oMyForm,
           // dataType: 'text',
            processData: false,
            contentType: false,
            type: 'POST',
            success: function(data){
                console.log(data)
            }
          });
}

Spring Controller (Version 3.0.0 release)

@RequestMapping(value = "/uploadMultipleFiles", method = RequestMethod.POST)
    public @ResponseBody String uploadMultipleFilesHandler(HttpServletRequest request, HttpServletResponse response)  {
  MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  System.out.println(multipartRequest);   
}

I have not included entire code of controller but i believe it should be sufficient for any pointer which you can provide.

Spring bean configuartion

<bean id="multipartResolver"
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">

        <property name="maxUploadSize" value="900000" />

</bean>

Exception

java.lang.ClassCastException: com.ibm.ws.webcontainer31.srt.SRTServletRequest31 cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest

Kindly help me figure out what i could do to resolve this exception and please note same code is working file in tomcat however WebSphere Liberty profile seems to have some issue.



from Spring mvc multiple file upload while working on WebSphere Liberty

Preventing premature completion of an async pipeable operator in RxJS

I'm creating pipeable operators using RxJS 6, and am unclear about how to complete() the observer when the operation is asynchronous.

For a synchronous operation, the logic is simple. In the example below, all values from the source Observable will be passed to observer.next(), and after that observer.complete() is called.

const syncOp = () => (source) =>
  new rxjs.Observable(observer => {
    return source.subscribe({
      next: (x) => observer.next(x),
      error: (e) => observer.error(err),
      complete: () => observer.complete()
    })
  });
  
rxjs.from([1, 2, 3]).pipe(syncOp()).subscribe(x => console.log(x));
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/6.2.2/rxjs.umd.min.js">
</script>

For an asynchronous operation, however, I'm a bit at a loss. In the example below, the asynchronous operation is represented by a call to setTimeout(). Obviously, observer.complete() will be called before any of the values are passed to observer.next().

const asyncOp = () => (source) =>
  new rxjs.Observable(observer => {
    return source.subscribe({
      next: (x) => setTimeout(() => observer.next(x), 100),
      error: (e) => observer.error(err),
      complete: () => observer.complete()
    })
  });
  
rxjs.from([1, 2, 3]).pipe(asyncOp()).subscribe(x => console.log(x));
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/6.2.2/rxjs.umd.min.js">
</script>

So the question is: what is the idiomatic RxJS approach to make it so that the call to observer.complete() is only made after all values are asynchronously passed to observer.next()? Should I be manually keeping track of pending calls or is there a more "reactive" solution?

(Note that the example above is a simplification of my actual code, and that the call to setTimeout() is meant to represent "any asynchronous operation". I'm looking for a general approach to dealing with async operations in pipeable operators, not advice on how to deal with delays or timeouts in RxJS.)



from Preventing premature completion of an async pipeable operator in RxJS

What is the Big O Complexity of Reversing the Order of Columns in Pandas DataFrame?

So lets say I have a DataFrame in pandas with a m rows and n columns. Let's also say that I wanted to reverse the order of the columns, which can be done with the following code:

df_reversed = df[df.columns[::-1]]

What is the Big O complexity of this operation? I'm assuming this would depend on the number of columns, but would it also depend on the number of rows?



from What is the Big O Complexity of Reversing the Order of Columns in Pandas DataFrame?

Cross Domain form submit Google Tag Manager auto trigger

I have some problem while getting data from another site. In this case I want to get the reservation data from the booking engine site and they want to pass the data to me with Google Tag Manager. I don't really understand what I should do when they just need GTM code. What I should create in my server to get the data from the booking engine with Google Tag Manager ?

This is the illustrations:

I have two sites called sites1.com and sites2.com. In sites1.com I put the Google Tag Manager scripts to push form submit data like full name, last name, email, etc. After somebody submit the form I want to get the submited data in sites1.com to sites2.com with Google Tag Manager. My problem is how to get the data after somebody submited the form in sites1.com in my sites2.com ?

Please anybody knows how to resolve my problem . Thanks in advance .



from Cross Domain form submit Google Tag Manager auto trigger

Unable to get provider com.crashlytics.android.CrashlyticsInitProvider

After implementation 'com.google.firebase:firebase-core:16.0.1' and classpath 'com.google.gms:google-services:4.0.1'

I started getting the following error when starting the application:

FATAL EXCEPTION: main Process: com.fentury.android, PID: 10771 java.lang.RuntimeException: Unable to get provider com.crashlytics.android.CrashlyticsInitProvider: io.fabric.sdk.android.services.concurrency.UnmetDependencyException: This app relies on Crashlytics. Please sign up for access at https://fabric.io/sign_up, install an Android build tool and ask a team member to invite you to this app's organization. at android.app.ActivityThread.installProvider(ActivityThread.java:5856) at android.app.ActivityThread.installContentProviders(ActivityThread.java:5445) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5384) at android.app.ActivityThread.-wrap2(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6119) 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: io.fabric.sdk.android.services.concurrency.UnmetDependencyException: This app relies on Crashlytics. Please sign up for access at https://fabric.io/sign_up, install an Android build tool and ask a team member to invite you to this app's organization. at com.crashlytics.android.core.CrashlyticsCore.onPreExecute(CrashlyticsCore.java:235) at com.crashlytics.android.core.CrashlyticsCore.onPreExecute(CrashlyticsCore.java:209) at io.fabric.sdk.android.InitializationTask.onPreExecute(InitializationTask.java:44) at io.fabric.sdk.android.services.concurrency.AsyncTask.executeOnExecutor(AsyncTask.java:611) at io.fabric.sdk.android.services.concurrency.PriorityAsyncTask.executeOnExecutor(PriorityAsyncTask.java:43) at io.fabric.sdk.android.Kit.initialize(Kit.java:69) at io.fabric.sdk.android.Fabric.initializeKits(Fabric.java:440) at io.fabric.sdk.android.Fabric.init(Fabric.java:384) at io.fabric.sdk.android.Fabric.setFabric(Fabric.java:342) at io.fabric.sdk.android.Fabric.with(Fabric.java:313) at com.crashlytics.android.CrashlyticsInitProvider.onCreate(CrashlyticsInitProvider.java:27) at android.content.ContentProvider.attachInfo(ContentProvider.java:1751) at android.content.ContentProvider.attachInfo(ContentProvider.java:1726) at android.app.ActivityThread.installProvider(ActivityThread.java:5853) ... 10 more

Also added in AndroidManifest.xml next line:

<meta-data android:name="firebase_crash_collection_enabled" android:value="false" />



from Unable to get provider com.crashlytics.android.CrashlyticsInitProvider

Webview does not show Google map Full control button

I implemented one Web Application in android in that i want to call one URL and in that Page Google map is there

My issue is that in google map +, - Buttons works perfectly but Fullscreen button shows white blank screen.

It's showing in chrome app

Please, give me a solution?



from Webview does not show Google map Full control button

Subclassing Numpy Array - Propagate Attributes

I would like to know how custom attributes of numpy arrays can be propagated, even when the array passes through functions like np.fromfunction.

For example, my class ExampleTensor defines an attribute attr that is set to 1 on default.

import numpy as np

class ExampleTensor(np.ndarray):
    def __new__(cls, input_array):
        return np.asarray(input_array).view(cls)

    def __array_finalize__(self, obj) -> None:
        if obj is None: return
        # This attribute should be maintained!
        self.attr = getattr(obj, 'attr', 1)

Slicing and basic operations between ExampleTensor instances will maintain the attributes, but using other numpy functions will not (probably because they create regular numpy arrays instead of ExampleTensors). My question: Is there a solution that persists the custom attributes when a regular numpy array is constructed out of subclassed numpy array instances?

Example to reproduce problem:

ex1 = ExampleTensor([[3, 4],[5, 6]])
ex1.attr = "some val"

print(ex1[0].attr)    # correctly outputs "some val"
print((ex1+ex1).attr) # correctly outputs "some val"

np.sum([ex1, ex1], axis=0).attr # Attribute Error: 'numpy.ndarray' object has no attribute 'attr'



from Subclassing Numpy Array - Propagate Attributes

If the button is ACTION_DOWN, can it be forcibly held down for 1 second?

Holds the current button (ACTION_DOWN) to get the current time when pressed. When I release the button (ACTION_UP), the current time is also taken, and the audio file is cut and pasted by the time difference. If the user presses and releases a button too fast, it will generate an invalid audio file. So I would like to implement the function of unconditional pressing more than 1 second.

Buttons ACTION_DOWN, ACTION_UP Is there a way to implement such functionality in a motion event? If you know, please give me a favor. Below is the source code for the touch listener.

recordBtn.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getAction()) {
                case MotionEvent.ACTION_DOWN: {
                    long currentDuration = vAudioPlayer.getCurrentDuration();
                    // 녹음 시작 ( combineList 사이즈가 짝수일 때 )
                    if (mRecordThread != null) {
                        if (combineList.size() % 2 == 0) {
                            mRecordThread.startFileWrite(currentDuration);
                            combineList.add(currentDuration);
                        }
                    }
                }

                // 버튼, 이미지 뷰 애니메이션
                micBg1.setVisibility(View.VISIBLE);
                micBg2.setVisibility(View.VISIBLE);

                micBg1.startAnimation(animMic1);
                micBg2.startAnimation(animMic2);

                //userImg.setImageBitmap(userImgBitmap);
                userImg.startAnimation(animZoomIn);
                // artistImg.setImageBitmap(artistBlurImg);
                artistImg.startAnimation(animZoomOut);

                break;
                case MotionEvent.ACTION_UP: {
                    long currentDuration = vAudioPlayer.getCurrentDuration();
                    if (mRecordThread != null) {
                        // 병합을 시작 ( combineList가 홀수일 때: 레코드 버튼을 눌렀을 때 combineList의 사이즈가 홀수가 된다 )
                        if (combineList.size() % 2 == 1) {
                            mRecordThread.stopFileWrite();

                            File waveFile = new File(RecordActivity.currentCreateFileName.replaceAll("/ucc/", "/tmp/")
                                    + "_" + calTime(combineList.get(combineList.size() - 1), false) + "_uv.pcm");

                            // 위의 경로에 해당 녹음 파일이 존재하면 wav 파일로 변환,
                            if (waveFile.exists()) {

                                copyWaveFile(RecordActivity.currentCreateFileName.replaceAll("/ucc/", "/tmp/") + "_" + calTime(combineList.get(combineList.size() - 1), false) + "_uv.pcm",
                                        RecordActivity.currentCreateFileName.replaceAll("/ucc/", "/tmp/") + "_" + calTime(combineList.get(combineList.size() - 1), false) + "_u0.wav");

                                // wav 볼륨 파일 증폭
                                if (mMp3ConcatThread != null) {
                                    mMp3ConcatThread.startCombine(null, 3333333333333333333L, combineList.get(combineList.size() - 1), currentDuration);
                                }
                            }

                            combineList.add(currentDuration);
                            // startCombine Thread 분기 처리( if old_position: 0, 3333333333333333333L, 7777777777777777777L, 그 외 )
                            if (combineList.size() == 2) {
                                // 0: 처음 한번 녹음할 때
                                mMp3ConcatThread.startCombine(null, 0, combineList.get(combineList.size() - 2), currentDuration);
                            } else {
                                // 그 외: 두번 이상 녹음할 때
                                mMp3ConcatThread.startCombine(null, combineList.get(combineList.size() - 3), combineList.get(combineList.size() - 2), currentDuration);
                            }
                        }
                    }
                }

                // 버튼, 이미지 뷰 애니메이션
                micBg1.setVisibility(View.GONE);
                micBg2.setVisibility(View.GONE);

                micBg1.clearAnimation();
                micBg2.clearAnimation();

                // userImg.setImageBitmap(userBlurImg);
                userImg.startAnimation(animZoomOut);
                // artistImg.setImageBitmap(artistImgBitmap);
                artistImg.startAnimation(animZoomIn);
                break;
            }
            return false;
        }
    });



from If the button is ACTION_DOWN, can it be forcibly held down for 1 second?

How to make a form which searches an item around a specific radius using google maps API?

I am working on a website in which I want to make a circle on google map either around current location or some manual address.

  • Users will have option to decide whether they want to make circle around current location or some random address they will provide. (Users would have the option to put manual address inside current location as shown below in an image)

  • Now we also need to make sure that circle is of particular radius (0-20/70km from the current location) as well and user needs to decide that as well. (The line beneath the current location will decide the radius which users can move here and there 0-70km)

For example: user want to create a circle from current location till 30KM or user want to create a circle from some random address till 20KM.

enter image description here

The HTML code which I have used in order to make a search bar for search radius is:

<div class="input-searchradius">
   <input class="form-control search_radius mb-4" type="text" placeholder="search radius">
</div>



Problem Statement:

(1) I am wondering what changes I need to make or code I need to add so that the items are being searched around a specific radius. I think, I need to integrate the code Google Maps circle but I am not sure how I can do that.

(2) On hit of search radius on the website the following options/screen will appear at the bottom:

enter image description here



from How to make a form which searches an item around a specific radius using google maps API?

How do you load an alternate jquery in a webpack module?

I need to load alternate versions of jQuery other than the one in my node_modules. I have a local copy of the script but I am unable to get it to load in my webpack app.ts. I have removed the global jQuery and resolve path for node_modules in my webpack config since I do not want the version from node_modules. However I can't figure out how I can pass the loaded jquery to the scripts that require it.

I have multiple entry points (app.ts) each which needs to be able to load a different jquery so I can not define jquery in the webpack config as I would like to use the same config for processing all my entry points.

app.ts

import jquery from '../../../js/jquery-3.3.1.js';

// tried this but didn't help
// window.$ = jquery;
// window.jquery = jquery;

// these two require jquery but fail, it only works if I add back in
// the webpack config to find jquery in node_modules which is what I 
// don't want. popper.js has the same issue as jquery.
import '../../../js/popper-1.12.9.min.js';
import '../../../js/bootstrap-4.0.0.js';
import './js/jquery.matchHeight-min.js';

...



from How do you load an alternate jquery in a webpack module?

How to remove every occurrence of sub-list from list

I have two lists:

big_list = [2, 1, 2, 3, 1, 2, 4]
sub_list = [1, 2]

I want to remove all sub_list occurrences in big_list.

result should be [2, 3, 4]

For strings you could use this:

'2123124'.replace('12', '')

But AFAIK this does not work for lists.

This is not a duplicate of Removing a sublist from a list since I want to remove all sub-lists from the big-list. In the other question the result should be [5,6,7,1,2,3,4].

Update: For simplicity I took integers in this example. But list items could be arbitrary objects.

Update2:

if big_list = [1, 2, 1, 2, 1] and sub_list = [1, 2, 1], I want the result to be [2, 1] (like '12121'.replace('121', ''))

Update3:

I don't like copy+pasting source code from StackOverflow into my code. That's why I created second question at software-recommendations: https://softwarerecs.stackexchange.com/questions/51273/library-to-remove-every-occurrence-of-sub-list-from-list-python

Update4: if you know a library to make this a one-liner, please write it as answer, since this is my preferred solution.



from How to remove every occurrence of sub-list from list

How can I detect when an element is visible after loading website in WKWebView?

I am trying to load a transit website so I can scrape the stop times for a given stop. After I load the url, the stop times are loaded in a bit later dynamically through javascript. My goal is to detect the presence of elements with a class of "stop-time". If these elements are present in the html I can then parse the html. But before I can parse the html I have to wait for these elements with class of "stop-time" to appear. I read through a bunch of other SO questions but I couldn't quite piece it together. I am implementing the didReceive message function but I'm not really sure how to load in the javascript I need to detect the presence of the elements (elements with class of "stop-time"). I successfully injected some javascript to prevent the location permission popup from showing.

override func viewDidLoad() {
    super.viewDidLoad()

    let contentController = WKUserContentController()
    let scriptSource = "navigator.geolocation.getCurrentPosition = function(success, error, options) {}; navigator.geolocation.watchPosition = function(success, error, options) {}; navigator.geolocation.clearWatch = function(id) {};"
    let script = WKUserScript(source: scriptSource, injectionTime: .atDocumentStart, forMainFrameOnly: true)
    contentController.addUserScript(script)

    let config = WKWebViewConfiguration()
    config.userContentController = contentController

    webView = WKWebView(frame: .zero, configuration: config)
    self.view = self.webView!

    loadStopTimes("https://www.website.com/stop/1000")
}

func loadStopTimes(_ busUrl: String) {
    let urlString = busUrl
    let url = URL(string: urlString)!
    let urlRequest = URLRequest(url: url)
    webView?.load(urlRequest)
}

func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
    if(message.name == "stopTimesLoaded") {
        // stop times now present so take the html and parse the stop times
    }
}



from How can I detect when an element is visible after loading website in WKWebView?

Reading Large Excel Files with SheetJS/js-xlsx?

I am using this package: https://www.npmjs.com/package/xlsx

However I can have some very large excel files that could contain 1 million rows.

I tested with 600K rows which is about 15mb excel file and my code is already crashing on localhost.

Is there away to stream it in? I know the documentation says they don't have any sort of streaming api but it talks about buffering?

 var reader = new FileReader();
    reader.onload = evt => {
      const bstr = evt.target.result;
      const wb = XLSX.read(bstr, { type: "binary" });
      const wsname = wb.SheetNames[0];
      const ws = wb.Sheets[wsname];
      const data = XLSX.utils.sheet_to_json(ws, { header: "A", defval: "" });
      });
    };
    reader.readAsBinaryString(this.file);



from Reading Large Excel Files with SheetJS/js-xlsx?