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 / 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’;
@lifeart
lifeart / instrument-test-build.js
Created November 21, 2022 10:53
Instrument vite build using nyc
// @ts-check
const fs = require('fs');
const path = require('path');
const os = require('os');
var { spawn } = require('child_process');
const systemCpuCores = os.cpus();
const pathToArtifacts = path.join(__dirname, '..', 'build', 'assets');
const processes = systemCpuCores.length > 1 ? systemCpuCores.length - 1 : 1;
@lifeart
lifeart / index.js
Created February 7, 2022 14:13
v2 addon migrator
import path from 'path';
import os from 'os';
import fs from 'fs-extra';
// https://github.com/embroider-build/embroider/blob/main/PORTING-ADDONS-TO-V2.md
async function migrate(entry) {
const { default: walkSync } = await import('walk-sync');
const files = () => walkSync(entry, {
ignore: [
'.git',
// A launch configuration that compiles the extension and then opens it inside a new window
{
"version": "0.1.0",
"configurations": [
{
"name": "Attach by Process ID",
"processId": "${command:PickProcess}",
"request": "attach",
"resolveSourceMapLocations": null,
"sourceMaps": true,
import Controller from '@ember/controller';
import { htmlSafe } from '@ember/template';
export default class ApplicationController extends Controller {
appName = htmlSafe('Ember <br> Twiddle');
}
@lifeart
lifeart / index.js
Created December 2, 2021 10:46
Ember-auto-import chunk recorder (in-repo-addon)
'use strict';
// eslint-disable-next-line node/no-extraneous-require
const { MergeTrees } = require('broccoli-merge-trees');
// eslint-disable-next-line node/no-extraneous-require
const Plugin = require('broccoli-plugin');
const fs = require('fs');
const path = require('path');
class ChunksWriter extends Plugin {