Thursday, October 25, 2018

Git: Resolve Conflicts in PR

What to do when GitHub does not allows you to merge a Pull Request due to conflicts!
First of all, rebase often to avoid this problem in most cases.
Sharing bits from my experience. The solutions that worked for me are:

1. git rebase

The best way is to do it locally using terminal or command prompt. Lets say you raised a PR from origin/develop to upstream/develop branch and got conflict. Go to your command prompt, rebase master onto develop and push to develop branch. PR should get resolved.
But this won’t work when the tips are just big time outdated.

Wednesday, August 16, 2017

Using Wiremock for quick and easy http mocks of your API

I published this article at the turn of the year in my company's internal blog. I am republishing it here thinking it might be useful to outside world who are looking at a concise guide.

WireMock is an HTTP mock server. At its core it is web server that can be primed to
  1. serve canned responses to particular requests (stubbing) and 
  2. that captures incoming requests so that they can be checked later (verification).
Imagine your application component is dependent on some other component for development or testing, here WireMock can come in and remove your dependency headaches.
You can agree the contract, design the stub and use it for your own component without tight integration with other component. This makes the development and testing much
easier and faster.

Monday, February 20, 2017

Stackoverflow Documentation | The way to go

Many months now, the Stackoverflow documentation is maturing with new examples and continuous edits to existing examples. It covers many programming languages, and should be on top of your TO-DOs if you are trying to broaden your skill set or even validate what you already have in your kitty.

If you feel it's good, you should consider making it awesome for others. Ultimately, giving back to the community only makes sure of technology's global reach and rapid development. Click here: http://stackoverflow.com/documentation.

Thursday, September 1, 2016

Recursion is all about trust.

Image credit: http://www.cr31.co.uk/logoarts/
The secret of recursion is only one thing. Trust. Here's a neat example to show you what it exactly means. Quoting Stephan van Hulst from Code Ranch here.

Say there's a long queue of people, and you want to know how many are in the queue. You can simply ask the guy in front of you how many people there are in the queue, and then add 1 for yourself. You don't care how the guy in front of you got the answer, you just trust that it's correct. The guy in front uses the same technique. This goes on all the way until the guy at the front of the queue is asked how many people there are in the queue. The guy at the front sees no people in front of him, so he just reports 1. He is the base case.

final class PersonInQueue {
 
  private final PersonInQueue next;
 
  int askForLengthOfQueue() {
    if (next == null)
      return 1;
 
    return next.askForLengthOfQueue() +1;
  }
}
Here's the post: Algorithm explanation if you want to have a look. The question was on Tower of Hanoi.

Sunday, April 10, 2016

IP v4 address matcher (regex)

IP address is a string in the form "A.B.C.D", where the value of A, B, C, and D may range from 0 to 255. Leading zeros are allowed. The length of A, B, C, or D can't be greater than 3.

image
The pattern is: ^(?:(?:25[0-5]?|2[0-4]?[0-9]?|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]?|2[0-4]?[0-9]?|[01]?[0-9][0-9]?)$

Java:
public class IPv4Regex {
	static final String ipV4Pattern = "^(?:(?:25[0-5]?|2[0-4]?[0-9]?|[01]?[0-9][0-9]?)\\.){3}"
			+ "(?:25[0-5]?|2[0-4]?[0-9]?|[01]?[0-9][0-9]?)$";
	
	public static void main(String[] args) {
		System.out.println("000.123.234.245".matches(ipV4Pattern));
	}
}