Skip to content

Instantly share code, notes, and snippets.

View coreylight's full-sized avatar
🚚
Up and up

Corey Light coreylight

🚚
Up and up
View GitHub Profile
// for browsers, ya silly!
performance.mark('start-party');
runThePartyAnimation();
performance.mark('end-party');
performance.measure('party-measure', 'start-party', 'end-party');
const measure = performance.getEntriesByType('measure')[0];
function hrMillis(measure) {
return (measure[0] * 1000) + (measure[1] / 1e6);
}
const databaseStartTime = process.hrtime();
await runTheDatabaseCall();
const databaseMeasure = process.hrtime(databaseStartTime);
const analyticsStartTime = process.hrtime();
await analyticsCall();
function hrMillis(measure) {
return (measure[0] * 1000) + (measure[1] / 1e6);
}
const millis = hrMillis(endTime);
console.log(millis);
// 8210.181641
const startTime = process.hrtime();
await runTheDatabaseCall();
const endTime = process.hrtime(startTime);
console.log(endTime);
// [ 8, 210181641 ]
const iopipeLib = require('iopipe');
const tracePlugin = require('iopipe-plugin-trace');
const iopipe = iopipeLib({
plugins: [tracePlugin()]
});
// wrap your lambda handler
exports.handler = iopipe((event, context) => {
const mark = context.iopipe.mark;
@coreylight
coreylight / sls-plugin-post-block-6.js
Last active May 5, 2017 14:16
Serverless Plugin Post Block 6
const wrapper = "require('iopipe')({token: 'TOKEN'})(REPLACE)";
shift(wrapper)
.find(shift.Identifier, {
name: 'REPLACE'
})
.replaceWith(found);
@coreylight
coreylight / sls-plugin-post-block-5.js
Created April 21, 2017 16:55
Serverless Plugin Post Block 5
exports
.handler = // 😎 this will work too
@coreylight
coreylight / sls-plugin-post-block-4.js
Created April 21, 2017 16:54
Serverless Plugin Post Block 4
exports.handler = //anything here
@coreylight
coreylight / sls-plugin-post-block-3.js
Created April 21, 2017 16:53
Serverless Plugin Post Block 3
const shift = require('jscodeshift');
const code = 'The string literal of the code to transform (from above)';
const searchObject = {
left: {
type: 'MemberExpression',
object: {
type: 'Identifier',
name: 'exports'
},
property: {
@coreylight
coreylight / sls-plugin-post-block-2.js
Last active May 5, 2017 14:16
Serverless Plugin Block 2
const uuid = require('uuid');
const iopipe = require('iopipe')({token: 'TOKEN'});
exports.handler = iopipe((event, context, callback) => {
const response = {
statusCode: 200,
body: JSON.stringify({
message: 'Your uuid is: ' + uuid.v4(),
input: event
})
};