Skip to content

Instantly share code, notes, and snippets.

View apapirovski's full-sized avatar

Anatoli Papirovski apapirovski

  • Los Angeles, CA
View GitHub Profile
@apapirovski
apapirovski / prefer-common-expectserror.js
Last active October 20, 2017 00:48
eslint rule for finding `assert.throws(fn, common.expectsError(err))`, put it in /tools/eslint-rules and add `prefer-common-expectserror: error` to /test/.eslintrc.yaml
'use strict';
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
const msg = 'Please use common.expectsError(fn, err) instead of ' +
'assert.throws(fn, common.expectsError(err)).';
function isAssertThrows(node) {
1) OPTIONS when error occurs in response handler should pass error to callback:
Error: expected 'true' response body, got 'GET,HEAD'
at error (node_modules/supertest/lib/test.js:275:13)
at Test._assertBody (node_modules/supertest/lib/test.js:201:16)
at Test._assertFunction (node_modules/supertest/lib/test.js:257:11)
at Test.assert (node_modules/supertest/lib/test.js:158:18)
at assert (node_modules/supertest/lib/test.js:137:12)
at node_modules/supertest/lib/test.js:134:5
at Test.Request.callback (node_modules/superagent/lib/node/index.js:691:12)
at IncomingMessage.<anonymous> (node_modules/superagent/lib/node/index.js:922:12)
'use strict';
const common = require('./test/common');
const { readFileSync } = require('fs');
const { join } = require('path');
const { createSecureContext } = require('tls');
const h2 = require('http2');
const key = loadKey('agent8-key.pem');
const cert = loadKey('agent8-cert.pem');
'use strict';
const h2 = require('http2');
const server = h2.createServer();
server.on('request', (req, res) => res.end());
server.on('timeout', () => console.log('timeout'));
server.listen(0, () => {
@apapirovski
apapirovski / hex2luma.js
Created May 2, 2012 20:16
Calculate luma (brightness) of a hexadecimal colour
// Calculate luma (brightness) of a hexadecimal colour
// ---------------------------------------------------
// You can use this to calculate whether two colours
// are suitable to be used as a background and text
function hex2luma(hex) {
return (
(parseInt(hex.substring(0, 2), 16) * 299) +
(parseInt(hex.substring(2, 4), 16) * 587) +
(parseInt(hex.substring(4, 6), 16) * 114)
@apapirovski
apapirovski / hex2rgba.js
Created May 2, 2012 19:55
Hexadecimal colour to RGBA
// Convert hex colour to rgba
// ---------------------------------
// hex: hex colour without leading #
// opacity: integer from 0 to 1
function hex2rgba(hex, opacity) {
var r = parseInt(hex.substring(0, 2), 16),
g = parseInt(hex.substring(2, 4), 16),
b = parseInt(hex.substring(4, 6), 16);
@apapirovski
apapirovski / ieDetect.js
Created September 22, 2011 16:09
Test for IE in JS using Conditional Comments
// Based on jamespadolsey's gist: https://gist.github.com/527683
// -----------------------------------------------------------------
// Was curious to see what method would yield the best 'performance'
// — turns out that using innerHTML and checking for text is
// marginally faster than using a Live NodeList.
//
// Of course, any performance gains can only be seen at 100+
// iterations, but still somewhat interesting.
(function (ie) {