Skip to content

Instantly share code, notes, and snippets.

View nishantkp's full-sized avatar
:octocat:
WFM

Nishant Patel nishantkp

:octocat:
WFM
View GitHub Profile
List<Pair<Integer, Integer>> indices = new ArrayList<>();
// indeices will be list containing a Pair
// Pair first and second will be indecies of the numbers whose some will be "b"
int[] a = {1, 3, 4, 5, 2}; // your list
int b = 5; // number you want to compare
for (int i = 0; i < a.length; i++) {
for (int j = i + 1; j < a.length; j++) {
if (b == a[i] + a[j]) {
indices.add(Pair.create(i, j));
@nishantkp
nishantkp / Network.java
Last active October 24, 2023 16:27
Find out application is connected to WIFI or cellular
/**
* Get reference to the connectivity manager
*/
ConnectivityManager connectivityManager =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
/**
* Find out whether device is connected to wifi or cellular at the moment
*/
public NetworkType getNetworkType() {
@nishantkp
nishantkp / README.md
Created March 15, 2019 03:19 — forked from lopspower/README.md
Android studio format code auto break line

Android studio format code auto break line

Twitter

To do this in Android Studio go to Preferences > Editor > Code Style

and set Right margin (columns) to 150 (or the line width you want)

Contributing

When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.

Please note we have a code of conduct, please follow it in all your interactions with the project.

Pull Request Process

  1. Ensure any install or build dependencies are removed before the end of the layer when doing a
@nishantkp
nishantkp / credential-validation.java
Created April 13, 2018 00:33
Validate user-email and password before performing login operation
/**
* Validate user email and password
* Email and password EditText fields are wrapped inside TextInputLayout
*
* @return true if email and password are valid, otherwise false
*/
private boolean isCredentialsValid() {
String emailAddress = edtEmail.getText().toString().trim();
String password = edtPassword.getText().toString();
if (TextUtils.isEmpty(emailAddress)
@nishantkp
nishantkp / GitHub-Forking.md
Created April 4, 2018 00:21 — forked from Chaser324/GitHub-Forking.md
GitHub Standard Fork & Pull Request Workflow

Whether you're trying to give back to the open source community or collaborating on your own projects, knowing how to properly fork and generate pull requests is essential. Unfortunately, it's quite easy to make mistakes or not know what you should do when you're initially learning the process. I know that I certainly had considerable initial trouble with it, and I found a lot of the information on GitHub and around the internet to be rather piecemeal and incomplete - part of the process described here, another there, common hangups in a different place, and so on.

In an attempt to coallate this information for myself and others, this short tutorial is what I've found to be fairly standard procedure for creating a fork, doing your work, issuing a pull request, and merging that pull request back into the original project.

Creating a Fork

Just head over to the GitHub page and click the "Fork" button. It's just that simple. Once you've done that, you can use your favorite git client to clone your repo or j

@nishantkp
nishantkp / border-round-corner.xml
Created April 3, 2018 03:00
Use this drawable to generate a border with round corners
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@null" />
<stroke
android:width="1dp"
android:color="@color/colorPrimary" />
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
@nishantkp
nishantkp / retrofit-gson-okhttp3.gradle
Last active April 3, 2018 01:55
ApiClient for retrofit
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'