Skip to content

Instantly share code, notes, and snippets.

@ajitid
ajitid / readme.md
Last active September 13, 2021 20:23
React + MobX useObservables

This hook is probably illegal to use. There is a reason why something like this doesn't ship with mobx-react-lite. (See something similar)

Usage

const somestate = useObservables(() =>
  store.getSomeState()
)

const [statex, statey] = useObservables(() => [store.statex, statey])
@ajitid
ajitid / App.js
Last active March 2, 2024 10:20
Okay-ish way get title and favicon on the browser
import { useState } from "react";
import ky from "ky";
import cheerio from "cheerio";
function App() {
const [url, setUrl] = useState("");
const [title, setTitle] = useState("");
const [faviconUrl, setFaviconUrl] = useState("");
const handleSubmit = async () => {
@ajitid
ajitid / merge-references.ts
Last active August 21, 2021 05:21
Merge references
import type { MutableRefObject } from 'react';
type References<T extends HTMLElement = HTMLElement> =
| MutableRefObject<unknown>
| ((element: T | null) => void)
| undefined
| null;
/**
* Utility function that let's you assign multiple references to a 'ref' prop
@ajitid
ajitid / Tabs.tsx
Created August 10, 2021 10:57
Tabs component by cloning children
import React, { useState, useMemo } from 'react'
import css from './tabs.module.scss'
/*
usage
<Tabs>
<Tab label="one">
<OneContent />
@ajitid
ajitid / pewpew.js
Last active August 3, 2021 21:28
🔫 pewpew — a quick and cheap fuzzy matcher
function pewpew(text, query) {
const textLen = text.length
const queryLen = query.length
if (queryLen > textLen) return false;
if(queryLen === textLen) return query === text
let textIdx = 0;
let queryIdx = 0;
@ajitid
ajitid / s.fish
Created July 25, 2021 15:06
automate vim using neovim-remote
function jqdoprocessoneach
# https://stackoverflow.com/a/965106/7683365
set -l old_file_path $argv[1]
set -l new_filename $argv[2]"."(echo $argv[1] | sed 's/.*\.//')
echo $old_file_path
# echo $new_filename
# sleep 1
nvr --remote-send '<cmd>e '$old_file_path'<cr>'
sleep 1
@ajitid
ajitid / parseMdLinks.ts
Last active September 1, 2021 04:39
Parse Markdown links (not safe as its usage might create XSS attack vector)
@ajitid
ajitid / butt.fish
Last active July 29, 2021 14:24
🍑 Butt - Target a dir in PWD
function butt
if [ "$argv[1]" = "" ]
echo "Please provide a dir name"
return 1
end
set -l up_times 0
set -l found 0
set -l path (string sub --start 2 $PWD)
@ajitid
ajitid / readme.md
Last active September 26, 2024 08:59
Collection

A collection of interesting and useful things

Other repositories I've created

  • An extension to invoke Sublime Merge commands in VS Code
  • Goparsify - A parser cominator library that lets you parse text and give meaning to the items in it
  • Lastly - Get song link for various music streaming platforms using Last.fm
  • Live server on Python
  • My dotfiles
@ajitid
ajitid / Default.sublime-commands
Last active June 15, 2022 02:34
Get notification on Git push when using Windows CLIs/Sublime Merge/Fork
[
{
"caption": "Create an Empty Commit...",
"command": "git",
"args": { "argv": ["commit", "--allow-empty", "-m", "$text"] }
},
{
"caption": "Delete Remote Tag (origin)...",
"command": "git",
"args": { "argv": ["push", "--delete", "origin", "$text"] }