Skip to content

Instantly share code, notes, and snippets.

View antfu's full-sized avatar

Anthony Fu antfu

View GitHub Profile
@antfu
antfu / run.ts
Created January 12, 2023 19:51
Remove members with no team from GitHub's org
import 'dotenv/config'
import { Octokit } from '@octokit/core'
const org = process.env.SPONSORS_ORG!
const token = process.env.SPONSORS_TOKEN!
const octokit = new Octokit({ auth: token })
const allMembers = await fetchMembers(org)
const membersWithoutTeam = new Set(allMembers.map(m => m.login))
@antfu
antfu / doc-table.md
Last active October 14, 2023 20:09
Doc Table in Markdown

Example

Name

Description


// port form https://github.com/bermi/element-xpath
// Create a safe reference to the getElementXpath object for use below.
const getElementXpath = function (el, callback) {
var err, result, nodes, i, n, segments, siblings, id_count;
try {
if (callback && (typeof callback !== "function")) {
throw new Error("Invalid callback supplied");
}
type Proxy = any[]
type Pop<T> = T extends [infer A, ...infer B] ? B : never
type Push<T> = T extends [...infer B] ? [any, ...B] : never
type Add<T extends Proxy, V extends Proxy> = [...T, ...V]
type Double<T extends Proxy> = [...T, ...T]
type Get<A extends Proxy> = A['length']
type AddOne<A extends Proxy> = Push<A>
type SubOne<A extends Proxy> = Pop<A>
import { UnionToIntersection } from 'utility-types';
type String<T> = T extends string ? T : any
type Keys<T, Field extends keyof T> =
T extends { [P in Field]: infer A }
? { [P in String<A>]: T }
: never
type LookupTable<Union, key extends keyof Union> = UnionToIntersection<Keys<Union, key>>
type Unexact<T> =
T extends null
? null
: T extends undefined
? undefined
: T extends number
? number
: T extends boolean
? boolean
: T extends string
type GetComponentProps<T> = T extends React.ComponentType<infer P>
? P
: T extends (props: any) => any
? Parameters<T>
: never;
class ClassComponent extends React.Component<{ a: number }> {
render() {
return <div />;
@antfu
antfu / git.sh
Created July 16, 2020 03:03
Git remove files from all history
git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch example.js'
@antfu
antfu / html2pdf.js
Created May 5, 2020 18:06
HTML to PDF
import puppeteer from 'puppeteer'
import fs from 'fs'
async function buildPDF(htmlString) {
const browser = await puppeteer.launch({ headless: true })
const page = await browser.newPage();
await page.setContent(htmlString, { waitUntil: 'networkidle0' })
const pdf = await page.pdf({
format: 'A4',
displayHeaderFooter: false,
@antfu
antfu / resume.json
Last active September 14, 2024 20:56
{
"basics": {
"name": "Anthony Fu",
"picture": "https://antfu.me/avatar.png",
"label": "Software Engineer",
"headline": "A ship in harbor is safe, but that is not what ships are built for.",
"summary": "My name is Anthony Fu, a master of computer science student and a freelance software engineer. My passion for software lies with dreaming up ideas and making them come true with elegant interfaces. I take great care in the experience, architecture, and code quality of the things I build.\n\nI am also an open-source enthusiast and maintainer. I love how collaboration and knowledge sharing happens through open-source and I am happy to see what I do could eventually feedback to the community and industry.",
"website": "https://antfu.me",
"address": "",
"projects_url": "https://antfu.me/projects",