Skip to content

Instantly share code, notes, and snippets.

View lifeart's full-sized avatar
🐹
Working from home

Alex Kanunnikov lifeart

🐹
Working from home
View GitHub Profile
@lifeart
lifeart / test.ts
Created December 27, 2023 08:33
test-vm
// @ts-check
// https://codepen.io/lifeart/pen/abMzEZm?editors=0110
// https://github.com/glimmerjs/glimmer-vm/issues/1540
/*
This is a proof of concept for a new approach to reactive programming.
It's related to Glimmer-VM's `@tracked` system, but without invalidation step.
We explicitly update DOM only when it's needed and only if tags are changed.
*/
let rowId = 1;
@lifeart
lifeart / index.js
Created November 2, 2023 11:38
resolve item selector on page with list of items
var classes = {};
var cnt = 1;
function hashForClass(rawClassName) {
const className = rawClassName.trim();
if (className in classes) {
classes[className].cnt++;
return classes[className].index;
} else {
classes[className] = {
@lifeart
lifeart / index.ts
Last active October 16, 2023 13:36
Lazy Services
class Bar {
doSomething() {
console.log('do something');
}
name: string;
}
type PromisifyProps<T> = {
[P in keyof T]: T[P] extends (...args: infer A) => infer R ? (...args: A) => Promise<R> : Promise<T[P]>;
};
@lifeart
lifeart / index.ts
Created August 8, 2023 12:28
Squares calculator
type Square = {
x: number;
width: number;
}
const squares: Square[] = [
{
x: 0,
width: 10,
},
{
@lifeart
lifeart / oauth2.ts
Last active July 21, 2023 19:02
React Oauth 2.0
// inspired by https://github.com/simplabs/ember-simple-auth/blob/master/packages/ember-simple-auth/addon/authenticators/oauth2-password-grant.js
import { LOGOUT_503_MESSAGE } from '@auth/messages';
/*
Idea is to have Authentication hub (HUB)
HUB could have multiple providers, our own provider is oauth2.0
Provider responsible for:
@lifeart
lifeart / index.js
Created July 5, 2023 08:24
QOI - The "Quite OK Image" format for fast, lossless image compression
// https://raw.githubusercontent.com/phoboslab/qoi/master/qoi.h
class QoiRGBA {
constructor(r = 0, g = 0, b = 0, a = 255) {
this.r = r;
this.g = g;
this.b = b;
this.a = a;
}
}
@lifeart
lifeart / basic.js
Last active June 29, 2023 10:08
Typescript custom diagnostics
const ts = require('typescript');
const fs = require('fs');
const path = require('path');
function getFileInfo(file, start) {
const { fileName } = file;
const { line, character } = file.getLineAndCharacterOfPosition(start);
return { fileName, line: line + 1, character: character + 1 };
}
@lifeart
lifeart / Polygon.ts
Last active April 28, 2023 14:38
Superannotate types
type JsonData = {
meta: Meta;
parameters: Parameter[];
}[];
interface Meta {
type: string; // The dictionary is a Polygon.
classId: number; // Class ID (one of the class IDs in “classes.json”). If the instance has an undefined class, the value should be -1 (classId": -1)
className?: string; // Class name. If the instance has an undefined class, the key should not be in the JSON.
createdBy?: User; // Information about the user who created the Polygon.
@lifeart
lifeart / index.js
Created March 16, 2023 08:27
Playwright using current browser
// ref https://twitter.com/underoot/status/1633430089802084352?s=52&t=0yc3BUdFiWnN-uQfrkt3xw
(async () = {
const port = 12345; // N port
const browser = await chromium. connectOverCDP(`http://localhost:${port}`);
const defaultContext = browser. contexts()[0];
const page await defaultContext.newPage();
// Do something with page
});
@lifeart
lifeart / readme.md
Last active November 22, 2022 11:11
material ui @mui imports transforment

To run:

npx jscodeshift ./src -t ./shifter.ts --extensions=tsx --parser=tsx -p

Not covered cases:

import capitalize from '@mui/utils/capitalize’;