-
-
Save isocroft/adf3263c2c3ff5d2119712ea6485f0c1 to your computer and use it in GitHub Desktop.
Show PostgreSQL current (running) process list;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT user, pid, client_addr, waiting, query, query_start, NOW() - query_start AS elapsed | |
| FROM pg_stat_activity | |
| WHERE query != '<IDLE>' | |
| -- AND EXTRACT(EPOCH FROM (NOW() - query_start)) > 1 | |
| ORDER BY elapsed DESC; |
Author
const fs = require('fs');
const PNG = require('pngjs').PNG;
const pixelMatch = require('pixelmatch');
module.exports = {
getPNGImageSimilarityPercentage (sourceImagePath, targetImagePath, diffImagePath = './diff.png') {
if (typeof(sourceImageFile) !== 'string'
|| !sourceImageFile.toLowerCase().endsWith('.png')) {
return Promise.reject(throw new Error(''));
}
if (typeof(targetImagePath) !== 'string'
|| !targetImagePath.toLowerCase().endsWith('.png')) {
return Promise.reject(throw new Error(''));
}
return new Promise ((res, rej) => {
const sourceImageFile = fs.createReadStream(sourceImagePath).pipe(new PNG()).on('parsed', doneReading);
const targetImageFile = fs.createReadStream(targetImagePath).pipe(new PNG()).on('parsed', doneReading);
let filesReadCount = 0;
function donReading () {
if (++filesReadCount < 2) return;
if (sourceImageFile.width !== targetImageFile.width
|| sourceImageFile.height !== targetImageFile.height) {
if (process.env.NODE_ENV === 'development') {
console.error('images have different dimensions');
}
rej(new Error('source and target image dimensions differ'));
}
const diffPNGImageFile = new PNG({
width: sourceImageFile.width,
height: sourceImageFile.height
});
const diffPixelsCount = pixelMatch(
sourceImageFile.data,
targetImageFile.data,
diffPNGImageFile.data,
sourceImageFile.width,
sourceImageFile.height
);
const sourceImageFileTotalPixelsCount = sourceImageFile.width * sourceImageFile.height;
const similarity = 100 - (diffPixelsCount / sourceImageFileTotalPixelsCount) * 100;
diffPNGImageFile.pack().pipe(fs.createWriteStream(diffImagePath)).on('done', () => {
res(`${similarity.toFixed(2)}%`);
});
}
});
}
};
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.