Skip to content

Instantly share code, notes, and snippets.

View wojtekmaj's full-sized avatar

Wojciech Maj wojtekmaj

View GitHub Profile
@wojtekmaj
wojtekmaj / test.sh
Created April 29, 2024 07:29
React 19 compatibility quick test
git switch -c react-19
yarn up react@beta react-dom@beta
npm pkg set resolutions.'@types/react'='npm:types-react@beta'
npm pkg set resolutions.'@types/react-dom'='npm:types-react-dom@beta'
yarn
yarn tsc
yarn unit
@wojtekmaj
wojtekmaj / use.ts
Last active February 26, 2024 08:34
use() hook you can use in React 18 (stable) today
/// <reference types="react/next" />
import { use as originalUse, useContext } from 'react';
const STATUS = {
PENDING: 'pending',
REJECTED: 'rejected',
FULFILLED: 'fulfilled',
} as const;
type TState<T> =
@wojtekmaj
wojtekmaj / index.ts
Last active October 23, 2023 06:25
GitHub monthly issues stats
import fs from 'node:fs';
import { asyncForEach, asyncForEachStrict } from '@wojtekmaj/async-array-utils';
import chalk from 'chalk';
import { endOfMonth, formatISO, startOfMonth } from 'date-fns';
const CACHE_DIR = '.cache';
const GITHUB_API_URL = 'https://api.github.com';
const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
const DEBUG = process.env.DEBUG === 'true';
@wojtekmaj
wojtekmaj / foreach.sh
Created June 6, 2023 09:04
Run a given script for each Git repository in the given directory
# Sample usage: bash ./foreach.sh ./update-dependencies.sh
script_dir=$(dirname -- "$( readlink -f -- "$0"; )")
echo "Running script $1 for each repository"
# Find all Git repositories, skipping node_modules directories
find . -maxdepth 4 -name ".git" -print0 | while read -d $'\0' repo; do
echo "Processing ${repo%/.git}"
@wojtekmaj
wojtekmaj / add-missing-import-extensions.txt
Last active April 30, 2024 15:08
Visual Studio Code-compatible regular expression to add all missing import extensions
# Find
import\s(([^;]|\n)*)\sfrom\s(['"])(\.{1,2}\/.*)(?<!\.js)(?<!\.(css|pdf|png|jpg|jsx|mjs|mp3|mp4|svg|ttf))(?<!\.(avif|json|webm|webp|woff))(?<!\.woff2)(['"]);
# Replace with
import $1 from $3$4.js$7;
@wojtekmaj
wojtekmaj / jest-to-vitest.sh
Last active April 26, 2024 14:08
Automatically migrate Jest project to Vitest
#!/bin/bash
# Ensure we're working on the latest version of the main branch
git switch main
git fetch
git pull
# Create a new branch
git switch -c vitest
@wojtekmaj
wojtekmaj / webpack-to-vite.sh
Created March 2, 2023 10:53
Automatically migrate Webpack project to Vite
#!/bin/bash
# Ensure we're working on the latest version of the main branch
git switch main
git fetch
git pull
# Create a new branch
git switch -c vite
@wojtekmaj
wojtekmaj / update-dependencies.sh
Created January 5, 2023 00:05
Update all your dependencies in /, /sample, /sample/*, /test directories
#!/bin/bash
# Define function
update_dependencies() {
rm -rf yarn.lock
touch yarn.lock
yarn
yarn dedupe
}
@wojtekmaj
wojtekmaj / update-year-in-licence.sh
Created January 4, 2023 23:58
Find all Git repositories recursively and update year in LICENSE if commit was made in current year
#!/bin/bash
current_year=$(date +%Y)
# Find all Git repositories, skipping node_modules directories
find . -type d -name .git -not -path '*/node_modules/*' -print0 | while read -d $'\0' repo; do
# Go to the repository directory
cd "${repo%/.git}"
# Check the year of the last commit
@wojtekmaj
wojtekmaj / feature-detection.js
Last active October 25, 2022 17:33
Image format feature detection
const isSafari = // ...
function getIsSupported(src) {
return new Promise((resolve) => {
const image = new Image();
image.onload = () => {
const isSupported = image.width > 0 && image.height > 0;
resolve(isSupported);
};