How to count the number of times a token comes up in a string in Javacc? - javacc

How can I count the number of times a token is contained in a string when parsing with Javacc? Do I need to keep a integer then increment this each time the token is shown? how?

Use a token manager decl to declare a counter. Increment it in a token action. See the docs and the FAQ for more: http://www.engr.mun.ca/~theo/JavaCC-FAQ/javacc-faq-moz.htm#tth_sEc3.16 .

Related

Get the last document and rate limit the client to one write every 5 minutes in cloud firestore

I have these values stored in documents inside a collection:
{
value: string,
currValId: number,
chosen: bool,
requestTime: number, // the time the request is sent, in unix milliseconds
userId: string // user's uid
}
I am validating the requestTime field with this function:
function timeWithinReach(claimedTime){
return request.resource.requestTime is number &&
request.time - claimedTime < 5 * 1000;
}
Where the claimedTime is the requestTime the client sends, and I am basically comparing it to the request's time and tolerating a latency of 5 seconds in the process.
What I want to do is, in my security rules I want to get the last document from the current user and check if the requestTime from the current request is at least 5 minutes later from the last document, and only allow a write if that is the case.
Is my approach correct? If so, how may I get the requestTime from the last document? If my approach is wrong and I am misunderstanding things, what is the best way of accomplishing this?

With all Firebase products, Is it possible to return a positive integer with out repeat

Same as SQL, you can add a new row with the primary key being auto incremental.
We need a counter where we can get unique values ​​even if we call them at the same time. (the result should be n and n+1)
Is it possible for all firebase products to create a counter that returns you a value that is never the same?
Eg.
It's possible to tell that user from firebase authentication is the first, second or third from a register (the sequence should never change) if it's so it would be great
A counter that gives you a number that never is the same even I and others request at the same time.
Main purpose
I want a 1-1 map, a positive integer (UInt32) to firebase account UID
eg. 1: aksd12391, 2: da1293nvs1dks, 4: 1is91jesoc
Using Transaction's Firestore (Concurrency)
It still returns the same not unique
Is it possible to create a counter that
returns you a value that is never the same?
Yes, you can use a numeric field in a Firestore document that you (transactionally) increment as explained here in the doc.
It's possible to tell that user from Firebase authentication is the
first, second or third from a register (the sequence should never
change)
Yes, you can assign a unique value (obtained as explained above) to a user, by, for example, saving a user profile in Firestore and assigning this value as a "functional" id.

How to return the total matches on a Cosmos db query

I have setup an api that will query our Cosmos db and return the JSON results back to the front end app. There is a user defined limit on the number of results. If the number of results exceed the limit then I pass back the token to the front end and they can call for the next group of rows. The issue is I would like to provide a count of the Total Number of Matches back to the application. I have looked at the query statistics but don't see where there is a total count.
On the call to CreateDocumentQuery, i'm setting MaxItemCount to the limit, and RequestContinuation either null or the continuationToken. Looking at QueryMetrics I found RetrievedDocumentCount, but that does not seem to have the correct value.
Thanks,
J
x-ms-max-item-count request header controls how many documents should be returned to user.
Default value is 100
if your query returns 150 documents, your request will return first 100 documents and it will return a continuation token in response header(x-ms-continuation). If there is a token, you need to send another request with the given token to get the rest of the data.
SDK should be doing that for you automatically. Can you share some of your code. I might have a better answer then.
You can check out my post about this too.
https://h-savran.blogspot.com/2019/04/introduction-to-continuation-tokens-in.html

Marketo REST API - increment field

If i have a custom object with an integer field, is there a way to send a request to increment this field by 1?
Or would i have to get that field's value, increment it and send it back?
Unfortunately, you cannot increment such a value with a single API call, so you either have to
keep track of your records outside of Marketo too, and update Marketo with the current value;
or you have to use two API calls: one to fetch the record, and a second one to send back the updated value.
Note:
While it is possible to increment/decrement the Score field type (which is also an integer field) with integer values, it is only possible to do so through the Change Score flow step within Marketo. Besides that, the Score type is not available for custom objects.
To be sure, I just have tried to increment an integer value via the API by setting “+1” as a sent value, but it was recorded as plain “1”, so the original record has been overwritten.

Modality work list - Which items are returned for C-FIND request of a sequence?

My question is a really basic question. Consider to query a modality work list to get some work items by a C-FIND query. Consider using a sequence (SQ) as Return Key attribute for the C-FIND query, for example: [0040,0100] (Scheduled Procedure Step) and universal matching.
What should I expect in the SCP's C-FIND response? Or, better say, what should I expect to find with regards of the scheduled procedure step for a specific work item? All the mandatory items that Modality Work List Information Model declare as encapsulated in the sequence? Should I instead explicitly issue a C-FIND request for those keys I want the SCP return in the response?
For example: if I want the SCP return the Scheduled Procedure Step Start Time and Scheduled Procedure Start Date, do I need to issue a specific C-FIND request with those keys or querying for Scheduled Procedure Step key is enough to force the SCP to send all items related to the Scheduled Procedure Step itself?
Yes, you should include the Scheduled Procedure Step Start Time / Date Tags into the 0040,0100 sequence.
See also Service Class Specifications (K6.1.2.2)
This will not ensure you will retrieve this information, because it depends on the Modality Worklist Provider, which information will be returned.
You could also request a Dicom Conformance Statement from the Modality Provider to know the necessary tags for request/retrieve.
As for table K.6-1, you can consider it as showing only the requirement of the SCP side or what SCP is required to use for matching key (i.e. query filter) and additional required attribute values to return (i.e. Return Key) with successful match. It is up to SCP’s implementation to support matching against required key but you can always expect SCP to use the values in matching key for query filter.
Also note that, SCP is only required to return values for attributes that are present in the C-FIND Request. One exception is the sequence matching and there you have the universal matching like mechanism where you can pass a zero length ITEM to retrieve entire sequence. So as stated in PS 3.4 section C.2.2.2.6, you can just include an empty ITEM (FFFE, E000) element with VR of SQ under Scheduled Procedure Step Sequence (0040, 0100) for universal matching.

Resources