Skip to content

Instantly share code, notes, and snippets.

Avatar
👋
say hi

brad oyler bradoyler

👋
say hi
View GitHub Profile
@bradoyler
bradoyler / .block
Last active Nov 28, 2021
Crude Oil Pipelines in US
View .block
license: mit
@bradoyler
bradoyler / mapReduce-WordCounter.js
Last active Jul 20, 2021
Using Map-Reduce in Javascript: counting words in a string.
View mapReduce-WordCounter.js
// for counting words in a string
var words="Hi there and hello there. Welcome and hello there.";
var wordcnt = words.replace(/[^\w\s]/g, "").split(/\s+/).reduce(function(map, word){
map[word] = (map[word]||0)+1;
return map;
}, Object.create(null));
@bradoyler
bradoyler / 24.md
Last active Jun 16, 2021
The 24 game in javascript
View 24.md

The 24 Game

  • tests one's mental arithmetic.

How it works:

  • You are randomly given four digits, each from one to nine, with repetitions allowed.
  • The goal is to enter an expression that evaluates to 24
Tips:
  • Only multiplication, division, addition, and subtraction operators/functions are allowed.
  • Division should use floating point or rational arithmetic, etc, to preserve remainders.
@bradoyler
bradoyler / .block
Last active Dec 18, 2020
US Flight animation (svg)
View .block
license: mit
View cacheService.js
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 / .block
Last active Jun 29, 2020
crime rates in US cities
View .block
license: mit
@bradoyler
bradoyler / child.html
Last active Apr 14, 2020
adaptive iframe using postMessage()
View child.html
<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 Apr 14, 2020
@azure/service-bus topic subscription test (send & receive) to confirm your subscription filters is working as expected
View service-bus-test.js
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 Mar 25, 2020
Client for Azure Application Insights REST API
View AppInsightsClient.ts
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 Mar 24, 2020
Application Insights helper for typescript function apps
View README.md

AppInsights helper

a typescript wrapper for Application Insights

Examples

Exception tracking

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

trackException({ exception: error })