Skip to content

Instantly share code, notes, and snippets.

View jthomas's full-sized avatar
💻
serverless all the things.

James Thomas jthomas

💻
serverless all the things.
View GitHub Profile
@jthomas
jthomas / README.md
Last active February 20, 2023 20:52
OpenWhisk Workshop

OpenWhisk Workshop

Hello 👋.

This workshop will teach you how to develop serverless applications, composed of loosely coupled microservice-like functions, using an open-source serverless platform.

Starting with getting the development environment set up, it'll move onto creating, deploying and invoking serverless functions for multiple runtimes. Once you are comfortable creating serverless functions, the next step is to connect functions to events, like message queues, allowing microservices to fire automatically. Finally, we'll demonstrate how to expose serverless functions as public API endpoints, allowing to build serverless web applications.

Welcome to the future of cloud development, you'll never want to manage another server again 😎.

@jthomas
jthomas / docker
Created October 19, 2017 14:43
Pushing logs over Lumberjack protocol using Node.js
$ docker run -p 5601:5601 -p 9200:9200 -p 5000:5000 -it --name old_elk sebp/elk:es241_l240_k461
@jthomas
jthomas / wake_up.js
Last active October 27, 2017 13:26
Apache OpenWhisk Advanced Alarm Schedule Events
var openwhisk = require('openwhisk');
var request = require('request-promise');
function getNextSunrise(lat, lng, when) {
const options = {
uri: 'https://api.sunrise-sunset.org/json',
qs: { lat: lat, lng: lng, when: when },
json: true
}
@jthomas
jthomas / counter.js
Created December 11, 2017 14:11
OpenWhisk Action - Storing State Without a Database
const openwhisk = require('openwhisk');
const main = async evt => {
const count = (evt.count || 0) + 1
// use client library to retrieve current function configuration
const ow = openwhisk()
const action = await ow.actions.get('counter')
// update default parameters with new value
@jthomas
jthomas / action.json
Last active January 31, 2021 04:16
IBM Cloud Monitoring service (Grafana) dashboards for monitoring IBM Cloud Functions (OpenWhisk) application metrics
{
"annotations": {
"list": []
},
"editable": true,
"gnetId": null,
"graphTooltip": 0,
"hideControls": false,
"id": 2309,
"links": [],
@jthomas
jthomas / package.json
Last active September 24, 2023 21:58
Using TensorFlow.js with MobileNet models for image classification on Node.js
{
"name": "tf-js",
"version": "1.0.0",
"main": "script.js",
"license": "MIT",
"dependencies": {
"@tensorflow-models/mobilenet": "^0.2.2",
"@tensorflow/tfjs": "^0.12.3",
"@tensorflow/tfjs-node": "^0.1.9",
"jpeg-js": "^0.3.4"
@jthomas
jthomas / index.js
Created August 10, 2018 11:44
Serverless Machine Learning With TensorFlow.js and IBM Cloud Functions (Apache OpenWhisk)
const tf = require('@tensorflow/tfjs')
const mobilenet = require('@tensorflow-models/mobilenet');
require('@tensorflow/tfjs-node')
const jpeg = require('jpeg-js');
const NUMBER_OF_CHANNELS = 3
const MODEL_PATH = 'mobilenet/model.json'
let mn_model
@jthomas
jthomas / primes-with-workers.js
Last active April 10, 2022 13:22
Calculating prime numbers on serverless platforms using Node.js Worker Threads and IBM Cloud Functions (Apache OpenWhisk)
'use strict';
const { Worker } = require('worker_threads');
const os = require('os')
const threadCount = os.cpus().length
const compute_primes = async (start, range) => {
return new Promise((resolve, reject) => {
let primes = []
console.log(`adding worker (${start} => ${start + range})`)
'use strict';
const min = 2
function main(params) {
const { start, end } = params
console.log(params)
const primes = []
let isPrime = true;
for (let i = start; i < end; i++) {
@jthomas
jthomas / workers.js
Created May 10, 2019 15:08
workers.js
'use strict';
const { Worker, isMainThread, parentPort, workerData } = require('worker_threads');
const min = 2
function generatePrimes(start, range) {
const primes = []
let isPrime = true;
let end = start + range;
for (let i = start; i < end; i++) {