InfyOm Blog

latest-post

Last week, we run into a problem for one of the large Gatsby + ReactJS + Laravel projects in hosting which is hosted with Apache Webserver on Amazon AWS EC2. The problem we were facing was, for some reason, when we reload the Gatsby website, it was giving a 404 error page.

If you open a home page and then a normal visit then the website will fully function, but if you reload the page then it gives an error. And we found it happens when we are using Dynamic routing of React Route in Gatsby as per show in Gatsby documentation here.

Also, what we found, if we test the website build with gatsby serve then it works fine. But while using Apache, it behaves differently and we found that this problem has been faced by lots of people over the internet.

So what we came up with is, we used gatsby serve with an apache proxy. Here is how we did it,

Step 1 - Setup Project

As a first step, clone the project on the server and run a command, gatsby build to create a gatsby build.

Step 2 - Setup PM2 for Gatsby Serve

The next step that we need to do is run gatsby serve. But as you know, we can not run this command directly via console, because as you exit from the console, the command will be terminated.

So we will be using pm2 package, a NodeJS utility that is used to run nodejs apps.

For that, we will need to install pm2 globally. Run the following command to install it,

npm install pm2 -g

You can find other installation ways here if you need.

Once the installation has been done, let's run the gatsby serve command via pm2. For that run the following command from the gatsby project folder,

pm2 start gatsby --name my-web-app -- serve

where my-web-app you can replace with the name of your app.

Once, it's running, try to test it, if it's working correctly by opening the URL http://your-ip-address:9000/. Make sure, port 9000 is opened on your server for traffic.

Step 3 - Configure Apache

Once, gatsby serve is working and tested. The next step is to configure apache to proxy all port 80 traffic to port 9000.

For that, edit your apache conf file (or virtual host conf file), and add the following lines (or configure it to something like the following),

<VirtualHost *:80>
        ServerName my-web-app.infyom.com

        ServerAdmin webmaster@infyom.com

        ProxyRequests On
        ProxyPass / http://localhost:9000/
        ProxyPassReverse / http://localhost:9000/

        ErrorLog ${APACHE_LOG_DIR}/my-web-app.infyom.com.error.log
        CustomLog ${APACHE_LOG_DIR}/my-web-app.log combined

        ......
        # any other options below as per your need
        ......
</VirtualHost>

The next step you need to do is restart your apache server by,

sudo service apache2 restart

And then you can just open the URL https://my-web-app.infyom.com and it should work fine.

Bonus

New Deployment

Whenever you deploy a new code, you again need to run gatsby build and then pm2 restart my-web-app. Then only it will take new changes.

Troubleshooting

Sometimes, we found that we need to restart apache as well after the new deployment. so if you run into any trouble, then make sure to restart apache as well and it should solve the problem.

I hope it may help you to resolve your 404 problem.

July 16, 20213 minutesuserMitul Golakiya

Posts

post

Basically, it works like a stack where each view is stacked on top of the other.

Create a drawable file for shadow view and assign the name image_shadow and add the below code in this file.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="10dp" />
    <gradient
    android:angle="270"
    android:centerX="300%"
    android:endColor="#99000000"
    android:startColor="#00000000"
    android:type="linear" />
    <size
    android:width="270dp"
    android:height="60dp" />
    <stroke
    android:width="1dp"
    android:color="#878787" />
</shape>

Now, open xml file and add the below code into it, and set this drawable file as view background.

<androidx.appcompat.widget.LinearLayoutCompat
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity">
<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <androidx.appcompat.widget.AppCompatImageView
        android:id="@+id/imageView"
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:scaleType="centerCrop"
        android:src="@drawable/shopping_image"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"/>
    <View android:id="@+id/view"
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:background="@drawable/image_shadow"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"/>
    <androidx.appcompat.widget.AppCompatTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:textColor="@android:color/white"
        android:text="Write your text here"
        android:textSize="25sp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="@+id/view"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.appcompat.widget.LinearLayoutCompat>

