Prevent NFC Service app from opening when reading empty tag with enableReaderMode - nfc

Moving from the enableForgroundDispatch (I don't seem to get it working on api 32) intent based way of reading NFC-tags to enableReaderMode. The latter one works well, but every now and then the NFC Service app is opening, showing 'emtpy tag' message. Is there a way to disable this, in code? It's true that the tags are empty, only reading and using the tag Id. Code look like the following;
Bundle opts = new Bundle();
opts.putInt(NfcAdapter.EXTRA_READER_PRESENCE_CHECK_DELAY, 250);
getNfcAdapter().enableReaderMode(this, tag -> {
// passing tag to get tag.getId()
myViewModel.setTag(tag);
}, NfcAdapter.FLAG_READER_NFC_A |
NfcAdapter.FLAG_READER_NFC_B |
NfcAdapter.FLAG_READER_NFC_F |
NfcAdapter.FLAG_READER_NFC_V |
NfcAdapter.FLAG_READER_NFC_BARCODE |
NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK |
NfcAdapter.FLAG_READER_NO_PLATFORM_SOUNDS
, opts);

Related

Why does the first response takes more time in GAS web app?

Edit: I am using clasp. Updated the code to the actual GAS!
I have a GAS deployed as a web app. We send POST requests from Slack via a slash command and it needs a response in less than 3000ms because GAS can't handle asynchronous code.
At the first request, it takes more than 3000ms to send a response but on the following requests, it is around 1500ms.
The doPost function looks like the following.
var exports = exports || {};
var module = module || { exports: exports };
Logger = BetterLog.useSpreadsheet('spreadsheetId');
function doPost(request) {
var startExecutionDate = new Date();
var path = request.parameter.path;
Logger.log("Request received with path: " + path);
var response = Responses.Error;
var token = request.parameter.token;
if (path.startsWith('/slack')) {
Logger.log("Slack request");
var slackRouter = new SlackRouter();
response = slackRouter.post(request);
// ...
}
// ...
}
And this is the code for the Slack Router.
var exports = exports || {};
var module = module || { exports: exports };
var SlackRouter = (function () {
function SlackRouter() {
}
SlackRouter.prototype.post = function (request) {
var path = request.parameter.path;
switch (path) {
case Routes.Team:
Logger.log("For team");
// ...
}
};
return SlackRouter;
}());
exports.SlackRouter = SlackRouter;
I have the timestamps for each log.
First attempt
| Timestamp | Delta in ms | Log Message |
|--------------|-------------|---------------|
| 11:22:34:164 | 0 | Path: ... |
| 11:22:35:354 | 1190 | Slack request |
| 11:22:35:462 | 108 | For team |
Second attempt
| Timestamp | Delta in ms | Log Message |
|--------------|-------------|---------------|
| 11:22:45:047 | 0 | Path: ... |
| 11:22:45:164 | 117 | Slack request |
| 11:22:45:350 | 186 | For team |
I had several ideas already like the web app goes to a sleep state but since we calculate delta from the first log message it doesn't make sense.
So what is going on behind the scenes? Are you aware of any easy workarounds? If possible I don't want to build a microservice to send a response to Slack in time and later send the actual response.
The Apps Script servers don't keep every script ever written or deployed loaded in memory, and so scripts that haven't been run in a while need to be loaded from disk first. This is usually referred to as a "cold start time" in Cloud providers.
Answered by Eric Koleda on Google Apps Script Community forum
The most glaring issue is your use of ES6 syntax in your doPost() method.
Google Apps Script does not support ES6 template string syntax and only partially supports destructuring assignments. So that might be your issue. Your doPost() probably fails to return a value as a result so Slack likely repeats the request until it times out.
Try removing the BetterLog library. That may be causing the initial first-time delay.
https://developers.google.com/apps-script/guides/libraries
Warning: A script that uses a library does not run as quickly as it would if all the code were contained within a single script project. Although libraries can make development and maintenance more convenient, you should use them sparingly in projects where speed is critical. Because of this issue, library use should be limited in add-ons.

What is the test case format in gherkin language?

I have a mock up profile page of a gym and I'm to write test cases for editing that profile page in gherkin language. I don't the gherkin test case format. Can anyone please help me with this?
There is no hard and fast rule to write the gherkin tests. But it is highly advisable that you write them by following recommended procedures, to make it understandable. The main purpose of gherkin is for someone apart from your team, understand the whole testing process.
There are three primary, conditions that you will have to satisfy writing gherkin.
Start your tests with the pre-defined statements i.e Given Then and When. Your feature file should have steps that should look like these:
Given I land on homepage
When I click on the signup button
Then I see the error
There are also other keywords like:
And - Connect more than two steps
Please refer to this documentation for more details:
https://github.com/cucumber/cucumber/wiki/Given-When-Then
In my opinion, this question has no scope; however, I'll try to answer. Gherkin is a language with no technical barriers; it enforces an entire team to write unambiguous requirement-based test specifications based on creative collaboration rather technical specifics. The base components of Gherkin have been explained in the first answer. So, I'd rather try to give a working example as requested in the question to understand the use of Given, When, Then clearly.
The following test (called test specification) is written in Gherkin in the feature file:
Feature: Google Book Searching from https://www.googleapis.com/books/v1/volumes?q={ID}
Scenario Outline: Verify that the response status code is 200 and content type is JSON.
Given webService endpoint is up
When user sends a get request to webService endpoint using following details
| ID | <ID> |
Then verify <statusCode> and <contentType> from webService endpoint response
Examples:
| ID | statusCode | contentType |
| 1 | 200 | "application/json; charset=UTF-8" |
| 9546 | 200 | "application/json; charset=UTF-8" |
| 9 | 200 | "application/json; charset=UTF-8" |
Now here is the step definition for the above test specification:
// for **Given** - as it has to ensure that the required webservice end-point is up:
#Given("webService endpoint is up")
public void webserviceEndpointIsUp() {
requestSpecification = new RequestSpecBuilder().
setBaseUri(prop.getProperty(BASE_URL)).
build();
}
// for **When** - as this is for the part when user sends the request to the webservice end-point and receives the response
#When("user sends a get request to webService endpoint using following details")
public void userSendsAGetRequestToWebServiceEndpointUsingID(Map<String, String> data) {
String ID = data.get("ID");
System.out.println("The current ID is: " + ID);
String pathParameters = "?q" + "=" + ID;
response = given().
spec(requestSpecification).
when().
get(pathParameters);
}
// for **Then** - finally, here is the then part. When we're verifying the actual stuff mentioned in the Scenario
#Then("verify {int} and {string} from webService endpoint response")
public void verifyResponseStatusCodeAndContentTypeFromWebServiceEndpointResponse(int statusCode, String contentType) {
Assert.assertEquals(statusCode, response.getStatusCode());
Assert.assertEquals(contentType, response.getContentType());
}
This is just one example that how tests are written in Gherkin, there is a lot more to learn to be able to write such scripts. So, I'll recommend to start off with the following links:
Writing Good Gherkin
Cucumeber-JVM Free Course

Appcelerator Ti.Blob text property is null

I came across a strange issue while reading files from Ti.Filesystem.applicationDataDirectory. Whenever I want to access the text property of the Ti.Blob returned by Ti.Filesystem.File.read() I get null
var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'foo.key');
var contents = f.read();
Ti.API.debug('contents: ' + JSON.stringify(contents));
var text = contents.text;
Ti.API.debug('text: ' + JSON.stringify(text)); // is NULL
The file was created like so
var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'foo.key');
f.write(JSON.stringify({foo: 'bar'});
I'm developing on Android by the way with 6.0.1.GA
TL;DR it's the file extension that's causing the problem
When looking at the Ti.Blob more thoroughly I found that it says mimeType : application/gpg-keys. After updating my code above so it uses foo.json as filename everything works as expected.

Accessing the Scenario Title and Example in a Cucumber After hook

How can I get the current Example out of a Ruby cucumber test in an After hook?
I can get the title with the code below. My Scenario has several Examples with it. Can I access the current Example being tested?
Feature file
Scenario Outline: Successful login with primary accounts
Given I start on the login page
When I log into Overview page with "<acct>"
Then I am on the Overview page
Examples:
| acct |
| account1 |
| account2 |
After hook
After do |scenario|
scenario.scenario_outline.title # will give me the title
How to I get the current Example?
Here is how I did it.
scenario_title = scenario.respond_to?(:scenario_outline) ? scenario.scenario_outline.title : ''
scenario_title_example = scenario.respond_to?(:name) ? scenario.name : ''
scenario_full_title = scenario_title + scenario_title_example

MAPI and Outlook address book

I'm developing one project using VC++ (MSDEV 2008), which has one function to send EMAIL with some attachments. I used MAPI functions to achieve this task.
I build the project with project setting "Character set: use Unicode character set" for UNICODE compatible support and file type is EXE extension. Here everything works fine.
Same project I build as OCX file extension. And I can display "new send mail" window with some attachments. Here the problem is
When I click address book icon ("To" button) to select the receiver mail id from the list. It displays the Address book dialog with title only "S" instead "Select Name: *". But this also works fine in EXE project.
Code:
HWND hWnd = this->GetSafeHwnd();
MAPIINIT_0 tMapInit = { 0, MAPI_MULTITHREAD_NOTIFICATIONS };
HRESULT hResult = MAPIInitialize( &tMapInit );
HMODULE hMapiMod = LoadLibrary(_T("mapi32.dll"));
ProcMapiLogon = (LPMAPILOGON)GetProcAddress( hMapiMod, "MAPILogon" );
(ProcMapiLogon)( (ULONG)hWnd, NULL, NULL, MAPI_LOGON_UI | MAPI_NEW_SESSION, 0, &hCurrentSession );
LPMAPISENDMAIL ProcMapiSendMail = NULL;
ProcMapiSendMail = (LPMAPISENDMAIL)GetProcAddress(hMapiMod, "MAPISendMail");
(ProcMapiSendMail)(hCurrentSession, (ULONG)hWnd, &myMsg, MAPI_DIALOG | MAPI_LOGON__UI, 0);
The question is why Address Book dialog’s title shows only “S” in OCX project. Same it works in exe project.
Kindly help me how to resolve the issue.
Additional note:
Thanks for your reply.
With Simple MAPI code, everything works fine (means I can display new send mail window and send it when I click ‘Send” button) except the “Address Book” dialog’s title (caption).
I tried extended MAPI functionalities also. When the project is built as .OCX file extension like “SendMail.ocx” still Address Book dialog’s title shows only “S”.
Extended MAPI Code:
HMODULE hMapiMod = LoadLibrary(_T("mapi32.dll"));
LPMAPISESSION lppSession;
LPMAPILOGONEX ProcMapiLogonEx = NULL;
ProcMapiLogonEx = (LPMAPILOGONEX)GetProcAddress( hMapiMod, "MAPILogonEx" );
ProcMapiLogonEx)( (ULONG)hWnd, NULL, NULL, MAPI_USE_DEFAULT | MAPI_UNICODE | MAPI_EXTENDED | MAPI_LOGON_UI | MAPI_NEW_SESSION, &lppSession );
Simple MAPI is ANSI only. The external MAPI dll has no idea that you complied as Unicode, all it sees is a string that it expects to be 0x0 terminated. Your Unicode (2 byte) strings have 0x0 for each ANSI character and double 0x0 at the end. Hence your string is terminated at the first 0x0.

Resources