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 / 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 / demo.js
Last active August 20, 2022 06:27
Reasons
class Foo {
constructor () {
if (this.hasQuestion) {
alert(42);
}
}
}
@lifeart
lifeart / example.js
Created July 14, 2021 14:22
glimmer inline components
import SecondComponent from 'foo/bar';
function MyComponent(args) { return { a: 1, b: 2, c: args.e } }
function hasHelperManagerFor() {
return true;
}
function hasComponentManagerFor() {
@lifeart
lifeart / ability.ts
Last active August 4, 2022 12:36
Simple Roles Management
import { get } from 'lodash';
const permissions = {
study: {
see: ['STUDY_MANAGER', 'DATA_ENTRY', 'ADMIN'],
create: ['DATA_ENTRY', 'ADMIN'],
edit: ['STUDY_DIRECTOR', 'DATA_ENTRY', 'ADMIN'],
}
}
@lifeart
lifeart / Lazy.ts
Last active July 24, 2022 11:39
Lazy glimmer 2 components
import { createTemplate, setComponentTemplate, templateOnlyComponent } from '@glimmer/core';
export default setComponentTemplate(
createTemplate(`<h1 ...attributes>AMA LAZY [{{@name}}]</h1>`),
templateOnlyComponent()
);
@lifeart
lifeart / index.js
Last active March 27, 2022 13:52
generic ember render tree capture
let EmberCore;
try {
EmberCore = requireModule('ember')['default'];
} catch {
EmberCore = window.Ember;
}
const keys = ['application','engine'];
//const isEmberApp = (el) => el._debugContainerKey && keys.includes(el._debugContainerKey.split(':')[0]);
@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,
@lifeart
lifeart / ember-cli-build.js
Last active January 28, 2022 18:57
Minimal Ember 3.28 app with runtime-defined components
'use strict';
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
module.exports = function (defaults) {
let app = new EmberApp(defaults, {});
// we need to add emebr-template-compiler into runtime
app.import('node_modules/ember-source/dist/ember-template-compiler.js');