Skip to content

Instantly share code, notes, and snippets.

View lukehoban's full-sized avatar

Luke Hoban lukehoban

View GitHub Profile
@lukehoban
lukehoban / speech.js
Last active December 28, 2023 15:14
Project Oxford Speech APIs Node.js Sample
var fs = require('fs');
var util = require('util');
var request = require('request');
var clientId = 'test-app'; // Can be anything
var clientSecret = 'f6f0bfec08274b8790520a9079b808af'; // API key from Azure marketplace
var str = 'This is a cool demo to call Microsoft text to speach service in Node.js.';
console.log('Converting from text -> speech -> text.');
@lukehoban
lukehoban / apigatewaydomain.ts
Last active September 25, 2023 07:41
API Gateway Domain Mapping in Pulumi
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
// The services we want to host on our domain...
const api1 = new aws.apigateway.x.API("api1", {
routes: [
{method: "GET", path: "/", eventHandler: async(ev) => {
return {
statusCode: 200,
body: JSON.stringify({hello: "world"}),
@lukehoban
lukehoban / index.ts
Created May 19, 2023 06:42
Pulumi Self-Hosted Cloud - Simple Kubernetes Deployment
import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";
import * as command from "@pulumi/command";
class ServiceDeployment extends pulumi.ComponentResource {
internalEndpoint: pulumi.Output<string>;
externalEndpoint?: pulumi.Output<string>;
service: k8s.core.v1.Service;
constructor(name: string, args: { name: string, image: string, replicas?: number, env?: Record<string, pulumi.Input<string>>, ports?: { port: number }[], loadBalancer?: boolean, volumes?: { name: string, mountPath: string, secret: k8s.core.v1.Secret }[] }, opts?: pulumi.ComponentResourceOptions) {
super("selfhosted:ServiceDeployment", name, {}, opts);
@lukehoban
lukehoban / __main__.py
Last active May 19, 2023 05:31
Pulumi without variables
import pulumi
import pulumi_aws as aws
from typing import Optional, Dict, Tuple
import asyncio
all_resources: Dict[Tuple[str, str], pulumi.Resource] = {}
def transform(args: pulumi.ResourceTransformationArgs) -> Optional[pulumi.ResourceTransformationResult]:
all_resources[(args.name, args.type_)] = args.resource
return None # do not actually modify the resource
@lukehoban
lukehoban / index.ts
Last active February 24, 2023 15:31
Simple Aurora Serverless + Lambda VPC example with Pulumi
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";
import * as random from "@pulumi/random";
// Construct a VPC
const vpc = new awsx.ec2.Vpc("vpc");
// Create an Aurora Serverless MySQL database
const dbsubnet = new aws.rds.SubnetGroup("dbsubnet", {
@lukehoban
lukehoban / lambda_test.go
Created February 25, 2020 06:19
Untyped Lambda Calculus, Chruch Numerals, Y Combinator in Golang
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
type V func(v V) V
@lukehoban
lukehoban / asyncloops.js
Last active May 31, 2021 23:18
Async/await and parallel loops
// ES6 w/ Promises
// Note: From a React starter template - see https://t.co/wkStq8y3I5
function fetchData(routes, params) {
let data = {};
return Promise.all(routes
.filter(route => route.handler.fetchData)
.map(route => {
return route.handler.fetchData(params).then(resp => {
data[route.name] = resp;
@lukehoban
lukehoban / waitForJob.ts
Last active August 4, 2020 21:03
Pulumi program which waits on Jobs during a Kubernetes deployment
import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";
import * as k8sOutput from "@pulumi/kubernetes/types/output";
import * as k8sapi from 'kubernetes-client';
const job = new k8s.batch.v1.Job("job", {
spec: {
template: {
spec: {
containers: [{
@lukehoban
lukehoban / es6features.md
Last active December 6, 2019 01:50
ECMAScript 6 Features

Note: Up to date version now at https://github.com/lukehoban/es6features

ECMAScript 6

Introduction

ECMAScript 6 is the upcoming version of the ECMAScript standard. This standard is targetting ratifcation in December 2014. ES6 is a significant update to the language, and the first update to the language since ES5 was standardized in 2009. Implementation of these features in major JavaScript engines is underway now.

See the draft ES6 standard for full specification of the ECMAScript 6 language.

ES6 includes the following new features:

@lukehoban
lukehoban / index.ts
Created June 20, 2019 00:25
Passing credentials to a Pulumi dynamic provider
import * as splunk from "./splunk"
async function getSecretValue(): Promise<string> {
return "abcd"
}
getSecretValue().then(secret => {
splunk.setAuth(secret);
new splunk.SavedSearch("foo", {});
});