Skip to content

Instantly share code, notes, and snippets.

val context = applicationContext
val pm = context.getSystemService(Context.POWER_SERVICE) as PowerManager
val isIgnoringBatteryOptimizations = pm.isIgnoringBatteryOptimizations(context.packageName)
if (isIgnoringBatteryOptimizations) {
// ✅ App is allowed to run without optimization ("Don't optimize" / "No restrictions")
} else {
// ⚠️ App is still restricted by battery optimization
import os
# Set the directory path
folder_path = './' # Replace with your folder path
# List all files and directories in the folder
all_entries = os.listdir(folder_path)
# Filter only files (exclude directories)
filenames = [f for f in all_entries if os.path.isfile(os.path.join(folder_path, f))]
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
import pandas as pd
# Sample DataFrame
data = {'Name': ['Alice', 'Bob', 'Charlie'],
'Age': [25, 30, 35],
'City': ['New York', 'Los Angeles', 'Chicago']}
df = pd.DataFrame(data)
val screenWidth = LocalConfiguration.current.screenWidthDp.dp.value
val naTextSp = when {
screenWidth < 390 -> 44.sp
else -> 48.sp
}
val uACRValTextSp = when {
screenWidth < 390 -> 20.sp
else -> 22.sp
static uint32_t measure_value_char_add(ble_mus_t * p_mus, const ble_mus_init_t * p_mus_init)
{
uint32_t err_code;
ble_gatts_char_md_t char_md;
ble_gatts_attr_md_t cccd_md;
ble_gatts_attr_t attr_char_value;
ble_uuid_t ble_uuid;
ble_gatts_attr_md_t attr_md;
// Add Measure Value characteristic
BluetoothLEDevice bluetoothLeDevice = await BluetoothLEDevice.FromIdAsync(id);
GattDeviceServicesResult result = await bluetoothLeDevice.GetGattServicesAsync();
if (result.Status == GattCommunicationStatus.Success) {
LogEvent("DEBUG: Services discovered successfully");
foreach (GattDeviceService service in result.Services) {
// Discover characteristics for each service
GattCharacteristicsResult characteristicsResult = await service.GetCharacteristicsAsync();
BluetoothLEDevice bluetoothLeDevice = await BluetoothLEDevice.FromIdAsync(id);
GattDeviceServicesResult result = await bluetoothLeDevice.GetGattServicesAsync();
if (result.Status == GattCommunicationStatus.Success) {
LogEvent("DEBUG: Services discovered successfully");
foreach (GattDeviceService service in result.Services) {
// Discover characteristics for each service
GattCharacteristicsResult characteristicsResult = await service.GetCharacteristicsAsync();
public class ReportGrievanceRequest {
// Initialize the objects
Context context;
ReportGrievanceCallback reportGrievanceCallback;
// Call Constructor to fetch objects
public ReportGrievanceRequest(Context context, ReportGrievanceCallback reportGrievanceCallback) {
this.context = context;
this.reportGrievanceCallback = reportGrievanceCallback;
@neelratanguria
neelratanguria / flask_concurrency.py
Created September 17, 2022 01:09
Example for achieving concurrency in flask endpoint
@signal_blueprint.route('/all-stats',)
async def signal_stats():
tasks = []
titles = []
tasks.append(asyncio.gather(signal_actions.get_total_count()))
titles.append("signal_count")
tasks.append(asyncio.gather(spir_actions.get_total_signal_count()))
titles.append("spir_signal_count")
tasks.append(asyncio.gather(spir_actions.get_total_unseg_features_count()))
def append_parent_path():
import sys
import os
# getting the name of the directory
# where the this file is present.
current = os.path.dirname(os.path.realpath(__file__))
# Getting the parent directory name
# where the current directory is present.
parent = os.path.dirname(current)