Skip to content

Instantly share code, notes, and snippets.

@prantae
prantae / filter_ble.kt
Created April 17, 2023 12:27
Filter device using service id during scan
private val gattCallback = object : BluetoothGattCallback() {
override fun onConnectionStateChange(gatt: BluetoothGatt, status: Int, newState: Int) {
super.onConnectionStateChange(gatt, status, newState)
if (newState == BluetoothProfile.STATE_CONNECTED) {
gatt.discoverServices() // Discover services when connected
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
// Handle disconnection
}
}
@prantae
prantae / asyncio_parallel.py
Last active April 21, 2023 11:01
Here's an example of creating multiple tasks with asyncio, running them in parallel, and waiting for them to complete:
import asyncio
async def task_1():
print("Task 1 started")
await asyncio.sleep(1)
print("Task 1 completed")
return "Task 1 result"
async def task_2():
print("Task 2 started")
@prantae
prantae / tk_asyncio.py
Created April 21, 2023 11:03
Use asyncio inside a class-based tkinter application by running the asyncio event loop in a separate thread and using tkinter to communicate between the threads.
import asyncio
import threading
import tkinter as tk
class App(tk.Tk):
def __init__(self):
super().__init__()
self.label = tk.Label(self, text="Click the button to start the task.")
self.label.pack()
package com.meditivern.meditivemodule
import android.util.Log
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.WritableArray
import com.facebook.react.bridge.WritableMap
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject
// Full Double Metaphone in pure JavaScript
function doubleMetaphone(word) {
word = word.toUpperCase().trim();
if (!word) return ["", ""];
let primary = "";
let alternate = "";
let index = 0;
function isVowel(ch) {