Skip to content

Instantly share code, notes, and snippets.


Mathias Pettersson mape

View GitHub Profile
mape / apmPatchPrisma.ts
Last active Oct 20, 2021
Elastic APM node client instrumenting Prisma 2 queries
View apmPatchPrisma.ts
import { condensePrismaQuery } from './utils';
// Screenshot of a trace sample:
// Service:
// Node module:
// Prisma:
// Using "@prisma/client": "dev"
// Thanks to
mape / main.ts
Last active Oct 11, 2017
Extract inferred return types from functions that are exported in TypeScript file
View main.ts
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;

Keybase proof

I hereby claim:

  • I am mape on github.
  • I am mape ( on keybase.
  • I have a public key whose fingerprint is 3E51 97BE 3A21 68F8 6761 5F3F 6F06 2EAE E658 A9ED

To claim this, I am signing this object:

mape / broken-https.js
Created Jan 3, 2011
Crashes on unstable node.
View broken-https.js
var http = require('http');
var google = http.createClient(443, '', true);
var request = google.request('GET', '/accounts/AuthSubSessionToken', {'host': ''});
request.on('response', function (response) {
console.log('STATUS: ' + response.statusCode);
console.log('HEADERS: ' + JSON.stringify(response.headers));
response.on('data', function (chunk) {
console.log('BODY: ' + chunk);
mape / nodeRedisBreaks.js
Created Nov 6, 2010
Simple test to show that node-redis corrupts data if the data contains special chars.
View nodeRedisBreaks.js
var redis = require('redis-node');
var redcli = redis.createClient();;
var testObj = {'a': 'ö'}
var jsonString = JSON.stringify(testObj);
console.log('Origin JSON string: '+jsonString);
console.log('JSON.parse(jsonString): ');
redcli.set('testJson', jsonString, function(err, status) {
View gist:604445
{ 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
View gist:597100
$ 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)
View Express error
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)
View gist:571507
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'
View gist:563609
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'