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 / correctuse-example-1.js
Last active September 30, 2023 06:47
Snippet for Avoiding the async/await hell medium article
async function selectPizza() {
const pizzaData = await getPizzaData() // async call
const chosenPizza = choosePizza() // sync call
await addPizzaToCart(chosenPizza) // async call
}
async function selectDrink() {
const drinkData = await getDrinkData() // async call
const chosenDrink = chooseDrink() // sync call
await addDrinkToCart(chosenDrink) // async call
@itaditya
itaditya / youtube-120x-volume.js
Last active December 29, 2022 20:50
Increase volume above 100% on youtube and other sites.
var videoElem = document.querySelector('video');
var audioCtx = new AudioContext();
var source = audioCtx.createMediaElementSource(videoElem);
var gainNode = audioCtx.createGain();
gainNode.gain.value = 5;
source.connect(gainNode);
gainNode.connect(audioCtx.destination);
@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',
}),
);
}
package main
import "fmt"
type person struct {
name string
age int
}
func (p person) print() {