Skip to content

Instantly share code, notes, and snippets.

View michael-land's full-sized avatar
👨‍💻
Building awesome tools

Michael Li michael-land

👨‍💻
Building awesome tools
View GitHub Profile
@danharper
danharper / background.js
Last active June 29, 2024 19:32
Bare minimum Chrome extension to inject a JS file into the given page when you click on the browser action icon. The script then inserts a new div into the DOM.
// this is the background code...
// listen for our browerAction to be clicked
chrome.browserAction.onClicked.addListener(function (tab) {
// for the current tab, inject the "inject.js" file & execute it
chrome.tabs.executeScript(tab.ib, {
file: 'inject.js'
});
});
@gunjanpatel
gunjanpatel / revert-a-commit.md
Last active July 25, 2024 19:20
Git HowTo: revert a commit already pushed to a remote repository

Revert the full commit

Sometimes you may want to undo a whole commit with all changes. Instead of going through all the changes manually, you can simply tell git to revert a commit, which does not even have to be the last one. Reverting a commit means to create a new commit that undoes all changes that were made in the bad commit. Just like above, the bad commit remains there, but it no longer affects the the current master and any future commits on top of it.

git revert {commit_id}

About History Rewriting

Delete the last commit

Deleting the last commit is the easiest case. Let's say we have a remote origin with branch master that currently points to commit dd61ab32. We want to remove the top commit. Translated to git terminology, we want to force the master branch of the origin remote repository to the parent of dd61ab32:

@swyxio
swyxio / react-router-state-manager.jsx
Last active July 26, 2022 10:43
Sync your state to your query params for copy-pastable state-in-URLs. React Router, Gatsby, and Svelte versions
// note - this was my rough working prototype, but still left some artifacts in the query params.
// todo: also need to debounce the history pushes
// see comments for production Gatsby and Svelte versions which delete nondefault keys in the query params
import React from 'react'
import queryString from "query-string"
export const connectRouterState = defaultURLState => Component => props => {
const { history, location } = props
// note: do not nest objects in URL state
@aparajita
aparajita / upgrade-node.sh
Last active May 27, 2023 21:32
Shell script to install the latest Node version using fnm, pnpm and jq
#!/bin/bash
localVersion=$(fnm ls | sort | tail -1 | perl -ne 'if (/.*(v\d+\.\d+\.\d+)/) { print "$1" }')
remoteVersion=$(fnm ls-remote | grep -E '.*v\d+\.\d+\.\d+' | tail -n 1 | perl -ne 'if (/^.*(v\d+\.\d+\.\d+)/) { print "$1" }')
if [[ "$remoteVersion" != "$localVersion" ]]; then
read -r -n 1 -p "Version $remoteVersion is available. Install it? [Y/n] " shouldInstall
echo
case "$shouldInstall" in
@gragland
gragland / use-optimistic-mutation-example.ts
Last active July 1, 2024 07:39
useOptimisticMutation for React Query. Optimistically update data in multiple locations with rollback on error.
import axios from 'axios'
import { useOptimisticMutation } from "./useOptimisticMutation.ts"
type Response = boolean
type Error = unknown
type MutationVariables = {itemId: string}
type Items = {id: string; name: string}[]
type Likes = {itemId: string}[]
type History = {type: string}[]