Categories
Learning Learning Tech

How to sync generated next.js out folder build to android/android studio in capacitor?

Hello, Welcome to the feel and question.

Here is a quick way do it out!

Build the Next.js project: Run the build command for your Next.js project, which typically generates a production-ready build in the “out”/ “build” folder.

npx next build && npx next export

Locate the build output: Once the build process is finished, locate the generated “out” folder in your Next.js project directory.

Copy the build output: Copy the entire contents of the “out” folder, including any subfolders and files.

Paste the build output in the Android project: Navigate to the root directory of your Android project in Capacitor. The default location is usually the “android” folder within your Capacitor project.

Paste the build output: Paste the contents of the “out” folder into the appropriate location in your Android project. By default, you can paste it into the “app/src/main/assets/public” directory of your Android project.

Sync the Android project: After pasting the build output, trigger a sync operation in Android Studio to ensure the changes are recognized. This can be done by clicking on the “Sync Project with Gradle Files” button or by selecting “File” -> “Sync Project with Gradle Files” in the Android Studio menu.

Build and run the Android project: Once the sync operation is complete, you can build and run your Android project to deploy the updated Next.js web application within your Capacitor app.

Voila you are done!.

Hope this question and learning helps.

Happy Learning!

Categories
Learning Learning Tech

Laravel getting error: Target class [App\Http\Controllers\GurbaniReadingController::class] does not exist. But file already exists!!

Hello Guys,

Facing this issue and struggling to find the cause?, okay then lets direct jump in to the fix I found or more precisely mistake I found!

In picture you might seeing controller name is different than I have mentioned below; I am changed it to Book, so don’t get confuse.

In my case I was wrapped the loading on controller in web.php route with single quotes!

Line of code causing this error:

Route::get('/book-readings/upload-photos', ['App\Http\Controllers\BookReadingController::class', 'uploadPhotos']);

Very carefully watch in above code code was wrapped in quotes: ‘App\Http\Controllers\BookReadingController::class’,
Controller should be loaded without single quotes;

And second important reason is it, this line should shall fall before the resource route if you have similar to this controller, in my case it was :

Route::resource('/book-readings', App\Http\Controllers\BookReadingController::class); 
// this line was defined before the above route I wanted to work! (I am not sure why this line causing to stop showing the page :/)

Finally I make these changes so everything started working smoothly & all routes loading fine and up!.

// Upload Audio Files:
Route::get('/book-readings/upload-photos', [App\Http\Controllers\BookReadingController::class, 'showPhotos'])->name('book-readings.upload-photos');
Route::post('/book-readings/upload-photos', [App\Http\Controllers\BookReadingController::class, 'uploadPhotos']);
Route::delete('/book-readings/upload-photos/{id}', [App\Http\Controllers\BookReadingController::class, 'destroyPhoto']);

Route::resource('/book-readings', App\Http\Controllers\BookReadingController::class);

Hope this will give you a hint to point the issue you might come up like this mostly when we are new and learning and developing new things!

Happy Learnings

Categories
Blog Learning

Curios Question: Wanted to know how much rate would cost me running 10W Laser Machine for 14 mins?

Hello

Welcome here, If you also wondering how much it would cost us for running certain electrical appliance at home for our small work or business and you wondering how to make those calculations to find the rate for that mins or hours of machine running assuming just its running in your home nothing else.

If you were looking for similar answer, lets dive how I have tried to find it out myself with help of latest tech programs online!

Lets Dig In!

Here how I frame my question using the data from my latest Electricity Bill (In India, I am using Tata Power the great source of electricity provider to the nation!)

Based on following data 101-300 Units Energy Charge: 5.65 rupee /kwh, RA charges 0.00 rupee /kwh, CSS charges: 0.35 rupee /kwh, Wheeling Charges : 2.21 rupee /kwh, Fixed Demand Charges: 125.00 rupees, ED 16.00%, Tose: 0.2604 rupee /kwh
If I am running a single machine of 10W laser for 14 mins how much my electricity bill would be?

Question I formed to put in the mouth of AI tool 😛

