Skip to content

Instantly share code, notes, and snippets.

Avatar

Henrik Blidh hbldh

View GitHub Profile
@hbldh
hbldh / bleak_characteristics_explorer_for_windows.py
Last active Mar 27, 2019
GATT Characteristics Explorer for Bleak running on Windows
View bleak_characteristics_explorer_for_windows.py
import logging
import asyncio
from bleak import BleakClient, BleakError
from bleak.uuids import uuidstr_to_str
# Python representation of <class 'Windows.Devices.Bluetooth.GenericAttributeProfile.GattCharacteristicProperties'>
GattCharacteristicsPropertiesEnum = {
None: ("None", "The characteristic doesn’t have any properties that apply"),
1: ("Broadcast", "The characteristic supports broadcasting"),
@hbldh
hbldh / data_collector.py
Last active Aug 29, 2020
MetaWear linear acceleration reading example (requires matplotlib for plotting)
View data_collector.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
import time
from pymetawear.discover import select_device
from pymetawear.client import MetaWearClient
@hbldh
hbldh / accelerometer_logging.py
Last active Apr 20, 2018
Logging in PyMetaWear
View accelerometer_logging.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
:mod:`accelerometer_logging`
==================
Created by hbldh <henrik.blidh@nedomkull.com>
Created on 2018-04-20
"""
@hbldh
hbldh / keyconv.py
Last active Mar 17, 2019
Convert a ssh-keygen public key to XML format for C# use.
View keyconv.py
def convert_openssh_key_to_xml(key, verbose=False):
"""Convert Public Key to XML format for C# usage.
See http://stackoverflow.com/a/13104466 for details.
.. code-block: python
>>> public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDz[...]"
>>> xml_public_key = convert_openssh_key_to_xml(public_key, verbose=True)
>>> print(xml_public_key)
@hbldh
hbldh / localize.ino
Created Nov 28, 2016
Particle Photon with Pozyx
View localize.ino
// This #include statement was automatically added by the Particle IDE.
#include "Pozyx/Pozyx.h"
#include "Pozyx/Pozyx_definitions.h"
#define BYTE_TO_BINARY(byte) \
(byte & 0x80 ? '1' : '0'), \
(byte & 0x40 ? '1' : '0'), \
(byte & 0x20 ? '1' : '0'), \
(byte & 0x10 ? '1' : '0'), \
(byte & 0x08 ? '1' : '0'), \
View accelerometer_generic.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
accelerometer_generic
=====================
Created by hbldh <henrik.blidh@nedomkull.com>
Created on 2016-08-26
"""
@hbldh
hbldh / keybase.md
Last active Aug 26, 2016
Keybase.io
View keybase.md

Keybase proof

I hereby claim:

  • I am hbldh on github.
  • I am hbldh (https://keybase.io/hbldh) on keybase.
  • I have a public key ASBSUjwfOP5idY55R1LuI08GgBiI-sNLr7IM4TdBfTxcXQo

To claim this, I am signing this object:

@hbldh
hbldh / dict_memory_foray.py
Last active May 24, 2016
Code for blog post "JSON and the Python dictionary"
View dict_memory_foray.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
dict_memory_foray
~~~~~~~~~~~~~~~~~
:copyright: 2016 by Henrik Blidh <henrik.blidh@nedomkull.com>
"""
@hbldh
hbldh / size_estimator.py
Created May 23, 2016
A method for recursively calculating the size of a Python dict in memory.
View size_estimator.py
import sys
def calculate_document_size_in_memory(doc):
"""A "size in memory" estimator for JSON documents/dicts.
:param doc: The document or list of documents to find size of.
:type doc: dict or list
:return: The size of the input document(s) in bytes.
:rtype: int
@hbldh
hbldh / records_mssql.py
Last active Mar 9, 2016
How to connect to a SQL Server 2012 on Azure using Records and pymssql as driver.
View records_mssql.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
:mod:`records_mssql`
===================
Created by hbldh <henrik.blidh@nedomkull.com>
Created on 2016-03-08
How to connect to Microsoft Azure SQL Server 2012 using PyMSSQL package.
You can’t perform that action at this time.