Skip to content

Instantly share code, notes, and snippets.

View gbrault's full-sized avatar
🏠
Working from home

Gilbert Brault gbrault

🏠
Working from home
  • Vence
View GitHub Profile
@gbrault
gbrault / load iframe including script
Last active April 18, 2016 07:37
How to load scripts in an iframe
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>frame</title>
</head>
<body>
<div id="test"></div>
@gbrault
gbrault / angular js function call
Last active July 19, 2016 11:36
How to call functions or watch variables in NODE-RED UI (angular.js)
<script>
(function(scope) {
scope.name = "Here I am!!!";
/* scope.fun = function(val){alert(val);return val}; */
scope.$watch('msg.payload', function(newValue, oldValue) {
/* Do something clever here */
if(!angular.equals(newValue, oldValue)){
alert(newValue);
}
});
@gbrault
gbrault / Play sound with Node-RED UI
Created July 19, 2016 12:01
Add this code in a Node-Red UI "Template" node
<script>
var playSound = (function beep() {
var snd = new Audio("data:audio/wav;base64,//uQRAAAAWMSLwUIYAAsYkXgoQwAEaYLWfkWgAI0wWs/ItAAAGDgYtAgAyN+QWaAAihwMWm4G8QQRDiMcCBcH3Cc+CDv/7xA4Tvh9Rz/y8QADBwMWgQAZG/ILNAARQ4GLTcDeIIIhxGOBAuD7hOfBB3/94gcJ3w+o5/5eIAIAAAVwWgQAVQ2ORaIQwEMAJiDg95G4nQL7mQVWI6GwRcfsZAcsKkJvxgxEjzFUgfHoSQ9Qq7KNwqHwuB13MA4a1q/DmBrHgPcmjiGoh//EwC5nGPEmS4RcfkVKOhJf+WOgoxJclFz3kgn//dBA+ya1GhurNn8zb//9NNutNuhz31f////9vt///z+IdAEAAAK4LQIAKobHItEIYCGAExBwe8jcToF9zIKrEdDYIuP2MgOWFSE34wYiR5iqQPj0JIeoVdlG4VD4XA67mAcNa1fhzA1jwHuTRxDUQ//iYBczjHiTJcIuPyKlHQkv/LHQUYkuSi57yQT//uggfZNajQ3Vmz+Zt//+mm3Wm3Q576v////+32///5/EOgAAADVghQAAAAA//uQZAUAB1WI0PZugAAAAAoQwAAAEk3nRd2qAAAAACiDgAAAAAAABCqEEQRLCgwpBGMlJkIz8jKhGvj4k6jzRnqasNKIeoh5gI7BJaC1A1AoNBjJgbyApVS4IDlZgDU5WUAxEKDNmmALHzZp0Fkz1FMTmGFl1FMEyodIavcCAUHDWrKAIA4aa2oCgILEBupZgHvAhEBcZ6joQBxS76AgccrFlczBvKLC0QI2cBoCFvfTDAo7eoOQInqDPBtvrDEZBNYN5xwNwxQRfw8ZQ5wQVLvO8OYU+mHvFLlDh05Mdg7BT6YrRPpCBznMB2r//xKJjyyOh+cImr2/4doscwD6neZjuZR4AgAABYAAAABy1xcdQtxYBYYZdifkU
@gbrault
gbrault / noderedmultiplex.json
Last active August 2, 2016 12:12
multiplexing messages between nodered server and client ui (node-red ui) see first comment for usage
[{"id":"a280b0ca.203e2","type":"ui_template","z":"78b2e9d1.c8c848","tab":"635f39f2.c5f958","name":"","group":"","order":1,"format":"<pre>--{{msg.payload}}--{{msg.sender}}--</pre><br>\nv1:{{v1}}<br>\nv2:{{v2}}<br>\nv3:{{v3}}<br>\n<script>\n(function(scope) {\n scope.v1=\"\";\n scope.v2=\"\";\n scope.v3=\"\";\n scope.$watch('msg.sender', function(newValue, oldValue) {\n if((this.msg===undefined)||(this.msg===null)){console.log(\"msg not defined\");return;}\n switch(this.msg.sender.substr(0,1)){\n case \"1\":\n this.v1=this.msg.payload;\n break;\n case \"2\":\n this.v2=this.msg.payload;\n break;\n case \"3\":\n this.v3=this.msg.payload;\n break;\n default:\n console.log(\"not existing case:\"+this.msg.sender);\n }\n }.bind(scope));\n})(scope);\n</script>","storeOutMessages":true,"fwdInMessages":true,"x":695,"y":204,"wires":[[]]},{
@gbrault
gbrault / Horizontal marimekko
Last active November 5, 2016 10:38
marimekko
Original work from http://www.clearlyandsimply.com/clearly_and_simply/2014/05/marimekko-charts-in-microsoft-excel.html
https://github.com/gbrault/gistfiles/blob/master/marimekko_template%20Vertical.xlsm
Transfomed work (see excel file marimekko_template - Horizontal Final):
https://github.com/gbrault/gistfiles/blob/master/marimekko_template%20-%20Horizontal%20Final.xlsm
look clearly and simply post for usage
Changes:
- Totals (rows, cols) and Competitors suppressed from initial schema
- Rows becomes Columns (Horizontal Marimekko)
- Cell A1 of "Colors" sheet is the thresold % to hide names
- names displayed instead of values
@gbrault
gbrault / node-red-dashboard.txt
Created November 10, 2016 09:55
How to extend node red dashboard: development setup
1. Make sure you have removed all global instances of node-red and dashboard on the developement machine
2. In a shell session (shell_1), create a directory to install node-red
3. cd this dir (node-red)
4. npm init
5. npm i node-red
6. cd node_modules/node-red
7. npm start
8. stop => the .node-red directory in <user> default directory should then be created
9. In a new shell (shell_2): cd <user>/.node-red/node_modules
10. git clone https://github.com/node-red/node-red-dashboard.git
Node-Red is a great piece of work but lake three key features:
* A file browser and editor
* A remote console
* An SQL manager for Sqlite
To extend Node-RED, three piece of software of interest
* ShellInABox: [see](https://github.com/shellinabox/shellinabox) a very nice https Linux console
* CloudCmd: [see](https://github.com/coderaiser/cloudcmd) a file and editor browser with a console as well (but less conformant than ShellInAbox)
* nrsqljs: [see](https://github.com/gbrault/nrsqljs) an SQL manager to browse and edit database tables for sqlite
@gbrault
gbrault / shrinksqlite3.js
Created November 15, 2016 16:21
How to shrink sqlite3.node verbose output for big tables
var sqlite3=require('sqlite3');
var pgu={
db: {},
res: {},
all: function (topic,bind=[]){
this.db.all(topic, bind, function(err, row) {
if (err) { console.log(err,msg); return null;}
else {
this.res=row;
console.log(JSON.stringify(this.res));
@gbrault
gbrault / cloudcmd.json
Last active November 20, 2016 17:37
start cloudcmd as a daemon with node-red
[
{
"id": "1e5321cd.1e8eee",
"type": "debug",
"z": "165dee9e.7db461",
"name": "",
"active": false,
"console": "false",
"complete": "true",
"x": 567.5,
@gbrault
gbrault / embeddcldcmd.json
Created November 20, 2016 17:39
Embedding a cloudcmd iframe into a node-red ui
[{"id":"b84481db.dc536","type":"ui_template","z":"9a1b4d5d.5c1f8","group":"1b2ddeac.a9d561","name":"File Browser & Editor","order":0,"width":"27","height":"15","format":"<iframe id=\"cloudcmd\" seamless width=\"100%\" height=\"100%\"></iframe>\n<script>\n(function(scope) {\n // debugger;\n window.ifr = document.getElementById(\"cloudcmd\");\n window.ifr.src=\"http://\"+window.location.hostname+\"/cldcmd\";\n})(scope);\n</script>","storeOutMessages":true,"fwdInMessages":true,"x":528,"y":218,"wires":[[]]},{"id":"1b2ddeac.a9d561","type":"ui_group","z":"","name":"Console","tab":"ed7c4d56.dbdb2","disp":false,"width":"27"},{"id":"ed7c4d56.dbdb2","type":"ui_tab","z":"","name":"File Browser","icon":"dashboard","order":4}]