Here is how AI calculated from the above that and calculate out the result for me:

To calculate the electricity bill, we need to convert the power consumption of the machine from Watts to kilowatts and then multiply it by the energy rate per unit.


10 W = 10/1000 kW = 0.01 kW

The time period is 14 minutes, which we need to convert to hours:

14 minutes = 14/60 hours = 0.2333 hours

The total energy consumption can be calculated as:

Energy consumed = Power x Time = 0.01 kW x 0.2333 hours = 0.002333 kWh

Now, we can calculate the energy charges, demand charges, and other charges as follows:

Energy Charges = Energy consumed x Energy rate per unit
= 0.002333 kWh x 5.65 Rs/kWh = 0.0132 Rs

Fixed Demand Charges = Fixed Demand Charges per billing cycle
= 125.00 Rs (for a single machine)

Wheeling Charges = Energy consumed x Wheeling charges per unit
= 0.002333 kWh x 2.21 Rs/kWh = 0.0051 Rs

CSS Charges = Energy consumed x CSS charges per unit
= 0.002333 kWh x 0.35 Rs/kWh = 0.0008 Rs

ED Charges = Energy charges + Wheeling charges + CSS charges
= 0.0132 Rs + 0.0051 Rs + 0.0008 Rs = 0.0191 Rs

Taxes and Other Surcharges = Energy charges + Wheeling charges + CSS charges + ED charges x Tose rate
= 0.0191 Rs x 0.2604 = 0.00498 Rs

Total Electricity Bill = Energy Charges + Fixed Demand Charges + Wheeling Charges + CSS Charges + ED Charges + Taxes and Other Surcharges
= 0.0132 Rs + 125.00 Rs + 0.0051 Rs + 0.0008 Rs + 0.0191 Rs + 0.00498 Rs
= 125.043 Rs (rounded off to two decimal places)

Therefore, if you run a single 10W laser machine for 14 minutes, your electricity bill would be approximately 125.043 Rs.

Then I said Wow so nice and quick, isn’t it?

But then thought & put my attention on the Fixed Demand Charges which 125/-, would it be a for day? then I thought No its for a month, so how it would calculate for a day? it simply as you would also know this to divide in my number of days in a month, right?

So to see if AI response the result back with more in detail with assuming and consuming similar data passed before, here is reframed question I have put (in the mouth of AI tool)

can you do this divide fixed charges by month of days and return everything again?

question for AI tool

This is what it finally answered back;

Sure, to calculate the fixed demand charges per day, we can divide the monthly fixed demand charges by the number of days in the month.

Assuming a 30-day billing cycle, the fixed demand charges per day would be:

Fixed Demand Charges per day = Fixed Demand Charges per month / Number of days in the month
= 125.00 Rs / 30 days
= 4.1667 Rs per day

Now, we can calculate the updated energy charges, wheeling charges, CSS charges, ED charges, and taxes and other surcharges per unit of energy consumed, which would be:

Energy Charges = 5.65 Rs /kWh
Wheeling Charges = 2.21 Rs /kWh
CSS Charges = 0.35 Rs /kWh
ED Charges = Energy charges + Wheeling charges + CSS charges
= 5.65 Rs/kWh + 2.21 Rs/kWh + 0.35 Rs/kWh
= 8.21 Rs/kWh

Taxes and Other Surcharges = ED charges x Tose rate
= 8.21 Rs/kWh x 0.2604
= 2.1384 Rs/kWh

To calculate the total electricity bill for running a 10W laser machine for 14 minutes per day, we can use the same method as before, but now we have updated values for the fixed demand charges, ED charges, and taxes and other surcharges.

Energy consumed per day = Energy consumed per hour x Hours per day
= 0.01 kW x 0.2333 hours/day
= 0.002333 kWh/day

Energy Charges per day = Energy consumed per day x Energy rate per unit
= 0.002333 kWh/day x 5.65 Rs/kWh
= 0.0132 Rs/day

Fixed Demand Charges per day = Fixed Demand Charges per month / Number of days in the month
= 125.00 Rs / 30 days
= 4.1667 Rs/day

