Skip to content

Instantly share code, notes, and snippets.

@mape
mape / apmPatchPrisma.ts
Last active October 20, 2021 20:26
Elastic APM node client instrumenting Prisma 2 queries
import { condensePrismaQuery } from './utils';
// Screenshot of a trace sample: https://i.imgur.com/XuhuQFq.png
// Service: https://www.elastic.co/apm
// Node module: https://github.com/elastic/apm-agent-nodejs
// Prisma: https://www.prisma.io/
// Using "@prisma/client": "dev"
// Thanks to https://github.com/prisma/prisma/pull/2902
@mape
mape / main.ts
Last active October 11, 2017 16:03
Extract inferred return types from functions that are exported in TypeScript file
import fs = require('fs');
import ts = require('typescript');
// Create the language service host to allow the LS to communicate with the host
const servicesHost: ts.LanguageServiceHost = {
getScriptFileNames: () => rootFileNames,
getScriptVersion: (fileName) => files[fileName] && files[fileName].version.toString(),
getScriptSnapshot: (fileName) => {
if (!fs.existsSync(fileName)) {
return undefined;
@mape
mape / broken-https.js
Created January 3, 2011 23:44
Crashes on unstable node.
var http = require('http');
var google = http.createClient(443, 'www.google.com', true);
var request = google.request('GET', '/accounts/AuthSubSessionToken', {'host': 'www.google.com'});
request.end();
request.on('response', function (response) {
console.log('STATUS: ' + response.statusCode);
console.log('HEADERS: ' + JSON.stringify(response.headers));
response.setEncoding('utf8');
response.on('data', function (chunk) {
console.log('BODY: ' + chunk);
@mape
mape / nodeRedisBreaks.js
Created November 6, 2010 14:01
Simple test to show that node-redis corrupts data if the data contains special chars.
var redis = require('redis-node');
var redcli = redis.createClient();
redcli.select(1);
var testObj = {'a': 'ö'}
var jsonString = JSON.stringify(testObj);
console.log('Origin JSON string: '+jsonString);
console.log('JSON.parse(jsonString): ');
console.log(JSON.parse(jsonString));
redcli.set('testJson', jsonString, function(err, status) {
{ message: 'ECONNREFUSED, Connection refused'
, stack: [Getter/Setter]
, errno: 111
, syscall: 'connect'
}
Error: ECONNREFUSED, Connection refused
at IOWatcher.callback (net:867:22)
at node.js:608:9
$ npm install html5
npm info it worked if it ends with ok
npm info version 0.2.2
npm ERR! Error installing html5@v0.2.2
npm ERR! Error: version not found: v0.2.2 undefined: html5/v0.2.2
npm ERR! at IncomingMessage.<anonymous> (/usr/local/lib/node/.npm/npm/0.2.2/package/lib/utils/registry/request.js:89:19)
npm ERR! at IncomingMessage.emit (events:43:20)
npm ERR! at HTTPParser.onMessageComplete (http:107:23)
npm ERR! at Client.ondata (http:901:22)
npm ERR! at IOWatcher.callback (net:494:29)
TypeError: Cannot read property '_bytesRead' of undefined
at Object.readFileSync (fs:118:44)
at cacheViewSync (/usr/local/lib/node/.npm/express/1.0.0rc3/package/lib/express/view.js:46:33)
at ServerResponse.render (/usr/local/lib/node/.npm/express/1.0.0rc3/package/lib/express/view.js:274:63)
at ServerResponse.render (/usr/local/lib/node/.npm/express/1.0.0rc3/package/lib/express/view.js:294:14)
at Object.<anonymous> (/home/mape/code/node-express-boilerplate/server.js:94:6)
at pass (/usr/local/lib/node/.npm/connect/0.2.5/package/lib/connect/middleware/router.js:70:27)
at Object.router [as handle] (/usr/local/lib/node/.npm/connect/0.2.5/package/lib/connect/middleware/router.js:85:10)
at next (/usr/local/lib/node/.npm/connect/0.2.5/package/lib/connect/index.js:244:23)
at next (/usr/local/lib/node/.npm/connect/0.2.5/package/lib/connect/index.js:246:17)
Object #<an Object> has no method 'indexOf'
[ 'TypeError: Object #<an Object> has no method \'indexOf\''
, ' at /var/www/node-project/server.js:54:15'
, ' at IncomingMessage.<anonymous> (/usr/local/lib/node/.npm/oauth/0.8.1/package/lib/oauth.js:237:42)'
, ' at IncomingMessage.emit (events:43:20)'
, ' at HTTPParser.onMessageComplete (http:107:23)'
, ' at Client.ondata (http:901:22)'
, ' at IOWatcher.callback (net:494:29)'
, ' at node.js:775:9'
]
Caught exception: Error: Uncaught, unspecified 'error' event.
[ 'Error: Uncaught, unspecified \'error\' event.'
, ' at Server.emit (events:14:15)'
, ' at Stream.<anonymous> (/home/node/.node_libraries/.npm/websocket-server/1.3.50/package/lib/ws/connection.js:99:14)'
, ' at Stream.emit (events:43:20)'
, ' at Array.0 (net:987:27)'
, ' at EventEmitter._tickCallback (node.js:53:20)'
, ' at node.js:764:9'
]
88.
Caught exception: Error: Uncaught, unspecified 'error' event.
[ 'Error: Uncaught, unspecified \'error\' event.'
, ' at Server.emit (events:14:15)'
, ' at Stream.<anonymous> (/home/node/.node_libraries/.npm/websocket-server/1.3.50/package/lib/ws/connection.js:99:14)'
, ' at Stream.emit (events:43:20)'
, ' at Array.0 (net:987:27)'
, ' at EventEmitter._tickCallback (node.js:53:20)'
, ' at node.js:764:9'
]