The Best Way of Checking for -Moz-Border-Radius Support

What is the best way to check for XHR2 file upload support?

if (new XMLHttpRequest().upload) {
// welcome home!
} else {
// not supported
}

Most elegant way to check sessionStorage support?

if (cookie1 === '9oz' || (window.sessionStorage && window.sessionStorage.getItem('sessionstoragecookie1') === '9oz')) {
// you've got a 9oz reference
} else {
// you haven't :(
}

How to check if a website has HTTP/2 protocol support

You can just check it in: Chrome Dev Tool (F12) → NetworkProtocol.

It will tell you the protocol used and the domain of each transfer.

Chrome Dev Tool (F12) -> Network -> Protocol

Legend

http/1.1 = HTTP/1.1

h2          = HTTP/2


Note: If you cannot see the Protocol column, just right-click on any header and check the "Protocol" label.

Best way to detect that HTML5 canvas is not supported

This is the technique used in Modernizr and basically every other library that does canvas work:

function isCanvasSupported(){
var elem = document.createElement('canvas');
return !!(elem.getContext && elem.getContext('2d'));
}

Since your question was for detection when it's not supported, I recommend using it like so:

if (!isCanvasSupported()){ ...

How to check browser for touchstart support using JS/jQuery?

You can detect if the event is supported by:

if ('ontouchstart' in document.documentElement) {
//...
}

Give a look to this article:

  • Detecting event support without browser sniffing

The isEventSupported function published there, is really good at detecting a wide variety of events, and it's cross-browser.

How to check if a service is running on Android?

I had the same problem not long ago. Since my service was local, I ended up simply using a static field in the service class to toggle state, as described by hackbod here

EDIT (for the record):

Here is the solution proposed by hackbod:

If your client and server code is part of the same .apk and you are
binding to the service with a concrete Intent (one that specifies the
exact service class), then you can simply have your service set a
global variable when it is running that your client can check.

We deliberately don't have an API to check whether a service is
running because, nearly without fail, when you want to do something
like that you end up with race conditions in your code.

What is the best way to support drag and drop when a browser doesn't support HTML5 drag and drop?

AFAIK a client cannot change the behaviour of a website. Some sites support Drag and Drop, while some don't. It all depends on the way website is designed. If you are owner of a website and would like to add D&D feature, check this solution.

Also some browsers may not support this feature. Try using some other browser.

Note: It seems you are new to stackoverflow. Upvote and accept the answers if you like.

Best way to check if ubuntu service has stopped in c#

Both services provide health endpoints that can be used to check their status from a remote server. There's no need to open a remote shell connection. In fact, it would be impossible to monitor large server farms if one had to SSH to each one.

In the simplest case, and ignoring networking issues, one can simply hit the health endpoints to check the status of both services. A rough implementation could look like this :

public async Task<bool> CheckBoth()
{
var client = new HttpClient
{
Timeout = TimeSpan.FromSeconds(30)
};

const string grafanaHealthUrl = "https://myGrafanaURL/api/health";
const string influxPingUrl = "https://myInfluxURL/ping";

var (grafanaOK, grafanaError) = await CheckAsync(client, grafanaHealthUrl,
HttpStatusCode.OK, "Grafana error");
var (influxOK, influxError) = await CheckAsync(client, influxPingUrl,
HttpStatusCode.NoContent,"InfluxDB error");

if (!influxOK || !grafanaOK)
{
//Do something with the errors
return false;
}
return true;

}

public async Task<(bool ok, string result)> CheckAsync(HttpClient client,
string healthUrl,
HttpStatusCode expected,
string errorMessage)
{
try
{
var status = await client.GetAsync(healthUrl);
if (status.StatusCode != expected)
{
//Failure message, get it and log it
var statusBody = await status.Content.ReadAsStringAsync();
//Possibly log it ....
return (ok: false, result: $"{errorMessage}: {statusBody}");
}
}
catch (TaskCanceledException)
{
return (ok: false, result: $"{errorMessage}: Timeout");
}
return (ok: true, "");
}

Perhaps a better solution would be to use Azure Monitor to ping the health URLs periodically and send an alert if they are down.



Related Topics



Leave a reply



Submit