That's it. You should be ready to go.

December 31, 20201 minuteauthorVivek Beladiya
post

Here we will learn, how to import annotations saved in the database using PDFTron.

In my last blog, we have learned how to save annotation in the database.

Events for import annotation

At the time of document load, we will get all annotations saved in the database using AJAX call and then we'll import that annotation. Now the question is if we import annotation than that will be drawn and again annotation changed event will fire and again annotation will be saved (as I say in my last blog), so this will become an infinite flow, but we can overcome this problem by checking if an annotation is imported or not. If an annotation is not imported then only we'll do save annotation in the database process otherwise we'll ignore it.\

When we draw any annotation "annotationChanged" event will be fired, and check if it is an imported annotation, then we can ignore it(eg, save annotation process).

Here is an example of how to import annotation from the database.

Example

WebViewer({
    path: 'path_to_the_PDFTron_'lib'_folder_on_your_server',
    css: 'webviewer_css',
    licenseKey: 'YOUR_PDF_TRON_LICENSE_KEY',
    initialDoc: 'YOUR_FILE URL' //url of a file to load
}, document.getElementById('viewer'))
    .then(function (instance) {
        let docViewer = instance.docViewer;
        let annotManager = instance.annotManager;
       
        annotManager.on('annotationChanged', (annots, action, e) => {
            //if annotation is imported we'll return
            if (e.imported) return;
            //when document will loaded we'll get annotations fro db
            docViewer.on('documentLoaded', function () {
                $.ajax({
                    url: `URL_TO_SAVE_ANNOTATION`,
                    type: 'GET',
                    success: function (result) {
                        if (result.success) {
                            result.data.forEach(annotationObj => {
                                annotManager.importAnnotations(annotationObj.annotation);
                            });
                        }
                    },
                    error: function (result) {
                        console.log(result);
                    }
                });
            });
        });
    });

December 28, 20201 minuteauthorMonika Vaghasiya
post

Simply put, the rule of 10 X is taking any target you set for your company or sales team, and multiplying it by 10.

So if the goal is to increase revenue by 5% using the 10X rule, you will increase that goal to 50%.

What the 10X rule does is force you and your sales team to think in terms of LEVERAGE. Because all of a sudden, instead of focusing on the “real” goal, the goal is achieved through the roof.

Contact customer acquisition with a solid plan. Build a foundation by developing relationships with your target audience.

Achieve customers differently as you progress toward strategic goals. Here are four lessons to guide your team:

1. Create an engagement

It is highly unlikely that a first time visitor will stumble upon your website and automatically purchase your products. Potential customers should be fully engaged with your brand before making a purchase.

2. Be present on social media

If you are not present on social media, you are lost in a huge market that your competitors are already taking advantage of.

Having a social media presence should also not be expensive. Creating a business account on Facebook, Twitter, Instagram, and LinkedIn is free. Just join discussions and groups related to your industry. Provide helpful answers to questions and insights on various posts to make yourself known.

3. Keep your sales simple

Everyone is on sale, even if your job or business has no impact, Cardo told those in attendance. And many entrepreneurs and professionals overreact to it.

Sales is a game of touch. It’s about finding someone who can buy, who has the power to make decisions, and who is interested. Then you contact them with offer fur, talk price, and ask. It's not always easy, though it's really easy. The most successful salespeople focus on simplifying their sales process.

4. Put your problem customers

We have it all - the customers that we meet today or in the future take up more of our time for business.

5. All your customers are committed to staying in touch after purchasing from you

Keep an eye out for ways you can sell them extra items. Don’t keep your customers engaged to monopolize your time, but you can help them gain an understanding of strategy opportunities.

6. Host an event

Hosting an event is a great way to do this because it gives potential customers the opportunity to meet your brand on a more personal level. Depending on your product or service, you can either host a personal event where customers can meet you or host an online webinar where it still feels personal - just like you are in front of your audience.

