Skip to content

Instantly share code, notes, and snippets.

@mironovdm
mironovdm / LE_autoconnect_timeout.md
Last active September 24, 2023 00:20
Change LE autoconnect timeout

This tool can read current or change default HCI_LE_AUTOCONN_TIMEOUT value for Bluetooth adapter on Linux. The default value is defined for the kernel 5.15 at include/net/bluetooth/hci.h:

#define HCI_LE_AUTOCONN_TIMEOUT	msecs_to_jiffies(4000)	/* 4 seconds */

and it can be too low if the advertising interval for a device is high (for power saving).

You can also change the value in /etc/bluetooth/main.conf, line LEAutoconnecttimeout. The value in ms and will be applied at boot or when bluetooth service is restarted.

The tool changes timeout to hardcoded value 16000ms. You can change value NEW_LE_AUTOCONN_TIMEOUT in the lower source file to required value .

@mironovdm
mironovdm / c_datetime.md
Last active April 11, 2021 11:10
С datetime functions

<sys/time.h>

int gettimeofday(struct timeval *restrict tv, struct timezone *restrict tz);

<time.h>

int clock_gettime(clockid_t clockid, struct timespec *tp);
int timespec_get(struct timespec *ts, int base);
@mironovdm
mironovdm / gist:1324ea0e9b71eb10fe3c77175296fec4
Last active August 8, 2019 21:14
Python web servers performance
"Hello world" web server benchmarks
HW: Intel Core i7-4700HQ, 8Gb DDR3
Ubuntu 18.04.2 LTS WSL, Python 3.6.7
w= - workers
lat= - avg. latency
SERVER ~RPS
-------------------------------------------
@mironovdm
mironovdm / socket_c.c
Last active April 15, 2021 21:15
C sockets
struct sockaddr {
unsigned short sa_family; // address family, AF_xxx
char sa_data[14]; // 14 bytes of protocol address
};
/* IPv4 AF_INET */
struct sockaddr_in {
short sin_family; // e.g. AF_INET, AF_INET6
unsigned short sin_port; // e.g. htons(3490)
@mironovdm
mironovdm / dict_attr.py
Last active February 6, 2019 12:56
Dictionary with accessing keys like an attributes
class DictWithAttributeAccess(dict):
def __getattr__(self, key):
return self[key]
def __setattr__(self, key, value):
self[key] = value
class AttrDict: