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 / 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++) {
'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 / 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 / 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 / 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 / Dockerfile
Created August 1, 2017 13:30
Custom Docker Skeleton for OpenWhisk
FROM openwhisk/dockerskeleton:latest
ADD actionproxy.py /actionProxy/
input {
stdin {
type => "stdin-type"
}
tcp {
port => 5000
type => syslog
}
udp {
port => 5000
@jthomas
jthomas / Dockerfile
Created July 31, 2017 14:16
Custom Docker image for using Python ML libraries on OpenWhisk
FROM openwhisk/python3action
# lapack-dev is available in community repo.
RUN echo "http://dl-4.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
# add package build dependencies
RUN apk add --no-cache \
g++ \
lapack-dev \
gfortran
@jthomas
jthomas / cargo.toml
Created January 18, 2017 15:08
Sample Cargo dependencies for JSON processing
[package]
name = "action"
version = "0.1.0"
authors = ["Me <me@email.com>"]
[dependencies]
rustc-serialize = "0.3"
@jthomas
jthomas / main.rs
Created January 18, 2017 15:05
Sample OpenWhisk Action using Rust
extern crate rustc_serialize;
use rustc_serialize::json;
use rustc_serialize::json::Json;
use std::env;
#[derive(RustcDecodable, RustcEncodable)]
pub struct Greeting {
message: String
}