Wheeling Charges per day = Energy consumed per day x Wheeling charges per unit
= 0.002333 kWh/day x 2.21 Rs/kWh
= 0.0051 Rs/day

CSS Charges per day = Energy consumed per day x CSS charges per unit
= 0.002333 kWh/day x 0.35 Rs/kWh
= 0.0008 Rs/day

ED Charges per day = Energy charges per day + Wheeling charges per day + CSS charges per day
= 0.0132 Rs/day + 0.0051 Rs/day + 0.0008 Rs/day
= 0.0191 Rs/day

Taxes and Other Surcharges per day = ED charges per day x Tose rate
= 0.0191 Rs/day x 0.2604
= 0.00498 Rs/day

Total Electricity Bill per day = Energy Charges per day + Fixed Demand Charges per day + Wheeling Charges per day + CSS Charges per day + ED Charges per day + Taxes and Other Surcharges per day
= 0.0132 Rs/day + 4.1667 Rs/day + 0.0051 Rs/day + 0.0008 Rs/day + 0.0191 Rs/day + 0.00498 Rs/day
= 4.2098 Rs/day

Therefore, if you run a single 10W laser machine for 14 minutes per day, your electricity bill would be approximately 4.2098 Rs/day

Hurray! Isn’t it fun?

Hope you enjoyed this puzzle solving question answer game when really you want to know the difficult question you have all time in our head, but latest techs help’s out in secs with such quick answers!

Keep exploring keep learning!

Source : Open AI Chat GPT

P.S. Not sure what it calculated it reflect exact what we are looking, I assuming it calculated to be accurate!

Categories
Javascript Learning

How to fix Uncaught TypeError: Cannot assign to read only property ‘0’ of object occurring in JavaScript?

Hello,

This type error mostly get in scenario when you try to sort the readyonly data array.

For me this was occoured when I tried to sort the direct result from my GraphQL query response data like below:

const sortedData = data.bhangarwalas.sort((a, b) => a?.firstname > b?.firstname ? 1 : -1);

In above, data.bhangarwalas is graphql query response results which is readonly in nature as response.

To fix this issue the solution is quick fix for which I have too google to know the result!

Error Screenshot Uncaught TypeError: Cannot assign to read only property ‘0’ of object ‘[object Array]’

Here is the quick solution:

const sortedData = [...data.bhangarwalas];
      sortedData.sort((a, b) => a?.firstname > b?.firstname ? 1 : -1);

In code above, We need to clone or you in other words, copying the “data.bhangarwalas” into new array variable and then over that variable, we need to perform sorting operation, which results us right response.

Hope this help you to solve the quick error or to know what scenario this type of error is generated.

Thanks for reading.

Happy learning!

Categories
Learning

What to do when you don’t quickly find UTS scan code at a Mumbai Railway Station you are at?

Hello,

You are facing too? Not to worry.

The challenge of finding UTS Mumbai Station Scan QR scan code if you are standing at other the end of the station where UTS scan code is not available quickly.

Just quickly jump over to this site : MUMBAI RAILWAY STATION UTS SCAN CODE find the station and scan the code right away and Book your ticket from UTS App.

UTS Scan code Mumbai [Western|Centeral|Eastern]

Incase if you not find the UTS Scan code you can quickly drop a note to them at  utsqrscan@doableyo.com to add your favorite station QR code on the list!

Hope this helps.

Thanks for visiting. Please share with your friends and family if you love their work!

Categories
Javascript Learning Tech

What to do when you get nextjs error (Module not found: Error: Can’t resolve ‘private-next-pages/’ in ‘/vercel/path0’) on vercel/nextjs deployment?

Hello,

If you too facing this error : Module not found: Error: Can’t resolve ‘private-next-pages/’ in ‘/vercel/path0’

while deploying your NextJs project over Vercel platform, please follow what solution and mistake I was doing.

Error Screenshot of error occurring from the NextJs Project deployment on vercel platform.

As, I tried to debug this error by right away check the the next in the log highlighted (in screenshot above) recommending to following alias rule to be set if you have touched you next.config.js file with any webpack settings.

