Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View hbldh's full-sized avatar

Henrik Blidh hbldh

View GitHub Profile
@hbldh
hbldh / subprocess_thread.py
Created February 4, 2015 09:32
Subprocess with timout. Inspired by http://stackoverflow.com/a/4825933
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
:mod:`subprocess_thread`
========================
.. module:: subprocess_thread
:platform: Unix, Windows
:synopsis:
@hbldh
hbldh / move_photos.py
Last active December 4, 2015 13:50
A simple program for rearranging files, e.g. photos in a photo collection.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
move_photos.py
==================
Created by: hbldh <henrik.blidh@nedomkull.com>
Created on: 2015-12-03, 22:34
"""
@hbldh
hbldh / serial_com_arduino.ino
Last active February 16, 2016 13:58
Sweet Chariot Code
int incomingByte; // a variable to read incoming serial data into
int pwm_a = 5; //PWM control for motor outputs 1 and 2
int pwm_b = 9; //PWM control for motor outputs 3 and 4
int dir_a = 4; //direction control for motor outputs 1 and 2
int dir_b = 8; //direction control for motor outputs 3 and 4
void setup() {
// Initialize serial communication on UART TX/RX
Serial.begin(9600);
@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.
@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 / 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 / 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 / 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 / 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 / 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)