December 26, 20202 minutesauthorAnkit Kalathiya
post

Development:








The Balanced Scorecard (BSC) was originally developed by Robert Kaplan of Harvard University and Dr. David Northon as a framework for measuring organizational performance using the more " BALANCED " set of performance measures.

Traditionally companies used only short-term financial performance as a measure of success but now non-financial strategic measures also added in order to focus on long-term success.
The BSC system evolved over the years and is now considered a fully integrated "Strategic Management System".

What is a Balanced Scorecard (BSC)?








  • A Balanced Scorecard is a performance metric used to identify, improve, and control a business's various internal processes and resulting outcomes.
  • Balance Scorecard is a framework to implement and manage strategies.
  • The Balance scorecard is derived from the idea of looking at strategic measures to get a more balanced view of performance. The concept of a Balanced Scorecard evolved beyond the simple use of perspectives, every business can implement it according to the requirements and therefore it is a holistic system for managing strategy.

Why do we need to implement it?








  • The key benefit of using a BSC framework is that it gives way to the organization  to "Connect the Dots" between various components of strategic planning and management and it means there will be a visible connection between Projects and Programs that people are working on it.
  • BSC framework also helps management to meet pre-decided targets.

Perspectives of Balanced Scorecard:







Indeed balanced scorecard plays a significant role to aid management to keep updated internal processes and the external Business world as well.
The framework Balanced Scorecard divided into four areas (perspectives) that are critical to business success as given below.
balanced_scorecard_perspectives.png 223.33 KB
  1. Financial 
  2. Internal process 
  3. Learning and Growth 
  4. Customer 
The BSC suggests that we view the Organization from four Perspectives to develop Objectives, Measures, Targets, and initiatives (relative to each of these points of view).

To know more details about all four perspectives, read my upcoming weekly Blogs.

December 06, 20202 minutesauthorMariyam Bemat
post
Few main things remember to test an Android Application which are mention below:

1. Functional testing test cases

There are many hands involved in creating a mobile app.  These stakeholders may have different expectations.  Functional testing determines whether a mobile app complies with these various requirements and uses.  Examine and validate all functions, features and competencies of a product.

Twelve functional test case scenario questions:

  1. Does the application work as intended when starting and stopping?  
  2. Does the app work accordingly on different mobile and operating system versions?
  3. Does the app behave accordingly in the event of external interruptions?
  4. (i.e. receiving SMS, minimized during an incoming phone call, etc.)
  5. Can the user download and install the app with no problem?
  6. Can the device multitask as expected when the app is in use or running in the background?
  7. Applications work satisfactorily after installing the app.
  8. Do social networking options like sharing, publishing, etc. work as needed?
  9. Do mandatory fields work as required?  Does the app support payment gateway transactions?
  10. Are page scrolling scenarios working as expected?
  11. Navigate between different modules as expected.
  12. Are appropriate error messages received if necessary? 

There are two ways to run functional testing: scripted and exploratory.


Scripted
Running scripted tests is just that - a structured scripted activity in which testers follow predetermined steps.  This allows QA testers to compare actual results with expected ones.  These types of tests are usually confirmatory in nature, meaning that you are confirming that the application can perform the desired function.  Testers generally run into more problems when they have more flexibility in test design.

Exploratory
Exploratory testing investigates and finds bugs and errors on the fly.  It allows testers to manually discover software problems that are often unforeseen;  where the QA team is testing so that most users actually use the app.  learning, test design, test execution and interpretation of test results as complementary activities that run in parallel throughout the project.  Related: Scripted Testing Vs Exploratory Testing: Is One Better Than The Other? 

2. Performance testing test cases

The primary goal of benchmarking is to ensure the performance and stability of your mobile application

