Skip to content

Instantly share code, notes, and snippets.

View Danwakeem's full-sized avatar
👹
Cool Crab

Dan Jarvis Danwakeem

👹
Cool Crab
View GitHub Profile
@Danwakeem
Danwakeem / telemetry-service.js
Last active January 21, 2023 14:56
Telemetry Service
const http = require('http');
const { EventEmitter } = require('node:events');
const TelemetryAPIService = ({
extensionIdentifier
}) => {
const baseUrl = `http://${process.env.AWS_LAMBDA_RUNTIME_API}/2022-07-01/telemetry`;
const keepAliveAgent = new http.Agent({ keepAlive: true });
const sandboxHostname = 'sandbox';
const telemetryEventEmitter = new EventEmitter();
@Danwakeem
Danwakeem / telemetry-warm-start.js
Last active January 21, 2023 14:56
Telemetry Warm Start
while(true) {
/**
* When our function resumes we get the response from the .next function and continue.
*
* Once we finish our work and we go back to the top of the while loop we will make
* the call to .next and our code immediately freezes.
*/
logger.log('Extension calling next: ', extensionIdentifier);
const event = await extensionAPIService.next({
extensionIdentifier
@Danwakeem
Danwakeem / telemetry-cold-start.js
Last active January 21, 2023 14:56
Telemetry Cold Start
#!/usr/bin/env node
// The #!/usr/bin/env node is important so that our lambda function
// knows we are trying to run our extension using nodejs.
const { EventTypes, ...extensionAPIService} = require('./api/extensions')();
const TelemetryAPIService = require('./api/telemetry');
const logger = require('./util/logger');
// We use a self invoking function so that our extension code will boot up on lambda start
(async function main () {
@Danwakeem
Danwakeem / extension-service-api.js
Created January 21, 2023 14:12
Extension Service API
const http = require('http');
const ExtensionAPIService = () => {
const baseUrl = `http://${process.env.AWS_LAMBDA_RUNTIME_API}/2020-01-01/extension`;
const keepAliveAgent = new http.Agent({ keepAlive: true });
let extensionId;
const EventTypes = {
Invoke: 'INVOKE',
Shutdown: 'SHUTDOWN',
};
@Danwakeem
Danwakeem / extension-warm-start.js
Created January 21, 2023 14:11
Extension Warm Start
while(true) {
/**
* When our function resumes we get the response from the .next function and continue.
*
* Once we finish our work and we go back to the top of the while loop we will make
* the call to .next and our code immediately freezes.
*/
const event = await extensionAPIService.next({
extensionIdentifier
});
@Danwakeem
Danwakeem / extension-cold-start.js
Created January 21, 2023 14:09
Simple Extension Cold Start Example
#!/usr/bin/env node
// The #!/usr/bin/env node is important so that our lambda function
// knows we are trying to run our extension using nodejs.
const { EventTypes, ...extensionAPIService} = require('./api/extensions')();
const logger = require('./util/logger');
// We use a self invoking function so that our extension code will boot up on lambda start
(async function main () {
@Danwakeem
Danwakeem / dummy.js
Last active October 14, 2021 22:32
Failed coding challenge 🤦‍♂️ (This is what I should have done)
const handleResult = (query, result) => {
const exp = RegExp(`(?<token>${query})`, 'g');
return result.replaceAll(exp, (_, match) => `<b>${match}</b>`);
}
console.log(handleResult('read', 'reading is fun') === '<b>read</b>ing is fun');
console.log(handleResult('read', 'reading is reading') === '<b>read</b>ing is <b>read</b>ing');
console.log(handleResult('s', 'ss is ss') === '<b>s</b><b>s</b> i<b>s</b> <b>s</b><b>s</b>');
@Danwakeem
Danwakeem / capacitor.cache.ts
Created January 18, 2021 14:37
Capacitor cache using modified auth0-react
import { Plugins } from '@capacitor/core';
const { Storage } = Plugins;
export class User {
name?: string;
given_name?: string;
family_name?: string;
middle_name?: string;
nickname?: string;
preferred_username?: string;
@Danwakeem
Danwakeem / .gitignore
Created August 11, 2020 13:39
IoT-Camera-Switch
node_modules
@Danwakeem
Danwakeem / dsn.test.js
Created July 24, 2018 16:53
IBM_DB DSN Test
const Pool = require("ibm_db").Pool;
const ool = new Pool();
const dsn = process.env.dsn;
const client = new Pool({ minPoolSize: 0, maxPoolSize: 0, connectionTimeout: 60 });
client.init(0, dsn);
client.open(dsn, () => console.log('Opened'));
client.open(dsn, () => console.log('Opened'));