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
import NodeCache from 'node-cache'; // or 'redis'
class CacheService {
constructor(ttlSeconds) {
// this could also be redis
this.cache = new NodeCache({ stdTTL: ttlSeconds, checkperiod: ttlSeconds * 0.2, useClones: false });
}
get(key, storeFunction) {
@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 / 🧽.gif
Created March 16, 2020 01:03 — forked from EvanBacon/🧽.gif
🥓
🧽.gif
@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 })
Object.getOwnPropertyNames(Date.prototype)
.filter(name => name.startsWith('to'))
.map(method => `${method}: ${(new Date())[method]()}`)
function numToColor (num, maxHue = 350, minHue = 0) {
const hue = num * (maxHue - minHue) + minHue
return `hsl(${hue}, 70%, 45%)`
}
@bradoyler
bradoyler / extract-folder-git.md
Created September 16, 2019 20:39
extract repo from git folder

git commands

git clone --mirror ssh://git@gituhub.com/user/repo.git filtered-repo
cd filtered-repo
git filter-branch --prune-empty --subdirectory-filter some/folder/path/ master
cd ..
git clone ./filtered-repo new-repo
cd new-repo
git status
@bradoyler
bradoyler / csproj-scanner.js
Last active July 30, 2019 14:30
scan csproj files for usage of ProjectReference
const glob = require('glob')
const fs = require('fs');
const xml2js = require('xml2js');
const path = require('path');
function parseFile (filePath, parser) {
fs.readFile(filePath, (err, data) => {
parser.parseString(data, (err, result) => {
const itemgroups = result.Project.ItemGroup;
if (itemgroups && itemgroups.length) {
@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')