Skip to content

Instantly share code, notes, and snippets.

View TotallyInformation's full-sized avatar

Julian Knight TotallyInformation

View GitHub Profile
@TotallyInformation
TotallyInformation / app.coffee
Created April 25, 2012 08:49
Failing to find asset with Connect-assets, Express, CoffeScript
# app.coffee
# We will call this automatically via `node server.js`
# this instanstiates the CoffeeScript compiler and automatically runs app.coffee through it & runs the resulting app.js
# Using `forever server.js` will reload server.js whenever there is a change to a file in the applications folders so we don't have to stop and restart the server when something changes.
# @see http://blogs.planetsoftware.com.au/felix/archive/2012/03/08/coffeeeeeeee.aspx
# -- Require our libaries --
express = require 'express'
@TotallyInformation
TotallyInformation / Capture.PNG
Last active February 29, 2016 08:45
Post data to InfluxDB
Capture.PNG
@TotallyInformation
TotallyInformation / nodered.conf
Created March 16, 2017 00:10 — forked from natcl/nodered.conf
Node-red startup file for Synology (/etc/init)
# only start this service after the httpd user process has started
#start on syno.network.ready
start on runlevel 2
# stop the service gracefully if the runlevel changes to 'reboot'
stop on runlevel [06]
# run the scripts as the 'admin' user. Running as root (the default) is a bad idea.
setuid admin
@TotallyInformation
TotallyInformation / CouchDb
Last active July 26, 2017 07:19
Example code illustrating the use of Tim Hall's Excel JSON classes in Microsoft Outlook
' Functions to read/write CouchDB on localhost
' @dependencies: Reference to 'Microsoft Scripting Runtime', RestHelpers (https://github.com/timhall/Excel-REST)
' VBA Ref: http://msdn.microsoft.com/en-us/library/gg251755%28v=office.15%29.aspx
' Outlook VBA Ref: http://msdn.microsoft.com/en-US/library/ee861520%28v=office.15%29.aspx
Option Explicit
' Replace back-ticks with double quotes for producing valid JSON
@TotallyInformation
TotallyInformation / test.md
Last active December 14, 2018 12:42
Example of GitHub Markdown & Gravizo

Alt text

custom_mark10 digraph G { size ="4,4"; main [shape=box]; main -> parse [weight=8]; parse -> execute;
@TotallyInformation
TotallyInformation / index.html
Created October 23, 2013 09:19
Example of using Node.js to monitor serial output from an Arduino
<!doctype html>
<html lang="en"><head>
<meta charset="utf-8">
<title>Node/Ardiuno Listener</title>
<meta name="description" content="Node/Ardiuno Listener">
<meta name="author" content="Julian Knight">
<link rel="stylesheet" href="css/styles.css?v=1.0">
<style type="text/css">
@TotallyInformation
TotallyInformation / README.md
Created September 7, 2019 16:54
How many node.js packages are installed

Not really a flow, sorry about that, because you need to change directory to the userDir which may be different on different installations.

However, when you are in the right folder, you can issue the following command to find out how many node.js packages you have installed. Including all of the sub-dependencies for every package (e.g. everything!).

npm ls | sed '/deduped$/d' | wc -l

You do need sed and wc though so this will only really work from Linux command lines (including the Windows WSL) - maybe Mac too?

@TotallyInformation
TotallyInformation / README.md
Last active September 7, 2019 17:02
Extract data from a complex HTML table

While Node-RED has some nodes for extracting data from HTML, the nodes are rather simplistic.

To do more complex processing, you can use the cheerio npm module directly. This module is used by the existing nodes but not all of the options are exposed in order to keep the node more easily comprehensible.

I've already published this info on my dev website so I won't repeat everything here. You can find the details at:

https://it.knightnet.org.uk/kb/nr-qa/extract-html-table.html

@TotallyInformation
TotallyInformation / README.md
Created February 11, 2018 21:30
Secure Home Automation Control via a Telegram Bot

Those who know me from the Google group and Slack will know that I have a bit of a "thing" about security. It isn't easy to secure a web service at the best of times and trying to do so via your home network with minimal resources is even harder.

So why not avoid the issue altogether! By instead using a bot with a secure messaging service, you don't need to expose Node-RED or a web server, mess with certificates, authentication and authorisation. Nor worry about how to secure websockets.

The flow listed here demonstrates a simple Telegram bot that shows the current status of a set of wireless switches (in my case that control lights) and that let you turn them on and off via a simple text interaction.

If you want the full details, including pictures and some info on wiring up MQTT and the other dependencies, you can find them on the Totally Information development blog.

@TotallyInformation
TotallyInformation / README.md
Created October 28, 2017 14:33
Example Web REST API with loop through record sets

Quite often, web REST API's return JSON data but are limited to the number of records they return.

Good API's also return the total number of records that could be returned along with the current offset (from start), the record limit and perhaps even a URL that lets you make the next call in the series.

Mailroute is a cloud service that pre-checks email for you, filtering out spam and viruses and letting you white-/black-list sending domains and email addresses.

It has a pretty good API that returns 20 records at a time. So, if you want to return a large number (all) of the white-/black-list entries, you need a flow that will loop through each recordset.

The attached flow does just that. It also makes use of links to keep the looping flow neat. Also uses JSONata in Change nodes instead of function nodes so reducing the level of JavaScript coding knowledge required.