Skip to content

Instantly share code, notes, and snippets.

View thomasvnl's full-sized avatar

Thomas V. thomasvnl

  • Dordrecht, The Netherlands
View GitHub Profile
@thomasvnl
thomasvnl / footer.php
Created December 22, 2014 12:34
WordPress Twenty Fifteen Disqus Thread modification to make it blend in with the rest of the template.
@thomasvnl
thomasvnl / nrftest.js
Last active December 14, 2016 22:04
Example of using the nRF24L01+ with Node.js on the Raspberry Pi
var spiDev = "/dev/spidev0.0";
var cePin = 24;
var irqPin = 25;
var nrf = require('nrf');
var radio = nrf.connect(spiDev, cePin, irqPin); // Connect to the radio
radio.channel(0x4c); // Set channel to 76
radio.dataRate('1Mbps') // Set data rate to 1Mbps
radio.crcBytes(2) // Set the CRC to 2
radio.autoRetransmit({
@thomasvnl
thomasvnl / jsonhandler.py
Created February 1, 2016 10:05 — forked from mminer/jsonhandler.py
A JSON request handler for Tornado.
import json
import tornado.web
class JsonHandler(BaseHandler):
"""Request handler where requests and responses speak JSON."""
def prepare(self):
# Incorporate request JSON into arguments dictionary.
if self.request.body:
try:
@thomasvnl
thomasvnl / user.js
Last active July 8, 2017 06:42
NodeJS Mongoose User Schema to be used within a default NodeJS application structure
// file: app/models/user.js
// Get an instance of mongoose and mongoose Schema
var mongoose = require('mongoose'),
bcrypt = require('bcrypt'),
Schema = mongoose.Schema,
SALTINESS = 42;
// Create Schema
var UserSchema = new Schema({
# mdadm --create /dev/md0 --level=1 --raid-devices=(int multiple of 2) /dev/sd* /dev/sd** ...
/*
IoT Manager mqtt device client https://play.google.com/store/apps/details?id=ru.esp8266.iotmanager
Based on Basic MQTT example with Authentication
PubSubClient library v 1.91.1 https://github.com/Imroy/pubsubclient
- connects to an MQTT server, providing userdescr and password
- subscribes to the topic "/IoTmanager" (waiting "HELLO" messages from mobile device)
- publishes config to the topic "/IoTmanager/config/deviceID/"
Tested with Arduino IDE 1.6.7 + ESP8266 Community Edition v 2.1.0-rc2
PubSubClient library v 1.91.1 https://github.com/Imroy/pubsubclient
@thomasvnl
thomasvnl / logging2.json
Created September 7, 2016 06:26 — forked from pmav99/config2.json
Python 3 logging configuration using JSON
{
"logging": {
"version": 1,
"disable_existing_loggers": true,
"formatters": {
"brief": {
"class": "logging.Formatter",
"datefmt": "%I:%M:%S",
"format": "%(levelname)-8s; %(name)-15s; %(message)s"
},
@thomasvnl
thomasvnl / get_item_from_dict_list_by_key_value.py
Last active October 4, 2016 12:55
Return an item from a list of dictionaries by comparing key:value combination
def get_item_from_dict_list_by_key_value(list, key, value):
"""
Return an item from a list by key:value combination if possible
:param list list:
:param str key:
:param * value:
:return dict|None:
"""
for item in list:
if item[key] == value:
@thomasvnl
thomasvnl / promote_item_to_first_position.py
Created October 4, 2016 12:56
Promote an item in a list to the first position
def promote_item_to_first_position(enumerator, key, value):
"""
Promotes an item to the first index of the list if it isn't already there. It moves the item from it's current
position and resets the list's indexes. Be careful to not use this on a giant list, because the operation could
be quite heavy. With small lists the impact is not noticeable.
:param enumerator:
:param key:
:param value:
:return:
"""
@thomasvnl
thomasvnl / get_set_value_by_multilevel_key.py
Created October 4, 2016 12:57
Get and set values by passing in a multilevel key, a data dictionary, and in case of setting also a value
def get_value_by_multilevel_key(key, data):
"""
returns a value by a multilevel key reference e.g. 'object.foo.bar' as key returns the value 10
(see below)
{
object: {
foo:
bar: 10
}
}