In my case I did have to touched the next.config.js file and so I have add the same lines of code recommend in the follow link of Next.js doc

https://nextjs.org/docs/messages/invalid-resolve-alias

But for me still I didn’t found the right solution, because was in the naming of folder under nextjs project.

Basically, I was loading the static content into the dynamic route in Nextjs (Like example reference here).

What I have missed was the name of the folder under pages directory I have created named as “learn” it should be similar to name “posts” as created one at root level of the project to hold the “.md” or “.html” file content to pass down to dynamic route page which will be under /pages/posts/[id].js

Sharing here screenshot of the directory where the naming was a mistake

Here highlighted “learn” folder should be same as “posts” below

After renaming the folder name “learn” to “posts” the error went off and found my deployment working successfully.

Hope this small mistake tip help you to solve this problem.

If you have found any mistake in the post. Please don’t hesitate to hit me on my email jat@doableyo.com to rectify.

Enjoyed reading this? How about sharing with your friends or in groups, this would help!

Thanks, Happy Learning!

Categories
Learning

ReactJS Component Skeleton for Register/Create Account

Hello,

Welcome, here is how you can create a get to started ReactJS Register/Create Account component from scratch with very basic fields for your website or application.

import React from "react";

function CreateAccount() {

    const [formValues, setFormValues] = useState({
        role: '',
        name: '',
        mobile: '',
        email: '',
        password: '',
        confirmPassword: ''
    });

    const handleInputChange = e => {
        const { name, value } = e.target;
        setFormValues({ ...formValues, [name]: value });
    };

    const handleSubmit = e => {
        e.preventDefault();
        // You can perform your form submission logic here
        console.log(formValues);
    };

    return (<>
        <div className="card">
            <div className="card-body">
                <form method="POST" action="https://doableyo.com/atamsamagam/admin/register">
                    {/* <input type="hidden" name="_token" defaultValue="zdDR1NfxywhlhmpIqNTZ7uNUvl1luoUe7X0N6GOh" /> 
                        for CSRF!
                    */}
                    <div className="form-group row">
                        <label htmlFor="role" className="col-md-4 col-form-label text-md-right">Role</label>
                        <div className="col-md-6">
                            <select id="role" name="role" className="form-control  text-capitalize" required autoComplete="role" autofocus>
                                {/* need a fix of admin */}
                                <option value="user">user</option>
                                <option value="admin">admin</option>
                            </select>
                        </div>
                    </div>
                    <div className="form-group row">
                        <label htmlFor="name" className="col-md-4 col-form-label text-md-right">Name</label>
                        <div className="col-md-6">
                            <input id="name" type="text" className="form-control " name="name" defaultValue required autoComplete="name" autofocus />
                        </div>
                    </div>
                    <div className="form-group row">
                        <label htmlFor="mobile" className="col-md-4 col-form-label text-md-right">Mobile</label>
                        <div className="col-md-6">
                            <input id="mobile" type="number" required minLength={10} maxLength={10} className="form-control " name="mobile" defaultValue autoComplete="mobile" />
                            <small>Enter without country code or + character</small>
                        </div>
                    </div>
                    <div className="form-group row">
                        <label htmlFor="email" className="col-md-4 col-form-label text-md-right">E-Mail Address</label>
                        <div className="col-md-6">
                            <input id="email" type="email" className="form-control " name="email" defaultValue required autoComplete="email" />
                        </div>
                    </div>
                    <div className="form-group row">
                        <label htmlFor="password" className="col-md-4 col-form-label text-md-right">Password</label>
                        <div className="col-md-6">
                            <input id="password" type="password" className="form-control " name="password" required autoComplete="new-password" />
                        </div>
                    </div>
                    <div className="form-group row">
                        <label htmlFor="password-confirm" className="col-md-4 col-form-label text-md-right">Confirm Password</label>
                        <div className="col-md-6">
                            <input id="password-confirm" type="password" className="form-control" name="password_confirmation" required autoComplete="new-password" />
                        </div>
                    </div>
                    <div className="form-group row mb-0">
                        <div className="col-md-6 offset-md-4">
                            <button type="submit" className="btn btn-primary">
                                Create
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>

    </>)
}

