Showing 'No internet connection' message in Ionic application

There are often times where you need to display No internet connection message to your users inside your Ionic Framework Android and iOS application.

Add Network information cordova plugin

Inorder to check internet connection, you need to have network information cordova plugin.

cordova plugin add org.apache.cordova.network-information

Check for internet connection inside Platform ready

Now, you have to check the internet connection inside platform ready as follows

angular.module('myApp', ['ionic'])

.run(function($ionicPlatform, $ionicPopup) {
  $ionicPlatform.ready(function() {

    // Check for network connection
    if(window.Connection) {
      if(navigator.connection.type == Connection.NONE) {
        $ionicPopup.confirm({
          title: 'No Internet Connection',
          content: 'Sorry, no Internet connectivity detected. Please reconnect and try again.'
        })
        .then(function(result) {
          if(!result) {
            ionic.Platform.exitApp();
          }
        });
      }
    }

  });
})

Have a nice day.

View comments

Clean up your local branches after merge and delete in GitHub

If you are a Github user, then you might familiar with Pull Requests. Github has an options to delete a branch after merging of pull request.

After a Pull Request has been merged, you’ll see a button to delete the lingering branch:

Above action will delete the branch only in the remote. Then there is a question: how do I clean up my local branches? I found an answer as follows

Lets say my test branch name feature-collaboration

1. List branches in local machine

The command git branch -a shows the test branch feature-collaboration is present on local and also present on remote

git branch -a

2. Prune/Cleanup the local references to remote branch

The command git remote prune origin --dry-run lists branches that can be deleted/pruned on your local. An option --dry-run is needed.

git remote prune origin --dry-run

Now go ahead and actually prune/cleanup the local references by running the command git remote prune origin. Note that you don't need an option --dry-run.

git remote prune origin

Again, run the command git branch -a will show the local status of branches.

git branch -a

Now you can notice that remotes/origin/feature-collaboration has been removed, but not the local branch feature-collaboration.

3. Delete local branch

If wanted, we can clean-up the local branch feature-collaboration as well

git branch -d

That's it. Have a nice day.

View comments

Restrict user access to Single S3 Bucket using Amazon IAM

S3 becomes de-facto standard for publishing files in the internet. When you work with the team, you might want to restrict an access of single S3 bucket to specific users. You can do it in IAM as follows

  1. Create Group
  2. Create User. Then use Manage Password to add a password for your user.
  3. Add User to the created Group
  4. Create and Attach Permission Policy for the group.

Step 1, 2 and 3 are straight forward. But creating and attaching permission policy needs some attention.

In Group tab, go to created group. Then click the Permissions tab and Click the Attach Policy button. You’ll be taken to Set Permissions page where you can Manage User Permissions. Here you can select a Select Policy Template option, then find the Amazon S3 Full Access and click Select button.

You will be prompted with Policy Name and Policy Document. You can change the policy name as you wish. In the Policy Document section, paste the following content

{
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "s3:ListAllMyBuckets",
            "Resource": "arn:aws:s3:::*"
        },
        {
            "Effect": "Allow",
            "Action": "s3:*",
            "Resource": [
                "arn:aws:s3:::mys3bucket",
                "arn:aws:s3:::mys3bucket/*"
            ]
        }
    ]
}

You are done. Have a nice day.

View comments