Skip to content

Instantly share code, notes, and snippets.

View danielkhan's full-sized avatar

Daniel Khan danielkhan

  • Sentry
  • Linz / Austria
  • X @dkhan
View GitHub Profile
/**
* Simple userland CPU profiler using v8-profiler
* Usage: require('[path_to]/CpuProfiler').init('datadir')
*
* @module CpuProfiler
* @type {exports}
*/
var fs = require('fs');
var profiler = require('v8-profiler');
@danielkhan
danielkhan / node-example.js
Last active September 1, 2021 00:40
node.js module.exports and exports explained
function Person(name) {
this.name = name;
}
var john = new Person('John');
// implicit done by node.js:
// exports = module.exports
exports.myperson = john;
// test = require('./lib/test');
const fs = require("fs");
setImmediate(() => {
process.stdout.write(`setImmediate (after poll phase)\n`);
process.nextTick(() => {
process.stdout.write(`nextTick (nested registered in setImmediate())\n`);
});
});
setTimeout(() => {
process.stdout.write(`setTimeout (timers phase)\n`);
@danielkhan
danielkhan / saml.js
Last active September 4, 2019 16:10
This is a hacked together version of passport-samls saml parser that supports shibboleth
var zlib = require('zlib');
var xml2js = require('xml2js');
var xmlCrypto = require('xml-crypto');
var crypto = require('crypto');
var xmldom = require('xmldom');
var querystring = require('querystring');
var moment = require('moment');
var xmlenc = require('xml-encryption');
var xpath = require('xpath');
extends ../layout/index
block content
#speakerDetail.container
.row
.col-sm-8
article.speakerslist
.container
.row
.col-sm-8
extends ../layout/index
block content
#speakerList.container
.row
.col-sm-8
article.speakerslist
.container
.row
.col-sm-8
h3.speakerslist-title Art in Full Bloom
header
.jumbotron.hidden-xs
// jumbotron
nav.navbar.navbar-inverse
.container
.navbar-header
button.navbar-toggle.collapsed(type='button', data-toggle='collapse', data-target='#navbar-collapse', aria-expanded='false')
span.sr-only Toggle navigation
span.icon-bar
span.icon-bar
const {
Tracer,
BatchRecorder,
ExplicitContext,
jsonEncoder: { JSON_V2 }
} = require('zipkin');
const zipkinMiddleware = require('zipkin-instrumentation-express').expressMiddleware;
const wrapRequest = require('zipkin-instrumentation-request');
const request = require('request');
module.exports.postProblemDetail = async (body, callback) => {
console.log(body);
if (body.type === "validate") {
return callback(null, success(say("Would you like to notify the person on call?", 'Notify Daniel')));
}
if (body.type === "custom") {
return callback(null, success(say(`Notified Daniel`)));
}
const axios = require('axios');
module.exports.handler = async (event, context, callback) => {
// Asynchronous HTTP GET
// In real projects, you want to add some error handling here.
const res = await axios.get('https://api.weather.gov/points/39.7456,-97.0892');
const response = {
statusCode: 200,