export default CreateAccount;

Source: Self Learned & AI ChatGPT Channel

Happy learning!

Categories
Blog Learning Learning

Picture tag in HTML

The <picture> tag in HTML is a semantic element that is used to define multiple source images for a single content. The <picture> element is used to specify multiple sources for an image, allowing the browser to choose the most appropriate source based on the user’s device and screen size. This allows you to display images that are optimized for different devices, without having to rely on JavaScript or CSS media queries.

Here’s an example of how you might use the <picture> tag:

<picture >
  < source srcset="large.jpg" media="(min-width: 800px)">
  < source srcset="small.jpg" media="(max-width: 799px)">
  < img src="small.jpg" alt="A picture">
</ picture >

In this example, the < source > elements define different sources for the image, based on the screen size of the user’s device. If the screen is at least 800 pixels wide, the browser will choose the large.jpg image, while if the screen is smaller than 800 pixels, it will choose the small.jpg image. The <img> element is used as a fallback for browsers that do not support the <picture> element.

hope you understand the basic concepts and use of Picture Tag in HTML

Source: AO Interaction Channel

Categories
Learning

What is the life cycle of an HTML request

Hello, Welcome

The life cycle of an HTML request can be divided into following stages:

  1. Request initiation: The request is initiated by the browser, usually in response to a user action, such as clicking a link, submitting a form, or refreshing the page.
  2. DNS Lookup: The browser checks the local cache and DNS servers to resolve the domain name to an IP address. If the domain name has not been resolved before, the browser will initiate a DNS lookup to obtain the IP address of the server.
  3. TCP Connection: The browser establishes a TCP connection with the server. This is the underlying communication channel that will be used to send the HTTP request and receive the response.
  4. Request sent: The browser sends an HTTP request to the server. The request includes information about the type of operation being performed (e.g., GET, POST, PUT, DELETE), the URL being requested, and any additional data that may be required (e.g., form data).
  5. Server processing: The server receives the request and processes it. This may involve retrieving data from a database, processing data, or generating a response.
  6. Response sent: The server generates an HTTP response and sends it back to the browser. The response includes information about the status of the request, the type of data being returned, and the actual data itself.
  7. Response received: The browser receives the response and processes it. This may involve updating the contents of the page, displaying an error message, or redirecting to another page.
  8. Resource loading: If the response includes references to additional resources (e.g., images, stylesheets, scripts), the browser will initiate separate requests for each of these resources.
  9. Page rendering: The browser uses the information in the response to render the final page.

This entire process can take place in a matter of milliseconds, allowing the user to interact with the web page in near-real-time.

Source: AI Interaction Channel

Happy learning!

Categories
Learning Tech

How to write basic Test case for React component using Jest or Enzyme

Lets quickly straight dive into it

import React from "react";
import { shallow } from "enzyme";
import TestComponent from "./TestComponent";

describe("TestComponent", () => {
  it("renders correctly", () => {
    const wrapper = shallow(<TestComponent />);
    expect(wrapper).toMatchSnapshot();
  });

  it("contains a button", () => {
    const wrapper = shallow(<TestComponent />);
    expect(wrapper.find("button").length).toEqual(1);
  });

  it("simulates click events", () => {
    const mockCallBack = jest.fn();
    const wrapper = shallow(<TestComponent handleClick={mockCallBack} />);
    wrapper.find("button").simulate("click");
    expect(mockCallBack.mock.calls.length).toEqual(1);
  });
});

In this example, the describe block creates a test suite for the TestComponent and the it blocks define individual test cases.

The shallow function from Enzyme is used to render a shallow version of the component.

The toMatchSnapshot assertion is used to check that the component is rendering correctly.

The find method is used to locate elements within the shallow render, and the simulate method is used to trigger events on those elements.

The jest.fn function is used to create a mock callback that can be passed as a prop to the component and tested.

Happy Learning.