Skip to content

Instantly share code, notes, and snippets.

View VarunBarad's full-sized avatar
🏡
Working remotely

Varun Barad VarunBarad

🏡
Working remotely
View GitHub Profile
@VarunBarad
VarunBarad / ConnectivityHelper.java
Last active February 15, 2018 06:40
Checking network connectivity on Android
public class ConnectivityHelper {
public static boolean isConnectedToNetwork(Context context) {
ConnectivityManager connectivityManager =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
boolean isConnected = false;
if (connectivityManager != null) {
NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
isConnected = (activeNetwork != null) && (activeNetwork.isConnectedOrConnecting());
}
// Java
public void rateApp(View rateMeButton) {
String packageName = this.getPackageName();
String playStoreAppUri = "market://details?id=" + packageName;
String playStoreSiteUri = "https://play.google.com/store/apps/details?id=" + packageName;
try {
Intent playStoreAppIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(playStoreAppUri));
startActivity(playStoreAppIntent);
} catch (ActivityNotFoundException e) {
// Kotlin
public fun rateApp(rateMeButton: View): Unit {
val packageName = this.packageName
val playStoreAppUri = "market://details?id=$packageName"
val playStoreSiteUri = "https://play.google.com/store/apps/details?id=$packageName"
try {
val playStoreAppIntent = Intent(Intent.ACTION_VIEW, Uri.parse(playStoreAppUri))
startActivity(playStoreAppIntent)
} catch (e: ActivityNotFoundException) {
@VarunBarad
VarunBarad / git-backup.py
Created March 3, 2019 10:33
Script to create a single-file backup of a git repository
#!/usr/bin/python3
import os
import sys
import re
import shutil
from git import Repo
from zipfile import ZipFile
def create_backup_zip(directory_to_backup):