Skip to content

Instantly share code, notes, and snippets.

@timgentry
timgentry / pretty_json.rb
Created January 14, 2020 09:09
Use of JSON::State to output more human readable JSON
require 'json'
hash = { 'a' => 1, 'b' => 2 }
state = JSON::State.new(indent: ' ',
space: ' ',
space_before: '',
object_nl: "\n",
array_nl: "\n")
hash.to_json # => "{\"a\":1,\"b\":2}"
@timgentry
timgentry / README.md
Last active November 6, 2019 19:06 — forked from HealthDataInsight/README.md
Example roll-your-own dashboard definition

Example roll-your-own dashboard definition

This example is intended to reproduce the CCG COMPASS dashboard using the new roll-you-own dashboard tool

@timgentry
timgentry / dot_file_parser.rb
Last active December 11, 2018 13:09
Rake example
# Parses Graphviz .dot files
class DotFileParser
EDGE_PATTERN = /"([^"]*)" -> "([^"]*)"/
NODE_PATTERN = /\A\t"([^"]*)" \[/
def initialize(filename)
@filename = filename
end
def each_edge
@timgentry
timgentry / powerbi_json_to_csv.rb
Created October 18, 2018 12:41
Converts PowerBI JSON payload to CSV
require 'json'
require 'csv'
hash = JSON.parse(File.read('querydata.json'))
CSV.open('data.csv', 'w') do |csv|
hash['results'].each do |result|
data = result['result']['data']
descriptor = data['descriptor']
dsr = data['dsr']
@timgentry
timgentry / assert_http_status.sh
Created October 8, 2018 09:06
A bash script providing test assertions on the status code of http(s) requests
#!/usr/bin/env bash
function assert_http_status {
local HTTP_CODE=$(curl -o /dev/null --silent --head --write-out '%{http_code}\n' $2)
echo "$2 returned status code $HTTP_CODE"
test $HTTP_CODE != $1 && (echo "FAIL: Expected $1"; exit 1)
echo
}
@timgentry
timgentry / contrived_example.json
Last active November 8, 2017 11:58
Contrived, almost exhaustive, example of a merged TNQL and CANQL generated DIR query
{
"action.actioninitiated": {
"equals": "QA"
},
"anomaly.prenatal.exists": {
"equals": true
},
"diagnosis.providercode": {
"equals": "RGT01"
},
@timgentry
timgentry / slack_nagios.sh
Last active March 22, 2017 00:00 — forked from matt448/slack_nagios.sh
Script to post Nagios notifications into a Slack channel
#!/bin/bash
# This script is used by Nagios to post alerts into a Slack channel
# using the Incoming WebHooks integration. Create the channel, botname
# and integration first and then add this notification script in your
# Nagios configuration.
#
# All variables that start with NAGIOS_ are provided by Nagios as
# environment variables when an notification is generated.
# A list of the env variables is available here:
getDatapoints = function(json, metric) {
return json.find(function(d) {
return d.target == metric
}).datapoints
}
getProgress = function(graphite_url) {
params = jQuery.param({
from: '-20seconds',
until: '-20seconds',
# Usage: $ REDMINE_API_KEY=1234567890 ruby planio.rb
require 'json'
require 'open-uri'
require 'statsd-ruby'
def parse_api_json(relative_path)
include OpenURI
# TODO: check the relative path is a json endpoint
@timgentry
timgentry / example_stat.sh
Created March 16, 2017 12:32
Random stat
while true; do echo -n "project.bob.example:$((RANDOM % 100))|c" | nc -w 1 -u 127.0.0.1 8125; done