Seven Performance test case scenarios ensure:

  1. Can the app handle the expected cargo volumes?
  2. What are the various mobile app and infrastructure bottlenecks preventing the app from performing as expected?
  3. Is the response time as expected?  Are battery drain, memory leaks, GPS and camera performance within the required guidelines?
  4. Current network coverage able to support the app at peak, medium and minimum user levels?
  5. Are there any performance issues if the network changes from / to Wi-Fi and 2G / 3G / 4G?
  6. How does the app behave during the intermittent phases of connectivity?
  7. Existing client-server configurations that provide the optimum performance level? 

3. Battery usage test cases

While battery usage is an important part of performance testing, mobile app developers must make it a top priority.  Apps are becoming more and more demanding in terms of computing power.  So, when developing your mobile app testing strategy, understand that battery-draining mobile apps degrade the user experience.  Device hardware - including battery life - varies by model and manufacturer.  Therefore, QA testing teams must have a variety of new and older devices on hand in their mobile device laboratory.  In addition, the test environment must replicate real applications such as operating system, network conditions (3G, 4G, WLAN, roaming) and multitasking from the point of view of the battery consumption test.

Seven battery usage test case scenarios to pay special attention to:

  1. Mobile app power consumption 
  2. User interface design that uses intense graphics or results in unnecessarily high database queries
  3. Battery life can allow the app to operate at expected charge volumes
  4. Battery  low and high performance requirements
  5. Application operation if used when battery is removed Battery usage and data leaks
  6. New features and updates do not introduce new battery usage and data 
  7. Related:  The secret art of battery testing on Android 

4. Usability Testing Test Cases

Usability testing of mobile applications provides end users with an intuitive and user-friendly interface.  This type of testing is usually done manually, to ensure the app is easy to use and meets real users' expectations.

Nine usability test case scenarios ensure:

  1. The buttons are of a user-friendly size. 
  2. The position, style, etc. of the buttons are consistent within the app
  3. Icons are consistent within the application
  4. The zoom in and out functions work as expected
  5. The keyboard can be minimized and maximized easily.
  6. The action or touching the wrong item can be easily undone.
  7. Context menus are not overloaded.
  8. Verbiage is simple, clear and easily visible.
  9. The end user can easily find the help menu or user manual in case of need.
  10. Related: High impact usability testing that is actually doable 

We will see more points in our next articles.

December 03, 20204 minutesauthorBhumi Khimani
post
Snackbars are fairly common in the Android app. Almost every app uses a snack bar to display some information about what's going on in the app. You can consider Snackbar as an alternative or the best version of Toasts in Android.

Step 1:- Using a normal Snackbar

To use Snackbar in your app, you just have to have the material design dependency in your app. Add Material design dependency to your build.Gradle app-level.

dependencies {
    implementation "com.google.android.material:$latest_version"
}
And then you can use the snack bar just like toast. For example:

Snackbar.make(view, "Show some message here", Snackbar.LENGTH_SHORT).show()
Step 2: Working with the MainActivity.xml


<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/coordinatorLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.application.snackbarapp.MainActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="show snackbar" />

    </RelativeLayout>

</android.support.design.widget.CoordinatorLayout>
Step 3: Creating a custom layout for a snack bar

Under Layout, the folder creates a layout for the snack bar that must be inflated when creating a snack bar under the mainactivity.java file.

import android.graphics.Color;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    private CoordinatorLayout coordinatorLayout;
    private Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        coordinatorLayout = findViewById(R.id.coordinatorLayout);
        button = findViewById(R.id.button);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showSnackbar();
            }
        });
    }

    public void showSnackbar() {
        Snackbar snackbar = Snackbar.make(coordinatorLayout, "Marked as Read", Snackbar.LENGTH_INDEFINITE)
                .setAction("UNDO", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Snackbar snackbar1 = Snackbar.make(coordinatorLayout, "Undo successful", Snackbar.LENGTH_SHORT);
                        snackbar1.show();
                    }
                })
                .setActionTextColor(Color.RED);

        snackbar.show();
    }
}

