Skip to content

Instantly share code, notes, and snippets.

View itaditya's full-sized avatar
🎯
Focusing

Aditya Agarwal itaditya

🎯
Focusing
View GitHub Profile
@itaditya
itaditya / search.txt
Created November 2, 2023 11:55
VS Code regex search by component prop
<Button .+ appearance.+>
@itaditya
itaditya / get-authors.ts
Last active November 2, 2023 09:27
get authors in a file from git
async function getAuthors(
filePath: string,
startLine: number,
endLine: number,
): Promise<{ author: string; email: string; commitTime: string }[]> {
const { stdout } = await execAsync(
`git log -s --max-count 10 --author-date-order --pretty='format: { "author": "%an", "email": "%aE", "committedAt":"%aI" }' -L ${startLine},${endLine}:${filePath}`,
);
const authors = stdout.split('\n').map((line) => {
@itaditya
itaditya / clear-notifications.applescript
Created September 14, 2022 11:12
Raycast Script to clear all MacOS Notifications
#!/usr/bin/osascript -l JavaScript
// Required parameters:
// @raycast.schemaVersion 1
// @raycast.title Clear Notifications
// @raycast.mode silent
// Optional parameters:
// @raycast.icon 🤖
@itaditya
itaditya / slot-example.jsx
Last active March 25, 2022 19:08
Use JSX pragma for declarative config like Compound Components
/** @jsx slot */
const selectConfig = (
<group title="Members" element={<MemberGroup />}>
<option>
First Option
</option>
<divider />
{members.map((member) => (
<option element={<SuggestionOption member={member} />}>
@itaditya
itaditya / createMatchBreakpointsExample.tsx
Created March 17, 2022 10:43
Mobile-first match breakpoints
import { render } from "solid-js/web";
import { createSignal, createEffect, createMemo, onCleanup, Show, Switch, Match } from "solid-js";
interface ArrayLike<T> {
readonly length: number;
readonly [n: number]: T;
}
function objectEntries<T>(o: { [s: string]: T } | ArrayLike<T>): [string, T][] {
return Object.entries(o);
@itaditya
itaditya / auth-storage.spec.ts
Created March 5, 2022 06:46
Demo Auth Storage
import { test } from '@playwright/test';
test.describe('When user logged-out', () => {
test('Test login page @flow=auth', async ({ page, context }) => {
await page.goto('https://remix-jokes.lol/login');
await page.locator('input[name="username"]').fill('itaditya');
await page.locator('input[name="password"]').fill('random');
await Promise.all([page.waitForNavigation(), page.locator('text=Submit').click()]);
@itaditya
itaditya / rtl-stale-mistake.test.js
Created February 14, 2022 16:22
Show that re-querying DOM nodes is necessary in React Testing Library based tests.
import React, { useState } from 'react';
import { fireEvent, render, screen } from '@testing-library/react';
function clickIncrement() {
fireEvent.click(
screen.getByRole('button', {
name: 'Increment',
}),
);
}
@itaditya
itaditya / getOs.js
Created October 5, 2021 13:53
Find if OS is mac or not.
function getOs() {
const MOD = /Mac|iPod|iPhone|iPad/.test(navigator.platform) ? 'mac' : 'win';
}
@itaditya
itaditya / requirement.js
Created August 30, 2021 12:06
Vite glob imports to React Router config
import convertToRoutes from 'your-awesome-oss-pkg';
const modules = {
'index.js': IndexComp,
'about.js': AboutComp,
'team.js': TeamComp,
'team/index.js': TeamIndexComp,
'team/join.js': TeamJoinComp,
'team/$username.js': TeamMemberComp,
};
@itaditya
itaditya / notes.md
Created August 30, 2021 11:46
Remix Router understanding

Remix treats nested routes files differently. Its not simply a flat list of routes. Take this example-

routes
  team
    index.js
    $username.js
  team.js