Skip to content

Instantly share code, notes, and snippets.

View iamandrewluca's full-sized avatar
🚨
Git Inspector!

Andrei Luca iamandrewluca

🚨
Git Inspector!
View GitHub Profile
@iamandrewluca
iamandrewluca / useStartTransition.tsx
Last active December 6, 2024 19:39
React startTransition wrapper
"use client";
import { startTransition, type TransitionFunction } from "react";
function useStartTransition<Args extends unknown[]>(
cb: (...args: Args) => ReturnType<TransitionFunction>,
) {
return (...args: Args) => startTransition(() => cb(...args));
}
  • npm init
  • git ignore
  • ni ts
  • add tsconfig.json, tsconfig.1.json, tsconfig2.json (+ schema)
  • add file.ts, file1.ts, file2.ts with params example
  • run from terminal, show IDE
  • add TS Config no property index
  • run from terminal, show IDE
  • Fix
  • run from terminal, show IDE
@iamandrewluca
iamandrewluca / tsconfig.json
Last active November 21, 2024 18:39
Strict tsconfig.json
{
"compilerOptions": {
"strict": true,
"noEmitOnError": false,
"useUnknownInCatchVariables": false,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"exactOptionalPropertyTypes": true,
@iamandrewluca
iamandrewluca / portal-provider.ts
Created November 19, 2024 11:49
Vue Portal Provider that nests/recurse
import {
inject,
provide,
type InjectionKey,
type SlotsType,
type ComputedRef,
computed,
toRef,
defineComponent,
} from 'vue';
@iamandrewluca
iamandrewluca / App.vue
Last active October 23, 2024 08:22
Vue Local Scope
<script setup>
import LocalScope from './LocalScope.vue'
</script>
<template>
<LocalScope item-classes="rounded p-3 bg-blue-500" #default="{ itemClasses }">
<div :class="itemClasses">
No Data
</div>
let key = document.querySelector(`[data-testid="issue.views.issue-base.foundation.breadcrumbs.current-issue.item"]`).textContent;
let title = document.querySelector(`[data-testid="issue.views.issue-base.foundation.summary.heading"]`).textContent;
let link = document.querySelector(`[data-testid="issue.views.issue-base.foundation.breadcrumbs.current-issue.item"]`).href;
let date = new Date().toLocaleDateString('it-IT');
let textMessage = `🔵 [${key}] - ${title} - ${date}`;
let htmlMessage = `🔵 [<a href="${link}">${key}</a>] - ${title} - ${date}`;
let textBlob = new Blob([textMessage], { type: 'text/plain' });
let htmlBlob = new Blob([htmlMessage], { type: 'text/html' });
let clipboardItem = new ClipboardItem({ [textBlob.type]: textBlob, [htmlBlob.type]: htmlBlob });
globalThis.navigator.clipboard.write([clipboardItem]);
const cacheControlDirective = new GraphQLDirective({
name: 'cacheControl',
locations: [
DirectiveLocation.FIELD_DEFINITION,
DirectiveLocation.OBJECT,
DirectiveLocation.INTERFACE,
DirectiveLocation.UNION,
],
args: {
maxAge: {
@iamandrewluca
iamandrewluca / remove-twitter.md
Created February 12, 2024 20:01
Remove Twitter

Get rid of all content from Twitter

How to use "Remove Tweets"

  1. Sign in to Twitter
  2. Go to your Profile
  3. Open DevTools and go to the 'Console' tab
  4. Copy and paste the following script
@iamandrewluca
iamandrewluca / YouTube-Watch-Later-Time.js
Created January 11, 2024 10:50
YouTube Watch Later Time
$$('ytd-playlist-video-renderer .style-scope ytd-thumbnail-overlay-time-status-renderer')
.map(e => e.textContent.trim().split(':').reverse())
.map(([s = '0', m = '0', h = '0']) => ({ s: parseInt(s), m: parseInt(m), h: parseInt(h) }))
.map(({ s, m, h }) => s + m * 60 + h * 3600)
.reduce((a, b) => a + b) / 3600
$$('.runtimeLabel')
.map(e => e.textContent.trim().replace('Length: ',''))
.map(text => {
const hasHours = text.includes('and')
const [hText, mText] = hasHours
? text.split(' and ')
: ['0 hrs', text]
const h = Number.parseInt(hText)
const m = Number.parseInt(mText)
return h * 60 + m