Skip to content

Instantly share code, notes, and snippets.

View jasonbyrne's full-sized avatar

Jason Byrne jasonbyrne

View GitHub Profile
@jasonbyrne
jasonbyrne / asset.ts
Created April 27, 2020 13:56
Figure out different asset domains based on which CDN provider
const hosts = {
cloudFlare: "https://flosports-video.s3.amazon.com",
stackPath: "https://cdn.stackpath.flosports.tv",
};
function isStackPath(request: Request): boolean {
const url = new URL(request.url);
return !!url.hostname.match(/stackpath/);
}
@jasonbyrne
jasonbyrne / webhook.ts
Created September 10, 2020 17:05
Flagpole <3s Ngrok
import flagpole from "flagpole";
import * as ngrok from "ngrok";
flagpole("Just a basic webhook callback", async (suite) => {
// Create webhook scenario
const webhook = await suite
.scenario("Wait for a webhook", "resource")
.webhook("GET /foo")
.next(async (context) => {
context.comment("Webhook was hit!");
@jasonbyrne
jasonbyrne / pubsub.ts
Last active November 19, 2020 01:45 — forked from johnnycardy/pubsub.ts
Simple pub/sub TypeScript class for Angular
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root',
})
export class PubSub {
private topics: { [id: string]: PubSubTopic } = {};
private constructor() {}
@jasonbyrne
jasonbyrne / kv-poc.js
Created February 24, 2021 16:46
Very basic POC to test CloudFlare workers with KV and waitUntil
addEventListener('fetch', event => event.respondWith(handleRequest(event)));
async function handleRequest(event) {
const request = event.request;
// Parse query string
const { searchParams } = new URL(request.url);
let qsName = searchParams.get('name');
// If name in query string, add it to kv async
if (qsName) {
// Run this async to response, but wait for it to complete before terminating
@jasonbyrne
jasonbyrne / exception-handler.ts
Last active December 22, 2021 03:30
Nest JS Exception Handler
import { ExceptionFilter, Catch, ArgumentsHost } from '@nestjs/common';
import { Response } from 'express';
import { IncomingMessage } from 'http';
import { HttpException, HttpStatus } from '@nestjs/common';
export const getStatusCode = (exception: unknown): number => {
return exception instanceof HttpException
? exception.getStatus()
: HttpStatus.INTERNAL_SERVER_ERROR;
};
@jasonbyrne
jasonbyrne / main.ts
Last active December 22, 2021 03:32
NestJS Bootstrap with custom global exception filter
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { GlobalExceptionFilter } from './exception-handler';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useGlobalFilters(new GlobalExceptionFilter());
await app.listen(3000);
}
bootstrap();
@jasonbyrne
jasonbyrne / VariantTemplate.ts
Created December 24, 2021 02:13
Flagpole Template Example for HLS Variant Validation
const variantTemplate = suite.template({
type: "hls",
next: {
"Should be a VOD with more than one segment": async (context) => {
await context.find("type").equals("vod");
const segments = await context.find("segments");
context.assert("There are ts segments", segments).length.greaterThan(1);
context
.assert("Every Segment URI ends with .ts", segments)
.every((segment) => String(segment.uri).endsWith(".ts"));
@jasonbyrne
jasonbyrne / hls.ts
Created December 24, 2021 02:19
Flagpole Suite Example for testing HLS stream manifests
import flagpole from "flagpole";
const masterManifestUrl = "https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8";
flagpole("HLS Testing Demo", async (suite) => {
suite
.scenario("Test Big Buck Bunny", "hls")
.open(masterManifestUrl)
.next(async (context) => {
await context.find("type").equals("master");
@jasonbyrne
jasonbyrne / value-wrapper.ts
Created January 16, 2022 18:01
String Value Wrapper
class WrappedValue {
constructor(
public name: string,
public value: string
) {}
}
const data: WrappedValue[] = [
new WrappedValue("First Name", "Jason"),
new WrappedValue("Last Name", "Byrne")
@jasonbyrne
jasonbyrne / generic-value-wrapper.ts
Created January 16, 2022 18:07
Generic Value Wrapper
class WrappedValue<T> {
constructor(
public name: string,
public value: T
) {}
}
const data: WrappedValue[] = [
new WrappedValue<string>("First Name", "Jason"),
new WrappedValue<string>("Last Name", "Byrne"),