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 / create table.gv
Last active December 14, 2016 17:12
CREATE TABLE graphviz file
strict digraph CT {
rankdir=LR
splines=ortho
node [style=rounded]
node [shape=box]
begin [shape=doublecircle]
point0 [shape=point]
point1 [shape=point]
point2 [label="2" shape=circle]
@gbrault
gbrault / knex 2.0
Created December 9, 2016 17:24
sqlite with search
[{"id":"226b6388.c3db4c","type":"function","z":"e81c960d.042c08","name":"sql exec","func":"var statements = msg.payload.split(\";\");\nflow.set('responses',[]);\nflow.set('statements',statements);\nflow.set('count',0);\nflow.set('exec', function(){\n context.global.knex.raw(flow.get('statements')[flow.get('count')]).then(\n\t function(resp){\n\t var responses = flow.get('responses');\n\t responses.push(resp);\n\t flow.set('count',flow.get('count')+1);\n\t if(flow.get('count')>=flow.get('statements').length){\n\t msg.payload = JSON.stringify(responses);\n\t msg.headers = {\n 'Content-type' : 'application/json'\n };\n\t node.send(msg);\n\t } else {\n\t flow.get('exec')();\n\t }\n\t }\n );\n} );\nflow.get('exec')();\nreturn null;","outputs":1,"noerr":0,"x":469,"y":159,"wires":[["ce9475a6.52c3d8","c6d5f352.65145"]]},{"id":"3faa0dfa.2ea942","type":"inject","z":"e81c960d.042c08","name
@gbrault
gbrault / knex.json
Last active December 8, 2016 17:57
display sqlite tables in node-red
[{"id":"8484baf5.275938","type":"function","z":"5479c4bc.d53f9c","name":"sql exec","func":"var statements = msg.payload.split(\";\");\nflow.set('responses',[]);\nflow.set('statements',statements);\nflow.set('count',0);\nflow.set('exec', function(){\n context.global.knex.raw(flow.get('statements')[flow.get('count')]).then(\n\t function(resp){\n\t var responses = flow.get('responses');\n\t responses.push(resp);\n\t flow.set('count',flow.get('count')+1);\n\t if(flow.get('count')>=flow.get('statements').length){\n\t msg.payload = JSON.stringify(responses);\n\t msg.headers = {\n 'Content-type' : 'application/json'\n };\n\t node.send(msg);\n\t } else {\n\t flow.get('exec')();\n\t }\n\t }\n );\n} );\nflow.get('exec')();\nreturn null;","outputs":1,"noerr":0,"x":413,"y":106,"wires":[["3c0038e1.30eaa8","85edeaec.462b58","44d17862.358b98"]]},{"id":"4e5783cd.149e3c","type":"inject","z":"547
@gbrault
gbrault / table.html
Created December 4, 2016 12:04
Node-Red dynamic Table template
<table>
<tr>
<th ng-repeat="(key,value) in table[0]">{{key}}</th>
</tr>
<tbody ng-repeat="row in table">
<tr ng-if="$even">
<td ng-repeat="(key,value) in row">{{value}}</td>
</tr>
<tr ng-if="$odd">
<td style="background-color:#f1f1f1" ng-repeat="(key,value) in row">{{value}}</td>
@gbrault
gbrault / fnr.bat
Created December 3, 2016 15:59
forever for node-red
forever --minUptime 20000 -d --workingDir ~<user directory> start %appdata%/npm/node_modules/node-red/red.js --settings <user directory>/.node-red/settings.js
[{"id":"b4136f45.81f27","type":"ui_text_input","z":"90462ac9.788148","name":"","label":"","group":"77c4cf05.cef57","order":2,"width":0,"height":0,"passthru":true,"mode":"text","delay":"0","topic":"","x":150,"y":102,"wires":[["db45416a.678c5"]]},{"id":"db45416a.678c5","type":"daemon","z":"90462ac9.788148","command":"ssh","args":"user@machine","cr":true,"redo":true,"op":"buffer","name":"","x":380,"y":102.5,"wires":[["ee20a566.57ebf8","67fcd515.3cfebc"],["289c9c07.d36f94","2af2373b.536088"],["790fd57b.3de79c"]]},{"id":"ee20a566.57ebf8","type":"function","z":"90462ac9.788148","name":"cast","func":"msg.payload=String.fromCharCode.apply(null,msg.payload);\n//node.warn(msg.payload.charCodeAt(0));\nif(msg.payload.indexOf(\">>>\")===0) return null;\nreturn msg;","outputs":1,"noerr":0,"x":599,"y":87,"wires":[["717c5dc2.1e7c24","30441594.f5bb1a"]]},{"id":"289c9c07.d36f94","type":"function","z":"90462ac9.788148","name":"cast","func":"msg.payload=String.fromCharCode.apply(null,msg.payload);\n//node.warn(msg.payload.charCo
@gbrault
gbrault / graph.json
Created November 23, 2016 17:27
create curves in node-red from template
[{"id":"ecd919a.85e57e8","type":"ui_template","z":"b2c9878b.bf87d8","group":"d8a1c35b.64585","name":"2 line charts time series","order":0,"width":"27","height":"10","format":"<nvd3-line-chart\n data=\"msg.Data\"\n id=\"exampleId\"\n width=1000\n height=300\n showXAxis=\"true\"\n xAxisTickFormat=\"xAxisTickFormatFunction()\"\n xaxisshowmaxmin=\"false\"\n xaxisstaggerlabels=\"true\"\n showYAxis=\"true\"\n yAxisTickFormat=\"yAxisTickFormatFunction()\"\n yaxisshowmaxmin=\"false\"\n tooltips=\"true\"\n interactive=\"true\"\n showLegend=\"true\"\n useInteractiveGuideLine=\"true\"\n callback=\"callbackFunction()\">\n</nvd3-line-chart>\n<md-button class=\"md-raised md-primary\" ng-click=\"reset()\">Reset</md-button>\n<script>\n(function(scope) {\n scope.flipflop=0;\n scope.range=[0,0];\n // console.log(scope);\n // debugger;\n scope.reset = function() {\n this.msg.range=null;\n this.send(this.msg);\n }.bind(scope);\n \n scope.xAxisT
@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}]
@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 / 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));