Skip to content

Instantly share code, notes, and snippets.

View slavafomin's full-sized avatar
✌️
Let's make this World a better place!

Slava Fomin II slavafomin

✌️
Let's make this World a better place!
View GitHub Profile
@slavafomin
slavafomin / 0-guide.md
Last active May 31, 2024 08:44
AWS EC2 Dynamic DNS

AWS EC2 Dynamic DNS

Use the provided script to update your Route 53 domain name to point to the EC2 instance IP address that changes dynamically on reboot.

# configure crontab
sudo -i
chmod ug=rx,o= /root/update-dns.sh
systemctl enable cron.service
crontab -e
@slavafomin
slavafomin / 0-gpg-encryption.md
Last active May 14, 2024 10:01
Using GPG encryption on Linux

GPG Encryption

List Keys

gpg --list-keys

Import Key

@slavafomin
slavafomin / 0.md
Last active January 9, 2024 18:35
JavaScript bytes copy benchmark (Uint8Array)

The most optimal way to copy bytes in JavaScript (Uint8Array)

Please read my post in Telegram: Don't use spread operator with byte arrays

Short summary

  1. Use target.set(source, offset) MDN
  2. Pre-alocate the entire array once
  3. Don't use ...spread operator with bytes
@slavafomin
slavafomin / jest-swc-typescript-esm.md
Last active May 18, 2024 06:16
Using Jest with SWC, TypeScript, and ESM

Using Jest with SWC, TypeScript, and ESM

Install dependencies

pnpm add -D jest @jest/globals @types/jest @swc/jest

Create jest.config.js file

{
"5.9.10.47:19949": {
"errors": {
"LITE_SERVER_UNKNOWN: timeout(during last block synchronization)": 2
},
"results": {}
},
"5.9.10.15:48014": {
"errors": {
"LITE_SERVER_NOTREADY: block is not applied": 38,
/**
* This module implements ECMAScript (stage-3) proposal:
* Promise with resolvers:
* https://github.com/tc39/proposal-promise-with-resolvers
*
* Copyright 2023 Slava Fomin II
*
* Permission is hereby granted, free of charge, to any
* person obtaining a copy of this software and associated
* documentation files (the “Software”), to deal in the
const isValid$ = (
merge(
value$.pipe(
distinctUntilChanged(),
map(() => undefined),
),
value$.pipe(
debounceTime(500),
withLatestFrom(isComplete$),
filter(([_, isComplete]) => isComplete),
@slavafomin
slavafomin / is-twa.ts
Last active May 1, 2023 12:05
TWA Main Button Emulation
import { WebApp } from '@grammyjs/web-app';
export function isTwa(): boolean {
return (
Boolean(WebApp.initData) ||
(WebApp.platform !== 'unknown')
);
{ "foo": 123456789123456789123 }
@slavafomin
slavafomin / 00-typescript-esm.md
Last active May 24, 2024 22:30
Using TypeScript with native ESM

Using TypeScript Node.js with native ESM

This reference guide shows how to configure a TypeScript Node.js project to work and compile to to native ESM.

Rationale

CommonJS module system was introduced by the Node.js developers due to the lack of the notion of "modules" in the original JavaScript (ECMAScript) language specification at that time. However, nowadays, ECMAScript has a standard module system called ESM — ECMAScript Modules, which is a part of the accepted standard. This way CommonJS could be considered vendor-specific and obsolete/legacy. Hopefully, TypeScript ecosystem now supports the "new" standard.

So the key benefits are: