Skip to content

Instantly share code, notes, and snippets.

@molda
molda / apitest.js
Last active September 22, 2021 17:49
Quick API server for testing - Total.js, Schemas, embedded flat file database
require('total.js').http('release'); // default port 8000
NEWSCHEMA('Product').make(function(schema) {
schema.define('name', String, true);
schema.define('price', Number, true);
schema.define('description', String);
// Query products
schema.setQuery(function(error, options, callback) {
@molda
molda / VisualFlow.js
Last active February 15, 2017 18:03
require('total.js').http('debug');
var util = require('util');
var EventEmitter = require('events');
// jen na test
var WSCONTROLLER = {
send: function(data){ console.log(data)}
}
require('total.js');
var Fs = require('fs');
function existsSync(filename, file) {
try {
var val = Fs.statSync(filename);
return val ? (file ? val.isFile() : true) : false;
} catch (e) {
return false;
}
@molda
molda / install.js
Last active November 20, 2017 07:39
Instalation script for Total.js Flow, Flowboard and DashBoard
require('total.js');
var Fs = require('fs');
var packageurl = 'https://cdn.rawgit.com/totaljs/{0}/{1}/{0}.package';
var repourl = 'https://api.github.com/repos/totaljs/{0}/commits';
var repos = ['flow', 'flowboard', 'dashboard'];
var packages = [];
F.path.mkdir(F.path.root('packages'));
@molda
molda / esp_rule_ip_mqtt.md
Created December 31, 2017 12:13
Rules for ESPEasy to report ip every 60s using mqtt

Rules for ESPEasy to report ip every 60s using mqtt

On System#Boot do
 Publish /%sysname%/online,{"ip":"%ip%"}
  timerSet,1,60
endon

On Rules#Timer=1 do
 Publish /%sysname%/online,{"ip":"%ip%"}
 timerSet,1,60
#include <ESP8266WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>
//AP definitions
#define AP_SSID "xxxxx"
#define AP_PASSWORD "xxxxxxxxxxxx"
#define IP_ADDRESS "192.168.0.107"
#define PORT 80
#define NAME "living_room"
@molda
molda / totald
Last active April 8, 2018 09:13
#! /usr/bin/env node
var Path = require('path');
if (process.argv[2] === '--help' || process.argv[2] === '-h') {
console.log('');
console.log('Runs in debug mode on port 8000 by default');
console.log('Add port number to run on different port');
console.log('Example: `$ totald 3000`');
console.log('');
#! /usr/bin/env node
var Path = require('path');
if (process.argv[2] === '--help' || process.argv[2] === '-h') {
console.log('');
console.log('Runs in release mode on port 8000 by default');
console.log('Add port number to run on different port');
console.log('Example: `$ totalr 3000`');
console.log('');
function everage(each) {
var count = 0;
var result = [];
var len = arr.length;
if (!each) {
var val = 0;
for (var i = 0; i < len; i++) {
val += arr[i];
}
return val / len;
@molda
molda / apexradialbar.js
Last active February 6, 2020 09:50
Apex Radial Bar
// <div data-jc="apexradialbar__system.hdd__val:used;max:total;labelformat:(val, max) => val.filesize(2, 'GB', true) + ' / ' + max.filesize(2, 'GB')">HDD</div>
COMPONENT('apexradialbar', '', function(self, config){
var chart, label, formatter2;
var val2, max2;
var converter = function(val, max) {
val2 = val;
max2 = max;
return (val * 100) / max;