Skip to content

Instantly share code, notes, and snippets.

View sznowicki's full-sized avatar

Szymon Nowicki sznowicki

View GitHub Profile
AES
# Pack a folder into a tar.gz file:
tar -zcvf my_folder.tar.gz my_folder/
# encrypt file.txt to file.enc using 256-bit AES in CBC mode
openssl enc -aes-256-cbc -in file.txt -out file.enc
# decrypt binary file.enc
openssl enc -d -aes-256-cbc -in file.enc -out file.txt
@sznowicki
sznowicki / index.html
Last active January 26, 2022 12:15
Deep clone: lodash vs native (https://jsbench.github.io/#1b1800fb38afce5e7d0167567337d216) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Deep clone: lodash vs native</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@sznowicki
sznowicki / index.html
Created January 25, 2022 14:07
Replacing URL known hostname to another hostname: search.replace vs parsing url (https://jsbench.github.io/#06180ee1547398ef1da3147e0efb90d7) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Replacing URL known hostname to another hostname: search.replace vs parsing url</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@sznowicki
sznowicki / index.html
Created January 25, 2022 13:27
Replacing URL known hostname to another hostname: search.replace vs parsing url (https://jsbench.github.io/#34d45d3c23534d1b5f18734d0eda12eb) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Replacing URL known hostname to another hostname: search.replace vs parsing url</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
function main() {
const arr = [1,2,3,5,5,6,7,7,5464,43,1,4,6,7,8,6,4,2,2,2,3,4,6,6];
const dedup = [...new Set(arr)];
console.log(dedup);
}
setInterval(main, 10);
@sznowicki
sznowicki / async-promise-getting-resolved.js
Created July 13, 2018 19:06
Async...await vs promise - getting already resolve promise
const p = new Promise((resolve) => resolve(1));
p.then(r => console.log('promise', r));
async function foo() {
const r = await p;
console.log('async', r);
}
foo();
@sznowicki
sznowicki / collapseAllDiff.js
Created February 14, 2018 12:45
Collapse all github.com pull request diff files which contains `text` in a filename.
function collapseAllDiff(text) {
document.querySelectorAll('.file-info a').forEach(el => {
if (el.title.indexOf(text) > -1){
console.log(el.closest('.file-header').querySelectorAll('.js-details-target')[0].click());
}
});
}
@sznowicki
sznowicki / lost-scope.js
Created May 16, 2017 12:45
ES6 lost "this" scope when method is assigned to a variable
class Foo {
static bar() {
return 'bar';
}
baz() {
return this.constructor.bar();
}
}
class CustomError {
get name() {
return 'foo';
}
get code() {
return 400;
}
test() {
@sznowicki
sznowicki / examples.js
Last active May 12, 2017 21:40
Breaking the Promise chain
// old-school callback hell
const callbackHell() = (cb) => {
foo1((err, result) => {
if (err) {
return cb(err);
}
foo2((err, result) => {
if (err) {
return cb(err);
}