Skip to content

Instantly share code, notes, and snippets.

@amit-y
amit-y / trace.js
Last active January 15, 2019 19:21
NR Transaction Trace formatter
const THRESHOLD = 1000;
const FONTS = {google: {families: ['Open Sans Condensed:300,300i,700']}};
const STYLESHEET = "body{font-family:'Open Sans Condensed',sans-serif}span.default{color:#00f}span.summary{color:gray;font-style:italic}span.hilite{color:red;font-weight:700}ul.tree li{list-style-type:none;position:relative}ul.tree li ul{display:none}ul.tree li.open>ul{display:block}ul.tree li a{color:#000;text-decoration:none}ul.tree li a:before{height:1em;padding:0 .1em;font-size:.8em;display:block;position:absolute;left:-1.3em;top:.2em}ul.tree li>a:not(:last-child):before{content:'+'}ul.tree li.open>a:not(:last-child):before{content:'-'}";
(function init(doc) {
function summaryElements(txt) {
var ret = [];
var br = doc.createElement('br');
ret.push(br);
var summarySpan = doc.createElement('span');
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use Scalar::Util qw(looks_like_number);
print "{\"name\":\"com.newrelic.mqswig\",\"protocol_version\":\"1\",\"integration_version\":\"1.0.0\",\"metrics\":[";
while (<>) {
@amit-y
amit-y / sample.json
Last active June 6, 2018 19:51
Sample JSON
{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
@amit-y
amit-y / com.newrelic.tcp-port-monitor-config.yaml
Created September 7, 2017 16:25
New Relic Infrastructure custom integration to monitor TCP ports (using Powershell)
integration_name: com.newrelic.tcp-port-monitor
instances:
- name: localhost
command: metrics
arguments:
server: localhost
port: 21
labels:
env: development
@amit-y
amit-y / iso8601.js
Last active August 2, 2016 19:27
ISO 8601 formatted date/time
Date.prototype.toISO8601 = function () {
var dateString = this.toString().split(" ");
return this.toJSON().substring(0,11)+dateString[4]+dateString[5].substr(3,3)+':'+dateString[5].slice(-2);
}
// example usage
(new Date).toISO8601();
@amit-y
amit-y / qsObj.js
Created May 26, 2015 19:19
Query string as an object
var queryStringToObj = function() {
var qs = location.search.substr(1).split(/&/);
var q = {};
for (var i=0; i<qs.length; i+=1) {
var queryVar = qs[i].split('=');
var key = decodeURIComponent(queryVar[0]);
var val = (queryVar[1] === undefined) ? null : decodeURIComponent(queryVar[1]);
q[key] = val;
}
return q;
@amit-y
amit-y / hasProps.js
Created May 26, 2015 19:11
_ mixin to check for property in deep object
_.mixin({
hasProps: function (o, propPath) {
var prop = propPath.split('.');
for (var p=0; p<prop.length; p++) {
if (!_.has(o, prop[p])) return false;
o = o[prop[p]];
}
return true;
}
});
@amit-y
amit-y / Gruntfile.js
Created February 9, 2015 22:25
Grunt task to search and replace strings in file
module.exports = function(grunt) {
// Load grunt tasks automatically
require('load-grunt-tasks')(grunt);
// Time how long tasks take. Can help when optimizing build times
require('time-grunt')(grunt);
// Project configuration.
grunt.initConfig({