Skip to content

Instantly share code, notes, and snippets.

View hbldh's full-sized avatar

Henrik Blidh hbldh

View GitHub Profile
@hbldh
hbldh / data_collector.py
Last active August 29, 2020 13:33
MetaWear linear acceleration reading example (requires matplotlib for plotting)
#!/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 April 20, 2018 09:56
Logging in PyMetaWear
#!/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 March 17, 2019 23:05
Convert a ssh-keygen public key to XML format for C# use.
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 November 28, 2016 14:13
Particle Photon with Pozyx
// 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'), \
@hbldh
hbldh / accelerometer_generic.py
Created August 26, 2016 14:06
MetaWear-CppAPI tests
#!/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 August 26, 2016 08:26
Keybase.io

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 13:59
Code for blog post "JSON and the Python dictionary"
#!/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 21:09
A method for recursively calculating the size of a Python dict in memory.
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 March 9, 2016 11:30
How to connect to a SQL Server 2012 on Azure using Records and pymssql as driver.
#!/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.