Skip to main content

Posts

Python program to get the LCM of two numbers

  def cal_lcm(a, b): return (a * b) // cal_hcf(a, b) print(cal_lcm(15, 9)) # output will be 45
Recent posts

Python Program To Find the Modulus with using modulus operator

  def cal_mod(dividend, divisor): # check the max divisor power of the dividend dividend_power = 1 while dividend > (divisor ** dividend_power) : dividend_power += 1 # reduce the dividend to the divisor_power + 1 # if dividend_power is greater then 2 if dividend_power > 2: while dividend > (divisor ** 2): dividend = cal_mod(dividend, (divisor ** (dividend_power - 1) )) dividend_power -= 1 while dividend >= divisor: dividend = dividend - divisor return dividend result = cal_mod(45645664566465456456878756765675699788866264623874682464, 16) print(result)

Unsubscribing an observer while running create, update or delete operations on modal in Laravel

Today I was trying to copy some data from one application to another application. The Data has some nested relationships so I created a custom feature to fetch the data using Apis and insert them one by one into my destination application. My problem while inserting the data was, there was an observer is set to File.php (for example) model that was running run logic to upload the incoming file to AWS s3 Cloude storage. But I am not really uploading anything while inserting the data. So, I want to stop the Observer from running the functionality while I was running my custom feature. While looking for some solution to my problem I came to a solution that I would like to share with you. File::unsetEventDispatcher(); I used this function call before running the logic only once and my observer stopped executing the code on Create and Update model event. You can also use the same code to stop the other event from executing while running some logic. You can get all the event displachers and ...

You are running 'create-react-app' 4.0.3 which is behind the latest release (5.0.1).

I was trying to create a new React app with the following command. > npx create-react-app react-app Then I get the following error: You are running `create-react-app` 4.0.3, which is behind the latest release (5.0.1). We no longer support global installation of Create React App. I also get some help instructions as well as: Please remove any global installs with one of the following commands: - npm uninstall -g create-react-app - yarn global remove create-react-app I tried to run the floowing command multiple times as suggested: > npm uninstall -g create-react-app Which ran fine with no error that means my create-react-app glabal installation uninstalled successfully. Then I again tried the same command to install the React app: > npx create-react-app react-app But I again get the same errors and suggestions. I repeated the same procedure multiple times but it did not work. Then I decided to look for the solution over a search engine. By no much time, I got some useful help th...

Call async function in loop for array and update the exiting array Javascript and Node Js

Here is a good example of the code to call async function in loop for element of an array and update the exiting array. In this example I have used the Array.prototype.entries() function to get the index and value of each array item of a simple array. Array.prototype.entries() method helps to iterate an array with index and element. function timeout(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } async function resolveAfter2Seconds(num) { await timeout(2000); return num; } async function main() { let arr = ["Saab", "Volvo", "BMW"]; for (let [index, val] of arr.entries()) { console.log(index, val); console.log(await resolveAfter2Seconds(val)); } } main();