November 30, 20201 minuteauthorVivek Beladiya
post
Hope you guys are familiar with Spatie Media Library. It's a very useful and time-saving package to manage file uploading.

It's also providing support to convert your images to thumbnails while storing images. you can generate a thumbnail of the image with the size (height, width) you want.

They are calling thumbnails to Conversions. You can generate multiple thumbnails with different sizes as you want.

So let's see some short example which helps us to create thumbnails of an uploaded image.

Implement the HasMediaTrait into your Model 

Here we have a User model and we want to generate a thumbnail of the user upload his profile image. you have to add  HasMediaTrait to the User model and need to extend  HasMedia.

use IlluminateDatabaseEloquentModel;
use SpatieMediaLibraryModelsMedia;
use SpatieMediaLibraryHasMediaHasMedia;
use SpatieMediaLibraryHasMediaHasMediaTrait;

class User extends Model implements HasMedia
{
    use HasMediaTrait;

    public function registerMediaConversions(Media $media = null)
    {
        $this->addMediaConversion('profile-thumb')
              ->width(150)
              ->height(150);
    }
}

Here we have defined function registerMediaConversions in which we can manage the size of a thumbnail, which means how much height or width we want for the thumbnail.

So when we upload an image using the media library, 

$media = User::first()->addMedia($pathToImage)->toMediaCollection();
it will auto-generate the thumbnails with given height and width. 

How to fetch the generated thumbnail? 












$media->getPath();  // the path to the where the original image is stored
$media->getPath('profile-thumb') // the path to the converted image with dimensions 150*150

$media->getUrl();  // the url to the where the original image is stored
$media->getUrl('profile-thumb') // the url to the converted image with dimensions 150*150

How to generate multiple thumbnails for a single image? 








..... in User Model .....
use SpatieImageManipulations;


    public function registerMediaConversions(Media $media = null)
    {
        $this->addMediaConversion('profile-thumb')
              ->width(150)
              ->height(150);
    }

        $this->addMediaConversion('old-profile-thumb')
              ->sepia()
              ->border(8, 'black', Manipulations::BORDER_OVERLAY);
    }
so, it will generate 2 thumbnails with different image properties. you can use different image properties directly while generating thumbnails.

That's it, you can read more about the spatie media library conversions (thumbnails) here

Keep connected to us for more interesting posts about laravel.  


November 28, 20202 minutesauthorVishal Ribdiya
post
While developing apps in Android Studio, developers can create an APK file and share it with other developers or to QA people for testing purposes.
APK can be created with two types:
                                                   1.Debug APK
                                                   2.Release APK
  • Debug APK is very fast in building and Release APK is a little bit slow.

How to create Release APK File:



  • Flowing below all steps 
  • Open android studio
  • Click Build on the toolbar
  • Click Generate Signed Bundle/APK.
    c1.PNG 14.37 KB
  •  Select APK 
  • Click the Next button
    c2.PNG 14.5 KB
  • After clicking the next button, you will see the following dialog.
  • Click the "Create new..." button, highlighted in the following image by a red circle if you are creating an APK for the first time. Otherwise, you can choose from existing.
    c3.PNG 13.29 KB
  • It will open one another dialog box
  • Key store path in select save location .jks file 
  • Fill in all the information
  • Set a valid name for key alias
  • Set 100 as validity years
  • Fill Certificate Information
  • Click OK
  • After you click on it, select "release" from the dialog box 
  • Select "V1 (Jar Signature)" & "V2 (Full APK Signature)" checkboxes
  • Click Finish
  • It will start the process of building your APK

How to create a debug .apk file



  • Click Build and select Build Bundles(s)/APK(s) 
  • select "Build APK(s)" from the dialog box 
  • It will start the process of building your debug APK file creating 
November 25, 20201 minuteauthorPankaj Valani