Skip to content

Instantly share code, notes, and snippets.

// Requires NodeJS and "noble" module: https://github.com/sandeepmistry/noble
// Based on: https://github.com/sandeepmistry/noble/issues/62
var noble = require('noble');
noble.on('stateChange', function(state) {
if (state === 'poweredOn' ) {
noble.startScanning([], false);
} else {
noble.stopScanning();
}
@taka-wang
taka-wang / example.py
Last active April 14, 2016 14:42
install mosquitto 1.4 on raspberry pi
import paho.mqtt.client as mqtt
# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, rc):
print("Connected with result code "+str(rc))
# Subscribing in on_connect() means that if we lose the connection and
# reconnect then subscriptions will be renewed.
client.subscribe("hello/world")
# The callback for when a PUBLISH message is received from the server.
@taka-wang
taka-wang / install.sh
Created January 19, 2015 05:39
Install vncserver on raspberry pi
sudo apt-get install tightvncserver
sudo nano /etc/init.d/tightvncserver
sudo chmod 755 /etc/init.d/tightvncserver
sudo update-rc.d tightvncserver defaults
# run tightvncserver
@taka-wang
taka-wang / blink.c
Last active March 6, 2016 18:18
Arduino Serial (LED, Servo, meArm)
@taka-wang
taka-wang / .config
Created December 14, 2015 16:02
Linkit Smart 7688 menuconfig
#
# Automatically generated file; DO NOT EDIT.
# OpenWrt Configuration
#
CONFIG_MODULES=y
CONFIG_HAVE_DOT_CONFIG=y
# CONFIG_TARGET_ppc44x is not set
# CONFIG_TARGET_realview is not set
# CONFIG_TARGET_arm64 is not set
# CONFIG_TARGET_sunxi is not set
@taka-wang
taka-wang / hex.go
Last active March 11, 2016 13:59
Hex bytes to string
package main
import (
"fmt"
"encoding/hex"
"strconv"
)
func main() {
a := []byte{0xFF, 0xFA} // []byte{255, 250}
@taka-wang
taka-wang / nodered
Last active March 14, 2016 03:19
node-red init script
#!/bin/sh
#
case "$1" in
start )
echo -n "Starting Node Services: "
sleep 5
cd /usr/bin/
./core > /tmp/core.log 2>&1 &
sleep 2
cd /root/node-red
@taka-wang
taka-wang / main.go
Last active April 16, 2023 18:34
golang mutex
// refer to http://stackoverflow.com/questions/8286806/go-programming-language-mutual-concurrent-execution
// https://gobyexample.com/mutexes
package main
import "sync"
var m sync.Mutex
var wg sync.WaitGroup
func routine1() {
#! /bin/sh
### BEGIN INIT INFO
# Provides: mosquitto
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: mosquitto MQTT v3.1 message broker
# Description:
@taka-wang
taka-wang / _service.md
Created March 19, 2016 07:20
Fixed links with working versions.

Sample service script for debianoids

Look at LSB init scripts for more information.

Usage

Copy to /etc/init.d:

# replace "$YOUR_SERVICE_NAME" with your service's name (whenever it's not enough obvious)