Skip to content

Instantly share code, notes, and snippets.

View jasonbyrne's full-sized avatar

Jason Byrne jasonbyrne

View GitHub Profile
@jasonbyrne
jasonbyrne / universal-install.sh
Created April 21, 2017 03:22
Bash function so you can just say install packageName regardless of apt or yum distro
#!/bin/bash
install(){
isApt=`command -v apt-get`
isYum=`command -v yum`
package=$1
if [ -n "$isApt" ]; then
apt-get -y install $package
elif [ -n "$isYum" ]; then
yum -y install $package
@jasonbyrne
jasonbyrne / php
Last active March 1, 2023 10:39
Beginnings of a Firestore CRUD Library for PHP
<?php
namespace PHPFireStore {
class FireStoreDocument {
private $fields = [];
private $name = null;
private $createTime = null;
private $updateTime = null;
@jasonbyrne
jasonbyrne / hls.ts
Last active June 15, 2018 21:37
Watch an HLS stream on the best rendition and publish an event whenever a new segment arrives. Then optionally upload it to S3.
let request = require('request');
let validUrl = require('valid-url');
class PubSub {
protected subscribers: { [key: string]: Function } = {};
public subscribe(callback: Function): string {
let key: string = Date.now() + '_' + Math.ceil(Math.random() * 10000);
this.subscribers[key] = callback;
@jasonbyrne
jasonbyrne / CountriesArray.js
Last active August 20, 2023 00:29
Three character country code to country name object for JavaScript
const countriesArray = [
{ name: "Aruba", value: "ABW" },
{ name: "Afghanistan", value: "AFG" },
{ name: "Angola", value: "AGO" },
{ name: "Anguilla", value: "AIA" },
{ name: "Åland Islands", value: "ALA" },
{ name: "Albania", value: "ALB" },
{ name: "Andorra", value: "AND" },
{ name: "Netherlands Antilles", value: "ANT" },
{ name: "United Arab Emirates", value: "ARE" },
@jasonbyrne
jasonbyrne / iframe-manifest-generator.ts
Last active October 19, 2018 06:01
Generate an iframe only manifest from a video file with ffprobe and Node
// Work in progress to convert this to TypeScript/Node:
// https://gist.github.com/biomancer/8d139177f520b9dd3495
import { exec } from "child_process";
/**
*
*/
export class IframeByteRange {
public packetTime: number;
@jasonbyrne
jasonbyrne / flagpole-itunes-api.js
Last active November 27, 2018 20:45
Sample to accompany blog post of testing a REST API with Flagpole automation: https://engineering.flosports.tv/rest-api-testing-with-flagpole-part-2-60abcc03eaf1
const { Flagpole } = require('flagpole');
const suite = Flagpole.Suite('iTunes API Test')
.base('https://itunes.apple.com');
suite.Scenario('Music Videos Search')
.open('/search?term=2pac&entity=musicVideo')
.json()
.assertions(function (response) {
let firstResult = response.select('results').first();
@jasonbyrne
jasonbyrne / fileHandler.ts
Last active April 19, 2021 02:24
Firebase Functions + Express file uploader handler
/* Firebase Functions messes with your request and will wreck your day because none of the
* traditional upload handlers with Express will work.
*
* Credit: https://stackoverflow.com/questions/47242340/how-to-perform-an-http-file-upload-using-express-on-cloud-functions-for-firebase
*/
const Busboy = require('busboy');
const allowedMethods: string[] = ['POST', 'PUT'];
export class FileUpload {
@jasonbyrne
jasonbyrne / client-side-framework.ts
Last active December 18, 2018 01:15
Roll your own framework experiment
import { isFunction } from 'util';
abstract class Listener {
protected listeners: { [eventName: string]: [Function] } = {};
public on(eventName: string, callback: Function) {
this.listeners[eventName] = this.listeners[eventName] || [];
this.listeners[eventName].push(callback);
}
@jasonbyrne
jasonbyrne / persist-me.js
Created December 21, 2018 05:47
Proof of Concept: Persistent Data with Lambda
let counter = 0;
exports.handler = async (event) => {
counter++;
return {
statusCode: 200,
body: JSON.stringify(counter),
};
};
@jasonbyrne
jasonbyrne / index.js
Created January 3, 2019 20:41
HLS Checker Lambda - Loads an HLS playlist and then all of the underlying chunklists and segments to make sure all of the files exist and basic validity checks.
const HLS = require('hls-parser');
const request = require('request');
const URL = require('url').URL
// Error codes
const ERROR = {
INVALID_PLAYLIST_URL: {
code: 100,
message: 'Invalid playlist URL'
},