Skip to content

Instantly share code, notes, and snippets.

View rsaryev's full-sized avatar

Saryev Rustam rsaryev

View GitHub Profile
@rsaryev
rsaryev / prisma-utils.ts
Last active May 28, 2024 11:27
Prisma analogue migrate rest command only programmatically, for testing purposes.
import { Prisma, PrismaClient } from '@prisma/client';
import { exec } from 'child_process';
import * as util from 'util';
const execPromisify = util.promisify(exec);
const prisma = new PrismaClient();
const tables = Prisma.dmmf.datamodel.models
.map((model) => model.dbName)
.filter((table) => table);
WITH RECURSIVE tree AS (SELECT *, id AS root_category
FROM categories
WHERE parentId IS NULL
UNION ALL
SELECT c.*, p.root_category
FROM categories c
JOIN tree p
ON c.parentId = p.id)
SELECT *
FROM tree
function test(strings, name, age) {
const str0 = strings[0];
const str1 = strings[1];
return `${str0}${name}${str1}${age}`;
}
const name = 'Rustam';
const age = 25;
console.log(test`My name is ${name} my age is ${age}`);
@rsaryev
rsaryev / topWords.js
Last active April 20, 2023 10:50
use Intl.Segmenter
function topWords(text, count = 3, lang = 'en') {
const wordMap = new Map();
const segmenter = new Intl.Segmenter(lang, { granularity: 'word' });
for (let { segment, index, isWordLike } of segmenter.segment(text)) {
if (!isWordLike) continue;
const word = segment;
wordMap.set(word, (wordMap.get(word) || 0) + 1);
}
return Array.from(wordMap)
.sort(([, countA], [, countB]) => countB - countA)
@rsaryev
rsaryev / index.js
Created April 27, 2023 20:00
This example is a simple implementation of a wrapper the Node.js http server.
const http = require('http')
const {parse} = require('url')
/**
* This example is a simple implementation of a wrapper the Node.js http server.
*/
class Router {
#routes
@rsaryev
rsaryev / similar_professions.ipynb
Last active August 15, 2023 22:36
similar professions based on a vector embeddings model
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rsaryev
rsaryev / multiply.js
Created December 14, 2023 23:26
Multiply list by integer (with restrictions
const multiply = (n, l) => l.map(a => Math.round(a / (1 / n)));