How can i change the URL string i'm fetching from after each fetch? [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 months ago.
The community is reviewing whether to reopen this question as of 6 months ago.
Improve this question
I need to fetch 12 different nums for every object, and there are 31 different objects.
Basically, the API string ends like this:
/count?publishedAt_gte=2022-01-01&publishedAt_lte=2022-02-01&newsSite_contains=1&_limit=500
'_contains=1' determines the object, =2 will render the next one, =3 the one after and so forth until '_contains=31'
'_gte=2022-01-01&publishedAt_lte=2022-02-01' determines the specific num value, as changing the months (2022-01-01 becomes 2022-02-01 and 2022-02-01 becomes 03..) will return a different num.
So the function should fetch the num value from the base url, push it in a array, then raise the months numbers by 1 and repeat 12 times, to then return at the starting month to change the 'contains' part and raise it by 1 - all of this 31 times. So we'll have 31 arrays, each with 12 nums.
Do you think it's doable, and how?

If it runs with Node you can use the URL module. It has methods to get/set and such for the query params.
If it runs in the browser you can use the URLSearchParams web API.
Regarding implementation, you can tell me the environment this function would be invoked in and I can write something down for you.

Related

Hex to Hex String [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 10 days ago.
The community is reviewing whether to reopen this question as of 7 days ago.
Improve this question
I am converting hex to hex strings then came across 2 ways to do it using the toString() method:
toString('hex')
toString(16)
I see a lot of resources online also use toString('hex') but when I tried to use it, it gives out an error message: RangeError: toString() radix argument must be between 2 and 36.
The toString(16) works perfect.
But just for curiousity, what is the story behind this? Is the toString('hex') deprecated of some sort? Or is there any specific use-case when that is used instead of toString(16)
Example:
let num = 0x7
console.log('Convert using toSting(hex): ' + num.toString('hex')) // throws an error
console.log('Convert using toSting(16): ' + num.toString(16))

React execute a function at varying time intervals [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 months ago.
Improve this question
I have an API which returns a list of objects. Each of these objects have a field called timeOut which contains some time interval in secs. Once the time interval of any object expires, some operation needs to performed on that particular object.
How can I achieve this in react ? I considered using setInterval on each object in the list, but it looks like a bad design.
Any help will be appreciated. Thank you.
You should use setTimeout instead of setInterval if you want an operation to run only once after the given time period. I believe this is your best bet to accomplish this task.
Otherwise, you will have to dive into even crazier designs like comparing the present date-time object from new Date() with the one you generated right after fetching your data, which will not only be complicated but also, more error-prone and inaccurate.
Let me know if you want help with the first method.

How to store javascript code in database? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I created a webshop for an online game where the users can buy in-game stuff. I have some special items which will be only availabe for a short period of time and I want to print out how much time left to buy it.
I wrote a JS code to countdown for a date, and now I want to store it in the database. Which is the best way to do it? Just a varchart with extremely long length? Or is it a more elegant way to deal with this?
You can use Function.prototype.toString method to convert a function into a string and then later use eval to execute the function.
You should use text type rather than varchar as it will likely be longer than maximum varchar length.
However, I would strongly discourage you to do this. A better approach would be to store something like a expiration date timestamp and calculate the availability based on that value.

Generating random id using current date [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm doing a bank oriented project. I have to generate Account Number using current date.
Example:
account no-20150409001.
'2015'-Year,
'04'-Month,
'09'-Date,
'001'-represents the number of the new member opening the account on that particular date
This number should change in every branch to avoid same account number.
How to do so?
and this is my code
http://jsfiddle.net/Jegannath/z9na41o5/#&togetherjs=ynHxlyDeO1
If this is really a bank related project, do not rely on client side JavaScript for something as critical as the account number generation.
Is there a reason for the "random" number requirement? If not, stick with a sequence, it is a lot easier to ensure uniqueness.
On the server side, using a branch prefix as suggested by #kuldeep.kamboj should cover collision.
You can use something like yyyyMMddBBnnnn where yyyy = year, MM = month, dd = day, BB = branch number, and nnnn as a sequence that resets per day.
Not sure,this is correct advise,
Go with branch code prefix and timestamp in suffix, this might be developer friend also, because in future after 30 year easily you can tell his account created date with the help of timestamp.
As well timestamps is kind of random number.
advisable is server side code.

I want to create a script which tells me when a post is posted [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to create a script in php, javascript or jquery which tells me when a post is posted like Facebook in facebook when we post a status it tells us posting time like 5 minute ago or so on. I have completed all other work.
Create a coloumn to the table where you save the post details as posted_at and have DATETIME as its data type,
Use $CurrentTime = date("Y-m-d H:i:s" ); and insert while you create the post i.e., insert
So while retrieving the data just find the difference between the posted time and current time by
$PostedTime = strtotime($FetchedData->posted_at) - strtotime(date("Y-m-d H:i:s" ));
Then you shall convert the difference time as per your wish.
You have to create function that will get one parameter "posted date" and it will calculate difference from today. it will generate string and return like "2 days ago/5 min ago" or date. it is depend on you.

Categories