Skip to content

Instantly share code, notes, and snippets.

View dp-singh's full-sized avatar
🎯
Focusing

Dharmendra Pratap Singh dp-singh

🎯
Focusing
View GitHub Profile
@dp-singh
dp-singh / ImageProcessor.java
Last active August 9, 2023 14:27
sample to show how to achieve rate limiter
import android.graphics.Bitmap;
import android.os.Handler;
import android.os.Looper;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
public class ImageProcessor {
private final ExecutorService executor = Executors.newSingleThreadExecutor();
@dp-singh
dp-singh / adb logs
Created August 10, 2022 10:33
Logs to share
XXXXXXX: data at index: 197 is:0.0
2022-08-10 11:32:22.552 9472-11151/com.horussight.app D/OCVTOOLS: XXXXXXXXXXXXX: data at index: 198 is:0.0
2022-08-10 11:32:22.553 9472-11151/com.horussight.app D/OCVTOOLS: XXXXXXXXXXXXX: data at index: 199 is:0.0
2022-08-10 11:32:22.553 9472-11151/com.horussight.app D/OCVTOOLS: XXXXXXXXXXXXX: data at index: 200 is:0.0
2022-08-10 11:32:22.553 9472-11151/com.horussight.app D/OCVTOOLS: XXXXXXXXXXXXX: data at index: 201 is:0.0
2022-08-10 11:32:22.553 9472-11151/com.horussight.app D/OCVTOOLS: XXXXXXXXXXXXX: data at index: 202 is:0.0
2022-08-10 11:32:22.553 9472-11151/com.horussight.app D/OCVTOOLS: XXXXXXXXXXXXX: data at index: 203 is:0.0
2022-08-10 11:32:22.553 9472-11151/com.horussight.app D/OCVTOOLS: XXXXXXXXXXXXX: data at index: 204 is:0.0
2022-08-10 11:32:22.553 9472-11151/com.horussight.app D/OCVTOOLS: XXXXXXXXXXXXX: data at index: 205 is:0.0
2022-08-10 11:32:22.554 9472-11151/com.horussight.app D/OCVTOOLS: XXXXXXXXXXXXX: data at index: 206 is:0.0
@dp-singh
dp-singh / resolution.kt
Created March 7, 2022 16:24
Change resolution function.
protected fun changeResolution(
api: UsbServiceApi,
resolution: CameraResolution = CameraResolution.SD,
afterUpdate: (() -> Unit)? = null
) {
lifecycle.coroutineScope.launch(UsbScheduler.dispatcher) {
if (!api.connectedDevice().isPresent) {
Timber.tag(TAG)
.e("Change resolution is called without the video device height=${resolution.height} width=${resolution.width}")
return@launch
@dp-singh
dp-singh / ActivityExt.kt
Created March 8, 2021 07:44
Auto Grant Requested Permissions to Self if Device Admin is enabled. MDM
private fun Activity.autoGrantRequestedPermissionsToSelf(componentName: ComponentName) {
val permissions: List<String> = retrievePermissions(this)
val mDevicePolicyManager = this.getSystemService(AppCompatActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
if (mDevicePolicyManager.isAdminActive(componentName)) {
Log.d("PERMISSION", "Device Admin enabled")
} else {
Log.d("PERMISSION", "Device Admin Disabled")
}
for (permission in permissions) {
val result = mDevicePolicyManager.getPermissionGrantState(componentName, packageName, permission)
@dp-singh
dp-singh / custometype.tx
Last active January 18, 2018 04:04
Typescript custom type
//JSON is way of communication between client and server
//custom type
type Task={
id: number;
title: string;
detail: string;
@dp-singh
dp-singh / loop.tx
Created January 18, 2018 03:04
Type Script loop
//declaration of array
var arr: number[];
//initilization of array
arr = [1, 2, 3, 4, 5, 5, 6, 7, 8]
//for loop
@dp-singh
dp-singh / java
Last active March 15, 2017 11:07
Location Observable using RxJava and retrolambda
import android.app.Application;
import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Looper;
import rx.Observable;
import android.text.TextUtils;
import io.realm.Case;
import io.realm.Realm;
import io.realm.RealmObject;
import io.realm.RealmResults;
public class RealmFullTextSearch {
public static <T extends RealmObject> RealmResults<T> search(Realm realm, Class<T> modelClass, String query, String fieldName, boolean partialSearch){
public class Drawables {
@NonNull
public static Drawable getSelectableDrawableFor(int color) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(
new int[]{android.R.attr.state_pressed},
new ColorDrawable(lightenOrDarken(color, 0.20D))
);
@dp-singh
dp-singh / 0_reuse_code.js
Created May 10, 2016 05:22
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console