Skip to content

Instantly share code, notes, and snippets.

Avatar
🖥️

Mohammed Al-Ameen mohammed-ali-1

🖥️
View GitHub Profile
@mohammed-ali-1
mohammed-ali-1 / deployment.yaml
Created Mar 15, 2019
deployment.yaml file for mqtt-service-provider
View deployment.yaml
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: mqtt-provider
spec:
replicas: 1
template:
metadata:
labels:
app: mqtt-service-provider
@mohammed-ali-1
mohammed-ali-1 / views.json
Created Mar 15, 2019
views.json file for CouchDB
View views.json
{
"_id": "_design/subscriptions",
"views": {
"host_topic_counts": {
"reduce": "_sum",
"map": "function (doc) {\n emit(doc.url + '#' + doc.topic, 1);\n}"
},
"host_topic_triggers": {
"map": "function (doc) {\n emit(doc.url + '#' + doc.topic, {trigger: doc._id, username: doc.username, password: doc.password});\n}"
},
@mohammed-ali-1
mohammed-ali-1 / addReadingToDb.js
Created Mar 12, 2019
OpenWhisk action that adds a message to the readings database
View addReadingToDb.js
function action(args) {
var request = require('sync-request');
var res = request('POST', 'http://COUCHDB_HOST:COUCHDB_PORT_NUMBER/readings/', {
json: {reading: args},
headers: {
'Content-Type': 'application/json',
},
});
}
@mohammed-ali-1
mohammed-ali-1 / getLatestTenReadings.js
Created Mar 12, 2019
OpenWhisk web action that returns the latest ten entries to the readings database
View getLatestTenReadings.js
function action(args) {
var request = require('sync-request');
var res = request(
'GET',
'http://COUCHDB_HOST:COUCHDB_PORT/readings/_all_docs?limit=10&include_docs=true&ascending=true'
);
var readings = JSON.parse(res.getBody().toString()).rows.map(elem => elem.doc.reading);
return {
body: readings
};
@mohammed-ali-1
mohammed-ali-1 / renderHtml.js
Last active Mar 14, 2019
OpenWhisk web action that returns a HTML page
View renderHtml.js
function main({reading}) {
var script = `
<script>
function latest_readings() {
const Http = new XMLHttpRequest();
//URL to getLatestTenReadings web action
const url='https://OPENWHISK_HOST:OPENWHISK_PORT/api/v1/web/guest/default/getLatestTenReadings';
Http.open("GET", url);