Generate new AccessToken each time user update his Information

im building a PWA app , where i implemented jwt token to auth users.

i have 2 main architecture problems ,but let me introduce you what im building .

i’m Building application that is all about dog lovers , this application is to post lost dogs, post dogs for an adoption , for dog owners to find a good dog services around them like vets and dog walkers etc

in my application you are registering with Facebook or Google,

in my application any user can open up services , if you are a dog walker you can easily open up a service fill in some basic stuff and people all around can find this new service .

i got [ auth , user , chat , association , dog , haircut, review , store , trainer , vet ,walker ] = micro services

i am planing to run it on Aws Ecs.

1st problem : JTW stay Outdated if i dont talk to Auth service and Re generate token for a user .

if user register new vet service, i must return him also a new access Token , or else his JWT token will be outdated with his old information that will not has that information about the newly created service.

right now im letting the micro services to talk between them and i really dont like this idea because i can easily get lost with debugging and logging them.

this is how creating new service look now

*each microservice holds in his ENV the key to read the JWT

User >

walkerService (creating new service) userService (updating User property “services” field with the new services pointer id) user object has “services” object inside , its has arrays that hold pointers to serviceDb authService (generating new updated access Token)

so what now ? each time user will do update or create service i should return new JWT ?

i can fix it using API GATEWAY , but …

2nd problem

if i create an api micro service, Api gateway , and move some of the logic into there i feel like im back into a monolith app , in api gateway i can do all stuff related to auth and actually remove the auth service at all , i can “bypass” the problem of direct talk between micro services because i can await for each micro service to finish his task before continue to the next task of the next micro service .

but then the api gateway become more logical and less simple like he should be with just auth , some throttle and routing around micro services…

For example , When in front end if you are watch a post of adoption ,

you actually looking at a document from the “dog” services , but , there also a field of owner (giving private name of the person who actually post this),

in the dog document i have for example the owner id

“dh83db34u9f” : { ownerId: “d236d8g2d83d4”, dogName: “Maya”, dogAge: “Etc..” }

so , before i return this document from the dog service , i also need to attach it the name of the owner so i need to ask from the “user” the public info for this user

and only then , combine this 2 into 1 object and Response to the Call…

i believe this api gateway shouldn’t do stuff like that , so i wonder should i create new service just for “crud” / “actions” ?

Assign resources that each have a certain amount of work they can provide to tasks that require a certain amount of work

I’m attempting to do a hobby automation project and have come to a roadblock. I have a certain problem I need to solve, but can’t think of the solution nor what the name for the problem would be.

Say we have n tasks where each task requires $ x_i$ amount of work to be done and m resources where each resource can provide $ y_j$ work. The total amount of work required will equal the the total amount of work the resources can provide, i.e. $ \sum_{i=1}^{n} y_i = \sum_{j=1}^{m}x_j$ . For all j from 1 to m, $ y_j \in \left \{1, 2, 6, 12, 24\right \}$ and each $ x_i = a*1 +b *2 + c*6+d*12+e*24$ . I was looking at task assignment problems, but those seemed to be a bit overkill since they were concerned with optimization where I’m just simply trying to slot the correct blocks in the right place so that I don’t have tasks that are given too few or too many resources.

My current guess is that you can iterate over each task, and give it the largest resource available that doesn’t go over the amount of work that is left for the task to be completed. It’s almost analagous to filling a jar with different sized rocks; the best way is to start with the largest rocks and then go down in size from there, so that the smaller rocks fill in the space between the larger ones. Am I not taking something into consideration that complicates this problem further? I’m sorry if this is an obvious one, but I’m a hobbyist programmer and couldn’t think of the name of the problem or of a good set of keywords to google. The closest I could find is task assignment so far.

[ Politics ] Open Question : About 3,000 people have died in China from the virus yet flu kills 50,000 Chinese each year so why is this virus seen as something worse?

