Skip to content

Instantly share code, notes, and snippets.

View pkavoo's full-sized avatar

Polycarp Kavoo pkavoo

  • Nairobi, Kenya
View GitHub Profile
@pkavoo
pkavoo / isGPSEnabled
Created April 2, 2020 21:39
Method for checking if GPS is enabled
public boolean isGPSEnabled(Context mContext) {
LocationManager locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
}
@pkavoo
pkavoo / isInterenetConnected
Last active April 2, 2020 21:38
Method for checking if internet is turned on
public static boolean isInternetConnected(Context ctx) {
ConnectivityManager connectivityMgr = (ConnectivityManager) ctx
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo wifi = connectivityMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
NetworkInfo mobile = connectivityMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
// Check if wifi or mobile network is available or not. If any of them is
// available or connected then it will return true, otherwise false;
if (wifi != null) {
if (wifi.isConnected()) {
return true;
@pkavoo
pkavoo / Draw Route Method
Created April 2, 2020 21:36
Here you can change the minimum time or distance to get new locations and draw on map
private LocationManager locationManager;
private android.location.LocationListener myLocationListener;
public void checkLocation() {
String serviceString = Context.LOCATION_SERVICE;
locationManager = (LocationManager) getSystemService(serviceString);
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
@pkavoo
pkavoo / twitter crawler.txt
Created November 6, 2019 23:46 — forked from vickyqian/twitter crawler.txt
A Python script to download all the tweets of a hashtag into a csv
import tweepy
import csv
import pandas as pd
####input your credentials here
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
@pkavoo
pkavoo / LatLngInterpolator.java
Last active July 6, 2019 09:31
interpolation is a method of constructing new data points within the range of a discrete set of known data points. This class loops through lat lng data and creates a data set
import com.google.android.gms.maps.model.LatLng;
import static java.lang.Math.asin;
import static java.lang.Math.atan2;
import static java.lang.Math.cos;
import static java.lang.Math.pow;
import static java.lang.Math.sin;
import static java.lang.Math.sqrt;
@pkavoo
pkavoo / MarkerAnimation.java
Last active July 6, 2019 09:30
Marker animation class
import android.os.Handler;
import android.os.SystemClock;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Interpolator;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
@pkavoo
pkavoo / MainActivity.java
Last active July 6, 2019 09:26
Java code for activity_main.xml layout file with fragment
import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Build;
import android.os.Bundle;
import android.os.Looper;
import android.view.View;
import android.widget.Toast;
import androidx.annotation.NonNull;
<?php
//getting the dboperation class
require_once '../includes/DbOperation.php';
//function validating all the paramters are available
//we will pass the required parameters to this function
function isTheseParametersAvailable($params){
//assuming all parameters are available
$available = true;
$missingparams = "";
<?php
class DbOperation
{
//Database connection link
private $con;
//Class constructor
function __construct()
{
<?php
//Class DbConnect
class DbConnect
{
//Variable to store database link
private $con;
//Class constructor