Skip to content

Instantly share code, notes, and snippets.

View gsbelarus's full-sized avatar

Andrej Kirejeŭ gsbelarus

View GitHub Profile
@gsbelarus
gsbelarus / unit_test_example.md
Created May 31, 2025 10:25
Unit Testing React Hooks with NextJS Back-End

tsconfig.server.json

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "module": "commonjs",
    "outDir": "dist",
    "lib": ["ES2024"],
    "target": "ES2024",
@gsbelarus
gsbelarus / index.js
Created May 1, 2025 09:52
High-Quality Transcription of Noisy Dual-Channel Phone Calls
import { exec } from 'child_process';
import { config } from "dotenv";
import fs, { createReadStream, existsSync, unlinkSync } from 'fs';
import OpenAI from 'openai';
import { promisify } from 'util';
const execPromise = promisify(exec);
config({ path: [ ".env.local", ".env" ] });
@gsbelarus
gsbelarus / zod_example.ts
Last active January 27, 2025 16:09
Example of Zod usage for the arcticle on dev.to
// link to the article:
// https://dev.to/andreik/zod-validatsiia-i-vyvod-tipov-na-osnovanii-skhiemy-dannykh-4n3l
import { z } from "https://deno.land/x/zod/mod.ts";
const Levels = ['J1', 'J2', 'J3', 'M1', 'M2', 'M3', 'S1', 'S2', 'S3'] as const;
const Skill = z.object({
id: z.string().uuid(),
name: z.string().min(1).max(60)
@gsbelarus
gsbelarus / client.ts
Last active July 30, 2021 16:26
Long polling server and client
import fetch from 'node-fetch';
const abortController = new AbortController();
const signal = abortController.signal;
process.stdin.on('readable', () => {
const s = process.stdin.read().toString() as string;
if (s.startsWith('abort')) {
console.log('aborting...');
abortController.abort();
@gsbelarus
gsbelarus / machine.js
Created March 31, 2020 08:54
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// Place your settings in this file to overwrite the default settings
{
"editor.tabSize": 2,
"editor.detectIndentation": true,
"editor.fontSize": 12,
"editor.minimap.enabled": false,
"editor.autoClosingBrackets": "beforeWhitespace",
"editor.renderIndentGuides": false,
"editor.fontFamily": "Consolas, Operator Mono, Courier New, monospace",
"editor.find.autoFindInSelection": true,
@gsbelarus
gsbelarus / maradona.ts
Created July 29, 2018 18:59
type checking for allowable football substitutions
type Player<Club extends string> = {
club: Club,
name: string
};
function createPlayer<Club extends string>(club: Club, name: string): Player<Club> {
return { club, name };
}
const maradona = createPlayer('Dynamo Brest', 'Maradona');
@gsbelarus
gsbelarus / pull_all.ts
Last active March 31, 2018 18:35
Pull all git repositiories according to specified directories list
const execFile = require('child_process').execFile;
const tscDirs = [
'/golden/ns/lib/gdmn-db',
'/golden/ns/lib/gdmn-orm',
];
const dirs = [
'/golden/gedemin',
'/golden/gedemin-public',
@gsbelarus
gsbelarus / gist:ab08e7af3b072d2c16bb793ef7820b3e
Last active December 29, 2017 12:59
find holes in id numeration
EXECUTE BLOCK
/* RETURNS(tbl VARCHAR(31), cnt INTEGER) */
AS
DECLARE VARIABLE rn VARCHAR(31);
DECLARE VARIABLE fn VARCHAR(31);
DECLARE VARIABLE id INTEGER;
DECLARE VARIABLE b INTEGER = 147000001;
DECLARE VARIABLE e INTEGER = 147000001;
DECLARE VARIABLE limit INTEGER;
DECLARE VARIABLE d INTEGER;
@gsbelarus
gsbelarus / Win1251_ToUTF8.vbs
Created May 5, 2016 14:49
Перекодировка WIN1251 в UTF-8 и замена служебных символов разметки XML
' перекодировка кириллицы в юникод
public function Win1251_ToUTF8(ByVal S)
dim Res, i, AscCode, Symb, b1, b2, utfc
Res = ""
for I = 1 to Len(S)
Symb = Mid(S, I, 1)
AscCode = Asc(Symb)
' кириллица кроме ё и Ё
if (AscCode >= 192) and (AscCode <= 255) then
Res = Res & "&#x0" & Hex(AscCode + &H410 - 192) & ";"