Skip to content

Instantly share code, notes, and snippets.

View bojanpotocnik's full-sized avatar

Bojan Potočnik bojanpotocnik

View GitHub Profile
#!/usr/bin/env bash
PACKAGE_NAME=com.my.package
# Block until the PACKAGE_NAME starts and print its PID
adb_wait_pid() { adb shell "until pidof $PACKAGE_NAME; do :; done"; }
# Wait for the app to start and show all its output
adb logcat -v color -v printable --pid $(adb_wait_pid)
@bojanpotocnik
bojanpotocnik / git-archive-with-submodules.sh
Last active June 12, 2023 07:50
Produce .tar.gz archive of a git repository, including all submodules (recursive)
#!/usr/bin/env bash
# git-archive-submodules - A script to produce an archive tar.gz file of the a git module including all git submodules
# The current working directory must be the root of the top-most git repository (script location does not matter)
# Available at https://gist.github.com/bojanpotocnik/e18c90f5993dca7ea495ce82bba1364f
# Based on https://github.com/nzanepro/git-archive-submodules/blob/master/bin/git-archive-submodules.sh
# Final archive file is created in this directory, named "<repository name>-<short hash>.tar.gz"
REPO_DIR="$(git rev-parse --show-toplevel)"
"""
Various utility classes for working with BlueZ via D-Bus
For this to work the following most be executed (installed) on most machines:
1. `sudo apt install bluez bluez-tools`
2. `sudo apt install python3-dbus libgirepository1.0-dev python3-gi`
3. `pip install PyGObject` globally or in the virtual environment
"""
import ctypes
import enum
@bojanpotocnik
bojanpotocnik / c_hexlify.c
Last active June 17, 2020 11:21
Function to get hex string representation of a buffer
/** Get "xx xx xx ..." string representation of the buffer - returned string MUST BE free()-d after use! */
static char * hexlify(const void * buffer, size_t len)
{
const uint8_t * p_buffer = (uint8_t *) buffer;
const size_t str_len = p_buffer ? len * 3 : sizeof("<null>");
char * const str = malloc(str_len);
if (!str) {
LOGE("Could not allocate %d bytes", (int) str_len);
return NULL;
@bojanpotocnik
bojanpotocnik / CLion_Ninja.md
Created August 7, 2019 11:57 — forked from arichardson/CLion_Ninja.md
Ninja support for CLion IDE

Ninja support for CLion IDE (working with newer versions of clion)

This script enables Ninja-powered builds in CLion IDE by wrapping around CMake, which it uses. See my blog post for details.

Disclaimer

This script is provided AS IS with no guarantees given or responsibilities taken by the author. This script relies on undocumented features of CLion IDE and may lead to instability of build and/or IDE. Use it on your own risk under WTFPL terms.

@bojanpotocnik
bojanpotocnik / rpy2_init.py
Created May 14, 2019 09:41
Initialize rpy2 in Python, imported in the file where r("") will be used
import os
import sys
from collections import OrderedDict
from typing import Any, Union
# Numpy and Pandas are sure installed if one wants to use R to do stuff...
import numpy as np
import pandas as pd
@bojanpotocnik
bojanpotocnik / enable_drag_and_drop_on_python_files.py
Created November 15, 2018 13:00
Enable drap-drop functionality on Windows for Python files
import enum
import subprocess
import sys
import winreg
from winreg import *
__author__ = "Bojan Potočnik"
# noinspection SpellCheckingInspection
@bojanpotocnik
bojanpotocnik / WifiScanner.kt
Created August 2, 2017 12:44
WifiScanner with regex including/excluding and LiveData
//package si.um.leis.
import android.arch.lifecycle.LiveData
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.net.wifi.WifiManager
import android.os.Handler
@bojanpotocnik
bojanpotocnik / StdlibCheatSheet.kt
Created June 23, 2017 09:15
Kotlin Standard Library lambdas
@file:Suppress("unused")
import kotlin.*
/*
* Author: Laboratory for Electronic and Information Systems (LEIS)
* Bojan Potocnik
* bojan.potocnik@um.si
*/
@bojanpotocnik
bojanpotocnik / compiler_utils.h
Last active March 22, 2017 07:38
Various C utility macros
/*
* compiler_utils.h
*
* Created: 2016, 2017
* Author: Bojan Potocnik
* info@bojanpotocnik.com
*/
#ifndef COMPILER_UTILS_H__
#define COMPILER_UTILS_H__