Skip to content

Instantly share code, notes, and snippets.

Avatar

Piyush Malaviya piyush-malaviya

  • Ahmedabad, Gujarat, India
View GitHub Profile
View Text Center
int xPos = (canvas.getWidth() / 2);
int yPos = (int) ((canvas.getHeight() / 2) - ((textPaint.descent() + textPaint.ascent()) / 2)) ;
//((textPaint.descent() + textPaint.ascent()) / 2) is the distance from the baseline to the center.
canvas.drawText("Hello", xPos, yPos, textPaint);
https://stackoverflow.com/a/38415380
@piyush-malaviya
piyush-malaviya / BasicOTA.h
Last active May 24, 2020
ESP8266/ESP32 Upload program over the air (OTA)
View BasicOTA.h
//#include <WiFi.h> // ESP32
//#include <ESPmDNS.h> // ESP32
#include <ESP8266WiFi.h> // ESP8266
#include <ESP8266mDNS.h> // ESP8266
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
void setupOTA(char ssid[], char password[]) {
Serial.begin(115200);
Serial.println("Booting");
View AccessibilityUtils.java
import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.GestureDescription;
import android.content.Context;
import android.graphics.Path;
import android.graphics.Rect;
import android.os.Build;
import android.provider.Settings;
import android.support.annotation.RequiresApi;
import android.text.TextUtils;
import android.util.Log;
View Global Exception Handling on android
Stackoverflow Link: https://stackoverflow.com/a/19968400
Handle uncaughtException, start activity:
public class MyApplication extends Application
{
public void onCreate ()
{
// Setup handler for uncaught exceptions.
Thread.setDefaultUncaughtExceptionHandler (new Thread.UncaughtExceptionHandler()
@piyush-malaviya
piyush-malaviya / MultiPartUtility.java
Created Nov 27, 2019 — forked from Antarix/MultiPartUtility.java
Uploading Multiple files at once with Post and Header parameter in Android
View MultiPartUtility.java
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
View DisplayUtils.java
import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.util.DisplayMetrics;
public class DisplayUtils {
private static DisplayUtils instance;
public static DisplayUtils getInstance() {
View sms_retriever_hash_v9.sh
Save the raw script file locally then run chmod u+x sms_retriever_hash_v9.sh
Stackoverflow: https://stackoverflow.com/questions/53849023/android-sms-retriever-api-computing-apps-hash-string-problem
View RegexUtils.java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexUtils {
//private static final String DISTANCE_PATTERN = "(?i)[0-9]{1,2}\\s??(?:mi|mile|miles|km)\\b";
private static final String DISTANCE_PATTERN = "(?i)((?:\\d+)?\\.?\\d+)\\s??(?:mi|mile|miles|km)\\b";
private static final String DISTANCE_UNIT_PATTERN = "(?i)(?:mi|mile|miles|km)\\b";
private static final String TIME_PATTERN = "(?i)[0-9]{1,2}\\s??(?:min|hr)";
private static final String TIME_UNIT_PATTERN = "(?i)(?:min|hr)";
@piyush-malaviya
piyush-malaviya / DeCryptor.java
Created Jun 21, 2019 — forked from JosiasSena/DeCryptor.java
Encryptor and Decryptor for data encryption.decryption using the Android KeyStore.
View DeCryptor.java
/**
_____ _____ _
| __ \ / ____| | |
| | | | ___| | _ __ _ _ _ __ | |_ ___ _ __
| | | |/ _ \ | | '__| | | | '_ \| __/ _ \| '__|
| |__| | __/ |____| | | |_| | |_) | || (_) | |
|_____/ \___|\_____|_| \__, | .__/ \__\___/|_|
__/ | |
|___/|_|
*/