If I’m not mistaken , China already has the situation almost under control.. so far around 3,000 Chinese have died from Coronavirus yet every year around 50,000 Chinese people die from flu .. So why is this virus as something worse than the flu ? Do you think governments aren’t releasing the real number of people who have died from this virus ?  Thank you 

How to group rows while filtering out values per each group?

Imagine you have the following setup:

CREATE TABLE namechanges (   id text,   new_name text,   change_date timestamp );  INSERT INTO namechanges VALUES   ('x', 'alice', '2020-03-01'),   ('y', 'Bob T.', '2020-03-03'),   ('x', 'Alice', '2020-03-05'),   ('z', 'charlie', '2020-03-07'),   ('x', 'Alice C.', '2020-03-09'),   ('z', 'Charlie Z.', '2020-03-11') 

How would look like a query that would retrieve just the current name for each id and return the following?

| id  | max        | | --- | ---------- | | z   | Charlie Z. | | y   | Bob T.     | | x   | Alice C.   | 

Here’s the example above on DB Fiddle if you want to play with it: https://www.db-fiddle.com/f/ugNcXhRyb44KTpqjFXmKDW/0

for each loop in vector passed to a function error

in for loop it shows error that: begin was not declared in the scope.

my code:

#include<bits/stdc++.h>  using namespace std; vector<int> v[1001];  void dfs(int i,vector<int> &v) {     for(int c: v[i])     cout<<c; }  int main() {      int n,e,a,b;     cin>>n>>e;      vector<bool> vis(n+1,0);     vector<int> v[n+1];     while(e--) {         cin>>a>>b;         v[a].push_back(b);         v[b].push_back(a);     }     dfs(1,v); } 

Encoding System that Assign Same Number of Bits for Each Character

I am trying to get a binary string that has been converted from text of a text file, I am able to get that but the problem is, I need each character to be represented by same number of bits, but that is not what I get (please see the below python code and corresponding output). For example, character i is represented by 1101001, which is 7 bits long, but character ! is represented by 100001, which is 6 bits long.

Is there any encoding/decoding system where each character takes same amount of bits?

content = open('a.txt', 'r').read() test_str = content # using join() + ord() + format()  ... Converting String to binary   Binary = ' '.join(format(ord(i), 'b') for i in test_str)  #Decimal=int(Binary, 2)    # printing original string   print("The original string is : " + str(test_str))  # printing result   print("The string after Binary conversion : \n" + str(Binary)) 

Output:

The original string is : Hi! Is there a solution? The string after Binary conversion :  1001000 1101001 100001 100000 1001001 1110011 100000 1110100 1101000 1100101 1110010 1100101 100000 1100001 100000 1110011 1101111 1101100 1110101 1110100 1101001 1101111 1101110 111111 

Should I generate a lot of random serial keys and pick one for each registration or generate 1 for each user?

I’m talking about Online activation. My current workflow is:

  1. User pays via paypal (without registration)
  2. Paypal performs a request to my API.
  3. My API returns a serial key to the user.
  4. Then the user is able to register using this serial key.

Is a “pay to register then use” and not a “register then pay to use”.

So the question is:

  • Should I generate (let’s say 100) keys and store them in DB then pick the first one available when someone pays via paypal? Isn’t this vulnerable to “guess” attacks?
  • Should I generate 1 random key each time a user pays via paypal? Can’t this approach generate 2 equal keys? I mean I have no info from the user except what paypal tells me so I should somehow use a random function OR loop the entire table comparing the serial keys.

Formal grammar with constraints on the number of each symbol

I have a language where each type of symbol is only allowed a particular number of times, but the order isn’t important. For example, lets say there are three symbols $ a, b, c$ , and a valid string in the language consists of at most 5 $ a$ , 3 $ b$ and 2 $ c$ characters. So $ ababbc$ is valid, $ ccbbbaaaaa$ is valid, but $ abcabcabc$ is not. I’m struggling to come up with a grammar that satisfies such constraints without resorting to enumerating each possibility. Is it possible to have a concise set of rules that encode these constraints?