Skip to content

Instantly share code, notes, and snippets.

View bradoyler's full-sized avatar
👋
say hi

brad oyler bradoyler

👋
say hi
View GitHub Profile
@bradoyler
bradoyler / child.html
Last active April 14, 2020 19:10
adaptive iframe using postMessage()
<h2> Hello World! </h2>
<script>
function iframeResize() {
var body = document.body, html = document.documentElement;
var height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
var location = document.location.href;
window.parent.postMessage(["setHeight", height, location], "*");
}
iframeResize();
$(window).resize(iframeResize);
@bradoyler
bradoyler / service-bus-test.js
Last active April 14, 2020 17:43
@azure/service-bus topic subscription test (send & receive) to confirm your subscription filters is working as expected
const { ServiceBusClient, ReceiveMode } = require('@azure/service-bus')
const connectionString = process.env['servicebus-connection']
async function send () {
const sbClient = ServiceBusClient.createFromConnectionString(connectionString)
const client = sbClient.createTopicClient('topic-name')
const sender = client.createSender()
// set label=TEST for use in subscription filter
const msg = { label: 'TEST', body: { foo: 'bar', ts: new Date() } }
@bradoyler
bradoyler / AppInsightsClient.ts
Last active March 25, 2020 02:35
Client for Azure Application Insights REST API
import * as rp from 'request-promise-native'
function convertTable (columns: any[], rows: any[]): any[] {
return rows.map((row: any[]) => columns.reduce((obj, col, idx) => {
obj[col.name] = row[idx]
return obj
}, {}))
}
// API reference @ https://dev.applicationinsights.io/reference
@bradoyler
bradoyler / README.md
Last active March 24, 2020 14:49
Application Insights helper for typescript function apps

AppInsights helper

a typescript wrapper for Application Insights

Examples

Exception tracking

import { trackException } from './appinsights-helper'

trackException({ exception: error })
@bradoyler
bradoyler / README.md
Last active March 19, 2020 15:56
Simple Rest API client for node with support for JWT (bearer authentication) - requires Axios

REST-client.js

Usage

const RestClient = require('./rest-client')
const client = RestClient({ baseURL: 'https://mydomain.com' })
client.setAuthHeader('my-auth-token') // optional

const { data } = await client.get('/articles')
@bradoyler
bradoyler / .aaa.md
Last active March 16, 2020 15:03
Flu Illness Cartogram

CDC ILI map

@bradoyler
bradoyler / README.md
Last active March 16, 2020 01:27
US Flights animation (Canvas2D)

Animating 3000 Flights using Canvas2D

Source code for animation used in #AirplaneMode

Orange dots = landing
Blue dots = takeoff

Config settings

var landingColor = '#fe761e';
@bradoyler
bradoyler / 🧽.gif
Created March 16, 2020 01:03 — forked from EvanBacon/🧽.gif
🥓
🧽.gif
@bradoyler
bradoyler / node-standards-v6.md
Last active February 5, 2020 05:58
Nodejs (6.x) standards

Node Standards (v6.x)

The 7 Commandments of Node:

  1. processes shall be small, and start instantly
  2. always communicate via message bus (Redis, RabbitMQ)
    • this is intended to avoid blocking IO like a slow HTTP request
  3. each process shall log to stdout
    • it's not the responsibility of the app to route logs
  4. a process shall not maintain state
  • avoid in-memory session ids, socket connections, etc
Object.getOwnPropertyNames(Date.prototype)
.filter(name => name.startsWith('to'))
.map(method => `${method}: ${(new Date())[method]()}`)