Skip to content

Instantly share code, notes, and snippets.

View lucasjellema's full-sized avatar

Lucas Jellema lucasjellema

View GitHub Profile
@lucasjellema
lucasjellema / pancake-party-0.js
Last active June 24, 2024 07:07
Simulating a birthday party where pancakes are served - this gist describes a naïve approach (no parallel or aysnchronous processing, no use of pipelining) and a smart approach (where those mechanisms are employed). The code demonstrates the use of asynchronous generators in combination with promises.
// pancake party for my son's birthday
// I have promised him pancakes. Each pancake has to be baked, decorated (syrup, sugar, jam, ..) and sliced (in bite size sections)
const numberOfGuests = 8
// assuming each guest eats exactly three pancakes
const totalNumberOfPancakes = numberOfGuests * 3
const numberOfPans = 1
// times in milliseconds
const timeToBakeOnePancake = 3000;
@lucasjellema
lucasjellema / pipelined-sensor-analysis-0
Created May 1, 2019 05:17
ES 2018 Demonstration of Promises, Asynchronous Generators and Pipelining (requires Node 10 or higher) for running agregates
const sleep = (milliseconds) => {
return new Promise(resolve => setTimeout(resolve, Math.floor(milliseconds)))
}
const lg = (msg) => {
const d = new Date()
console.log(`${d.getSeconds()}.${Math.round(d.getMilliseconds() / 100)} - ${msg}`)
}
// each sensor has a slightly randomized timeput period, suggesting a different and somewhat varying production rate of measurements
@lucasjellema
lucasjellema / pipelined-sensor-analysis-1.js
Created May 1, 2019 05:19
ES 2018 Demonstration of Promises, Asynchronous Generators and Pipelining (requires Node 10 or higher) - Time Windowed Aggregates
const sleep = (milliseconds) => {
return new Promise(resolve => setTimeout(resolve, Math.floor(milliseconds)))
}
const lg = (msg) => {
const d = new Date()
console.log(`${d.getSeconds()}.${Math.round(d.getMilliseconds() / 100)} - ${msg}`)
}
// each sensor has a slightly randomized timeput period, suggesting a different and somewhat varying production rate of measurements
@lucasjellema
lucasjellema / pipelined-sensor-analysis-1.js
Created May 1, 2019 05:19
ES 2018 Demonstration of Promises, Asynchronous Generators and Pipelining (requires Node 10 or higher) - Time Windowed Aggregates
const sleep = (milliseconds) => {
return new Promise(resolve => setTimeout(resolve, Math.floor(milliseconds)))
}
const lg = (msg) => {
const d = new Date()
console.log(`${d.getSeconds()}.${Math.round(d.getMilliseconds() / 100)} - ${msg}`)
}
// each sensor has a slightly randomized timeput period, suggesting a different and somewhat varying production rate of measurements
@lucasjellema
lucasjellema / welcome.sh
Last active December 18, 2019 14:50
Example of how to call a function in a Linux Shell Script - passing in input parameters and receiving the result from the function (in a way that resembles modern programming languages)
# a global variable
WELCOME_ROOT=Hello
# invoke this function with two arguments:
# 1. (FROM_VAR) the name of the greeter
# 2. (TO_VAR) the name of the greetee
# this function returns a welcoming message
get_welcoming_message()
{
FROM_VAR=$1
const debug = function (debugBuffer, msg) {
// using the full UTC string is a bit heavy handed perhaps; only minutes, seconds and ms would be quite enough, or just the timestamp in ms
debugBuffer.push(`${new Date().toUTCString()} ${msg}`)
}
const spillDebugBeans = function (debugBuffer) {
debugBuffer.forEach(msg => { console.log(`DEBUG: ${msg}`) });
}// spillDebugBeans
const calculateSums = async function (sums) {
@lucasjellema
lucasjellema / debug-upon-error-2.js
Created July 7, 2020 14:41
Collect debug messages to only print to output when an exception occurs
const debugBuffer = []
const savepoints = {}
const debug = function (msg) {
// using the full UTC string is a bit heavy handed perhaps; only minutes, seconds and ms would be quite enough, or just the timestamp in ms
debugBuffer.push(`${new Date().toUTCString()} ${msg}`)
}
const setSavepoint = function (savepoint) {
savepoints[savepoint] = debugBuffer.length
@lucasjellema
lucasjellema / readme.md
Last active December 5, 2023 09:22
OCI NoSQL Database SQL

To create the table, we need a DDL statement - it still feels weird to say stuff like that regarding a NoSQL database

CREATE TABLE TWEETS_TABLE(id LONG, text STRING, author STRING, tweet_timestamp TIMESTAMP(0), language STRING, hashtags STRING, PRIMARY KEY(SHARD(id))) USING TTL 1 DAYS

This can be done in OCI CLI. It is convenient to first set the compartment OCID

export COMPARTMENT_OCID=ocid................................

Then:

@lucasjellema
lucasjellema / build_specification.yaml
Last active April 24, 2023 09:58
function tweetretriever build specification file
version: 0.1
component: build
timeoutInSeconds: 6000
runAs: root
shell: bash
env:
# these are local variables to the build config
variables:
FUNCTION_DIRECTORY: "tweet_retriever_source/functions/tweet-summarizer"
# # the value of a vaultVariable is the secret-id (in OCI ID format) stored in the OCI Vault service
@lucasjellema
lucasjellema / functions.tf
Created November 29, 2021 21:42
terraform composite for function on OCI
### Repository in the Container Image Registry for the container images underpinning the function
resource "oci_artifacts_container_repository" "container_repository_for_function" {
# note: repository = store for all images versions of a specific container image - so it included the function name
compartment_id = var.compartment_ocid
display_name = "${local.ocir_repo_name}/${var.function_name}"
is_immutable = false
is_public = false
}
resource "null_resource" "Login2OCIR" {