Skip to content

Instantly share code, notes, and snippets.

View Tom910's full-sized avatar

Andrey Marchenko Tom910

View GitHub Profile
@Tom910
Tom910 / README.md
Last active March 20, 2023 19:36
Windows - Powertoys - Keyboard Manager - Common macOS keys mapping
@Tom910
Tom910 / gist:2b20f870555cf1e8193c4ab370426af5
Created January 6, 2023 12:03
Compress An Image Before Upload With JavaScript
// https://pqina.nl/blog/compress-image-before-upload?ck_subscriber_id=887774617
<input type="file" multiple class="my-image-field" />
<script>
const compressImage = async (file, { quality = 1, type = file.type }) => {
// Get as image data
const imageBitmap = await createImageBitmap(file);
// Draw to canvas
Score
avif - 0.9132000000000002
webp - 0.8198000000000002
higher better
window.onerror = function(message, file, line, column, error) {
var errorToReport = {
type: error ? error.type : '',
message: message,
file: file,
line: line,
column: column,
stack: error ? error.stack : '',
userAgent: navigator.userAgent,
href: location.href
@Tom910
Tom910 / search.js
Last active February 27, 2017 15:45
var Benchmark = require('benchmark');
var expect = require('expect');
var suite = new Benchmark.Suite;
var test = [];
for (var s = 0; s < 1000000; s++) {
test.push(s);
}
var Benchmark = require('benchmark');
var expect = require('expect');
var suite = new Benchmark.Suite;
var test = {
reasons: [],
chunks: []
};
for (var s = 0; s < 5000; s++) {
/*
❯ node -v
v14.15.1
❯ node Map-vs-native-cache.js
Testing caching
Map x 57.19 ops/sec ±1.83% (59 runs sampled)
Native x 50.16 ops/sec ±2.87% (63 runs sampled)
Fastest is Map
*/
@Tom910
Tom910 / Object-keys-vs-for-in.js
Last active January 24, 2017 10:12
Object-keys-vs-for-in
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite;
var testObject = {};
for (var s = 0; s < 1000; s++) {
testObject[s] = Math.floor(Math.random() * 10000);
}
console.log('Testing iteration of object')
@Tom910
Tom910 / gist:37d3c863103c87741d835738af03b3ba
Created January 13, 2017 08:04
for-cache-vs-no-cache
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite;
var testArray = [];
for (var s = 0; s < 1000; s++) {
testArray.push(s * 2);
}
suite